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.HPKE.Interface.DH.fst | Hacl.HPKE.Interface.DH.dh_p256 | val dh_p256:dh_st (DH.DH_P256) True | val dh_p256:dh_st (DH.DH_P256) True | let dh_p256 : dh_st (DH.DH_P256) True = fun o k i ->
push_frame();
let tmp = create (size 64) (u8 0) in
(**) let h0 = HyperStack.ST.get() in
(**) nat_from_bytes_le_zero_is_zero 32 (as_seq h0 (gsub tmp (size 0) (size 32)));
(**) nat_from_bytes_le_zero_is_zero 32 (as_seq h0 (gsub tmp (size 32) (size 32)));
let res = Hacl.Impl.P256.DH.ecp256dh_r tmp i k in
copy o tmp;
pop_frame();
(* change_error_code res *)
if res then 0ul else 1ul | {
"file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 138,
"start_col": 0,
"start_line": 128
} | module Hacl.HPKE.Interface.DH
open FStar.HyperStack
open FStar.HyperStack.All
module HST = FStar.HyperStack.ST
open Lib.Buffer
open Lib.IntTypes
open Lib.ByteBuffer
module DH = Spec.Agile.DH
module S = Spec.Agile.HPKE
#reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
unfold noextract
let nsize_key (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 32ul
unfold noextract
let nsize_public (a:DH.algorithm) =
match a with
| DH.DH_Curve25519 -> 32ul
| DH.DH_P256 -> 64ul
inline_for_extraction noextract
let dh_st (a:DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> k:lbuffer uint8 (nsize_key a)
-> i:lbuffer uint8 (nsize_public a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 k /\ live h0 i /\
disjoint o i /\ disjoint o k)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (
let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded
| 1ul -> None? output
| _ -> False))
inline_for_extraction noextract
let secret_to_public_st (a: DH.algorithm) (p:Type0) =
o:lbuffer uint8 (nsize_public a)
-> i:lbuffer uint8 (nsize_key a)
-> Stack UInt32.t
(requires fun h0 ->
p /\
live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\
(let output = DH.secret_to_public a (as_seq h0 i) in
match result with
| 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output
| 1ul -> None? output
| _ -> False))
[@ Meta.Attribute.specialize]
noextract
assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True
[@ Meta.Attribute.specialize]
noextract
assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True
(** Instantiations for Curve25519 **)
inline_for_extraction noextract
let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i ->
Hacl.Curve25519_51.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_51.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res
inline_for_extraction noextract
let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled)
inline_for_extraction noextract
let secret_to_public_c64 : secret_to_public_st (DH.DH_Curve25519) vale_p = fun o i ->
Hacl.Curve25519_64.secret_to_public o i;
0ul
inline_for_extraction noextract
let dh_c64 : dh_st (DH.DH_Curve25519) vale_p = fun o k i ->
push_frame();
let zeros = create 32ul (u8 0) in
Hacl.Curve25519_64.scalarmult o k i;
let res = if lbytes_eq o zeros then 1ul else 0ul in
pop_frame();
res
// TODO: After unification of error codes, this should be removed
inline_for_extraction noextract
let change_error_code (r:uint64) : Pure UInt32.t
(requires v r = 0 \/ v r = pow2 64 - 1)
(ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0))
= let r' = logand r (u64 1) in
logand_mask r (u64 1) 1;
let r' = cast U32 SEC r' in
Lib.RawIntTypes.u32_to_UInt32 r'
inline_for_extraction noextract
let secret_to_public_p256 : secret_to_public_st (DH.DH_P256) True = fun o i ->
let res = Hacl.Impl.P256.DH.ecp256dh_i o i in
if res then 0ul else 1ul
(* change_error_code res *)
let rec nat_from_bytes_le_zero_is_zero (n:size_nat{n >= 1}) (s:Lib.ByteSequence.lbytes n)
: Lemma (requires s `Seq.equal` Lib.Sequence.create n (u8 0))
(ensures Lib.ByteSequence.nat_from_bytes_le s == 0)
= let open Lib.Sequence in
let open Lib.ByteSequence in
if n = 1 then nat_from_intseq_le_lemma0 s
else (
nat_from_intseq_le_slice_lemma s 1;
nat_from_bytes_le_zero_is_zero (n-1) (slice s 1 n);
nat_from_intseq_le_lemma0 (slice s 0 1)
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Spec.Agile.HPKE.fsti.checked",
"Spec.Agile.DH.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.P256.DH.fsti.checked",
"Hacl.Curve25519_64.fsti.checked",
"Hacl.Curve25519_51.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.HPKE.Interface.DH.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE.Interface",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.HPKE.Interface.DH.dh_st Spec.Agile.DH.DH_P256 Prims.l_True | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Hacl.HPKE.Interface.DH.nsize_public",
"Spec.Agile.DH.DH_P256",
"Hacl.HPKE.Interface.DH.nsize_key",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"FStar.UInt32.t",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Lib.Buffer.copy",
"Lib.Buffer.MUT",
"Hacl.Impl.P256.DH.ecp256dh_r",
"Hacl.HPKE.Interface.DH.nat_from_bytes_le_zero_is_zero",
"Lib.Buffer.as_seq",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.size",
"Lib.Buffer.gsub",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"FStar.HyperStack.ST.push_frame"
] | [] | false | false | false | true | false | let dh_p256:dh_st (DH.DH_P256) True =
| fun o k i ->
push_frame ();
let tmp = create (size 64) (u8 0) in
let h0 = HyperStack.ST.get () in
nat_from_bytes_le_zero_is_zero 32 (as_seq h0 (gsub tmp (size 0) (size 32)));
nat_from_bytes_le_zero_is_zero 32 (as_seq h0 (gsub tmp (size 32) (size 32)));
let res = Hacl.Impl.P256.DH.ecp256dh_r tmp i k in
copy o tmp;
pop_frame ();
if res then 0ul else 1ul | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.mk_impl | val mk_impl (a: hash_alg) (m: m_spec a) : impl | val mk_impl (a: hash_alg) (m: m_spec a) : impl | let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|) | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 52,
"start_col": 0,
"start_line": 52
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.hash_alg -> m: Hacl.Hash.Definitions.m_spec a -> Hacl.Hash.Definitions.impl | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Hacl.Hash.Definitions.m_spec",
"Prims.Mkdtuple2",
"Hacl.Hash.Definitions.impl"
] | [] | false | false | false | false | false | let mk_impl (a: hash_alg) (m: m_spec a) : impl =
| (| a, m |) | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.get_alg | val get_alg (i: impl) : hash_alg | val get_alg (i: impl) : hash_alg | let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 56,
"start_col": 0,
"start_line": 55
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Hacl.Hash.Definitions.impl -> Spec.Hash.Definitions.hash_alg | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.impl",
"Spec.Hash.Definitions.hash_alg",
"Hacl.Hash.Definitions.m_spec"
] | [] | false | false | false | true | false | let get_alg (i: impl) : hash_alg =
| match i with | (| a , m |) -> a | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lemma_bit_xor_is_sum_mod2 | val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2) | val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2) | let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL) | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 98,
"start_col": 0,
"start_line": 85
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC -> b: Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC
-> FStar.Pervasives.Lemma (requires Lib.IntTypes.v a <= 1 /\ Lib.IntTypes.v b <= 1)
(ensures Lib.IntTypes.v (a ^. b) == (Lib.IntTypes.v a + Lib.IntTypes.v b) % 2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.UInt32.t",
"FStar.UInt32.logxor",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Lib.IntTypes.logxor_spec",
"FStar.UInt64.t",
"FStar.UInt64.logxor",
"FStar.UInt64.__uint_to_t"
] | [] | false | false | true | false | false | let lemma_bit_xor_is_sum_mod2 #a_t a b =
| match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL) | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.cswap2 | val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2))) | val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2))) | let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2) | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 78,
"start_col": 0,
"start_line": 75
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
bit: Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC {Lib.IntTypes.v bit <= 1} ->
p1: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len ->
p2: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThanOrEqual",
"Lib.Buffer.lbuffer",
"Hacl.Spec.Bignum.cswap2_lemma",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.unit",
"Hacl.Bignum.cswap2",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let cswap2 #a_t len ctx_len k bit p1 p2 =
| let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2) | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_pow2 | val lexp_pow2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h res /\ live h ctx /\ live h a /\
disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) | val lexp_pow2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h res /\ live h ctx /\ live h a /\
disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) | let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res) | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 166,
"start_col": 0,
"start_line": 148
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
ctx: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) ctx_len ->
a: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len ->
b: Lib.IntTypes.size_t ->
res: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.Loops.for",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__lsqr",
"Prims.unit",
"Lib.LoopCombinators.unfold_repeat",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.LoopCombinators.eq_repeat0",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.logical",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.as_seq",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.LoopCombinators.repeat",
"Lib.Exponentiation.Definition.sqr",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid",
"Prims.int",
"FStar.HyperStack.ST.get",
"Lib.Buffer.copy"
] | [] | false | true | false | false | false | let lexp_pow2 #a_t len ctx_len k ctx a b res =
| copy res a;
let h0 = ST.get () in
[@@ inline_let ]let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@@ inline_let ]let spec h0 = S.sqr k.to.comm_monoid in
[@@ inline_let ]let inv h (i: nat{i <= v b}) =
modifies (loc res) h0 h /\ k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0)
in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul
b
inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res) | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.bn_get_bits_c | val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l)) | val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l)) | let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 253,
"start_col": 0,
"start_line": 241
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bLen: Lib.IntTypes.size_t ->
bBits:
Lib.IntTypes.size_t{(Lib.IntTypes.v bBits - 1) / Lib.IntTypes.bits b_t < Lib.IntTypes.v bLen} ->
b: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t b_t Lib.IntTypes.SEC) bLen ->
l:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v l /\ Lib.IntTypes.v l < Lib.IntTypes.bits b_t /\
0 < Lib.IntTypes.v bBits % Lib.IntTypes.v l }
-> FStar.HyperStack.ST.Stack (Lib.IntTypes.uint_t b_t Lib.IntTypes.SEC) | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.bits",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Prims.op_Modulus",
"Hacl.Bignum.bn_get_bits",
"Hacl.Bignum.Definitions.limb",
"Prims.unit",
"Hacl.Spec.Bignum.bn_get_bits_lemma",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims._assert",
"FStar.Math.Lemmas.lemma_div_le",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Prims.int",
"FStar.Mul.op_Star",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Star_Bang",
"Lib.IntTypes.op_Slash_Dot",
"FStar.Math.Lemmas.euclidean_division_definition"
] | [] | false | true | false | false | false | let bn_get_bits_c #b_t bLen bBits b l =
| Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == (v bBits / v l) * v l);
let i = bBits /. l *! l in
assert (v i == (v bBits / v l) * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.bn_get_bits_l | val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i)) | val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i)) | let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 225,
"start_col": 0,
"start_line": 206
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bLen: Lib.IntTypes.size_t ->
bBits:
Lib.IntTypes.size_t{(Lib.IntTypes.v bBits - 1) / Lib.IntTypes.bits b_t < Lib.IntTypes.v bLen} ->
b: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t b_t Lib.IntTypes.SEC) bLen ->
l: Lib.IntTypes.size_t{0 < Lib.IntTypes.v l /\ Lib.IntTypes.v l < Lib.IntTypes.bits b_t} ->
i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v bBits / Lib.IntTypes.v l}
-> FStar.HyperStack.ST.Stack (Lib.IntTypes.uint_t b_t Lib.IntTypes.SEC) | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.bits",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Hacl.Bignum.bn_get_bits",
"Hacl.Bignum.Definitions.limb",
"Prims.unit",
"Hacl.Spec.Bignum.bn_get_bits_lemma",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims._assert",
"FStar.Math.Lemmas.lemma_div_le",
"Prims.eq2",
"Prims.int",
"FStar.Mul.op_Star",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Bang",
"Lib.IntTypes.op_Star_Bang",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Math.Lemmas.distributivity_add_right",
"FStar.Math.Lemmas.lemma_mult_le_left",
"Prims.op_Modulus",
"Lib.IntTypes.op_Percent_Dot",
"Prims.op_Equality",
"FStar.Math.Lemmas.euclidean_division_definition"
] | [] | false | true | false | false | false | let bn_get_bits_l #b_t bLen bBits b l i =
| Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@@ inline_let ]let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lprecomp_get_consttime | val lprecomp_get_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len ->
pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) | val lprecomp_get_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len ->
pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) | let lprecomp_get_consttime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_consttime #a_t len ctx_len k a table_len table bits_l tmp | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 505,
"start_col": 0,
"start_line": 504
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv
let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc
let mk_lexp_fw_table #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res =
assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul then
lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
//-------------------------------------
let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len
-> Hacl.Impl.Exponentiation.pow_a_to_small_b_st a_t
len
ctx_len
k
l
table_len
(Hacl.Impl.Exponentiation.table_inv_precomp len ctx_len k l table_len) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"FStar.Ghost.erased",
"Lib.Sequence.lseq",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.op_LessThan",
"Prims.pow2",
"Hacl.Impl.PrecompTable.lprecomp_get_consttime",
"Prims.unit"
] | [] | false | false | false | false | false | let lprecomp_get_consttime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
| PT.lprecomp_get_consttime #a_t len ctx_len k a table_len table bits_l tmp | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_fw_f_st | val lexp_fw_f_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc))) | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 350,
"start_col": 0,
"start_line": 318
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.CONST",
"Lib.Buffer.disjoint",
"Hacl.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.Buffer.as_seq",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.Exponentiation.exp_fw_f",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid"
] | [] | false | false | false | false | true | let lexp_fw_f_st
(a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(l: size_window_t a_t len)
(table_len: table_len_t len)
(table_inv: table_inv_t a_t len table_len)
=
|
ctx: lbuffer (uint_t a_t SEC) ctx_len ->
a: lbuffer (uint_t a_t SEC) len ->
bLen: size_t ->
bBits: size_t{(v bBits - 1) / bits a_t < v bLen} ->
b: lbuffer (uint_t a_t SEC) bLen ->
table: clbuffer (uint_t a_t SEC) (table_len *! len) ->
i: size_t{v i < v bBits / v l} ->
acc: lbuffer (uint_t a_t SEC) len ->
tmp: lbuffer (uint_t a_t SEC) len
-> Stack unit
(requires
fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\ live h tmp /\
disjoint tmp a /\ disjoint tmp b /\ disjoint tmp acc /\ disjoint tmp ctx /\
disjoint tmp table /\ disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\ BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures
fun h0 _ h1 ->
modifies (loc acc |+| loc tmp) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec
k.to.comm_monoid
(k.to.refl (as_seq h0 a))
(v bBits)
(BD.bn_v h0 b)
(v l)
(v i)
(k.to.refl (as_seq h0 acc))) | false |
|
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_fw_f | val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv | val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv | let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 116,
"end_line": 368,
"start_col": 0,
"start_line": 366
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len ->
pow_a_to_small_b:
Hacl.Impl.Exponentiation.pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv
-> Hacl.Impl.Exponentiation.lexp_fw_f_st a_t len ctx_len k l table_len table_inv | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Hacl.Impl.Exponentiation.pow_a_to_small_b_st",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Hacl.Impl.Exponentiation.lmul_acc_pow_a_bits_l",
"Prims.unit",
"Hacl.Impl.Exponentiation.lexp_pow2_in_place"
] | [] | false | false | false | false | false | let lexp_fw_f
#a_t
len
ctx_len
k
l
table_len
table_inv
pow_a_to_small_b
ctx
a
bLen
bBits
b
table
i
acc
tmp
=
| lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b
table i acc tmp | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_pow2_in_place | val lexp_pow2_in_place:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t ->
Stack unit
(requires fun h ->
live h a /\ live h ctx /\ disjoint a ctx /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\
k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) | val lexp_pow2_in_place:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t ->
Stack unit
(requires fun h ->
live h a /\ live h ctx /\ disjoint a ctx /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\
k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) | let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc) | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 186,
"start_col": 0,
"start_line": 169
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
ctx: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) ctx_len ->
a: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len ->
b: Lib.IntTypes.size_t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.Loops.for",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__lsqr",
"Prims.unit",
"Lib.LoopCombinators.unfold_repeat",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.LoopCombinators.eq_repeat0",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.logical",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.as_seq",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.LoopCombinators.repeat",
"Lib.Exponentiation.Definition.sqr",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid",
"Prims.int",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
| let h0 = ST.get () in
[@@ inline_let ]let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@@ inline_let ]let spec h0 = S.sqr k.to.comm_monoid in
[@@ inline_let ]let inv h (i: nat{i <= v b}) =
modifies (loc acc) h0 h /\ k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0)
in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul
b
inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc) | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.extra_state | val extra_state (a: hash_alg) : Type0 | val extra_state (a: hash_alg) : Type0 | let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 36,
"start_col": 0,
"start_line": 29
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.hash_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.PUB",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Lib.IntTypes.v",
"Spec.Hash.Definitions.block_length",
"Lib.IntTypes.U128",
"Prims.unit"
] | [] | false | false | false | true | true | let extra_state (a: hash_alg) : Type0 =
| match a with
| Blake2S -> s: uint_t U64 PUB {v s % block_length a = 0}
| Blake2B -> s: uint_t U128 PUB {v s % block_length a = 0}
| MD5
| SHA1
| SHA2_224
| SHA2_256
| SHA2_384
| SHA2_512
| SHA3_224
| SHA3_256
| SHA3_384
| SHA3_512
| Shake128
| Shake256 -> unit | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.alloca_st | val alloca_st : i: Hacl.Hash.Definitions.impl -> Type0 | let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1)) | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 213,
"start_col": 0,
"start_line": 205
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Hacl.Hash.Definitions.impl -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.impl",
"Prims.unit",
"Hacl.Hash.Definitions.state",
"FStar.Monotonic.HyperStack.mem",
"Prims.b2t",
"FStar.Monotonic.HyperStack.is_stack_region",
"FStar.Monotonic.HyperStack.get_tip",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.eq2",
"FStar.Monotonic.HyperHeap.rid",
"LowStar.Monotonic.Buffer.frameOf",
"Hacl.Hash.Definitions.impl_word",
"LowStar.Buffer.trivial_preorder",
"Spec.Hash.Definitions.words_state",
"Hacl.Hash.Definitions.get_alg",
"Hacl.Hash.Definitions.as_seq",
"Spec.Agile.Hash.init",
"LowStar.Monotonic.Buffer.live",
"LowStar.Monotonic.Buffer.fresh_loc",
"LowStar.Monotonic.Buffer.loc_buffer"
] | [] | false | false | false | true | true | let alloca_st (i: impl) =
| unit
-> ST.StackInline (state i)
(requires (fun h -> HS.is_stack_region (HS.get_tip h)))
(ensures
(fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\ B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\ B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1)) | false |
|
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lprecomp_get_vartime | val lprecomp_get_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len ->
pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) | val lprecomp_get_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len ->
pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) | let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 501,
"start_col": 0,
"start_line": 500
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv
let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc
let mk_lexp_fw_table #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res =
assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul then
lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
//------------------------------------- | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len
-> Hacl.Impl.Exponentiation.pow_a_to_small_b_st a_t
len
ctx_len
k
l
table_len
(Hacl.Impl.Exponentiation.table_inv_precomp len ctx_len k l table_len) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"FStar.Ghost.erased",
"Lib.Sequence.lseq",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.op_LessThan",
"Prims.pow2",
"Hacl.Impl.PrecompTable.lprecomp_get_vartime",
"Prims.unit"
] | [] | false | false | false | false | false | let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
| PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lmul_acc_pow_a_bits_l | val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv | val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv | let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame () | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 314,
"start_col": 0,
"start_line": 306
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len ->
pow_a_to_small_b:
Hacl.Impl.Exponentiation.pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv
-> Hacl.Impl.Exponentiation.lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Hacl.Impl.Exponentiation.pow_a_to_small_b_st",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__lmul",
"FStar.Ghost.hide",
"Lib.Sequence.lseq",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims._assert",
"Prims.pow2",
"Lib.IntTypes.int_t",
"Hacl.Impl.Exponentiation.bn_get_bits_l",
"FStar.HyperStack.ST.push_frame",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let lmul_acc_pow_a_bits_l
#a_t
len
ctx_len
k
l
table_len
table_inv
pow_a_to_small_b
ctx
a
bLen
bBits
b
table
i
acc
tmp
=
| let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame () | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.blocks_t | val blocks_t : a: Spec.Hash.Definitions.hash_alg -> Type0 | let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 } | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 198,
"start_col": 0,
"start_line": 197
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.hash_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Hash.Definitions.block_length"
] | [] | false | false | false | true | true | let blocks_t (a: hash_alg) =
| b: B.buffer uint8 {B.length b % block_length a = 0} | false |
|
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_fw_acc0_st | val lexp_fw_acc0_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l)) | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 469,
"start_col": 0,
"start_line": 443
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.op_disEquality",
"Prims.int",
"Prims.op_Modulus",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.CONST",
"Lib.Buffer.disjoint",
"Hacl.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.Buffer.as_seq",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.Exponentiation.exp_fw_acc0",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid"
] | [] | false | false | false | false | true | let lexp_fw_acc0_st
(a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(l: size_window_t a_t len)
(table_len: table_len_t len)
(table_inv: table_inv_t a_t len table_len)
=
|
ctx: lbuffer (uint_t a_t SEC) ctx_len ->
a: lbuffer (uint_t a_t SEC) len ->
bLen: size_t ->
bBits: size_t{(v bBits - 1) / bits a_t < v bLen} ->
b: lbuffer (uint_t a_t SEC) bLen ->
table: clbuffer (uint_t a_t SEC) (table_len *! len) ->
acc: lbuffer (uint_t a_t SEC) len
-> Stack unit
(requires
fun h ->
v bBits % v l <> 0 /\ live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\ disjoint acc ctx /\
disjoint acc table /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ table_inv (as_seq h a) (as_seq h table))
(ensures
fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l)) | false |
|
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.malloc_st | val malloc_st : i: Hacl.Hash.Definitions.impl -> Type0 | let malloc_st (i:impl) = r:HS.rid -> ST.ST (state i)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
B.live h1 s /\
M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\
B.freeable s)) | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 18,
"end_line": 224,
"start_col": 0,
"start_line": 216
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *)
noextract inline_for_extraction
let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Hacl.Hash.Definitions.impl -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.impl",
"FStar.Monotonic.HyperHeap.rid",
"Hacl.Hash.Definitions.state",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.is_eternal_region",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Hacl.Hash.Definitions.impl_word",
"LowStar.Buffer.trivial_preorder",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"LowStar.Monotonic.Buffer.fresh_loc",
"LowStar.Monotonic.Buffer.loc_addr_of_buffer",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.loc_region_only",
"LowStar.Monotonic.Buffer.freeable"
] | [] | false | false | false | true | true | let malloc_st (i: impl) =
| r: HS.rid
-> ST.ST (state i)
(requires (fun h -> ST.is_eternal_region r))
(ensures
(fun h0 s h1 ->
B.live h1 s /\ M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\ B.freeable s)) | false |
|
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.init_st | val init_st : i: Hacl.Hash.Definitions.impl -> Type0 | let init_st (i:impl) = s:state i -> ST.Stack unit
(requires (fun h ->
B.live h s))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i))) | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 232,
"start_col": 0,
"start_line": 227
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *)
noextract inline_for_extraction
let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1))
noextract inline_for_extraction
let malloc_st (i:impl) = r:HS.rid -> ST.ST (state i)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
B.live h1 s /\
M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\
B.freeable s)) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Hacl.Hash.Definitions.impl -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.impl",
"Hacl.Hash.Definitions.state",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.live",
"Hacl.Hash.Definitions.impl_word",
"LowStar.Buffer.trivial_preorder",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer",
"Prims.eq2",
"Spec.Hash.Definitions.words_state",
"Hacl.Hash.Definitions.get_alg",
"Hacl.Hash.Definitions.as_seq",
"Spec.Agile.Hash.init"
] | [] | false | false | false | true | true | let init_st (i: impl) =
| s: state i
-> ST.Stack unit
(requires (fun h -> B.live h s))
(ensures
(fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\ as_seq h1 s == Spec.Agile.Hash.init (get_alg i))) | false |
|
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.m_spec | val m_spec (a: hash_alg) : Type0 | val m_spec (a: hash_alg) : Type0 | let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 26,
"start_col": 0,
"start_line": 20
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.hash_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Hacl.Impl.Blake2.Core.m_spec",
"Prims.unit"
] | [] | false | false | false | true | true | let m_spec (a: hash_alg) : Type0 =
| match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5
| SHA1
| SHA2_224
| SHA2_256
| SHA2_384
| SHA2_512
| SHA3_224
| SHA3_256
| SHA3_384
| SHA3_512
| Shake128
| Shake256 -> unit | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.impl_state_length | val impl_state_length : i: Hacl.Hash.Definitions.impl -> Prims.int | let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 90,
"end_line": 80,
"start_col": 0,
"start_line": 73
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Hacl.Hash.Definitions.impl -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.impl",
"FStar.UInt32.v",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Blake2.Core.row_len",
"Spec.Hash.Definitions.to_blake_alg",
"Hacl.Hash.Definitions.get_spec",
"Spec.Hash.Definitions.state_word_length",
"Prims.int",
"Spec.Hash.Definitions.hash_alg",
"Hacl.Hash.Definitions.get_alg"
] | [] | false | false | false | true | false | let impl_state_length (i: impl) =
| [@@ inline_let ]let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5
| SHA1
| SHA2_224
| SHA2_256
| SHA2_384
| SHA2_512
| SHA3_224
| SHA3_256
| SHA3_384
| SHA3_512
| Shake128
| Shake256 -> state_word_length a | false |
|
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.impl_word | val impl_word : i: Hacl.Hash.Definitions.impl -> Type0 | let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 70,
"start_col": 0,
"start_line": 63
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Hacl.Hash.Definitions.impl -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.impl",
"Hacl.Impl.Blake2.Core.element_t",
"Spec.Hash.Definitions.to_blake_alg",
"Hacl.Hash.Definitions.get_spec",
"Spec.Hash.Definitions.word",
"Spec.Hash.Definitions.hash_alg",
"Hacl.Hash.Definitions.get_alg"
] | [] | false | false | false | true | true | let impl_word (i: impl) =
| [@@ inline_let ]let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5
| SHA1
| SHA2_224
| SHA2_256
| SHA2_384
| SHA2_512
| SHA3_224
| SHA3_256
| SHA3_384
| SHA3_512
| Shake128
| Shake256 -> word a | false |
|
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lemma_pow2_is_divisible_by_2 | val lemma_pow2_is_divisible_by_2: l:pos -> Lemma (pow2 l % 2 = 0) | val lemma_pow2_is_divisible_by_2: l:pos -> Lemma (pow2 l % 2 = 0) | let lemma_pow2_is_divisible_by_2 l =
Math.Lemmas.pow2_plus 1 (l - 1);
assert_norm (pow2 1 = 2);
assert (pow2 l = 2 * pow2 (l - 1));
Math.Lemmas.lemma_mod_mul_distr_l 2 (pow2 (l - 1)) 2 | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 513,
"start_col": 0,
"start_line": 509
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv
let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc
let mk_lexp_fw_table #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res =
assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul then
lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
//-------------------------------------
let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp
let lprecomp_get_consttime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_consttime #a_t len ctx_len k a table_len table bits_l tmp | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Prims.pos -> FStar.Pervasives.Lemma (ensures Prims.pow2 l % 2 = 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Prims.pow2",
"Prims.op_Subtraction",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"FStar.Pervasives.assert_norm",
"FStar.Math.Lemmas.pow2_plus"
] | [] | true | false | true | false | false | let lemma_pow2_is_divisible_by_2 l =
| Math.Lemmas.pow2_plus 1 (l - 1);
assert_norm (pow2 1 = 2);
assert (pow2 l = 2 * pow2 (l - 1));
Math.Lemmas.lemma_mod_mul_distr_l 2 (pow2 (l - 1)) 2 | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_fw_loop_st | val lexp_fw_loop_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc))) | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 399,
"start_col": 0,
"start_line": 372
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.CONST",
"Lib.Buffer.disjoint",
"Hacl.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.Buffer.as_seq",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.LoopCombinators.repeati",
"Lib.Exponentiation.exp_fw_f",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid"
] | [] | false | false | false | false | true | let lexp_fw_loop_st
(a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(l: size_window_t a_t len)
(table_len: table_len_t len)
(table_inv: table_inv_t a_t len table_len)
=
|
ctx: lbuffer (uint_t a_t SEC) ctx_len ->
a: lbuffer (uint_t a_t SEC) len ->
bLen: size_t ->
bBits: size_t{(v bBits - 1) / bits a_t < v bLen} ->
b: lbuffer (uint_t a_t SEC) bLen ->
table: clbuffer (uint_t a_t SEC) (table_len *! len) ->
acc: lbuffer (uint_t a_t SEC) len
-> Stack unit
(requires
fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\ disjoint a acc /\
disjoint a ctx /\ disjoint b acc /\ disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\ table_inv (as_seq h a) (as_seq h table))
(ensures
fun h0 _ h1 ->
modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l)
(S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
(k.to.refl (as_seq h0 acc))) | false |
|
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.fixed_len_impl | val fixed_len_impl : Type0 | let fixed_len_impl = i:impl { not (is_shake (dfst i)) } | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 317,
"start_col": 0,
"start_line": 317
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *)
noextract inline_for_extraction
let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1))
noextract inline_for_extraction
let malloc_st (i:impl) = r:HS.rid -> ST.ST (state i)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
B.live h1 s /\
M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\
B.freeable s))
noextract inline_for_extraction
let init_st (i:impl) = s:state i -> ST.Stack unit
(requires (fun h ->
B.live h s))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i)))
noextract inline_for_extraction
let update_st (i:impl{is_md (get_alg i)}) =
s:state i ->
block:B.buffer uint8 { B.length block = block_length (get_alg i) } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h block /\ B.disjoint s block))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update (get_alg i) (as_seq h0 s) (B.as_seq h0 block)))
noextract inline_for_extraction
let pad_st (a: md_alg) = len:len_t a -> dst:B.buffer uint8 ->
ST.Stack unit
(requires (fun h ->
len_v a len `less_than_max_input_length` a /\
B.live h dst /\
B.length dst = pad_length a (len_v a len)))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer dst) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Hash.MD.pad a (len_v a len))))
// Note: we cannot take more than 4GB of data because we are currently
// constrained by the size of buffers...
noextract inline_for_extraction
let update_multi_st (i:impl) =
s:state i ->
ev:extra_state (get_alg i) ->
blocks:blocks_t (get_alg i) ->
n:size_t { B.length blocks = block_length (get_alg i) * v n } ->
ST.Stack unit
(requires (fun h ->
Spec.Agile.Hash.update_multi_pre (get_alg i) (ev_v ev) (B.as_seq h blocks) /\
B.live h s /\ B.live h blocks /\ B.disjoint s blocks))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update_multi (get_alg i) (as_seq h0 s) (ev_v ev) (B.as_seq h0 blocks)))
noextract inline_for_extraction
let prev_len_t (a: hash_alg) =
if is_keccak a then
unit
else
prev_len:len_t a { len_v a prev_len % block_length a = 0 }
noextract inline_for_extraction
let prev_len_v #a (prev_len: prev_len_t a): Spec.Hash.Incremental.Definitions.prev_length_t a
=
if is_keccak a then
()
else
len_v a prev_len
noextract inline_for_extraction
let extra_state_of_prev_length #a (x: Spec.Hash.Incremental.Definitions.prev_length_t a): Spec.Agile.Hash.extra_state a =
match a with
| Blake2B | Blake2S -> x
| _ -> ()
noextract inline_for_extraction
let update_last_st (i:impl) =
let a = get_alg i in
s:state i ->
prev_len:prev_len_t a ->
input:B.buffer uint8 {
(if is_keccak a then True else (B.length input + len_v a prev_len) `less_than_max_input_length` a) /\
B.length input <= block_length a
} ->
input_len:size_t { B.length input = v input_len } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h input /\ B.disjoint s input /\
Spec.Agile.Hash.update_multi_pre a (extra_state_of_prev_length (prev_len_v prev_len)) (B.as_seq h input)))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Hash.Incremental.update_last a (as_seq h0 s)
(prev_len_v prev_len)
(B.as_seq h0 input))) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.impl",
"Prims.b2t",
"Prims.op_Negation",
"Spec.Hash.Definitions.is_shake",
"FStar.Pervasives.dfst",
"Spec.Hash.Definitions.hash_alg",
"Hacl.Hash.Definitions.m_spec"
] | [] | false | false | false | true | true | let fixed_len_impl =
| i: impl{not (is_shake (dfst i))} | false |
|
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lmul_acc_pow_a_bits_l_st | val lmul_acc_pow_a_bits_l_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc))) | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 290,
"start_col": 0,
"start_line": 258
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//--------------------------------------------------- | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.CONST",
"Lib.Buffer.disjoint",
"Hacl.Bignum.Definitions.bn_v",
"Prims.pow2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.Buffer.as_seq",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.Exponentiation.mul_acc_pow_a_bits_l",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid"
] | [] | false | false | false | false | true | let lmul_acc_pow_a_bits_l_st
(a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(l: size_window_t a_t len)
(table_len: table_len_t len)
(table_inv: table_inv_t a_t len table_len)
=
|
ctx: lbuffer (uint_t a_t SEC) ctx_len ->
a: lbuffer (uint_t a_t SEC) len ->
bLen: size_t ->
bBits: size_t{(v bBits - 1) / bits a_t < v bLen} ->
b: lbuffer (uint_t a_t SEC) bLen ->
table: clbuffer (uint_t a_t SEC) (table_len *! len) ->
i: size_t{v i < v bBits / v l} ->
acc: lbuffer (uint_t a_t SEC) len ->
tmp: lbuffer (uint_t a_t SEC) len
-> Stack unit
(requires
fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\ live h tmp /\
disjoint tmp a /\ disjoint tmp b /\ disjoint tmp acc /\ disjoint tmp ctx /\
disjoint tmp table /\ disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\ BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures
fun h0 _ h1 ->
modifies (loc acc |+| loc tmp) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec
k.to.comm_monoid
(k.to.refl (as_seq h0 a))
(v bBits)
(BD.bn_v h0 b)
(v l)
(v i)
(k.to.refl (as_seq h0 acc))) | false |
|
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_fw_vartime | val lexp_fw_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len ->
lexp_fw_st a_t len ctx_len k l | val lexp_fw_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len ->
lexp_fw_st a_t len ctx_len k l | let lexp_fw_vartime #a_t len ctx_len k l ctx a bLen bBits b acc =
[@inline_let]
let table_len = 1ul <<. l in
assert (v table_len == pow2 (v l));
Math.Lemmas.pow2_le_compat (v l) 1;
assert (1 < v table_len /\ v table_len * v len <= max_size_t);
lexp_fw_gen #a_t len ctx_len k l table_len
(lprecomp_get_vartime len ctx_len k l table_len)
ctx a bLen bBits b acc | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 557,
"start_col": 0,
"start_line": 548
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv
let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc
let mk_lexp_fw_table #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res =
assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul then
lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
//-------------------------------------
let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp
let lprecomp_get_consttime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_consttime #a_t len ctx_len k a table_len table bits_l tmp
val lemma_pow2_is_divisible_by_2: l:pos -> Lemma (pow2 l % 2 = 0)
let lemma_pow2_is_divisible_by_2 l =
Math.Lemmas.pow2_plus 1 (l - 1);
assert_norm (pow2 1 = 2);
assert (pow2 l = 2 * pow2 (l - 1));
Math.Lemmas.lemma_mod_mul_distr_l 2 (pow2 (l - 1)) 2
inline_for_extraction noextract
val lexp_fw_gen:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len{1 < v table_len /\ v table_len == pow2 (v l)}
-> lprecomp_get:pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) ->
lexp_fw_st a_t len ctx_len k l
let lexp_fw_gen #a_t len ctx_len k l table_len lprecomp_get ctx a bLen bBits b res =
push_frame ();
Math.Lemmas.pow2_lt_compat 32 (v l);
lemma_pow2_is_divisible_by_2 (v l);
let table = create (table_len *! len) (uint #a_t #SEC 0) in
PT.lprecomp_table #a_t len ctx_len k ctx a table_len table;
[@inline_let]
let table_inv : table_inv_t a_t len table_len =
table_inv_precomp len ctx_len k l table_len in
let h1 = ST.get () in
assert (table_inv (as_seq h1 a) (as_seq h1 table));
mk_lexp_fw_table len ctx_len k l table_len
table_inv lprecomp_get
ctx a bLen bBits b (to_const table) res;
pop_frame () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len
-> Hacl.Impl.Exponentiation.lexp_fw_st a_t len ctx_len k l | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Hacl.Impl.Exponentiation.lexp_fw_gen",
"Hacl.Impl.Exponentiation.lprecomp_get_vartime",
"Prims.unit",
"Prims._assert",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"FStar.Math.Lemmas.pow2_le_compat",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.pow2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Less_Less_Dot",
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | false | false | let lexp_fw_vartime #a_t len ctx_len k l ctx a bLen bBits b acc =
| [@@ inline_let ]let table_len = 1ul <<. l in
assert (v table_len == pow2 (v l));
Math.Lemmas.pow2_le_compat (v l) 1;
assert (1 < v table_len /\ v table_len * v len <= max_size_t);
lexp_fw_gen #a_t len ctx_len k l table_len (lprecomp_get_vartime len ctx_len k l table_len) ctx a
bLen bBits b acc | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.word_len | val word_len (a: md_alg) : n: size_t{v n = word_length a} | val word_len (a: md_alg) : n: size_t{v n = word_length a} | let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 117,
"start_col": 0,
"start_line": 114
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.md_alg
-> n: Lib.IntTypes.size_t{Lib.IntTypes.v n = Spec.Hash.Definitions.word_length a} | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.md_alg",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Spec.Hash.Definitions.word_length"
] | [] | false | false | false | false | false | let word_len (a: md_alg) : n: size_t{v n = word_length a} =
| match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_fw_acc0 | val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv | val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv | let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 488,
"start_col": 0,
"start_line": 484
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len ->
pow_a_to_small_b:
Hacl.Impl.Exponentiation.pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv
-> Hacl.Impl.Exponentiation.lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Hacl.Impl.Exponentiation.pow_a_to_small_b_st",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"FStar.Ghost.hide",
"Lib.Sequence.lseq",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.unit",
"Lib.IntTypes.int_t",
"Hacl.Impl.Exponentiation.bn_get_bits_c",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.op_Percent_Dot",
"Prims.op_Modulus",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let lexp_fw_acc0
#a_t
len
ctx_len
k
l
table_len
table_inv
pow_a_to_small_b
ctx
a
bLen
bBits
b
table
acc
=
| let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.get_spec | val get_spec (i: impl) : m_spec (get_alg i) | val get_spec (i: impl) : m_spec (get_alg i) | let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 60,
"start_col": 0,
"start_line": 59
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Hacl.Hash.Definitions.impl -> Hacl.Hash.Definitions.m_spec (Hacl.Hash.Definitions.get_alg i) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.impl",
"Spec.Hash.Definitions.hash_alg",
"Hacl.Hash.Definitions.m_spec",
"Hacl.Hash.Definitions.get_alg"
] | [] | false | false | false | false | false | let get_spec (i: impl) : m_spec (get_alg i) =
| match i with | (| a , m |) -> m | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.hash_len | val hash_len (a: fixed_len_alg) : n: size_t{v n = hash_length a} | val hash_len (a: fixed_len_alg) : n: size_t{v n = hash_length a} | let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 20,
"end_line": 157,
"start_col": 0,
"start_line": 144
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.fixed_len_alg
-> n: Lib.IntTypes.size_t{Lib.IntTypes.v n = Spec.Hash.Definitions.hash_length a} | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.fixed_len_alg",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Prims.l_and",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.max_size_t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Spec.Hash.Definitions.hash_length"
] | [] | false | false | false | false | false | let hash_len (a: fixed_len_alg) : n: size_t{v n = hash_length a} =
| match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_fw_consttime | val lexp_fw_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len ->
lexp_fw_st a_t len ctx_len k l | val lexp_fw_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len ->
lexp_fw_st a_t len ctx_len k l | let lexp_fw_consttime #a_t len ctx_len k l ctx a bLen bBits b acc =
[@inline_let]
let table_len = 1ul <<. l in
assert (v table_len == pow2 (v l));
Math.Lemmas.pow2_le_compat (v l) 1;
assert (1 < v table_len /\ v table_len * v len <= max_size_t);
lexp_fw_gen #a_t len ctx_len k l table_len
(lprecomp_get_consttime len ctx_len k l table_len)
ctx a bLen bBits b acc | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 569,
"start_col": 0,
"start_line": 560
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv
let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc
let mk_lexp_fw_table #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res =
assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul then
lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
//-------------------------------------
let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp
let lprecomp_get_consttime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_consttime #a_t len ctx_len k a table_len table bits_l tmp
val lemma_pow2_is_divisible_by_2: l:pos -> Lemma (pow2 l % 2 = 0)
let lemma_pow2_is_divisible_by_2 l =
Math.Lemmas.pow2_plus 1 (l - 1);
assert_norm (pow2 1 = 2);
assert (pow2 l = 2 * pow2 (l - 1));
Math.Lemmas.lemma_mod_mul_distr_l 2 (pow2 (l - 1)) 2
inline_for_extraction noextract
val lexp_fw_gen:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len{1 < v table_len /\ v table_len == pow2 (v l)}
-> lprecomp_get:pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) ->
lexp_fw_st a_t len ctx_len k l
let lexp_fw_gen #a_t len ctx_len k l table_len lprecomp_get ctx a bLen bBits b res =
push_frame ();
Math.Lemmas.pow2_lt_compat 32 (v l);
lemma_pow2_is_divisible_by_2 (v l);
let table = create (table_len *! len) (uint #a_t #SEC 0) in
PT.lprecomp_table #a_t len ctx_len k ctx a table_len table;
[@inline_let]
let table_inv : table_inv_t a_t len table_len =
table_inv_precomp len ctx_len k l table_len in
let h1 = ST.get () in
assert (table_inv (as_seq h1 a) (as_seq h1 table));
mk_lexp_fw_table len ctx_len k l table_len
table_inv lprecomp_get
ctx a bLen bBits b (to_const table) res;
pop_frame ()
let lexp_fw_vartime #a_t len ctx_len k l ctx a bLen bBits b acc =
[@inline_let]
let table_len = 1ul <<. l in
assert (v table_len == pow2 (v l));
Math.Lemmas.pow2_le_compat (v l) 1;
assert (1 < v table_len /\ v table_len * v len <= max_size_t);
lexp_fw_gen #a_t len ctx_len k l table_len
(lprecomp_get_vartime len ctx_len k l table_len)
ctx a bLen bBits b acc | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len
-> Hacl.Impl.Exponentiation.lexp_fw_st a_t len ctx_len k l | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Hacl.Impl.Exponentiation.lexp_fw_gen",
"Hacl.Impl.Exponentiation.lprecomp_get_consttime",
"Prims.unit",
"Prims._assert",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"FStar.Math.Lemmas.pow2_le_compat",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.pow2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Less_Less_Dot",
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | false | false | let lexp_fw_consttime #a_t len ctx_len k l ctx a bLen bBits b acc =
| [@@ inline_let ]let table_len = 1ul <<. l in
assert (v table_len == pow2 (v l));
Math.Lemmas.pow2_le_compat (v l) 1;
assert (1 < v table_len /\ v table_len * v len <= max_size_t);
lexp_fw_gen #a_t len ctx_len k l table_len (lprecomp_get_consttime len ctx_len k l table_len) ctx a
bLen bBits b acc | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_rl_vartime | val lexp_rl_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h ctx /\
disjoint a res /\ disjoint b res /\ disjoint a b /\
disjoint ctx a /\ disjoint ctx res /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a))
(ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_rl #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) | val lexp_rl_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h ctx /\
disjoint a res /\ disjoint b res /\ disjoint a b /\
disjoint ctx a /\ disjoint ctx res /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a))
(ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_rl #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) | let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
) | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 54,
"start_col": 0,
"start_line": 24
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
ctx: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) ctx_len ->
a: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len ->
bLen: Lib.IntTypes.size_t ->
bBits:
Lib.IntTypes.size_t{(Lib.IntTypes.v bBits - 1) / Lib.IntTypes.bits a_t < Lib.IntTypes.v bLen} ->
b: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) bLen ->
res: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Loops.for",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__lsqr",
"Prims.unit",
"Prims.op_Negation",
"Hacl.Spec.Bignum.Base.unsafe_bool_of_limb0",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__lmul",
"Prims.bool",
"Hacl.Spec.Bignum.bn_get_ith_bit_lemma",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Hacl.Bignum.bn_get_ith_bit",
"Lib.LoopCombinators.unfold_repeati",
"FStar.Pervasives.Native.tuple2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.LoopCombinators.eq_repeati0",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.logical",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Prims.eq2",
"FStar.Pervasives.Native.fst",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"FStar.Pervasives.Native.snd",
"Lib.LoopCombinators.repeati",
"Lib.Exponentiation.exp_rl_f",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid",
"Hacl.Bignum.Definitions.bn_v",
"Prims.int",
"FStar.Pervasives.Native.Mktuple2",
"Hacl.Impl.Exponentiation.Definitions.refl",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__lone"
] | [] | false | true | false | false | false | let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
| k.lone ctx acc;
let h0 = ST.get () in
[@@ inline_let ]let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a))
in
[@@ inline_let ]let spec (h: mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@@ inline_let ]let inv h (i: nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\ k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\ snd res == k.to.refl (as_seq h a))
in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul
bBits
inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then k.lmul ctx acc a acc;
k.lsqr ctx a a) | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.ev_v | val ev_v (#a: hash_alg) (ev: extra_state a) : Spec.Hash.Definitions.extra_state a | val ev_v (#a: hash_alg) (ev: extra_state a) : Spec.Hash.Definitions.extra_state a | let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> () | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 46,
"start_col": 0,
"start_line": 39
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ev: Hacl.Hash.Definitions.extra_state a -> Spec.Hash.Definitions.extra_state a | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Hacl.Hash.Definitions.extra_state",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.PUB",
"Lib.IntTypes.U128",
"Spec.Hash.Definitions.extra_state"
] | [] | false | false | false | false | false | let ev_v (#a: hash_alg) (ev: extra_state a) : Spec.Hash.Definitions.extra_state a =
| match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5
| SHA1
| SHA2_224
| SHA2_256
| SHA2_384
| SHA2_512
| SHA3_224
| SHA3_256
| SHA3_384
| SHA3_512
| Shake128
| Shake256 -> () | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.block_len | val block_len (a: hash_alg) : n: size_t{v n = block_length a} | val block_len (a: hash_alg) : n: size_t{v n = block_length a} | let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 20,
"end_line": 131,
"start_col": 0,
"start_line": 120
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.hash_alg
-> n: Lib.IntTypes.size_t{Lib.IntTypes.v n = Spec.Hash.Definitions.block_length a} | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.op_Division",
"Spec.Hash.Definitions.rate",
"Spec.Hash.Definitions.SHA3_224",
"Spec.Hash.Definitions.SHA3_256",
"Spec.Hash.Definitions.SHA3_384",
"Spec.Hash.Definitions.SHA3_512",
"Spec.Hash.Definitions.Shake128",
"Spec.Hash.Definitions.Shake256",
"Lib.IntTypes.size_t",
"Prims.l_or",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Prims.op_disEquality",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Spec.Hash.Definitions.block_length"
] | [] | false | false | false | false | false | let block_len (a: hash_alg) : n: size_t{v n = block_length a} =
| match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 ->
assert_norm ((rate SHA3_224 / 8 / 8) * 8 = 144);
144ul
| SHA3_256 ->
assert_norm ((rate SHA3_256 / 8 / 8) * 8 = 136);
136ul
| SHA3_384 ->
assert_norm ((rate SHA3_384 / 8 / 8) * 8 = 104);
104ul
| SHA3_512 ->
assert_norm ((rate SHA3_512 / 8 / 8) * 8 = 72);
72ul
| Shake128 ->
assert_norm ((rate Shake128 / 8 / 8) * 8 = 168);
168ul
| Shake256 ->
assert_norm ((rate Shake256 / 8 / 8) * 8 = 136);
136ul
| Blake2S -> 64ul
| Blake2B -> 128ul | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.pad_st | val pad_st : a: Spec.Hash.Definitions.md_alg -> Type0 | let pad_st (a: md_alg) = len:len_t a -> dst:B.buffer uint8 ->
ST.Stack unit
(requires (fun h ->
len_v a len `less_than_max_input_length` a /\
B.live h dst /\
B.length dst = pad_length a (len_v a len)))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer dst) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Hash.MD.pad a (len_v a len)))) | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 70,
"end_line": 255,
"start_col": 0,
"start_line": 247
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *)
noextract inline_for_extraction
let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1))
noextract inline_for_extraction
let malloc_st (i:impl) = r:HS.rid -> ST.ST (state i)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
B.live h1 s /\
M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\
B.freeable s))
noextract inline_for_extraction
let init_st (i:impl) = s:state i -> ST.Stack unit
(requires (fun h ->
B.live h s))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i)))
noextract inline_for_extraction
let update_st (i:impl{is_md (get_alg i)}) =
s:state i ->
block:B.buffer uint8 { B.length block = block_length (get_alg i) } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h block /\ B.disjoint s block))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update (get_alg i) (as_seq h0 s) (B.as_seq h0 block))) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.md_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.md_alg",
"Spec.Hash.Definitions.len_t",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.b2t",
"Spec.Hash.Definitions.less_than_max_input_length",
"Spec.Hash.Definitions.len_v",
"LowStar.Monotonic.Buffer.live",
"LowStar.Buffer.trivial_preorder",
"Prims.op_Equality",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"Spec.Hash.Definitions.pad_length",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer",
"FStar.Seq.Base.equal",
"LowStar.Monotonic.Buffer.as_seq",
"Spec.Hash.MD.pad"
] | [] | false | false | false | true | true | let pad_st (a: md_alg) =
| len: len_t a -> dst: B.buffer uint8
-> ST.Stack unit
(requires
(fun h ->
(len_v a len) `less_than_max_input_length` a /\ B.live h dst /\
B.length dst = pad_length a (len_v a len)))
(ensures
(fun h0 _ h1 ->
M.(modifies (loc_buffer dst) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Hash.MD.pad a (len_v a len)))) | false |
|
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.hash_word_len | val hash_word_len (a: md_alg) : n: size_t{v n = hash_word_length a} | val hash_word_len (a: md_alg) : n: size_t{v n = hash_word_length a} | let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 141,
"start_col": 0,
"start_line": 134
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.md_alg
-> n: Lib.IntTypes.size_t{Lib.IntTypes.v n = Spec.Hash.Definitions.hash_word_length a} | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.md_alg",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Spec.Hash.Definitions.hash_word_length"
] | [] | false | false | false | false | false | let hash_word_len (a: md_alg) : n: size_t{v n = hash_word_length a} =
| match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.mk_lexp_fw_table | val mk_lexp_fw_table:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_table_st a_t len ctx_len k l table_len table_inv | val mk_lexp_fw_table:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_table_st a_t len ctx_len k l table_len table_inv | let mk_lexp_fw_table #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res =
assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul then
lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 96,
"end_line": 496,
"start_col": 0,
"start_line": 491
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv
let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len ->
pow_a_to_small_b:
Hacl.Impl.Exponentiation.pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv
-> Hacl.Impl.Exponentiation.lexp_fw_table_st a_t len ctx_len k l table_len table_inv | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Hacl.Impl.Exponentiation.pow_a_to_small_b_st",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Hacl.Impl.Exponentiation.lexp_fw_loop",
"Prims.unit",
"Prims.op_disEquality",
"FStar.UInt32.t",
"Lib.IntTypes.op_Percent_Dot",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Exponentiation.lexp_fw_acc0",
"Prims.bool",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__lone",
"Prims._assert",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus"
] | [] | false | false | false | false | false | let mk_lexp_fw_table
#a_t
len
ctx_len
k
l
table_len
table_inv
pow_a_to_small_b
ctx
a
bLen
bBits
b
table
res
=
| assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul
then lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.impl_state_len | val impl_state_len (i: impl) : s: size_t{size_v s == impl_state_length i} | val impl_state_len (i: impl) : s: size_t{size_v s == impl_state_length i} | let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 97,
"start_col": 0,
"start_line": 83
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Hacl.Hash.Definitions.impl
-> s: Lib.IntTypes.size_t{Lib.IntTypes.size_v s == Hacl.Hash.Definitions.impl_state_length i} | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.impl",
"FStar.UInt32.__uint_to_t",
"Spec.Hash.Definitions.hash_alg",
"FStar.Pervasives.Native.Mktuple2",
"Hacl.Impl.Blake2.Core.m_spec",
"Lib.IntTypes.size_t",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.size_v",
"Hacl.Hash.Definitions.impl_state_length",
"Prims.unit",
"Lib.IntTypes.mul_mod_lemma",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Blake2.Core.row_len",
"Spec.Hash.Definitions.to_blake_alg",
"Hacl.Hash.Definitions.get_spec",
"Hacl.Hash.Definitions.m_spec",
"Hacl.Hash.Definitions.get_alg"
] | [] | false | false | false | false | false | let impl_state_len (i: impl) : s: size_t{size_v s == impl_state_length i} =
| [@@ inline_let ]let a = get_alg i in
[@@ inline_let ]let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32 | Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256 | Blake2B, Blake2.M256 -> 4ul | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.as_seq | val as_seq (#i: impl) (h: HS.mem) (s: state i) : GTot (words_state (get_alg i)) | val as_seq (#i: impl) (h: HS.mem) (s: state i) : GTot (words_state (get_alg i)) | let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 111,
"start_col": 0,
"start_line": 104
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i } | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h: FStar.Monotonic.HyperStack.mem -> s: Hacl.Hash.Definitions.state i
-> Prims.GTot (Spec.Hash.Definitions.words_state (Hacl.Hash.Definitions.get_alg i)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Hacl.Hash.Definitions.impl",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Hash.Definitions.state",
"Hacl.Hash.Definitions.get_alg",
"Hacl.Impl.Blake2.Core.state_v",
"Spec.Blake2.Definitions.Blake2S",
"Hacl.Hash.Definitions.get_spec",
"Spec.Blake2.Definitions.Blake2B",
"LowStar.Monotonic.Buffer.as_seq",
"Hacl.Hash.Definitions.impl_word",
"LowStar.Buffer.trivial_preorder",
"Spec.Hash.Definitions.words_state"
] | [] | false | false | false | false | false | let as_seq (#i: impl) (h: HS.mem) (s: state i) : GTot (words_state (get_alg i)) =
| match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5
| SHA1
| SHA2_224
| SHA2_256
| SHA2_384
| SHA2_512
| SHA3_224
| SHA3_256
| SHA3_384
| SHA3_512
| Shake128
| Shake256 -> B.as_seq h s | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.update_multi_st | val update_multi_st : i: Hacl.Hash.Definitions.impl -> Type0 | let update_multi_st (i:impl) =
s:state i ->
ev:extra_state (get_alg i) ->
blocks:blocks_t (get_alg i) ->
n:size_t { B.length blocks = block_length (get_alg i) * v n } ->
ST.Stack unit
(requires (fun h ->
Spec.Agile.Hash.update_multi_pre (get_alg i) (ev_v ev) (B.as_seq h blocks) /\
B.live h s /\ B.live h blocks /\ B.disjoint s blocks))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update_multi (get_alg i) (as_seq h0 s) (ev_v ev) (B.as_seq h0 blocks))) | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 95,
"end_line": 272,
"start_col": 0,
"start_line": 260
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *)
noextract inline_for_extraction
let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1))
noextract inline_for_extraction
let malloc_st (i:impl) = r:HS.rid -> ST.ST (state i)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
B.live h1 s /\
M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\
B.freeable s))
noextract inline_for_extraction
let init_st (i:impl) = s:state i -> ST.Stack unit
(requires (fun h ->
B.live h s))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i)))
noextract inline_for_extraction
let update_st (i:impl{is_md (get_alg i)}) =
s:state i ->
block:B.buffer uint8 { B.length block = block_length (get_alg i) } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h block /\ B.disjoint s block))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update (get_alg i) (as_seq h0 s) (B.as_seq h0 block)))
noextract inline_for_extraction
let pad_st (a: md_alg) = len:len_t a -> dst:B.buffer uint8 ->
ST.Stack unit
(requires (fun h ->
len_v a len `less_than_max_input_length` a /\
B.live h dst /\
B.length dst = pad_length a (len_v a len)))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer dst) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Hash.MD.pad a (len_v a len))))
// Note: we cannot take more than 4GB of data because we are currently
// constrained by the size of buffers... | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Hacl.Hash.Definitions.impl -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.impl",
"Hacl.Hash.Definitions.state",
"Hacl.Hash.Definitions.extra_state",
"Hacl.Hash.Definitions.get_alg",
"Hacl.Hash.Definitions.blocks_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"Lib.IntTypes.uint8",
"LowStar.Buffer.trivial_preorder",
"FStar.Mul.op_Star",
"Spec.Hash.Definitions.block_length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Spec.Agile.Hash.update_multi_pre",
"Hacl.Hash.Definitions.ev_v",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Monotonic.Buffer.live",
"Hacl.Hash.Definitions.impl_word",
"LowStar.Monotonic.Buffer.disjoint",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer",
"Prims.eq2",
"Spec.Hash.Definitions.words_state",
"Hacl.Hash.Definitions.as_seq",
"Spec.Agile.Hash.update_multi"
] | [] | false | false | false | true | true | let update_multi_st (i: impl) =
|
s: state i ->
ev: extra_state (get_alg i) ->
blocks: blocks_t (get_alg i) ->
n: size_t{B.length blocks = block_length (get_alg i) * v n}
-> ST.Stack unit
(requires
(fun h ->
Spec.Agile.Hash.update_multi_pre (get_alg i) (ev_v ev) (B.as_seq h blocks) /\ B.live h s /\
B.live h blocks /\ B.disjoint s blocks))
(ensures
(fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update_multi (get_alg i) (as_seq h0 s) (ev_v ev) (B.as_seq h0 blocks))) | false |
|
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.hash_t | val hash_t : a: Spec.Hash.Definitions.fixed_len_alg -> Type0 | let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a } | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 200,
"start_col": 0,
"start_line": 200
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 } | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.fixed_len_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.fixed_len_alg",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Hash.Definitions.hash_length"
] | [] | false | false | false | true | true | let hash_t (a: fixed_len_alg) =
| b: B.buffer uint8 {B.length b = hash_length a} | false |
|
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.prev_len_t | val prev_len_t : a: Spec.Hash.Definitions.hash_alg -> Type0 | let prev_len_t (a: hash_alg) =
if is_keccak a then
unit
else
prev_len:len_t a { len_v a prev_len % block_length a = 0 } | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 279,
"start_col": 0,
"start_line": 275
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *)
noextract inline_for_extraction
let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1))
noextract inline_for_extraction
let malloc_st (i:impl) = r:HS.rid -> ST.ST (state i)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
B.live h1 s /\
M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\
B.freeable s))
noextract inline_for_extraction
let init_st (i:impl) = s:state i -> ST.Stack unit
(requires (fun h ->
B.live h s))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i)))
noextract inline_for_extraction
let update_st (i:impl{is_md (get_alg i)}) =
s:state i ->
block:B.buffer uint8 { B.length block = block_length (get_alg i) } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h block /\ B.disjoint s block))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update (get_alg i) (as_seq h0 s) (B.as_seq h0 block)))
noextract inline_for_extraction
let pad_st (a: md_alg) = len:len_t a -> dst:B.buffer uint8 ->
ST.Stack unit
(requires (fun h ->
len_v a len `less_than_max_input_length` a /\
B.live h dst /\
B.length dst = pad_length a (len_v a len)))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer dst) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Hash.MD.pad a (len_v a len))))
// Note: we cannot take more than 4GB of data because we are currently
// constrained by the size of buffers...
noextract inline_for_extraction
let update_multi_st (i:impl) =
s:state i ->
ev:extra_state (get_alg i) ->
blocks:blocks_t (get_alg i) ->
n:size_t { B.length blocks = block_length (get_alg i) * v n } ->
ST.Stack unit
(requires (fun h ->
Spec.Agile.Hash.update_multi_pre (get_alg i) (ev_v ev) (B.as_seq h blocks) /\
B.live h s /\ B.live h blocks /\ B.disjoint s blocks))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update_multi (get_alg i) (as_seq h0 s) (ev_v ev) (B.as_seq h0 blocks))) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.hash_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Spec.Hash.Definitions.is_keccak",
"Prims.unit",
"Prims.bool",
"Spec.Hash.Definitions.len_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Spec.Hash.Definitions.len_v",
"Spec.Hash.Definitions.block_length"
] | [] | false | false | false | true | true | let prev_len_t (a: hash_alg) =
| if is_keccak a then unit else prev_len: len_t a {len_v a prev_len % block_length a = 0} | false |
|
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.update_st | val update_st : i: Hacl.Hash.Definitions.impl{Spec.Hash.Definitions.is_md (Hacl.Hash.Definitions.get_alg i)}
-> Type0 | let update_st (i:impl{is_md (get_alg i)}) =
s:state i ->
block:B.buffer uint8 { B.length block = block_length (get_alg i) } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h block /\ B.disjoint s block))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update (get_alg i) (as_seq h0 s) (B.as_seq h0 block))) | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 244,
"start_col": 0,
"start_line": 235
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *)
noextract inline_for_extraction
let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1))
noextract inline_for_extraction
let malloc_st (i:impl) = r:HS.rid -> ST.ST (state i)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
B.live h1 s /\
M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\
B.freeable s))
noextract inline_for_extraction
let init_st (i:impl) = s:state i -> ST.Stack unit
(requires (fun h ->
B.live h s))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i))) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Hacl.Hash.Definitions.impl{Spec.Hash.Definitions.is_md (Hacl.Hash.Definitions.get_alg i)}
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.impl",
"Prims.b2t",
"Spec.Hash.Definitions.is_md",
"Hacl.Hash.Definitions.get_alg",
"Hacl.Hash.Definitions.state",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Prims.op_disEquality",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Hash.Definitions.block_length",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Hacl.Hash.Definitions.impl_word",
"LowStar.Monotonic.Buffer.disjoint",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer",
"Prims.eq2",
"Spec.Hash.Definitions.words_state",
"Hacl.Hash.Definitions.as_seq",
"Spec.Agile.Hash.update",
"LowStar.Monotonic.Buffer.as_seq"
] | [] | false | false | false | false | true | let update_st (i: impl{is_md (get_alg i)}) =
| s: state i -> block: B.buffer uint8 {B.length block = block_length (get_alg i)}
-> ST.Stack unit
(requires (fun h -> B.live h s /\ B.live h block /\ B.disjoint s block))
(ensures
(fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s == Spec.Agile.Hash.update (get_alg i) (as_seq h0 s) (B.as_seq h0 block))) | false |
|
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_fw_gen | val lexp_fw_gen:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len{1 < v table_len /\ v table_len == pow2 (v l)}
-> lprecomp_get:pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) ->
lexp_fw_st a_t len ctx_len k l | val lexp_fw_gen:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len{1 < v table_len /\ v table_len == pow2 (v l)}
-> lprecomp_get:pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) ->
lexp_fw_st a_t len ctx_len k l | let lexp_fw_gen #a_t len ctx_len k l table_len lprecomp_get ctx a bLen bBits b res =
push_frame ();
Math.Lemmas.pow2_lt_compat 32 (v l);
lemma_pow2_is_divisible_by_2 (v l);
let table = create (table_len *! len) (uint #a_t #SEC 0) in
PT.lprecomp_table #a_t len ctx_len k ctx a table_len table;
[@inline_let]
let table_inv : table_inv_t a_t len table_len =
table_inv_precomp len ctx_len k l table_len in
let h1 = ST.get () in
assert (table_inv (as_seq h1 a) (as_seq h1 table));
mk_lexp_fw_table len ctx_len k l table_len
table_inv lprecomp_get
ctx a bLen bBits b (to_const table) res;
pop_frame () | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 545,
"start_col": 0,
"start_line": 528
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv
let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame ()
inline_for_extraction noextract
let lexp_fw_acc0_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h -> v bBits % v l <> 0 /\
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_acc0 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
inline_for_extraction noextract
val lexp_fw_acc0:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_acc0_st a_t len ctx_len k l table_len table_inv
let lexp_fw_acc0 #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
let h0 = ST.get () in
assert (v (bBits %. l) == v bBits % v l);
let bits_c = bn_get_bits_c bLen bBits b l in
pow_a_to_small_b ctx (as_seq h0 a) table bits_c acc
let mk_lexp_fw_table #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res =
assert (v (bBits %. l) = v bBits % v l);
if bBits %. l <> 0ul then
lexp_fw_acc0 len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
else k.lone ctx res;
lexp_fw_loop len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table res
//-------------------------------------
let lprecomp_get_vartime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_vartime #a_t len ctx_len k a table_len table bits_l tmp
let lprecomp_get_consttime #a_t len ctx_len k l table_len ctx a table bits_l tmp =
PT.lprecomp_get_consttime #a_t len ctx_len k a table_len table bits_l tmp
val lemma_pow2_is_divisible_by_2: l:pos -> Lemma (pow2 l % 2 = 0)
let lemma_pow2_is_divisible_by_2 l =
Math.Lemmas.pow2_plus 1 (l - 1);
assert_norm (pow2 1 = 2);
assert (pow2 l = 2 * pow2 (l - 1));
Math.Lemmas.lemma_mod_mul_distr_l 2 (pow2 (l - 1)) 2
inline_for_extraction noextract
val lexp_fw_gen:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len{1 < v table_len /\ v table_len == pow2 (v l)}
-> lprecomp_get:pow_a_to_small_b_st a_t len ctx_len k l table_len
(table_inv_precomp len ctx_len k l table_len) ->
lexp_fw_st a_t len ctx_len k l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len:
Hacl.Impl.Exponentiation.table_len_t len
{1 < Lib.IntTypes.v table_len /\ Lib.IntTypes.v table_len == Prims.pow2 (Lib.IntTypes.v l)} ->
lprecomp_get:
Hacl.Impl.Exponentiation.pow_a_to_small_b_st a_t
len
ctx_len
k
l
table_len
(Hacl.Impl.Exponentiation.table_inv_precomp len ctx_len k l table_len)
-> Hacl.Impl.Exponentiation.lexp_fw_st a_t len ctx_len k l | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.pow2",
"Hacl.Impl.Exponentiation.pow_a_to_small_b_st",
"Hacl.Impl.Exponentiation.table_inv_precomp",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Exponentiation.mk_lexp_fw_table",
"Lib.Buffer.to_const",
"Lib.Buffer.MUT",
"Prims._assert",
"Lib.Buffer.as_seq",
"Lib.IntTypes.op_Star_Bang",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Exponentiation.table_inv_t",
"Hacl.Impl.PrecompTable.lprecomp_table",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.mul",
"Lib.Buffer.create",
"Lib.IntTypes.uint",
"Hacl.Impl.Exponentiation.lemma_pow2_is_divisible_by_2",
"FStar.Math.Lemmas.pow2_lt_compat",
"FStar.HyperStack.ST.push_frame"
] | [] | false | false | false | false | false | let lexp_fw_gen #a_t len ctx_len k l table_len lprecomp_get ctx a bLen bBits b res =
| push_frame ();
Math.Lemmas.pow2_lt_compat 32 (v l);
lemma_pow2_is_divisible_by_2 (v l);
let table = create (table_len *! len) (uint #a_t #SEC 0) in
PT.lprecomp_table #a_t len ctx_len k ctx a table_len table;
[@@ inline_let ]let table_inv:table_inv_t a_t len table_len =
table_inv_precomp len ctx_len k l table_len
in
let h1 = ST.get () in
assert (table_inv (as_seq h1 a) (as_seq h1 table));
mk_lexp_fw_table len ctx_len k l table_len table_inv lprecomp_get ctx a bLen bBits b
(to_const table) res;
pop_frame () | false |
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.collect_arr' | val collect_arr' (bs: list binder) (c: comp) : Tac (list binder * comp) | val collect_arr' (bs: list binder) (c: comp) : Tac (list binder * comp) | let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 7,
"end_line": 21,
"start_col": 0,
"start_line": 11
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | bs: Prims.list FStar.Stubs.Reflection.Types.binder -> c: FStar.Stubs.Reflection.Types.comp
-> FStar.Tactics.Effect.Tac
(Prims.list FStar.Stubs.Reflection.Types.binder * FStar.Stubs.Reflection.Types.comp) | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.Types.comp",
"FStar.Stubs.Reflection.V1.Builtins.inspect_comp",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Tactics.V1.SyntaxHelpers.collect_arr'",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Tactics.V1.Builtins.inspect",
"FStar.Stubs.Reflection.V1.Data.comp_view"
] | [
"recursion"
] | false | true | false | false | false | let rec collect_arr' (bs: list binder) (c: comp) : Tac (list binder * comp) =
| match inspect_comp c with
| C_Total t ->
(match inspect t with
| Tv_Arrow b c -> collect_arr' (b :: bs) c
| _ -> (bs, c))
| _ -> (bs, c) | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.hash_st | val hash_st : a: Spec.Hash.Definitions.fixed_len_alg -> Type0 | let hash_st (a: fixed_len_alg) =
output:hash_t a->
input:B.buffer uint8 ->
input_len:size_t { B.length input = v input_len } ->
ST.Stack unit
(requires (fun h ->
B.live h input /\
B.live h output /\
B.disjoint input output /\
B.length input `less_than_max_input_length` a))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer output) h0 h1) /\
Seq.equal (B.as_seq h1 output) (Spec.Agile.Hash.hash a (B.as_seq h0 input)))) | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 341,
"start_col": 0,
"start_line": 329
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *)
noextract inline_for_extraction
let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1))
noextract inline_for_extraction
let malloc_st (i:impl) = r:HS.rid -> ST.ST (state i)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
B.live h1 s /\
M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\
B.freeable s))
noextract inline_for_extraction
let init_st (i:impl) = s:state i -> ST.Stack unit
(requires (fun h ->
B.live h s))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i)))
noextract inline_for_extraction
let update_st (i:impl{is_md (get_alg i)}) =
s:state i ->
block:B.buffer uint8 { B.length block = block_length (get_alg i) } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h block /\ B.disjoint s block))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update (get_alg i) (as_seq h0 s) (B.as_seq h0 block)))
noextract inline_for_extraction
let pad_st (a: md_alg) = len:len_t a -> dst:B.buffer uint8 ->
ST.Stack unit
(requires (fun h ->
len_v a len `less_than_max_input_length` a /\
B.live h dst /\
B.length dst = pad_length a (len_v a len)))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer dst) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Hash.MD.pad a (len_v a len))))
// Note: we cannot take more than 4GB of data because we are currently
// constrained by the size of buffers...
noextract inline_for_extraction
let update_multi_st (i:impl) =
s:state i ->
ev:extra_state (get_alg i) ->
blocks:blocks_t (get_alg i) ->
n:size_t { B.length blocks = block_length (get_alg i) * v n } ->
ST.Stack unit
(requires (fun h ->
Spec.Agile.Hash.update_multi_pre (get_alg i) (ev_v ev) (B.as_seq h blocks) /\
B.live h s /\ B.live h blocks /\ B.disjoint s blocks))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update_multi (get_alg i) (as_seq h0 s) (ev_v ev) (B.as_seq h0 blocks)))
noextract inline_for_extraction
let prev_len_t (a: hash_alg) =
if is_keccak a then
unit
else
prev_len:len_t a { len_v a prev_len % block_length a = 0 }
noextract inline_for_extraction
let prev_len_v #a (prev_len: prev_len_t a): Spec.Hash.Incremental.Definitions.prev_length_t a
=
if is_keccak a then
()
else
len_v a prev_len
noextract inline_for_extraction
let extra_state_of_prev_length #a (x: Spec.Hash.Incremental.Definitions.prev_length_t a): Spec.Agile.Hash.extra_state a =
match a with
| Blake2B | Blake2S -> x
| _ -> ()
noextract inline_for_extraction
let update_last_st (i:impl) =
let a = get_alg i in
s:state i ->
prev_len:prev_len_t a ->
input:B.buffer uint8 {
(if is_keccak a then True else (B.length input + len_v a prev_len) `less_than_max_input_length` a) /\
B.length input <= block_length a
} ->
input_len:size_t { B.length input = v input_len } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h input /\ B.disjoint s input /\
Spec.Agile.Hash.update_multi_pre a (extra_state_of_prev_length (prev_len_v prev_len)) (B.as_seq h input)))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Hash.Incremental.update_last a (as_seq h0 s)
(prev_len_v prev_len)
(B.as_seq h0 input)))
inline_for_extraction noextract
let fixed_len_impl = i:impl { not (is_shake (dfst i)) }
noextract inline_for_extraction
let finish_st (i:fixed_len_impl) =
s:state i -> dst:hash_t (get_alg i) -> ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h dst /\ B.disjoint s dst))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer dst `loc_union` loc_buffer s) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Agile.Hash.finish (get_alg i) (as_seq h0 s) ()))) | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.fixed_len_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.fixed_len_alg",
"Hacl.Hash.Definitions.hash_t",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"LowStar.Monotonic.Buffer.disjoint",
"Spec.Hash.Definitions.less_than_max_input_length",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer",
"FStar.Seq.Base.equal",
"LowStar.Monotonic.Buffer.as_seq",
"Spec.Agile.Hash.hash"
] | [] | false | false | false | true | true | let hash_st (a: fixed_len_alg) =
| output: hash_t a -> input: B.buffer uint8 -> input_len: size_t{B.length input = v input_len}
-> ST.Stack unit
(requires
(fun h ->
B.live h input /\ B.live h output /\ B.disjoint input output /\
(B.length input) `less_than_max_input_length` a))
(ensures
(fun h0 _ h1 ->
B.(modifies (loc_buffer output) h0 h1) /\
Seq.equal (B.as_seq h1 output) (Spec.Agile.Hash.hash a (B.as_seq h0 input)))) | false |
|
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.collect_arr_bs | val collect_arr_bs : typ -> Tac (list binder * comp) | val collect_arr_bs : typ -> Tac (list binder * comp) | let collect_arr_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c) | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 26,
"start_col": 0,
"start_line": 24
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.typ
-> FStar.Tactics.Effect.Tac
(Prims.list FStar.Stubs.Reflection.Types.binder * FStar.Stubs.Reflection.Types.comp) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.typ",
"Prims.list",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.Types.comp",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Base.rev",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.SyntaxHelpers.collect_arr'",
"Prims.Nil",
"FStar.Stubs.Reflection.V1.Builtins.pack_comp",
"FStar.Stubs.Reflection.V1.Data.C_Total"
] | [] | false | true | false | false | false | let collect_arr_bs t =
| let bs, c = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c) | false |
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.collect_arr | val collect_arr : typ -> Tac (list typ * comp) | val collect_arr : typ -> Tac (list typ * comp) | let collect_arr t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
let ts = List.Tot.Base.map type_of_binder bs in
(List.Tot.Base.rev ts, c) | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 32,
"start_col": 0,
"start_line": 29
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.typ
-> FStar.Tactics.Effect.Tac
(Prims.list FStar.Stubs.Reflection.Types.typ * FStar.Stubs.Reflection.Types.comp) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.typ",
"Prims.list",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.Types.comp",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Base.rev",
"FStar.List.Tot.Base.map",
"FStar.Reflection.V1.Derived.type_of_binder",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.SyntaxHelpers.collect_arr'",
"Prims.Nil",
"FStar.Stubs.Reflection.V1.Builtins.pack_comp",
"FStar.Stubs.Reflection.V1.Data.C_Total"
] | [] | false | true | false | false | false | let collect_arr t =
| let bs, c = collect_arr' [] (pack_comp (C_Total t)) in
let ts = List.Tot.Base.map type_of_binder bs in
(List.Tot.Base.rev ts, c) | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.prev_len_v | val prev_len_v (#a: _) (prev_len: prev_len_t a) : Spec.Hash.Incremental.Definitions.prev_length_t a | val prev_len_v (#a: _) (prev_len: prev_len_t a) : Spec.Hash.Incremental.Definitions.prev_length_t a | let prev_len_v #a (prev_len: prev_len_t a): Spec.Hash.Incremental.Definitions.prev_length_t a
=
if is_keccak a then
()
else
len_v a prev_len | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 20,
"end_line": 287,
"start_col": 0,
"start_line": 282
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *)
noextract inline_for_extraction
let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1))
noextract inline_for_extraction
let malloc_st (i:impl) = r:HS.rid -> ST.ST (state i)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
B.live h1 s /\
M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\
B.freeable s))
noextract inline_for_extraction
let init_st (i:impl) = s:state i -> ST.Stack unit
(requires (fun h ->
B.live h s))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i)))
noextract inline_for_extraction
let update_st (i:impl{is_md (get_alg i)}) =
s:state i ->
block:B.buffer uint8 { B.length block = block_length (get_alg i) } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h block /\ B.disjoint s block))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update (get_alg i) (as_seq h0 s) (B.as_seq h0 block)))
noextract inline_for_extraction
let pad_st (a: md_alg) = len:len_t a -> dst:B.buffer uint8 ->
ST.Stack unit
(requires (fun h ->
len_v a len `less_than_max_input_length` a /\
B.live h dst /\
B.length dst = pad_length a (len_v a len)))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer dst) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Hash.MD.pad a (len_v a len))))
// Note: we cannot take more than 4GB of data because we are currently
// constrained by the size of buffers...
noextract inline_for_extraction
let update_multi_st (i:impl) =
s:state i ->
ev:extra_state (get_alg i) ->
blocks:blocks_t (get_alg i) ->
n:size_t { B.length blocks = block_length (get_alg i) * v n } ->
ST.Stack unit
(requires (fun h ->
Spec.Agile.Hash.update_multi_pre (get_alg i) (ev_v ev) (B.as_seq h blocks) /\
B.live h s /\ B.live h blocks /\ B.disjoint s blocks))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update_multi (get_alg i) (as_seq h0 s) (ev_v ev) (B.as_seq h0 blocks)))
noextract inline_for_extraction
let prev_len_t (a: hash_alg) =
if is_keccak a then
unit
else
prev_len:len_t a { len_v a prev_len % block_length a = 0 } | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | prev_len: Hacl.Hash.Definitions.prev_len_t a -> Spec.Hash.Incremental.Definitions.prev_length_t a | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Hacl.Hash.Definitions.prev_len_t",
"Spec.Hash.Definitions.is_keccak",
"Prims.bool",
"Spec.Hash.Definitions.len_v",
"Spec.Hash.Incremental.Definitions.prev_length_t"
] | [] | false | false | false | false | false | let prev_len_v #a (prev_len: prev_len_t a) : Spec.Hash.Incremental.Definitions.prev_length_t a =
| if is_keccak a then () else len_v a prev_len | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.extra_state_of_prev_length | val extra_state_of_prev_length (#a: _) (x: Spec.Hash.Incremental.Definitions.prev_length_t a)
: Spec.Agile.Hash.extra_state a | val extra_state_of_prev_length (#a: _) (x: Spec.Hash.Incremental.Definitions.prev_length_t a)
: Spec.Agile.Hash.extra_state a | let extra_state_of_prev_length #a (x: Spec.Hash.Incremental.Definitions.prev_length_t a): Spec.Agile.Hash.extra_state a =
match a with
| Blake2B | Blake2S -> x
| _ -> () | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 293,
"start_col": 0,
"start_line": 290
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *)
noextract inline_for_extraction
let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1))
noextract inline_for_extraction
let malloc_st (i:impl) = r:HS.rid -> ST.ST (state i)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
B.live h1 s /\
M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\
B.freeable s))
noextract inline_for_extraction
let init_st (i:impl) = s:state i -> ST.Stack unit
(requires (fun h ->
B.live h s))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i)))
noextract inline_for_extraction
let update_st (i:impl{is_md (get_alg i)}) =
s:state i ->
block:B.buffer uint8 { B.length block = block_length (get_alg i) } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h block /\ B.disjoint s block))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update (get_alg i) (as_seq h0 s) (B.as_seq h0 block)))
noextract inline_for_extraction
let pad_st (a: md_alg) = len:len_t a -> dst:B.buffer uint8 ->
ST.Stack unit
(requires (fun h ->
len_v a len `less_than_max_input_length` a /\
B.live h dst /\
B.length dst = pad_length a (len_v a len)))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer dst) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Hash.MD.pad a (len_v a len))))
// Note: we cannot take more than 4GB of data because we are currently
// constrained by the size of buffers...
noextract inline_for_extraction
let update_multi_st (i:impl) =
s:state i ->
ev:extra_state (get_alg i) ->
blocks:blocks_t (get_alg i) ->
n:size_t { B.length blocks = block_length (get_alg i) * v n } ->
ST.Stack unit
(requires (fun h ->
Spec.Agile.Hash.update_multi_pre (get_alg i) (ev_v ev) (B.as_seq h blocks) /\
B.live h s /\ B.live h blocks /\ B.disjoint s blocks))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update_multi (get_alg i) (as_seq h0 s) (ev_v ev) (B.as_seq h0 blocks)))
noextract inline_for_extraction
let prev_len_t (a: hash_alg) =
if is_keccak a then
unit
else
prev_len:len_t a { len_v a prev_len % block_length a = 0 }
noextract inline_for_extraction
let prev_len_v #a (prev_len: prev_len_t a): Spec.Hash.Incremental.Definitions.prev_length_t a
=
if is_keccak a then
()
else
len_v a prev_len | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Spec.Hash.Incremental.Definitions.prev_length_t a -> Spec.Hash.Definitions.extra_state a | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"Spec.Hash.Incremental.Definitions.prev_length_t",
"Spec.Hash.Definitions.extra_state"
] | [] | false | false | false | false | false | let extra_state_of_prev_length #a (x: Spec.Hash.Incremental.Definitions.prev_length_t a)
: Spec.Agile.Hash.extra_state a =
| match a with
| Blake2B | Blake2S -> x
| _ -> () | false |
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.collect_abs' | val collect_abs' (bs: list binder) (t: term) : Tac (list binder * term) (decreases t) | val collect_abs' (bs: list binder) (t: term) : Tac (list binder * term) (decreases t) | let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t) | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 18,
"end_line": 39,
"start_col": 0,
"start_line": 35
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
let ts = List.Tot.Base.map type_of_binder bs in
(List.Tot.Base.rev ts, c) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | bs: Prims.list FStar.Stubs.Reflection.Types.binder -> t: FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(Prims.list FStar.Stubs.Reflection.Types.binder * FStar.Stubs.Reflection.Types.term) | FStar.Tactics.Effect.Tac | [
""
] | [] | [
"Prims.list",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.Types.term",
"FStar.Tactics.V1.SyntaxHelpers.collect_abs'",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Tactics.V1.Builtins.inspect"
] | [
"recursion"
] | false | true | false | false | false | let rec collect_abs' (bs: list binder) (t: term) : Tac (list binder * term) (decreases t) =
| match inspect t with
| Tv_Abs b t' -> collect_abs' (b :: bs) t'
| _ -> (bs, t) | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.max_input_len64 | val max_input_len64 (a: _) : U64.(x: t{0 < v x /\ (v x) `less_than_max_input_length` a}) | val max_input_len64 (a: _) : U64.(x: t{0 < v x /\ (v x) `less_than_max_input_length` a}) | let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1)) | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 194,
"start_col": 0,
"start_line": 171
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64 | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Hash.Definitions.hash_alg
-> x:
FStar.UInt64.t
{ 0 < FStar.UInt64.v x /\
Spec.Hash.Definitions.less_than_max_input_length (FStar.UInt64.v x) a } | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.hash_alg",
"FStar.UInt64.uint_to_t",
"FStar.Pervasives.normalize_term",
"FStar.UInt.uint_t",
"FStar.UInt64.n",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.unit",
"FStar.Pervasives.normalize_term_spec",
"Prims.int",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"FStar.UInt64.t",
"Prims.l_and",
"FStar.UInt64.v",
"Spec.Hash.Definitions.less_than_max_input_length",
"FStar.Pervasives.allow_inversion"
] | [] | false | false | false | false | false | let max_input_len64 a : U64.(x: t{0 < v x /\ (v x) `less_than_max_input_length` a}) =
| let _ = allow_inversion hash_alg in
match a with
| MD5
| SHA1
| SHA2_224
| SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384
| SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224
| SHA3_256
| SHA3_384
| SHA3_512
| Shake128
| Shake256 ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1)) | false |
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.collect_abs | val collect_abs : term -> Tac (list binder * term) | val collect_abs : term -> Tac (list binder * term) | let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t') | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 30,
"end_line": 44,
"start_col": 0,
"start_line": 42
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
let ts = List.Tot.Base.map type_of_binder bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(Prims.list FStar.Stubs.Reflection.Types.binder * FStar.Stubs.Reflection.Types.term) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Base.rev",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.SyntaxHelpers.collect_abs'",
"Prims.Nil"
] | [] | false | true | false | false | false | let collect_abs t =
| let bs, t' = collect_abs' [] t in
(List.Tot.Base.rev bs, t') | false |
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.finish_st | val finish_st : i: Hacl.Hash.Definitions.fixed_len_impl -> Type0 | let finish_st (i:fixed_len_impl) =
s:state i -> dst:hash_t (get_alg i) -> ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h dst /\ B.disjoint s dst))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer dst `loc_union` loc_buffer s) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Agile.Hash.finish (get_alg i) (as_seq h0 s) ()))) | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 87,
"end_line": 326,
"start_col": 0,
"start_line": 320
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *)
noextract inline_for_extraction
let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1))
noextract inline_for_extraction
let malloc_st (i:impl) = r:HS.rid -> ST.ST (state i)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
B.live h1 s /\
M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\
B.freeable s))
noextract inline_for_extraction
let init_st (i:impl) = s:state i -> ST.Stack unit
(requires (fun h ->
B.live h s))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i)))
noextract inline_for_extraction
let update_st (i:impl{is_md (get_alg i)}) =
s:state i ->
block:B.buffer uint8 { B.length block = block_length (get_alg i) } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h block /\ B.disjoint s block))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update (get_alg i) (as_seq h0 s) (B.as_seq h0 block)))
noextract inline_for_extraction
let pad_st (a: md_alg) = len:len_t a -> dst:B.buffer uint8 ->
ST.Stack unit
(requires (fun h ->
len_v a len `less_than_max_input_length` a /\
B.live h dst /\
B.length dst = pad_length a (len_v a len)))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer dst) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Hash.MD.pad a (len_v a len))))
// Note: we cannot take more than 4GB of data because we are currently
// constrained by the size of buffers...
noextract inline_for_extraction
let update_multi_st (i:impl) =
s:state i ->
ev:extra_state (get_alg i) ->
blocks:blocks_t (get_alg i) ->
n:size_t { B.length blocks = block_length (get_alg i) * v n } ->
ST.Stack unit
(requires (fun h ->
Spec.Agile.Hash.update_multi_pre (get_alg i) (ev_v ev) (B.as_seq h blocks) /\
B.live h s /\ B.live h blocks /\ B.disjoint s blocks))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update_multi (get_alg i) (as_seq h0 s) (ev_v ev) (B.as_seq h0 blocks)))
noextract inline_for_extraction
let prev_len_t (a: hash_alg) =
if is_keccak a then
unit
else
prev_len:len_t a { len_v a prev_len % block_length a = 0 }
noextract inline_for_extraction
let prev_len_v #a (prev_len: prev_len_t a): Spec.Hash.Incremental.Definitions.prev_length_t a
=
if is_keccak a then
()
else
len_v a prev_len
noextract inline_for_extraction
let extra_state_of_prev_length #a (x: Spec.Hash.Incremental.Definitions.prev_length_t a): Spec.Agile.Hash.extra_state a =
match a with
| Blake2B | Blake2S -> x
| _ -> ()
noextract inline_for_extraction
let update_last_st (i:impl) =
let a = get_alg i in
s:state i ->
prev_len:prev_len_t a ->
input:B.buffer uint8 {
(if is_keccak a then True else (B.length input + len_v a prev_len) `less_than_max_input_length` a) /\
B.length input <= block_length a
} ->
input_len:size_t { B.length input = v input_len } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h input /\ B.disjoint s input /\
Spec.Agile.Hash.update_multi_pre a (extra_state_of_prev_length (prev_len_v prev_len)) (B.as_seq h input)))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Hash.Incremental.update_last a (as_seq h0 s)
(prev_len_v prev_len)
(B.as_seq h0 input)))
inline_for_extraction noextract
let fixed_len_impl = i:impl { not (is_shake (dfst i)) } | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Hacl.Hash.Definitions.fixed_len_impl -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.fixed_len_impl",
"Hacl.Hash.Definitions.state",
"Hacl.Hash.Definitions.hash_t",
"Hacl.Hash.Definitions.get_alg",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Hacl.Hash.Definitions.impl_word",
"LowStar.Buffer.trivial_preorder",
"Lib.IntTypes.uint8",
"LowStar.Monotonic.Buffer.disjoint",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.Monotonic.Buffer.loc_buffer",
"FStar.Seq.Base.equal",
"LowStar.Monotonic.Buffer.as_seq",
"Spec.Agile.Hash.finish",
"Hacl.Hash.Definitions.as_seq"
] | [] | false | false | false | true | true | let finish_st (i: fixed_len_impl) =
| s: state i -> dst: hash_t (get_alg i)
-> ST.Stack unit
(requires (fun h -> B.live h s /\ B.live h dst /\ B.disjoint s dst))
(ensures
(fun h0 _ h1 ->
M.(modifies ((loc_buffer dst) `loc_union` (loc_buffer s)) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Agile.Hash.finish (get_alg i) (as_seq h0 s) ()))) | false |
|
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_fw_loop | val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv | val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv | let lexp_fw_loop #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table acc =
push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@inline_let]
let spec (h:mem) = S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) in
[@inline_let]
let inv h (i:nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table) in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul (bBits /. l) inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b
ctx a bLen bBits b table i acc tmp
);
pop_frame () | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 439,
"start_col": 0,
"start_line": 414
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL)
//r0 = acc; r1 = a
let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame ()
let lexp_pow2 #a_t len ctx_len k ctx a b res =
copy res a;
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 res) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc res) h0 h /\
k.to.linv (as_seq h res) /\
k.to.refl (as_seq h res) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx res res)
let lexp_pow2_in_place #a_t len ctx_len k ctx acc b =
let h0 = ST.get () in
[@ inline_let]
let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@ inline_let]
let spec h0 = S.sqr k.to.comm_monoid in
[@ inline_let]
let inv h (i:nat{i <= v b}) =
modifies (loc acc) h0 h /\
k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeat i (spec h0) (refl1 0) in
Loops.eq_repeat0 (spec h0) (refl1 0);
Lib.Loops.for 0ul b inv
(fun j ->
Loops.unfold_repeat (v b) (spec h0) (refl1 0) (v j);
k.lsqr ctx acc acc)
//---------------------------------------------------
#set-options "--z3rlimit 100"
inline_for_extraction noextract
val bn_get_bits_l:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t}
-> i:size_t{v i < v bBits / v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == S.get_bits_l (v bBits) (BD.bn_v h0 b) (v l) (v i))
let bn_get_bits_l #b_t bLen bBits b l i =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits -! bBits %. l) = v bBits - v bBits % v l);
[@inline_let] let bk = bBits -! bBits %. l in
assert (v bk == v bBits - v bBits % v l);
Math.Lemmas.lemma_mult_le_left (v l) (v i + 1) (v bBits / v l);
assert (v l * (v i + 1) <= v l * (v bBits / v l));
Math.Lemmas.distributivity_add_right (v l) (v i) 1;
assert (v l * v i + v l <= v bk);
assert (v (bk -! l *! i -! l) == v bk - v l * v i - v l);
let k = bk -! l *! i -! l in
assert (v k == v bk - v l * v i - v l);
Math.Lemmas.lemma_div_le (v k) (v bBits - 1) (bits b_t);
assert (v k / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v k) (v l);
BN.bn_get_bits bLen b k l
inline_for_extraction noextract
val bn_get_bits_c:
#b_t:inttype_a
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits b_t < v bLen}
-> b:lbuffer (uint_t b_t SEC) bLen
-> l:size_t{0 < v l /\ v l < bits b_t /\ 0 < v bBits % v l} ->
Stack (uint_t b_t SEC)
(requires fun h -> live h b /\
BD.bn_v h b < pow2 (v bBits))
(ensures fun h0 r h1 -> h0 == h1 /\
v r == (BD.bn_v h0 b / pow2 (v bBits / v l * v l)) % pow2 (v l))
let bn_get_bits_c #b_t bLen bBits b l =
Math.Lemmas.euclidean_division_definition (v bBits) (v l);
assert (v (bBits /. l *! l) == v bBits / v l * v l);
let i = bBits /. l *! l in
assert (v i == v bBits / v l * v l);
assert (v i <= v bBits - 1);
Math.Lemmas.lemma_div_le (v i) (v bBits - 1) (bits b_t);
assert (v i / bits b_t < v bLen);
let h0 = ST.get () in
SN.bn_get_bits_lemma (as_seq h0 b) (v i) (v l);
BN.bn_get_bits bLen b i l
//---------------------------------------------------
inline_for_extraction noextract
let lmul_acc_pow_a_bits_l_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.mul_acc_pow_a_bits_l #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc * a^b_i
inline_for_extraction noextract
val lmul_acc_pow_a_bits_l:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lmul_acc_pow_a_bits_l_st a_t len ctx_len k l table_len table_inv
let lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
let h0 = ST.get () in
push_frame ();
let bits_l = bn_get_bits_l bLen bBits b l i in
assert (v bits_l < pow2 (v l));
pow_a_to_small_b ctx (as_seq h0 a) table bits_l tmp;
k.lmul ctx acc tmp acc;
pop_frame ()
inline_for_extraction noextract
let lexp_fw_f_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> i:size_t{v i < v bBits / v l}
-> acc:lbuffer (uint_t a_t SEC) len
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
live h tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint tmp acc /\ disjoint tmp ctx /\ disjoint tmp table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc |+| loc tmp) h0 h1 /\
k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
S.exp_fw_f #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l) (v i) (k.to.refl (as_seq h0 acc)))
// acc <- acc^(2^l) * a^b_i
inline_for_extraction noextract
val lexp_fw_f:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_f_st a_t len ctx_len k l table_len table_inv
let lexp_fw_f #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp =
lexp_pow2_in_place len ctx_len k ctx acc l;
lmul_acc_pow_a_bits_l #a_t len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc tmp
inline_for_extraction noextract
let lexp_fw_loop_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(l:size_window_t a_t len)
(table_len:table_len_t len)
(table_inv:table_inv_t a_t len table_len) =
ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> acc:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h acc /\ live h ctx /\ live h table /\
disjoint a acc /\ disjoint a ctx /\ disjoint b acc /\
disjoint acc ctx /\ disjoint acc table /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
table_inv (as_seq h a) (as_seq h table))
(ensures fun h0 _ h1 -> modifies (loc acc) h0 h1 /\ k.to.linv (as_seq h1 acc) /\
k.to.refl (as_seq h1 acc) ==
Loops.repeati (v bBits / v l) (S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a))
(v bBits) (BD.bn_v h0 b) (v l)) (k.to.refl (as_seq h0 acc)))
inline_for_extraction noextract
val lexp_fw_loop:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> l:size_window_t a_t len
-> table_len:table_len_t len
-> table_inv:table_inv_t a_t len table_len
-> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv ->
lexp_fw_loop_st a_t len ctx_len k l table_len table_inv | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
l: Hacl.Impl.Exponentiation.size_window_t a_t len ->
table_len: Hacl.Impl.Exponentiation.table_len_t len ->
table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len ->
pow_a_to_small_b:
Hacl.Impl.Exponentiation.pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv
-> Hacl.Impl.Exponentiation.lexp_fw_loop_st a_t len ctx_len k l table_len table_inv | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Hacl.Impl.Exponentiation.size_window_t",
"Hacl.Impl.Exponentiation.table_len_t",
"Hacl.Impl.Exponentiation.table_inv_t",
"Hacl.Impl.Exponentiation.pow_a_to_small_b_st",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.Loops.for",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Slash_Dot",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Hacl.Impl.Exponentiation.lexp_fw_f",
"Lib.LoopCombinators.unfold_repeati",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Lib.LoopCombinators.eq_repeati0",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.logical",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Lib.Buffer.as_seq",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.LoopCombinators.repeati",
"Lib.Buffer.CONST",
"Lib.Exponentiation.exp_fw_f",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid",
"Hacl.Bignum.Definitions.bn_v",
"Prims.int",
"FStar.HyperStack.ST.get",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.Buffer.create",
"Lib.IntTypes.uint",
"FStar.HyperStack.ST.push_frame"
] | [] | false | false | false | false | false | let lexp_fw_loop
#a_t
len
ctx_len
k
l
table_len
table_inv
pow_a_to_small_b
ctx
a
bLen
bBits
b
table
acc
=
| push_frame ();
let tmp = create len (uint #a_t #SEC 0) in
let h0 = ST.get () in
[@@ inline_let ]let refl1 i : GTot k.to.a_spec = k.to.refl (as_seq h0 acc) in
[@@ inline_let ]let spec (h: mem) =
S.exp_fw_f k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l)
in
[@@ inline_let ]let inv h (i: nat{i <= v bBits / v l}) =
modifies (loc acc |+| loc tmp) h0 h /\ k.to.linv (as_seq h acc) /\
k.to.refl (as_seq h acc) == Loops.repeati i (spec h0) (refl1 0) /\
table_inv (as_seq h a) (as_seq h table)
in
Loops.eq_repeati0 (v bBits / v l) (spec h0) (refl1 0);
Lib.Loops.for 0ul
(bBits /. l)
inv
(fun i ->
Loops.unfold_repeati (v bBits / v l) (spec h0) (refl1 0) (v i);
lexp_fw_f len ctx_len k l table_len table_inv pow_a_to_small_b ctx a bLen bBits b table i acc
tmp);
pop_frame () | false |
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.fail | val fail : m: Prims.string -> FStar.Tactics.Effect.Tac a | let fail (#a:Type) (m:string) = raise #a (TacticFailure m) | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 48,
"start_col": 0,
"start_line": 48
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
let ts = List.Tot.Base.map type_of_binder bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.Derived *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: Prims.string -> FStar.Tactics.Effect.Tac a | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.string",
"FStar.Tactics.Effect.raise",
"FStar.Stubs.Tactics.Common.TacticFailure"
] | [] | false | true | false | false | false | let fail (#a: Type) (m: string) =
| raise #a (TacticFailure m) | false |
|
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.collect_app' | val collect_app' (args: list argv) (t: term) : Tac (term * list argv) | val collect_app' (args: list argv) (t: term) : Tac (term * list argv) | let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args) | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 93,
"start_col": 0,
"start_line": 88
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
let ts = List.Tot.Base.map type_of_binder bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m)
let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (pack_comp (C_Total (mk_arr bs cod))))
let rec mk_arr_curried (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack_curried (Tv_Arrow b cod)
| (b::bs) -> pack_curried (Tv_Arrow b (pack_comp (C_Total (mk_arr_curried bs cod))))
let rec mk_tot_arr (bs: list binder) (cod : term) : Tac term =
match bs with
| [] -> cod
| (b::bs) ->
pack (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr bs cod))))
let lookup_lb_view (lbs:list letbinding) (nm:name) : Tac lb_view =
let o = FStar.List.Tot.Base.find
(fun lb ->
let lbv = inspect_lb lb in
(inspect_fv lbv.lb_fv) = nm)
lbs
in
match o with
| Some lb -> inspect_lb lb
| None -> fail "lookup_lb_view: Name not in let group"
let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | args: Prims.list FStar.Stubs.Reflection.V1.Data.argv -> t: FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Stubs.Reflection.Types.term * Prims.list FStar.Stubs.Reflection.V1.Data.argv) | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Stubs.Reflection.V1.Data.argv",
"FStar.Stubs.Reflection.Types.term",
"FStar.Tactics.V1.SyntaxHelpers.collect_app'",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.Mktuple2",
"Prims.b2t",
"FStar.Stubs.Reflection.V1.Data.notAscription",
"FStar.Tactics.V1.SyntaxHelpers.inspect_unascribe"
] | [
"recursion"
] | false | true | false | false | false | let rec collect_app' (args: list argv) (t: term) : Tac (term * list argv) =
| match inspect_unascribe t with
| Tv_App l r -> collect_app' (r :: args) l
| _ -> (t, args) | false |
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.collect_app | val collect_app : t: FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Stubs.Reflection.Types.term * Prims.list FStar.Stubs.Reflection.V1.Data.argv) | let collect_app = collect_app' [] | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 95,
"start_col": 0,
"start_line": 95
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
let ts = List.Tot.Base.map type_of_binder bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m)
let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (pack_comp (C_Total (mk_arr bs cod))))
let rec mk_arr_curried (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack_curried (Tv_Arrow b cod)
| (b::bs) -> pack_curried (Tv_Arrow b (pack_comp (C_Total (mk_arr_curried bs cod))))
let rec mk_tot_arr (bs: list binder) (cod : term) : Tac term =
match bs with
| [] -> cod
| (b::bs) ->
pack (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr bs cod))))
let lookup_lb_view (lbs:list letbinding) (nm:name) : Tac lb_view =
let o = FStar.List.Tot.Base.find
(fun lb ->
let lbv = inspect_lb lb in
(inspect_fv lbv.lb_fv) = nm)
lbs
in
match o with
| Some lb -> inspect_lb lb
| None -> fail "lookup_lb_view: Name not in let group"
let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv
(* Helpers for dealing with nested applications and arrows *)
let rec collect_app' (args : list argv) (t : term)
: Tac (term * list argv) =
match inspect_unascribe t with
| Tv_App l r ->
collect_app' (r::args) l
| _ -> (t, args) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Stubs.Reflection.Types.term * Prims.list FStar.Stubs.Reflection.V1.Data.argv) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.V1.SyntaxHelpers.collect_app'",
"Prims.Nil",
"FStar.Stubs.Reflection.V1.Data.argv"
] | [] | false | true | false | false | false | let collect_app =
| collect_app' [] | false |
|
Hacl.Hash.Definitions.fst | Hacl.Hash.Definitions.update_last_st | val update_last_st : i: Hacl.Hash.Definitions.impl -> Type0 | let update_last_st (i:impl) =
let a = get_alg i in
s:state i ->
prev_len:prev_len_t a ->
input:B.buffer uint8 {
(if is_keccak a then True else (B.length input + len_v a prev_len) `less_than_max_input_length` a) /\
B.length input <= block_length a
} ->
input_len:size_t { B.length input = v input_len } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h input /\ B.disjoint s input /\
Spec.Agile.Hash.update_multi_pre a (extra_state_of_prev_length (prev_len_v prev_len)) (B.as_seq h input)))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Hash.Incremental.update_last a (as_seq h0 s)
(prev_len_v prev_len)
(B.as_seq h0 input))) | {
"file_name": "code/hash/Hacl.Hash.Definitions.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 314,
"start_col": 0,
"start_line": 296
} | module Hacl.Hash.Definitions
module HS = FStar.HyperStack
module ST = FStar.HyperStack.ST
module M = LowStar.Modifies
module B = LowStar.Buffer
module Blake2 = Hacl.Impl.Blake2.Core
open Lib.IntTypes
open Spec.Hash.Definitions
open FStar.Mul
#set-options "--z3rlimit 25 --fuel 0 --ifuel 1"
(** The low-level types that our clients need to be aware of, in order to
successfully call this module. *)
inline_for_extraction noextract
let m_spec (a:hash_alg) : Type0 =
match a with
| Blake2S | Blake2B -> Blake2.m_spec
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let extra_state (a:hash_alg) : Type0 =
match a with
| Blake2S -> s:uint_t U64 PUB{ v s % block_length a = 0 }
| Blake2B -> s:uint_t U128 PUB{ v s % block_length a = 0 }
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> unit
inline_for_extraction noextract
let ev_v (#a:hash_alg) (ev:extra_state a) : Spec.Hash.Definitions.extra_state a =
match a with
| Blake2S -> v #U64 #PUB ev
| Blake2B -> v #U128 #PUB ev
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> ()
inline_for_extraction
type impl = a:hash_alg & m_spec a
inline_for_extraction noextract
let mk_impl (a:hash_alg) (m:m_spec a) : impl = (|a, m|)
inline_for_extraction noextract
let get_alg (i:impl) : hash_alg =
match i with (|a, m|) -> a
inline_for_extraction noextract
let get_spec (i:impl) : m_spec (get_alg i) =
match i with (|a, m|) -> m
inline_for_extraction noextract
let impl_word (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> Blake2.element_t (to_blake_alg a) (get_spec i)
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> word a
inline_for_extraction noextract
let impl_state_length (i:impl) =
[@inline_let] let a = get_alg i in
match a with
| Blake2S | Blake2B -> UInt32.v (4ul *. Blake2.row_len (to_blake_alg a) (get_spec i))
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> state_word_length a
inline_for_extraction noextract
let impl_state_len (i:impl) : s:size_t{size_v s == impl_state_length i} =
[@inline_let] let a = get_alg i in
[@inline_let] let m = get_spec i in
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 | SHA2_256 | SHA2_384 | SHA2_512 -> 8ul
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> 25ul
| _ ->
(**) mul_mod_lemma 4ul (Blake2.row_len (to_blake_alg a) (get_spec i));
match a, m with
| Blake2S, Blake2.M32
| Blake2B, Blake2.M32 | Blake2B, Blake2.M128 -> 16ul
| Blake2S, Blake2.M128 | Blake2S, Blake2.M256
| Blake2B, Blake2.M256 -> 4ul
inline_for_extraction noextract
type state (i:impl) =
b:B.buffer (impl_word i) { B.length b = impl_state_length i }
inline_for_extraction noextract
let as_seq (#i:impl) (h:HS.mem) (s:state i) : GTot (words_state (get_alg i)) =
match get_alg i with
| Blake2S -> Blake2.state_v #Spec.Blake2.Blake2S #(get_spec i) h s
| Blake2B -> Blake2.state_v #Spec.Blake2.Blake2B #(get_spec i) h s
| MD5 | SHA1
| SHA2_224 | SHA2_256
| SHA2_384 | SHA2_512
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 -> B.as_seq h s
inline_for_extraction
let word_len (a: md_alg) : n:size_t { v n = word_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 4ul
| SHA2_384 | SHA2_512 -> 8ul
inline_for_extraction
let block_len (a: hash_alg): n:size_t { v n = block_length a } =
match a with
| MD5 | SHA1 | SHA2_224 | SHA2_256 -> 64ul
| SHA2_384 | SHA2_512 -> 128ul
| SHA3_224 -> assert_norm (rate SHA3_224/8/8*8 = 144); 144ul
| SHA3_256 -> assert_norm (rate SHA3_256/8/8*8 = 136); 136ul
| SHA3_384 -> assert_norm (rate SHA3_384/8/8*8 = 104); 104ul
| SHA3_512 -> assert_norm (rate SHA3_512/8/8*8 = 72); 72ul
| Shake128 -> assert_norm (rate Shake128/8/8*8 = 168); 168ul
| Shake256 -> assert_norm (rate Shake256/8/8*8 = 136); 136ul
| Blake2S -> 64ul
| Blake2B -> 128ul
inline_for_extraction
let hash_word_len (a: md_alg): n:size_t { v n = hash_word_length a } =
match a with
| MD5 -> 4ul
| SHA1 -> 5ul
| SHA2_224 -> 7ul
| SHA2_256 -> 8ul
| SHA2_384 -> 6ul
| SHA2_512 -> 8ul
inline_for_extraction
let hash_len (a: fixed_len_alg): n:size_t { v n = hash_length a } =
match a with
| MD5 -> 16ul
| SHA1 -> 20ul
| SHA2_224 -> 28ul
| SHA2_256 -> 32ul
| SHA2_384 -> 48ul
| SHA2_512 -> 64ul
| Blake2S -> 32ul
| Blake2B -> 64ul
| SHA3_224 -> 28ul
| SHA3_256 -> 32ul
| SHA3_384 -> 48ul
| SHA3_512 -> 64ul
/// Maximum input length, but fitting on a 64-bit integer (since the streaming
/// module doesn't bother taking into account lengths that are greater than
/// that). The comment previously was:
///
/// Note that we keep the total length at run-time, on 64 bits, but require that
/// it abides by the size requirements for the smaller hashes -- we're not
/// interested at this stage in having an agile type for lengths that would be
/// up to 2^125 for SHA384/512.
module U64 = FStar.UInt64
inline_for_extraction noextract
let max_input_len64 a: U64.(x:t { 0 < v x /\ v x `less_than_max_input_length` a }) =
let _ = allow_inversion hash_alg in
match a with
| MD5 | SHA1
| SHA2_224 | SHA2_256 ->
assert_norm (0 < pow2 61 - 1 && pow2 61 < pow2 64);
normalize_term_spec (pow2 61 - 1);
U64.uint_to_t (normalize_term (pow2 61 - 1))
| SHA2_384 | SHA2_512 ->
assert_norm (pow2 64 < pow2 125 - 1);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2S ->
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| Blake2B ->
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
| SHA3_224 | SHA3_256 | SHA3_384 | SHA3_512 | Shake128 | Shake256 ->
// TODO: relax this?
assert_norm (pow2 64 < pow2 128);
normalize_term_spec (pow2 64 - 1);
U64.uint_to_t (normalize_term (pow2 64 - 1))
noextract inline_for_extraction
let blocks_t (a: hash_alg) =
b:B.buffer uint8 { B.length b % block_length a = 0 }
let hash_t (a: fixed_len_alg) = b:B.buffer uint8 { B.length b = hash_length a }
(** The types of all stateful operations for a hash algorithm. *)
noextract inline_for_extraction
let alloca_st (i:impl) = unit -> ST.StackInline (state i)
(requires (fun h ->
HS.is_stack_region (HS.get_tip h)))
(ensures (fun h0 s h1 ->
M.(modifies M.loc_none h0 h1) /\
B.frameOf s == HS.get_tip h0 /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i) /\
B.live h1 s /\
B.fresh_loc (M.loc_buffer s) h0 h1))
noextract inline_for_extraction
let malloc_st (i:impl) = r:HS.rid -> ST.ST (state i)
(requires (fun h ->
ST.is_eternal_region r))
(ensures (fun h0 s h1 ->
B.live h1 s /\
M.(modifies M.loc_none h0 h1) /\
B.fresh_loc (M.loc_addr_of_buffer s) h0 h1 /\
M.(loc_includes (loc_region_only true r) (loc_addr_of_buffer s)) /\
B.freeable s))
noextract inline_for_extraction
let init_st (i:impl) = s:state i -> ST.Stack unit
(requires (fun h ->
B.live h s))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s == Spec.Agile.Hash.init (get_alg i)))
noextract inline_for_extraction
let update_st (i:impl{is_md (get_alg i)}) =
s:state i ->
block:B.buffer uint8 { B.length block = block_length (get_alg i) } ->
ST.Stack unit
(requires (fun h ->
B.live h s /\ B.live h block /\ B.disjoint s block))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update (get_alg i) (as_seq h0 s) (B.as_seq h0 block)))
noextract inline_for_extraction
let pad_st (a: md_alg) = len:len_t a -> dst:B.buffer uint8 ->
ST.Stack unit
(requires (fun h ->
len_v a len `less_than_max_input_length` a /\
B.live h dst /\
B.length dst = pad_length a (len_v a len)))
(ensures (fun h0 _ h1 ->
M.(modifies (loc_buffer dst) h0 h1) /\
Seq.equal (B.as_seq h1 dst) (Spec.Hash.MD.pad a (len_v a len))))
// Note: we cannot take more than 4GB of data because we are currently
// constrained by the size of buffers...
noextract inline_for_extraction
let update_multi_st (i:impl) =
s:state i ->
ev:extra_state (get_alg i) ->
blocks:blocks_t (get_alg i) ->
n:size_t { B.length blocks = block_length (get_alg i) * v n } ->
ST.Stack unit
(requires (fun h ->
Spec.Agile.Hash.update_multi_pre (get_alg i) (ev_v ev) (B.as_seq h blocks) /\
B.live h s /\ B.live h blocks /\ B.disjoint s blocks))
(ensures (fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Agile.Hash.update_multi (get_alg i) (as_seq h0 s) (ev_v ev) (B.as_seq h0 blocks)))
noextract inline_for_extraction
let prev_len_t (a: hash_alg) =
if is_keccak a then
unit
else
prev_len:len_t a { len_v a prev_len % block_length a = 0 }
noextract inline_for_extraction
let prev_len_v #a (prev_len: prev_len_t a): Spec.Hash.Incremental.Definitions.prev_length_t a
=
if is_keccak a then
()
else
len_v a prev_len
noextract inline_for_extraction
let extra_state_of_prev_length #a (x: Spec.Hash.Incremental.Definitions.prev_length_t a): Spec.Agile.Hash.extra_state a =
match a with
| Blake2B | Blake2S -> x
| _ -> () | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.MD.fst.checked",
"Spec.Hash.Incremental.Definitions.fst.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Blake2.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Impl.Blake2.Core.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Hash.Definitions.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Blake2.Core",
"short_module": "Blake2"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowStar.Modifies",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Hacl.Hash.Definitions.impl -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.Definitions.impl",
"Hacl.Hash.Definitions.state",
"Hacl.Hash.Definitions.prev_len_t",
"LowStar.Buffer.buffer",
"Lib.IntTypes.uint8",
"Prims.l_and",
"Spec.Hash.Definitions.is_keccak",
"Prims.l_True",
"Prims.bool",
"Prims.b2t",
"Spec.Hash.Definitions.less_than_max_input_length",
"Prims.op_Addition",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"Spec.Hash.Definitions.len_v",
"Prims.logical",
"Prims.op_LessThanOrEqual",
"Spec.Hash.Definitions.block_length",
"Lib.IntTypes.size_t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.U32",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.live",
"Hacl.Hash.Definitions.impl_word",
"LowStar.Monotonic.Buffer.disjoint",
"Spec.Agile.Hash.update_multi_pre",
"Hacl.Hash.Definitions.extra_state_of_prev_length",
"Hacl.Hash.Definitions.prev_len_v",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer",
"Prims.eq2",
"Lib.Sequence.seq",
"Spec.Hash.Definitions.word",
"Hacl.Hash.Definitions.get_alg",
"Prims.nat",
"FStar.Seq.Base.length",
"Spec.Hash.Definitions.state_word_length",
"Hacl.Hash.Definitions.as_seq",
"Spec.Hash.Incremental.Definitions.update_last",
"Spec.Hash.Definitions.hash_alg"
] | [] | false | false | false | true | true | let update_last_st (i: impl) =
| let a = get_alg i in
s: state i ->
prev_len: prev_len_t a ->
input:
B.buffer uint8
{ (if is_keccak a
then True
else (B.length input + len_v a prev_len) `less_than_max_input_length` a) /\
B.length input <= block_length a } ->
input_len: size_t{B.length input = v input_len}
-> ST.Stack unit
(requires
(fun h ->
B.live h s /\ B.live h input /\ B.disjoint s input /\
Spec.Agile.Hash.update_multi_pre a
(extra_state_of_prev_length (prev_len_v prev_len))
(B.as_seq h input)))
(ensures
(fun h0 _ h1 ->
B.(modifies (loc_buffer s) h0 h1) /\
as_seq h1 s ==
Spec.Hash.Incremental.update_last a
(as_seq h0 s)
(prev_len_v prev_len)
(B.as_seq h0 input))) | false |
|
LowParse.BitFields.fsti | LowParse.BitFields.uint_t_uint_to_t_v | val uint_t_uint_to_t_v (#tot #t: _) (cl: uint_t tot t) (x: t)
: Lemma (cl.uint_to_t (cl.v x) == x) [SMTPat (cl.uint_to_t (cl.v x))] | val uint_t_uint_to_t_v (#tot #t: _) (cl: uint_t tot t) (x: t)
: Lemma (cl.uint_to_t (cl.v x) == x) [SMTPat (cl.uint_to_t (cl.v x))] | let uint_t_uint_to_t_v #tot #t (cl: uint_t tot t) (x: t) : Lemma
(cl.uint_to_t (cl.v x) == x)
[SMTPat (cl.uint_to_t (cl.v x))]
= cl.uint_to_t_v x | {
"file_name": "src/lowparse/LowParse.BitFields.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 18,
"end_line": 289,
"start_col": 0,
"start_line": 286
} | module LowParse.BitFields
module U = FStar.UInt
type ubitfield (tot: nat) (sz: nat) = (x: U.uint_t tot { x < pow2 sz })
// IMPORTANT: these bitfield operators are defined in a least
// significant bit (LSB) first fashion.
val get_bitfield
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Tot (ubitfield tot (hi - lo))
val get_bitfield_logor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi)
val get_bitfield_logxor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi)
val set_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Tot (U.uint_t tot)
val get_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(get_bitfield (set_bitfield x lo hi v) lo hi == v)
val get_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot })
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi'))
val set_bitfield_set_bitfield_same_gen
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot })
(v' : ubitfield tot (hi' - lo'))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v'))
let set_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(v' : ubitfield tot (hi - lo))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v'))
= set_bitfield_set_bitfield_same_gen x lo hi v lo hi v'
val set_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo'))
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v))
val set_bitfield_full
(#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot)
: Lemma
(set_bitfield x 0 tot y == y)
val set_bitfield_empty
(#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0)
: Lemma
(set_bitfield x i i y == x)
val get_bitfield_zero
(tot: pos)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield #tot 0 lo hi == 0)
val get_bitfield_full
(#tot: pos)
(x: U.uint_t tot)
: Lemma
(get_bitfield x 0 tot == x)
val get_bitfield_empty
(#tot: pos)
(x: U.uint_t tot)
(i: nat { i <= tot })
: Lemma
(get_bitfield x i i == 0)
val lt_pow2_get_bitfield_hi
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (x < pow2 mi))
(ensures (get_bitfield x mi tot == 0))
val get_bitfield_hi_lt_pow2
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (get_bitfield x mi tot == 0))
(ensures (x < pow2 mi))
val get_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo })
: Lemma
(get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi'))
val get_bitfield_zero_inner
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi })
: Lemma
(ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0))
val set_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(set_bitfield x lo hi (get_bitfield x lo hi) == x)
val get_bitfield_partition_2_gen
(#tot: pos)
(lo: nat)
(mi: nat)
(hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x lo mi == get_bitfield y lo mi /\
get_bitfield x mi hi == get_bitfield y mi hi
))
(ensures (
get_bitfield x lo hi == get_bitfield y lo hi
))
val get_bitfield_partition_2
(#tot: pos)
(mid: nat { mid <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 mid == get_bitfield y 0 mid /\
get_bitfield x mid tot == get_bitfield y mid tot
))
(ensures (
x == y
))
let rec get_bitfield_partition_prop
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Tot bool
(decreases l)
= match l with
| [] ->
get_bitfield x lo hi = get_bitfield y lo hi
| mi :: q ->
lo <= mi && mi <= hi &&
get_bitfield_partition_prop x y mi hi q &&
get_bitfield x lo mi = get_bitfield y lo mi
val get_bitfield_partition
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Lemma
(requires (get_bitfield_partition_prop x y lo hi l))
(ensures (get_bitfield x lo hi == get_bitfield y lo hi))
let get_bitfield_partition_3
(#tot: pos)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 lo == get_bitfield y 0 lo /\
get_bitfield x lo hi == get_bitfield y lo hi /\
get_bitfield x hi tot == get_bitfield y hi tot
))
(ensures (x == y))
= assert_norm (get_bitfield_partition_prop x y 0 tot [lo; hi]); // does not need fuel, thanks to normalization
get_bitfield_partition x y 0 tot [lo; hi];
get_bitfield_full x;
get_bitfield_full y
val get_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
: Lemma
(x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat))
val set_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
(v: ubitfield tot1 (hi - lo))
: Lemma
(x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat))
val set_bitfield_bound
(#tot: pos)
(x: U.uint_t tot)
(bound: nat { bound <= tot /\ x < pow2 bound })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= bound })
(v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v < pow2 bound)
val set_bitfield_set_bitfield_get_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= hi - lo }) (v' : ubitfield tot (hi' - lo'))
: Lemma
( let v = set_bitfield (get_bitfield x lo hi) lo' hi' v' in
v < pow2 (hi - lo) /\
set_bitfield x lo hi v == set_bitfield x (lo + lo') (lo + hi') v' )
val get_bitfield_eq
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo))
val get_bitfield_eq_2
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo))
val set_bitfield_eq
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo))
module U32 = FStar.UInt32
inline_for_extraction
noextract
noeq
type uint_t (tot: pos) (t: Type) = {
v: (t -> Tot (U.uint_t tot));
uint_to_t: (U.uint_t tot -> Tot t);
v_uint_to_t: ((x: U.uint_t tot) -> Lemma (v (uint_to_t x) == x));
uint_to_t_v: ((x: t) -> Lemma (uint_to_t (v x) == x));
get_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) (U32.v lo) (U32.v hi) }));
set_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> (z: t { v z < pow2 (U32.v hi - U32.v lo) }) -> Tot (y : t { v y == set_bitfield (v x) (U32.v lo) (U32.v hi) (v z)}));
get_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) lo hi }));
set_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y : t { v y == set_bitfield (v x) lo hi (v z)}));
logor: ((x: t) -> (y: t) -> Tot (z: t { v z == v x `U.logor` v y }));
bitfield_eq_lhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot t);
bitfield_eq_rhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y: t { bitfield_eq_lhs x lo hi == y <==> (get_bitfield x lo hi <: t) == z }));
}
inline_for_extraction
let bitfield (#tot: pos) (#t: Type) (cl: uint_t tot t) (sz: nat { sz <= tot }) : Tot Type =
(x: t { cl.v x < pow2 sz })
let uint_t_v_uint_to_t #tot #t (cl: uint_t tot t) (x: U.uint_t tot) : Lemma
(cl.v (cl.uint_to_t x) == x)
[SMTPat (cl.v (cl.uint_to_t x))]
= cl.v_uint_to_t x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.BitFields.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | cl: LowParse.BitFields.uint_t tot t -> x: t
-> FStar.Pervasives.Lemma (ensures Mkuint_t?.uint_to_t cl (Mkuint_t?.v cl x) == x)
[SMTPat (Mkuint_t?.uint_to_t cl (Mkuint_t?.v cl x))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"LowParse.BitFields.uint_t",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t_v",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let uint_t_uint_to_t_v #tot #t (cl: uint_t tot t) (x: t)
: Lemma (cl.uint_to_t (cl.v x) == x) [SMTPat (cl.uint_to_t (cl.v x))] =
| cl.uint_to_t_v x | false |
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.lookup_lb_view | val lookup_lb_view (lbs: list letbinding) (nm: name) : Tac lb_view | val lookup_lb_view (lbs: list letbinding) (nm: name) : Tac lb_view | let lookup_lb_view (lbs:list letbinding) (nm:name) : Tac lb_view =
let o = FStar.List.Tot.Base.find
(fun lb ->
let lbv = inspect_lb lb in
(inspect_fv lbv.lb_fv) = nm)
lbs
in
match o with
| Some lb -> inspect_lb lb
| None -> fail "lookup_lb_view: Name not in let group" | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 78,
"start_col": 0,
"start_line": 69
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
let ts = List.Tot.Base.map type_of_binder bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m)
let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (pack_comp (C_Total (mk_arr bs cod))))
let rec mk_arr_curried (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack_curried (Tv_Arrow b cod)
| (b::bs) -> pack_curried (Tv_Arrow b (pack_comp (C_Total (mk_arr_curried bs cod))))
let rec mk_tot_arr (bs: list binder) (cod : term) : Tac term =
match bs with
| [] -> cod
| (b::bs) ->
pack (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr bs cod)))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | lbs: Prims.list FStar.Stubs.Reflection.Types.letbinding -> nm: FStar.Stubs.Reflection.Types.name
-> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.V1.Data.lb_view | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Stubs.Reflection.Types.letbinding",
"FStar.Stubs.Reflection.Types.name",
"Prims.b2t",
"Prims.op_Equality",
"FStar.Stubs.Reflection.V1.Builtins.inspect_fv",
"FStar.Stubs.Reflection.V1.Data.__proj__Mklb_view__item__lb_fv",
"FStar.Stubs.Reflection.V1.Builtins.inspect_lb",
"FStar.Stubs.Reflection.V1.Data.lb_view",
"FStar.Tactics.V1.SyntaxHelpers.fail",
"FStar.Pervasives.Native.option",
"FStar.List.Tot.Base.find",
"Prims.precedes",
"Prims.bool"
] | [] | false | true | false | false | false | let lookup_lb_view (lbs: list letbinding) (nm: name) : Tac lb_view =
| let o =
FStar.List.Tot.Base.find (fun lb ->
let lbv = inspect_lb lb in
(inspect_fv lbv.lb_fv) = nm)
lbs
in
match o with
| Some lb -> inspect_lb lb
| None -> fail "lookup_lb_view: Name not in let group" | false |
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.mk_arr | val mk_arr (bs: list binder) (cod: comp) : Tac term | val mk_arr (bs: list binder) (cod: comp) : Tac term | let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (pack_comp (C_Total (mk_arr bs cod)))) | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 61,
"end_line": 55,
"start_col": 0,
"start_line": 50
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
let ts = List.Tot.Base.map type_of_binder bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | bs: Prims.list FStar.Stubs.Reflection.Types.binder -> cod: FStar.Stubs.Reflection.Types.comp
-> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.Types.comp",
"FStar.Tactics.V1.SyntaxHelpers.fail",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Tactics.V1.Builtins.pack",
"FStar.Stubs.Reflection.V1.Data.Tv_Arrow",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Stubs.Reflection.V1.Builtins.pack_comp",
"FStar.Stubs.Reflection.V1.Data.comp_view",
"FStar.Stubs.Reflection.V1.Data.C_Total",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Tactics.V1.SyntaxHelpers.mk_arr"
] | [
"recursion"
] | false | true | false | false | false | let rec mk_arr (bs: list binder) (cod: comp) : Tac term =
| match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| b :: bs -> pack (Tv_Arrow b (pack_comp (C_Total (mk_arr bs cod)))) | false |
Hacl.Impl.Exponentiation.fst | Hacl.Impl.Exponentiation.lexp_mont_ladder_swap_consttime | val lexp_mont_ladder_swap_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h ctx /\
disjoint a res /\ disjoint b res /\ disjoint a b /\
disjoint ctx a /\ disjoint ctx res /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a))
(ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_mont_ladder_swap #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) | val lexp_mont_ladder_swap_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h ctx /\
disjoint a res /\ disjoint b res /\ disjoint a b /\
disjoint ctx a /\ disjoint ctx res /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a))
(ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_mont_ladder_swap #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) | let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0)) in
[@inline_let]
let spec (h:mem) = S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let (acc1, a1, sw1) = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\
acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a; // a = (a * acc) % n
k.lsqr ctx acc acc; // a = (a * a) % n
sw.(0ul) <- bit
);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame () | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 145,
"start_col": 0,
"start_line": 102
} | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module BN = Hacl.Bignum
module SN = Hacl.Spec.Bignum
module BB = Hacl.Bignum.Base
module PT = Hacl.Impl.PrecompTable
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let lexp_rl_vartime #a_t len ctx_len k ctx a bLen bBits b acc =
k.lone ctx acc;
let h0 = ST.get () in
[@inline_let]
let refl1 i : GTot (k.to.a_spec & k.to.a_spec) =
(refl (as_seq h0 acc), refl (as_seq h0 a)) in
[@inline_let]
let spec (h:mem) = S.exp_rl_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b) in
[@inline_let]
let inv h (i:nat{i <= v bBits}) =
modifies (loc a |+| loc acc) h0 h /\
k.to.linv (as_seq h a) /\
k.to.linv (as_seq h acc) /\
(let res = Loops.repeati i (spec h0) (refl1 0) in
fst res == k.to.refl (as_seq h acc) /\
snd res == k.to.refl (as_seq h a)) in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul bBits inv
(fun i ->
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b i in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v i);
if not (BB.unsafe_bool_of_limb0 bit) then
k.lmul ctx acc a acc; // acc = (acc * a) % n
k.lsqr ctx a a // a = (a * a) % n
)
inline_for_extraction noextract
val cswap2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> bit:uint_t a_t SEC{v bit <= 1}
-> p1:lbuffer (uint_t a_t SEC) len
-> p2:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h p1 /\ live h p2 /\ disjoint p1 p2 /\
k.to.linv (as_seq h p1) /\ k.to.linv (as_seq h p2))
(ensures fun h0 _ h1 -> modifies (loc p1 |+| loc p2) h0 h1 /\
k.to.linv (as_seq h1 p1) /\ k.to.linv (as_seq h1 p2) /\
(k.to.refl (as_seq h1 p1), k.to.refl (as_seq h1 p2)) ==
S.cswap (v bit) (k.to.refl (as_seq h0 p1)) (k.to.refl (as_seq h0 p2)))
let cswap2 #a_t len ctx_len k bit p1 p2 =
let h0 = ST.get () in
BN.cswap2 len bit p1 p2;
SN.cswap2_lemma bit (as_seq h0 p1) (as_seq h0 p2)
val lemma_bit_xor_is_sum_mod2: #a_t:inttype_a -> a:uint_t a_t SEC -> b:uint_t a_t SEC -> Lemma
(requires v a <= 1 /\ v b <= 1)
(ensures v (a ^. b) == (v a + v b) % 2)
let lemma_bit_xor_is_sum_mod2 #a_t a b =
match a_t with
| U32 ->
logxor_spec a b;
assert_norm (UInt32.logxor 0ul 0ul == 0ul);
assert_norm (UInt32.logxor 0ul 1ul == 1ul);
assert_norm (UInt32.logxor 1ul 0ul == 1ul);
assert_norm (UInt32.logxor 1ul 1ul == 0ul)
| U64 ->
logxor_spec a b;
assert_norm (UInt64.logxor 0uL 0uL == 0uL);
assert_norm (UInt64.logxor 0uL 1uL == 1uL);
assert_norm (UInt64.logxor 1uL 0uL == 1uL);
assert_norm (UInt64.logxor 1uL 1uL == 0uL) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt64.fsti.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.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
ctx: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) ctx_len ->
a: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len ->
bLen: Lib.IntTypes.size_t ->
bBits:
Lib.IntTypes.size_t{(Lib.IntTypes.v bBits - 1) / Lib.IntTypes.bits a_t < Lib.IntTypes.v bLen} ->
b: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) bLen ->
res: Lib.Buffer.lbuffer (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) len
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Exponentiation.cswap2",
"Lib.IntTypes.int_t",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"FStar.UInt32.__uint_to_t",
"Lib.Loops.for",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Lib.Buffer.op_Array_Assignment",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__lsqr",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__lmul",
"Hacl.Impl.Exponentiation.lemma_bit_xor_is_sum_mod2",
"Lib.Sequence.index",
"Lib.Buffer.as_seq",
"Lib.IntTypes.op_Hat_Dot",
"Hacl.Spec.Bignum.bn_get_ith_bit_lemma",
"Hacl.Bignum.Definitions.limb",
"Hacl.Bignum.bn_get_ith_bit",
"Lib.IntTypes.op_Subtraction_Bang",
"Lib.LoopCombinators.unfold_repeati",
"FStar.Pervasives.Native.tuple3",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Prims.nat",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.LoopCombinators.eq_repeati0",
"Prims.logical",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.op_GreaterThanOrEqual",
"Lib.LoopCombinators.repeati",
"Lib.Exponentiation.exp_mont_ladder_swap_f",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid",
"Hacl.Bignum.Definitions.bn_v",
"FStar.Pervasives.Native.Mktuple3",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__lone",
"Lib.Buffer.lbuffer_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.uint",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let lexp_mont_ladder_swap_consttime #a_t len ctx_len k ctx a bLen bBits b acc =
| push_frame ();
let sw = create 1ul (uint #a_t #SEC 0) in
k.lone ctx acc;
let h0 = ST.get () in
[@@ inline_let ]let refl1 i : GTot (k.to.a_spec & k.to.a_spec & nat) =
(k.to.refl (as_seq h0 acc), k.to.refl (as_seq h0 a), v (LSeq.index (as_seq h0 sw) 0))
in
[@@ inline_let ]let spec (h: mem) =
S.exp_mont_ladder_swap_f k.to.comm_monoid (v bBits) (BD.bn_v h0 b)
in
[@@ inline_let ]let inv h (i: nat{i <= v bBits}) =
modifies (loc a |+| loc acc |+| loc sw) h0 h /\ k.to.linv (as_seq h a) /\ k.to.linv (as_seq h acc) /\
v (LSeq.index (as_seq h sw) 0) <= 1 /\
(let acc1, a1, sw1 = Loops.repeati i (spec h0) (refl1 0) in
a1 == k.to.refl (as_seq h a) /\ acc1 == k.to.refl (as_seq h acc) /\
sw1 == v (LSeq.index (as_seq h sw) 0))
in
Loops.eq_repeati0 (v bBits) (spec h0) (refl1 0);
Lib.Loops.for 0ul
bBits
inv
(fun i ->
let h2 = ST.get () in
Loops.unfold_repeati (v bBits) (spec h0) (refl1 0) (v i);
let bit = BN.bn_get_ith_bit bLen b (bBits -! i -! 1ul) in
SN.bn_get_ith_bit_lemma (as_seq h0 b) (v bBits - v i - 1);
let sw1 = bit ^. sw.(0ul) in
lemma_bit_xor_is_sum_mod2 #a_t bit (LSeq.index (as_seq h2 sw) 0);
cswap2 len ctx_len k sw1 acc a;
k.lmul ctx a acc a;
k.lsqr ctx acc acc;
sw.(0ul) <- bit);
let sw0 = sw.(0ul) in
cswap2 len ctx_len k sw0 acc a;
pop_frame () | false |
Vale.AsLowStar.MemoryHelpers.fst | Vale.AsLowStar.MemoryHelpers.as_vale_buffer_len | val as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
: Lemma (V.buffer_length (as_vale_buffer x) == (B.length x * view_n src) / view_n t)
[SMTPat (V.buffer_length (as_vale_buffer x))] | val as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
: Lemma (V.buffer_length (as_vale_buffer x) == (B.length x * view_n src) / view_n t)
[SMTPat (V.buffer_length (as_vale_buffer x))] | let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t)) | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 24,
"start_col": 0,
"start_line": 21
} | module Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module ME = Vale.X64.Memory
module VSig = Vale.AsLowStar.ValeSig
module IX64 = Vale.Interop.X64
friend Vale.X64.Memory
friend Vale.X64.Memory_Sems
friend Vale.X64.Stack_i
friend Vale.X64.Stack_Sems
friend Vale.X64.Decls
friend Vale.X64.StateLemmas
friend Vale.X64.MemoryAdapters | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fst.checked",
"Vale.X64.Stack_Sems.fst.checked",
"Vale.X64.Stack_i.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.Memory_Sems.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Decls.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.MemoryHelpers.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MES"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | x: Vale.Interop.Base.buf_t src t
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Decls.buffer_length (Vale.X64.MemoryAdapters.as_vale_buffer x) ==
LowStar.Monotonic.Buffer.length x * Vale.Interop.Types.view_n src /
Vale.Interop.Types.view_n t)
[SMTPat (Vale.X64.Decls.buffer_length (Vale.X64.MemoryAdapters.as_vale_buffer x))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buf_t",
"LowStar.BufferView.Up.length_eq",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"Vale.X64.Memory.uint_view",
"Prims.unit",
"LowStar.BufferView.Down.length_eq",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"LowStar.Buffer.trivial_preorder"
] | [] | true | false | true | false | false | let as_vale_buffer_len (#src #t: base_typ) (x: buf_t src t) =
| let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t)) | false |
LowParse.BitFields.fsti | LowParse.BitFields.set_bitfield_set_bitfield_same | val set_bitfield_set_bitfield_same
(#tot: pos)
(x: U.uint_t tot)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(v v': ubitfield tot (hi - lo))
: Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v')) | val set_bitfield_set_bitfield_same
(#tot: pos)
(x: U.uint_t tot)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(v v': ubitfield tot (hi - lo))
: Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v')) | let set_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(v' : ubitfield tot (hi - lo))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v'))
= set_bitfield_set_bitfield_same_gen x lo hi v lo hi v' | {
"file_name": "src/lowparse/LowParse.BitFields.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 55,
"end_line": 56,
"start_col": 0,
"start_line": 50
} | module LowParse.BitFields
module U = FStar.UInt
type ubitfield (tot: nat) (sz: nat) = (x: U.uint_t tot { x < pow2 sz })
// IMPORTANT: these bitfield operators are defined in a least
// significant bit (LSB) first fashion.
val get_bitfield
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Tot (ubitfield tot (hi - lo))
val get_bitfield_logor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi)
val get_bitfield_logxor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi)
val set_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Tot (U.uint_t tot)
val get_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(get_bitfield (set_bitfield x lo hi v) lo hi == v)
val get_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot })
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi'))
val set_bitfield_set_bitfield_same_gen
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot })
(v' : ubitfield tot (hi' - lo'))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v')) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.BitFields.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: FStar.UInt.uint_t tot ->
lo: Prims.nat ->
hi: Prims.nat{lo <= hi /\ hi <= tot} ->
v: LowParse.BitFields.ubitfield tot (hi - lo) ->
v': LowParse.BitFields.ubitfield tot (hi - lo)
-> FStar.Pervasives.Lemma
(ensures
LowParse.BitFields.set_bitfield (LowParse.BitFields.set_bitfield x lo hi v) lo hi v' ==
LowParse.BitFields.set_bitfield x lo hi v') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.BitFields.ubitfield",
"Prims.op_Subtraction",
"LowParse.BitFields.set_bitfield_set_bitfield_same_gen",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"LowParse.BitFields.set_bitfield",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let set_bitfield_set_bitfield_same
(#tot: pos)
(x: U.uint_t tot)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(v v': ubitfield tot (hi - lo))
: Lemma (ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v')) =
| set_bitfield_set_bitfield_same_gen x lo hi v lo hi v' | false |
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.mk_arr_curried | val mk_arr_curried (bs: list binder) (cod: comp) : Tac term | val mk_arr_curried (bs: list binder) (cod: comp) : Tac term | let rec mk_arr_curried (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack_curried (Tv_Arrow b cod)
| (b::bs) -> pack_curried (Tv_Arrow b (pack_comp (C_Total (mk_arr_curried bs cod)))) | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 88,
"end_line": 61,
"start_col": 0,
"start_line": 57
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
let ts = List.Tot.Base.map type_of_binder bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m)
let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (pack_comp (C_Total (mk_arr bs cod)))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | bs: Prims.list FStar.Stubs.Reflection.Types.binder -> cod: FStar.Stubs.Reflection.Types.comp
-> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.Types.comp",
"FStar.Tactics.V1.SyntaxHelpers.fail",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Tactics.V1.Builtins.pack_curried",
"FStar.Stubs.Reflection.V1.Data.Tv_Arrow",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Stubs.Reflection.V1.Builtins.pack_comp",
"FStar.Stubs.Reflection.V1.Data.comp_view",
"FStar.Stubs.Reflection.V1.Data.C_Total",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Tactics.V1.SyntaxHelpers.mk_arr_curried"
] | [
"recursion"
] | false | true | false | false | false | let rec mk_arr_curried (bs: list binder) (cod: comp) : Tac term =
| match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack_curried (Tv_Arrow b cod)
| b :: bs -> pack_curried (Tv_Arrow b (pack_comp (C_Total (mk_arr_curried bs cod)))) | false |
Steel.FractionalPermission.fst | Steel.FractionalPermission.writeable | val writeable (p: perm) : GTot bool | val writeable (p: perm) : GTot bool | let writeable (p: perm) : GTot bool =
MkPerm?.v p = one | {
"file_name": "lib/steel/Steel.FractionalPermission.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 19,
"end_line": 33,
"start_col": 0,
"start_line": 32
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.FractionalPermission
open FStar.Real
/// This module defines fractional permissions, to be used with Steel references
/// A fractional permission is a real value between 0 (excluded) and 1.
/// 1 represents full ownership, while any fraction corresponds to a shared
/// permission.
/// Note: Does not use real literals, but rather the wrappers one, zero, two, …
/// Real literals are currently not supported by Meta-F*'s reflection framework
[@@erasable]
noeq type perm : Type0 =
| MkPerm: v:real{ v >. zero } -> perm | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.FractionalPermission.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Steel.FractionalPermission.perm -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.FractionalPermission.perm",
"Prims.op_Equality",
"FStar.Real.real",
"Steel.FractionalPermission.__proj__MkPerm__item__v",
"FStar.Real.one",
"Prims.bool"
] | [] | false | false | false | false | false | let writeable (p: perm) : GTot bool =
| MkPerm?.v p = one | false |
MerkleTree.Low.VectorExtras.fst | MerkleTree.Low.VectorExtras.shrink | val shrink:
#a:Type -> vec:vector a ->
new_size:uint32_t{new_size <= size_of vec} ->
HST.ST (vector a)
(requires (fun h0 -> live h0 vec /\ freeable vec))
(ensures (fun h0 r h1 ->
live h1 vec /\ live h1 r /\ size_of r = new_size /\
frameOf r = frameOf vec /\
hmap_dom_eq h0 h1 /\
freeable r /\
modifies (loc_vector vec) h0 h1 /\
loc_vector vec == loc_vector r /\
S.equal (S.slice (V.as_seq h0 vec) 0 (U32.v new_size))
(S.slice (V.as_seq h1 r) 0 (U32.v new_size)))) | val shrink:
#a:Type -> vec:vector a ->
new_size:uint32_t{new_size <= size_of vec} ->
HST.ST (vector a)
(requires (fun h0 -> live h0 vec /\ freeable vec))
(ensures (fun h0 r h1 ->
live h1 vec /\ live h1 r /\ size_of r = new_size /\
frameOf r = frameOf vec /\
hmap_dom_eq h0 h1 /\
freeable r /\
modifies (loc_vector vec) h0 h1 /\
loc_vector vec == loc_vector r /\
S.equal (S.slice (V.as_seq h0 vec) 0 (U32.v new_size))
(S.slice (V.as_seq h1 r) 0 (U32.v new_size)))) | let shrink #a vec new_size =
Vec new_size (Vec?.cap vec) (Vec?.vs vec) | {
"file_name": "src/MerkleTree.Low.VectorExtras.fst",
"git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | {
"end_col": 43,
"end_line": 127,
"start_col": 0,
"start_line": 126
} | module MerkleTree.Low.VectorExtras
module B = LowStar.Buffer
module S = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
open LowStar.BufferOps
open Hacl.Hash.Lemmas
open FStar.Integers
open LowStar.Modifies
open LowStar.Regional
open LowStar.Vector
open LowStar.RVector
module V = LowStar.Vector
module RV = LowStar.RVector
(** Some extra functions on top of LowStar.Vector... used for Merkle Tree. *)
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
inline_for_extraction
let move_left #a (b: B.buffer a) (dst src: U32.t) (l: U32.t): HST.Stack unit
(requires fun h0 ->
B.live h0 b /\
U32.v src + U32.v l <= B.length b /\
U32.v dst <= U32.v src)
(ensures fun h0 _ h1 ->
B.(modifies (loc_buffer b) h0 h1) /\ (
let b0 = B.as_seq h0 b in
let b1 = B.as_seq h1 b in
let src = U32.v src in
let dst = U32.v dst in
let l = U32.v l in
S.slice b1 dst (dst + l) `S.equal` S.slice b0 src (src + l)))
=
let h0 = HST.get () in
[@inline_let]
let inv (h: HS.mem) (i: nat) =
let b0 = B.as_seq h0 b in
let b1 = B.as_seq h b in
let src = U32.v src in
let dst = U32.v dst in
let l = U32.v l in
i <= l /\
B.(modifies (loc_buffer b) h0 h) /\
S.slice b1 dst (dst + i) `S.equal` S.slice b0 src (src + i) /\
S.slice b1 (src + i) (src + l) `S.equal` S.slice b0 (src + i) (src + l)
in
let f (i: U32.t { U32.(0 <= v i /\ v i < v l) }): HST.Stack unit
(requires fun h0 -> inv h0 (U32.v i))
(ensures fun h0 _ h1 -> U32.(inv h0 (v i) /\ inv h1 (v i + 1)))
=
let h00 = HST.get () in
calc (==) {
S.index (B.as_seq h0 b) U32.(v src + v i);
(==) {}
S.index (S.slice (B.as_seq h0 b) U32.(v src + v i) U32.(v src + v l)) 0;
(==) {}
S.index (S.slice (B.as_seq h00 b) U32.(v src + v i) U32.(v src + v l)) 0;
(==) {}
S.index (B.as_seq h00 b) U32.(v src + v i);
};
b.(dst `U32.add` i) <- b.(src `U32.add` i);
let h = HST.get () in
let b0 = B.as_seq h0 b in
let b1 = B.as_seq h b in
let src = U32.v src in
let dst = U32.v dst in
let l = U32.v l in
let i = U32.v i in
calc (S.equal) {
S.slice b1 dst (dst + (i + 1));
(S.equal) { lemma_slice_ijk b1 dst (dst + i) (dst + i + 1) }
S.slice b1 dst (dst + i) `S.append` S.slice b1 (dst + i) (dst + i + 1);
(S.equal) { }
S.slice b0 src (src + i) `S.append` S.slice b1 (dst + i) (dst + i + 1);
(S.equal) { }
S.slice b0 src (src + i) `S.append` S.cons (S.index b1 (dst + i)) S.empty;
(S.equal) { }
S.slice b0 src (src + i) `S.append` S.cons (S.index b0 (src + i)) S.empty;
(S.equal) { }
S.slice b0 src (src + i) `S.append` S.slice b0 (src + i) (src + i + 1);
(S.equal) { lemma_slice_ijk b0 src (src + i) (src + i + 1) }
S.slice b0 src (src + (i + 1));
};
let s1 = S.slice b1 (src + (i + 1)) (src + l) in
let s0 = S.slice b0 (src + (i + 1)) (src + l) in
let aux (j: nat { j < S.length s0 }): Lemma (S.index s0 j == S.index s1 j)
[ SMTPat (S.index s0 j); SMTPat (S.index s1 j) ]
=
calc (==) {
S.index s0 j;
(==) {}
S.index (S.slice b0 (src + i) (src + l)) (j + 1);
(==) {}
S.index (S.slice b1 (src + i) (src + l)) (j + 1);
(==) {}
S.index s1 j;
}
in
()
in
C.Loops.for 0ul l inv f
inline_for_extraction
val shrink:
#a:Type -> vec:vector a ->
new_size:uint32_t{new_size <= size_of vec} ->
HST.ST (vector a)
(requires (fun h0 -> live h0 vec /\ freeable vec))
(ensures (fun h0 r h1 ->
live h1 vec /\ live h1 r /\ size_of r = new_size /\
frameOf r = frameOf vec /\
hmap_dom_eq h0 h1 /\
freeable r /\
modifies (loc_vector vec) h0 h1 /\
loc_vector vec == loc_vector r /\
S.equal (S.slice (V.as_seq h0 vec) 0 (U32.v new_size)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Hacl.Hash.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Calc.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "MerkleTree.Low.VectorExtras.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Modifies",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "MerkleTree.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
vec: LowStar.Vector.vector a ->
new_size: LowStar.Vector.uint32_t{new_size <= LowStar.Vector.size_of vec}
-> FStar.HyperStack.ST.ST (LowStar.Vector.vector a) | FStar.HyperStack.ST.ST | [] | [] | [
"LowStar.Vector.vector",
"LowStar.Vector.uint32_t",
"Prims.b2t",
"FStar.Integers.op_Less_Equals",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"LowStar.Vector.size_of",
"LowStar.Vector.Vec",
"LowStar.Vector.__proj__Vec__item__cap",
"LowStar.Vector.__proj__Vec__item__vs"
] | [] | false | true | false | false | false | let shrink #a vec new_size =
| Vec new_size (Vec?.cap vec) (Vec?.vs vec) | false |
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.inspect_unascribe | val inspect_unascribe (t: term) : Tac (tv: term_view{notAscription tv}) | val inspect_unascribe (t: term) : Tac (tv: term_view{notAscription tv}) | let rec inspect_unascribe (t:term) : Tac (tv:term_view{notAscription tv}) =
match inspect t with
| Tv_AscribedT t _ _ _
| Tv_AscribedC t _ _ _ ->
inspect_unascribe t
| tv -> tv | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 12,
"end_line": 85,
"start_col": 0,
"start_line": 80
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
let ts = List.Tot.Base.map type_of_binder bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m)
let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (pack_comp (C_Total (mk_arr bs cod))))
let rec mk_arr_curried (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack_curried (Tv_Arrow b cod)
| (b::bs) -> pack_curried (Tv_Arrow b (pack_comp (C_Total (mk_arr_curried bs cod))))
let rec mk_tot_arr (bs: list binder) (cod : term) : Tac term =
match bs with
| [] -> cod
| (b::bs) ->
pack (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr bs cod))))
let lookup_lb_view (lbs:list letbinding) (nm:name) : Tac lb_view =
let o = FStar.List.Tot.Base.find
(fun lb ->
let lbv = inspect_lb lb in
(inspect_fv lbv.lb_fv) = nm)
lbs
in
match o with
| Some lb -> inspect_lb lb
| None -> fail "lookup_lb_view: Name not in let group" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(tv: FStar.Stubs.Reflection.V1.Data.term_view{FStar.Stubs.Reflection.V1.Data.notAscription tv}) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Tactics.V1.SyntaxHelpers.inspect_unascribe",
"FStar.Stubs.Reflection.V1.Data.term_view",
"Prims.b2t",
"FStar.Stubs.Reflection.V1.Data.notAscription",
"FStar.Stubs.Reflection.Types.comp",
"FStar.Stubs.Tactics.V1.Builtins.inspect"
] | [
"recursion"
] | false | true | false | false | false | let rec inspect_unascribe (t: term) : Tac (tv: term_view{notAscription tv}) =
| match inspect t with
| Tv_AscribedT t _ _ _ | Tv_AscribedC t _ _ _ -> inspect_unascribe t
| tv -> tv | false |
LowParse.BitFields.fsti | LowParse.BitFields.get_bitfield_partition_prop | val get_bitfield_partition_prop
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(l: list nat)
: Tot bool (decreases l) | val get_bitfield_partition_prop
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(l: list nat)
: Tot bool (decreases l) | let rec get_bitfield_partition_prop
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Tot bool
(decreases l)
= match l with
| [] ->
get_bitfield x lo hi = get_bitfield y lo hi
| mi :: q ->
lo <= mi && mi <= hi &&
get_bitfield_partition_prop x y mi hi q &&
get_bitfield x lo mi = get_bitfield y lo mi | {
"file_name": "src/lowparse/LowParse.BitFields.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 47,
"end_line": 176,
"start_col": 0,
"start_line": 162
} | module LowParse.BitFields
module U = FStar.UInt
type ubitfield (tot: nat) (sz: nat) = (x: U.uint_t tot { x < pow2 sz })
// IMPORTANT: these bitfield operators are defined in a least
// significant bit (LSB) first fashion.
val get_bitfield
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Tot (ubitfield tot (hi - lo))
val get_bitfield_logor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi)
val get_bitfield_logxor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi)
val set_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Tot (U.uint_t tot)
val get_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(get_bitfield (set_bitfield x lo hi v) lo hi == v)
val get_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot })
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi'))
val set_bitfield_set_bitfield_same_gen
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot })
(v' : ubitfield tot (hi' - lo'))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v'))
let set_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(v' : ubitfield tot (hi - lo))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v'))
= set_bitfield_set_bitfield_same_gen x lo hi v lo hi v'
val set_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo'))
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v))
val set_bitfield_full
(#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot)
: Lemma
(set_bitfield x 0 tot y == y)
val set_bitfield_empty
(#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0)
: Lemma
(set_bitfield x i i y == x)
val get_bitfield_zero
(tot: pos)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield #tot 0 lo hi == 0)
val get_bitfield_full
(#tot: pos)
(x: U.uint_t tot)
: Lemma
(get_bitfield x 0 tot == x)
val get_bitfield_empty
(#tot: pos)
(x: U.uint_t tot)
(i: nat { i <= tot })
: Lemma
(get_bitfield x i i == 0)
val lt_pow2_get_bitfield_hi
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (x < pow2 mi))
(ensures (get_bitfield x mi tot == 0))
val get_bitfield_hi_lt_pow2
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (get_bitfield x mi tot == 0))
(ensures (x < pow2 mi))
val get_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo })
: Lemma
(get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi'))
val get_bitfield_zero_inner
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi })
: Lemma
(ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0))
val set_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(set_bitfield x lo hi (get_bitfield x lo hi) == x)
val get_bitfield_partition_2_gen
(#tot: pos)
(lo: nat)
(mi: nat)
(hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x lo mi == get_bitfield y lo mi /\
get_bitfield x mi hi == get_bitfield y mi hi
))
(ensures (
get_bitfield x lo hi == get_bitfield y lo hi
))
val get_bitfield_partition_2
(#tot: pos)
(mid: nat { mid <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 mid == get_bitfield y 0 mid /\
get_bitfield x mid tot == get_bitfield y mid tot
))
(ensures (
x == y
)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.BitFields.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: FStar.UInt.uint_t tot ->
y: FStar.UInt.uint_t tot ->
lo: Prims.nat ->
hi: Prims.nat{lo <= hi /\ hi <= tot} ->
l: Prims.list Prims.nat
-> Prims.Tot Prims.bool | Prims.Tot | [
"total",
""
] | [] | [
"Prims.pos",
"FStar.UInt.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.list",
"Prims.op_Equality",
"LowParse.BitFields.ubitfield",
"Prims.op_Subtraction",
"LowParse.BitFields.get_bitfield",
"Prims.op_AmpAmp",
"LowParse.BitFields.get_bitfield_partition_prop",
"Prims.bool"
] | [
"recursion"
] | false | false | false | false | false | let rec get_bitfield_partition_prop
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(l: list nat)
: Tot bool (decreases l) =
| match l with
| [] -> get_bitfield x lo hi = get_bitfield y lo hi
| mi :: q ->
lo <= mi && mi <= hi && get_bitfield_partition_prop x y mi hi q &&
get_bitfield x lo mi = get_bitfield y lo mi | false |
Steel.FractionalPermission.fst | Steel.FractionalPermission.lesser_equal_perm | val lesser_equal_perm (p1 p2: perm) : GTot bool | val lesser_equal_perm (p1 p2: perm) : GTot bool | let lesser_equal_perm (p1 p2:perm) : GTot bool =
MkPerm?.v p1 <=. MkPerm?.v p2 | {
"file_name": "lib/steel/Steel.FractionalPermission.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 32,
"end_line": 45,
"start_col": 0,
"start_line": 44
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.FractionalPermission
open FStar.Real
/// This module defines fractional permissions, to be used with Steel references
/// A fractional permission is a real value between 0 (excluded) and 1.
/// 1 represents full ownership, while any fraction corresponds to a shared
/// permission.
/// Note: Does not use real literals, but rather the wrappers one, zero, two, …
/// Real literals are currently not supported by Meta-F*'s reflection framework
[@@erasable]
noeq type perm : Type0 =
| MkPerm: v:real{ v >. zero } -> perm
/// A reference is only safely writeable if we have full permission
let writeable (p: perm) : GTot bool =
MkPerm?.v p = one
/// Helper around splitting a permission in half
let half_perm (p: perm) : Tot perm =
MkPerm ((MkPerm?.v p) /. two)
/// Helper to combine two permissions into one
let sum_perm (p1 p2: perm) : Tot perm =
MkPerm (MkPerm?.v p1 +. MkPerm?.v p2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.FractionalPermission.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | p1: Steel.FractionalPermission.perm -> p2: Steel.FractionalPermission.perm -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.FractionalPermission.perm",
"FStar.Real.op_Less_Equals_Dot",
"Steel.FractionalPermission.__proj__MkPerm__item__v",
"Prims.bool"
] | [] | false | false | false | false | false | let lesser_equal_perm (p1 p2: perm) : GTot bool =
| MkPerm?.v p1 <=. MkPerm?.v p2 | false |
Steel.FractionalPermission.fst | Steel.FractionalPermission.lesser_perm | val lesser_perm (p1 p2: perm) : GTot bool | val lesser_perm (p1 p2: perm) : GTot bool | let lesser_perm (p1 p2:perm) : GTot bool =
MkPerm?.v p1 <. MkPerm?.v p2 | {
"file_name": "lib/steel/Steel.FractionalPermission.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 31,
"end_line": 48,
"start_col": 0,
"start_line": 47
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.FractionalPermission
open FStar.Real
/// This module defines fractional permissions, to be used with Steel references
/// A fractional permission is a real value between 0 (excluded) and 1.
/// 1 represents full ownership, while any fraction corresponds to a shared
/// permission.
/// Note: Does not use real literals, but rather the wrappers one, zero, two, …
/// Real literals are currently not supported by Meta-F*'s reflection framework
[@@erasable]
noeq type perm : Type0 =
| MkPerm: v:real{ v >. zero } -> perm
/// A reference is only safely writeable if we have full permission
let writeable (p: perm) : GTot bool =
MkPerm?.v p = one
/// Helper around splitting a permission in half
let half_perm (p: perm) : Tot perm =
MkPerm ((MkPerm?.v p) /. two)
/// Helper to combine two permissions into one
let sum_perm (p1 p2: perm) : Tot perm =
MkPerm (MkPerm?.v p1 +. MkPerm?.v p2)
/// Helper to compare two permissions
let lesser_equal_perm (p1 p2:perm) : GTot bool =
MkPerm?.v p1 <=. MkPerm?.v p2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.FractionalPermission.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | p1: Steel.FractionalPermission.perm -> p2: Steel.FractionalPermission.perm -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.FractionalPermission.perm",
"FStar.Real.op_Less_Dot",
"Steel.FractionalPermission.__proj__MkPerm__item__v",
"Prims.bool"
] | [] | false | false | false | false | false | let lesser_perm (p1 p2: perm) : GTot bool =
| MkPerm?.v p1 <. MkPerm?.v p2 | false |
Vale.AsLowStar.MemoryHelpers.fst | Vale.AsLowStar.MemoryHelpers.buffer_readable_reveal | val buffer_readable_reveal
(#max_arity:nat)
(src bt:base_typ)
(x:buf_t src bt)
(args:IX64.arity_ok max_arity arg)
(h0:HS.mem{mem_roots_p h0 args}) : Lemma (
let mem = mk_mem args h0 in
ME.buffer_readable (create_initial_vale_heap mem) (as_vale_buffer x) <==>
List.memP (mut_to_b8 src x) (ptrs_of_mem mem)) | val buffer_readable_reveal
(#max_arity:nat)
(src bt:base_typ)
(x:buf_t src bt)
(args:IX64.arity_ok max_arity arg)
(h0:HS.mem{mem_roots_p h0 args}) : Lemma (
let mem = mk_mem args h0 in
ME.buffer_readable (create_initial_vale_heap mem) (as_vale_buffer x) <==>
List.memP (mut_to_b8 src x) (ptrs_of_mem mem)) | let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 125,
"end_line": 44,
"start_col": 0,
"start_line": 44
} | module Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module ME = Vale.X64.Memory
module VSig = Vale.AsLowStar.ValeSig
module IX64 = Vale.Interop.X64
friend Vale.X64.Memory
friend Vale.X64.Memory_Sems
friend Vale.X64.Stack_i
friend Vale.X64.Stack_Sems
friend Vale.X64.Decls
friend Vale.X64.StateLemmas
friend Vale.X64.MemoryAdapters
let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let state_eq_down_mem (va_s1:V.va_state) (s1:_) = ()
let rec loc_eq (args:list arg)
: Lemma (VSig.mloc_modified_args args == loc_modified_args args)
= match args with
| [] -> ()
| hd :: tl -> loc_eq tl
let relate_modifies args m0 m1 = loc_eq args
let reveal_readable #src #t x s = ()
let reveal_imm_readable #src #t x s = ()
let readable_live #src #t x s = () | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fst.checked",
"Vale.X64.Stack_Sems.fst.checked",
"Vale.X64.Stack_i.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.Memory_Sems.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Decls.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.MemoryHelpers.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MES"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
src: Vale.Arch.HeapTypes_s.base_typ ->
bt: Vale.Arch.HeapTypes_s.base_typ ->
x: Vale.Interop.Base.buf_t src bt ->
args: Vale.Interop.X64.arity_ok max_arity Vale.Interop.Base.arg ->
h0: FStar.Monotonic.HyperStack.mem{Vale.Interop.Base.mem_roots_p h0 args}
-> FStar.Pervasives.Lemma
(ensures
(let mem = Vale.Interop.Base.mk_mem args h0 in
Vale.X64.Memory.buffer_readable (Vale.X64.MemoryAdapters.create_initial_vale_heap mem)
(Vale.X64.MemoryAdapters.as_vale_buffer x) <==>
FStar.List.Tot.Base.memP (Vale.Interop.Base.mut_to_b8 src x)
(Vale.Interop.Heap_s.ptrs_of_mem mem))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buf_t",
"Vale.Interop.X64.arity_ok",
"Vale.Interop.Base.arg",
"FStar.Monotonic.HyperStack.mem",
"Vale.Interop.Base.mem_roots_p",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Memory.vale_full_heap",
"Vale.X64.Memory.vale_heap",
"Vale.X64.Memory.get_vale_heap",
"Prims.unit"
] | [] | true | false | true | false | false | let buffer_readable_reveal #max_arity src bt x args h0 =
| FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap | false |
Vale.AsLowStar.MemoryHelpers.fst | Vale.AsLowStar.MemoryHelpers.lemma_as_mem_as_vale_mem | val lemma_as_mem_as_vale_mem (h:interop_heap) : Lemma
(ensures as_mem (create_initial_vale_heap h) == h)
[SMTPat (as_mem (create_initial_vale_heap h))] | val lemma_as_mem_as_vale_mem (h:interop_heap) : Lemma
(ensures as_mem (create_initial_vale_heap h) == h)
[SMTPat (as_mem (create_initial_vale_heap h))] | let lemma_as_mem_as_vale_mem h = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 101,
"end_line": 46,
"start_col": 0,
"start_line": 46
} | module Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module ME = Vale.X64.Memory
module VSig = Vale.AsLowStar.ValeSig
module IX64 = Vale.Interop.X64
friend Vale.X64.Memory
friend Vale.X64.Memory_Sems
friend Vale.X64.Stack_i
friend Vale.X64.Stack_Sems
friend Vale.X64.Decls
friend Vale.X64.StateLemmas
friend Vale.X64.MemoryAdapters
let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let state_eq_down_mem (va_s1:V.va_state) (s1:_) = ()
let rec loc_eq (args:list arg)
: Lemma (VSig.mloc_modified_args args == loc_modified_args args)
= match args with
| [] -> ()
| hd :: tl -> loc_eq tl
let relate_modifies args m0 m1 = loc_eq args
let reveal_readable #src #t x s = ()
let reveal_imm_readable #src #t x s = ()
let readable_live #src #t x s = ()
let readable_imm_live #src #t x s = ()
let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fst.checked",
"Vale.X64.Stack_Sems.fst.checked",
"Vale.X64.Stack_i.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.Memory_Sems.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Decls.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.MemoryHelpers.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MES"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | h: Vale.Interop.Heap_s.interop_heap
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.MemoryAdapters.as_mem (Vale.X64.MemoryAdapters.create_initial_vale_heap h) == h)
[SMTPat (Vale.X64.MemoryAdapters.as_mem (Vale.X64.MemoryAdapters.create_initial_vale_heap h))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Interop.Heap_s.interop_heap",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Memory.vale_full_heap",
"Vale.X64.Memory.vale_heap",
"Vale.X64.Memory.get_vale_heap",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_as_mem_as_vale_mem h =
| FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap | false |
LowParse.BitFields.fsti | LowParse.BitFields.uint_t_v_uint_to_t | val uint_t_v_uint_to_t (#tot #t: _) (cl: uint_t tot t) (x: U.uint_t tot)
: Lemma (cl.v (cl.uint_to_t x) == x) [SMTPat (cl.v (cl.uint_to_t x))] | val uint_t_v_uint_to_t (#tot #t: _) (cl: uint_t tot t) (x: U.uint_t tot)
: Lemma (cl.v (cl.uint_to_t x) == x) [SMTPat (cl.v (cl.uint_to_t x))] | let uint_t_v_uint_to_t #tot #t (cl: uint_t tot t) (x: U.uint_t tot) : Lemma
(cl.v (cl.uint_to_t x) == x)
[SMTPat (cl.v (cl.uint_to_t x))]
= cl.v_uint_to_t x | {
"file_name": "src/lowparse/LowParse.BitFields.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 18,
"end_line": 284,
"start_col": 0,
"start_line": 281
} | module LowParse.BitFields
module U = FStar.UInt
type ubitfield (tot: nat) (sz: nat) = (x: U.uint_t tot { x < pow2 sz })
// IMPORTANT: these bitfield operators are defined in a least
// significant bit (LSB) first fashion.
val get_bitfield
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Tot (ubitfield tot (hi - lo))
val get_bitfield_logor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi)
val get_bitfield_logxor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi)
val set_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Tot (U.uint_t tot)
val get_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(get_bitfield (set_bitfield x lo hi v) lo hi == v)
val get_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot })
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi'))
val set_bitfield_set_bitfield_same_gen
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot })
(v' : ubitfield tot (hi' - lo'))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v'))
let set_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(v' : ubitfield tot (hi - lo))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v'))
= set_bitfield_set_bitfield_same_gen x lo hi v lo hi v'
val set_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo'))
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v))
val set_bitfield_full
(#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot)
: Lemma
(set_bitfield x 0 tot y == y)
val set_bitfield_empty
(#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0)
: Lemma
(set_bitfield x i i y == x)
val get_bitfield_zero
(tot: pos)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield #tot 0 lo hi == 0)
val get_bitfield_full
(#tot: pos)
(x: U.uint_t tot)
: Lemma
(get_bitfield x 0 tot == x)
val get_bitfield_empty
(#tot: pos)
(x: U.uint_t tot)
(i: nat { i <= tot })
: Lemma
(get_bitfield x i i == 0)
val lt_pow2_get_bitfield_hi
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (x < pow2 mi))
(ensures (get_bitfield x mi tot == 0))
val get_bitfield_hi_lt_pow2
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (get_bitfield x mi tot == 0))
(ensures (x < pow2 mi))
val get_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo })
: Lemma
(get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi'))
val get_bitfield_zero_inner
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi })
: Lemma
(ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0))
val set_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(set_bitfield x lo hi (get_bitfield x lo hi) == x)
val get_bitfield_partition_2_gen
(#tot: pos)
(lo: nat)
(mi: nat)
(hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x lo mi == get_bitfield y lo mi /\
get_bitfield x mi hi == get_bitfield y mi hi
))
(ensures (
get_bitfield x lo hi == get_bitfield y lo hi
))
val get_bitfield_partition_2
(#tot: pos)
(mid: nat { mid <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 mid == get_bitfield y 0 mid /\
get_bitfield x mid tot == get_bitfield y mid tot
))
(ensures (
x == y
))
let rec get_bitfield_partition_prop
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Tot bool
(decreases l)
= match l with
| [] ->
get_bitfield x lo hi = get_bitfield y lo hi
| mi :: q ->
lo <= mi && mi <= hi &&
get_bitfield_partition_prop x y mi hi q &&
get_bitfield x lo mi = get_bitfield y lo mi
val get_bitfield_partition
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Lemma
(requires (get_bitfield_partition_prop x y lo hi l))
(ensures (get_bitfield x lo hi == get_bitfield y lo hi))
let get_bitfield_partition_3
(#tot: pos)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 lo == get_bitfield y 0 lo /\
get_bitfield x lo hi == get_bitfield y lo hi /\
get_bitfield x hi tot == get_bitfield y hi tot
))
(ensures (x == y))
= assert_norm (get_bitfield_partition_prop x y 0 tot [lo; hi]); // does not need fuel, thanks to normalization
get_bitfield_partition x y 0 tot [lo; hi];
get_bitfield_full x;
get_bitfield_full y
val get_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
: Lemma
(x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat))
val set_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
(v: ubitfield tot1 (hi - lo))
: Lemma
(x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat))
val set_bitfield_bound
(#tot: pos)
(x: U.uint_t tot)
(bound: nat { bound <= tot /\ x < pow2 bound })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= bound })
(v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v < pow2 bound)
val set_bitfield_set_bitfield_get_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= hi - lo }) (v' : ubitfield tot (hi' - lo'))
: Lemma
( let v = set_bitfield (get_bitfield x lo hi) lo' hi' v' in
v < pow2 (hi - lo) /\
set_bitfield x lo hi v == set_bitfield x (lo + lo') (lo + hi') v' )
val get_bitfield_eq
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo))
val get_bitfield_eq_2
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo))
val set_bitfield_eq
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo))
module U32 = FStar.UInt32
inline_for_extraction
noextract
noeq
type uint_t (tot: pos) (t: Type) = {
v: (t -> Tot (U.uint_t tot));
uint_to_t: (U.uint_t tot -> Tot t);
v_uint_to_t: ((x: U.uint_t tot) -> Lemma (v (uint_to_t x) == x));
uint_to_t_v: ((x: t) -> Lemma (uint_to_t (v x) == x));
get_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) (U32.v lo) (U32.v hi) }));
set_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> (z: t { v z < pow2 (U32.v hi - U32.v lo) }) -> Tot (y : t { v y == set_bitfield (v x) (U32.v lo) (U32.v hi) (v z)}));
get_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) lo hi }));
set_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y : t { v y == set_bitfield (v x) lo hi (v z)}));
logor: ((x: t) -> (y: t) -> Tot (z: t { v z == v x `U.logor` v y }));
bitfield_eq_lhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot t);
bitfield_eq_rhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y: t { bitfield_eq_lhs x lo hi == y <==> (get_bitfield x lo hi <: t) == z }));
}
inline_for_extraction
let bitfield (#tot: pos) (#t: Type) (cl: uint_t tot t) (sz: nat { sz <= tot }) : Tot Type =
(x: t { cl.v x < pow2 sz }) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.BitFields.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | cl: LowParse.BitFields.uint_t tot t -> x: FStar.UInt.uint_t tot
-> FStar.Pervasives.Lemma (ensures Mkuint_t?.v cl (Mkuint_t?.uint_to_t cl x) == x)
[SMTPat (Mkuint_t?.v cl (Mkuint_t?.uint_to_t cl x))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"LowParse.BitFields.uint_t",
"FStar.UInt.uint_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v_uint_to_t",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let uint_t_v_uint_to_t #tot #t (cl: uint_t tot t) (x: U.uint_t tot)
: Lemma (cl.v (cl.uint_to_t x) == x) [SMTPat (cl.v (cl.uint_to_t x))] =
| cl.v_uint_to_t x | false |
Vale.AsLowStar.MemoryHelpers.fst | Vale.AsLowStar.MemoryHelpers.as_vale_immbuffer_len | val as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
: Lemma (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n src) / view_n t)
[SMTPat (V.buffer_length (as_vale_immbuffer x))] | val as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
: Lemma (V.buffer_length (as_vale_immbuffer x) == (B.length x * view_n src) / view_n t)
[SMTPat (V.buffer_length (as_vale_immbuffer x))] | let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t)) | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 29,
"start_col": 0,
"start_line": 26
} | module Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module ME = Vale.X64.Memory
module VSig = Vale.AsLowStar.ValeSig
module IX64 = Vale.Interop.X64
friend Vale.X64.Memory
friend Vale.X64.Memory_Sems
friend Vale.X64.Stack_i
friend Vale.X64.Stack_Sems
friend Vale.X64.Decls
friend Vale.X64.StateLemmas
friend Vale.X64.MemoryAdapters
let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fst.checked",
"Vale.X64.Stack_Sems.fst.checked",
"Vale.X64.Stack_i.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.Memory_Sems.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Decls.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.MemoryHelpers.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MES"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | x: Vale.Interop.Base.ibuf_t src t
-> FStar.Pervasives.Lemma
(ensures
Vale.X64.Decls.buffer_length (Vale.X64.MemoryAdapters.as_vale_immbuffer x) ==
LowStar.Monotonic.Buffer.length x * Vale.Interop.Types.view_n src /
Vale.Interop.Types.view_n t)
[SMTPat (Vale.X64.Decls.buffer_length (Vale.X64.MemoryAdapters.as_vale_immbuffer x))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.ibuf_t",
"LowStar.BufferView.Up.length_eq",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.BufferView.Up.mk_buffer",
"FStar.UInt8.t",
"Vale.X64.Memory.uint_view",
"Prims.unit",
"LowStar.BufferView.Down.length_eq",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"LowStar.ImmutableBuffer.immutable_preorder"
] | [] | true | false | true | false | false | let as_vale_immbuffer_len (#src #t: base_typ) (x: ibuf_t src t) =
| let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t)) | false |
LowParse.BitFields.fsti | LowParse.BitFields.get_bitfield_partition_3 | val get_bitfield_partition_3
(#tot: pos)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(x y: U.uint_t tot)
: Lemma
(requires
(get_bitfield x 0 lo == get_bitfield y 0 lo /\ get_bitfield x lo hi == get_bitfield y lo hi /\
get_bitfield x hi tot == get_bitfield y hi tot)) (ensures (x == y)) | val get_bitfield_partition_3
(#tot: pos)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(x y: U.uint_t tot)
: Lemma
(requires
(get_bitfield x 0 lo == get_bitfield y 0 lo /\ get_bitfield x lo hi == get_bitfield y lo hi /\
get_bitfield x hi tot == get_bitfield y hi tot)) (ensures (x == y)) | let get_bitfield_partition_3
(#tot: pos)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 lo == get_bitfield y 0 lo /\
get_bitfield x lo hi == get_bitfield y lo hi /\
get_bitfield x hi tot == get_bitfield y hi tot
))
(ensures (x == y))
= assert_norm (get_bitfield_partition_prop x y 0 tot [lo; hi]); // does not need fuel, thanks to normalization
get_bitfield_partition x y 0 tot [lo; hi];
get_bitfield_full x;
get_bitfield_full y | {
"file_name": "src/lowparse/LowParse.BitFields.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 21,
"end_line": 203,
"start_col": 0,
"start_line": 188
} | module LowParse.BitFields
module U = FStar.UInt
type ubitfield (tot: nat) (sz: nat) = (x: U.uint_t tot { x < pow2 sz })
// IMPORTANT: these bitfield operators are defined in a least
// significant bit (LSB) first fashion.
val get_bitfield
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Tot (ubitfield tot (hi - lo))
val get_bitfield_logor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi)
val get_bitfield_logxor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi)
val set_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Tot (U.uint_t tot)
val get_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(get_bitfield (set_bitfield x lo hi v) lo hi == v)
val get_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot })
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi'))
val set_bitfield_set_bitfield_same_gen
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot })
(v' : ubitfield tot (hi' - lo'))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v'))
let set_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(v' : ubitfield tot (hi - lo))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v'))
= set_bitfield_set_bitfield_same_gen x lo hi v lo hi v'
val set_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo'))
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v))
val set_bitfield_full
(#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot)
: Lemma
(set_bitfield x 0 tot y == y)
val set_bitfield_empty
(#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0)
: Lemma
(set_bitfield x i i y == x)
val get_bitfield_zero
(tot: pos)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield #tot 0 lo hi == 0)
val get_bitfield_full
(#tot: pos)
(x: U.uint_t tot)
: Lemma
(get_bitfield x 0 tot == x)
val get_bitfield_empty
(#tot: pos)
(x: U.uint_t tot)
(i: nat { i <= tot })
: Lemma
(get_bitfield x i i == 0)
val lt_pow2_get_bitfield_hi
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (x < pow2 mi))
(ensures (get_bitfield x mi tot == 0))
val get_bitfield_hi_lt_pow2
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (get_bitfield x mi tot == 0))
(ensures (x < pow2 mi))
val get_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo })
: Lemma
(get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi'))
val get_bitfield_zero_inner
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi })
: Lemma
(ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0))
val set_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(set_bitfield x lo hi (get_bitfield x lo hi) == x)
val get_bitfield_partition_2_gen
(#tot: pos)
(lo: nat)
(mi: nat)
(hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x lo mi == get_bitfield y lo mi /\
get_bitfield x mi hi == get_bitfield y mi hi
))
(ensures (
get_bitfield x lo hi == get_bitfield y lo hi
))
val get_bitfield_partition_2
(#tot: pos)
(mid: nat { mid <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 mid == get_bitfield y 0 mid /\
get_bitfield x mid tot == get_bitfield y mid tot
))
(ensures (
x == y
))
let rec get_bitfield_partition_prop
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Tot bool
(decreases l)
= match l with
| [] ->
get_bitfield x lo hi = get_bitfield y lo hi
| mi :: q ->
lo <= mi && mi <= hi &&
get_bitfield_partition_prop x y mi hi q &&
get_bitfield x lo mi = get_bitfield y lo mi
val get_bitfield_partition
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Lemma
(requires (get_bitfield_partition_prop x y lo hi l))
(ensures (get_bitfield x lo hi == get_bitfield y lo hi)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.BitFields.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
lo: Prims.nat ->
hi: Prims.nat{lo <= hi /\ hi <= tot} ->
x: FStar.UInt.uint_t tot ->
y: FStar.UInt.uint_t tot
-> FStar.Pervasives.Lemma
(requires
LowParse.BitFields.get_bitfield x 0 lo == LowParse.BitFields.get_bitfield y 0 lo /\
LowParse.BitFields.get_bitfield x lo hi == LowParse.BitFields.get_bitfield y lo hi /\
LowParse.BitFields.get_bitfield x hi tot == LowParse.BitFields.get_bitfield y hi tot)
(ensures x == y) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt.uint_t",
"LowParse.BitFields.get_bitfield_full",
"Prims.unit",
"LowParse.BitFields.get_bitfield_partition",
"Prims.Cons",
"Prims.Nil",
"FStar.Pervasives.assert_norm",
"LowParse.BitFields.get_bitfield_partition_prop",
"Prims.eq2",
"LowParse.BitFields.ubitfield",
"Prims.op_Subtraction",
"LowParse.BitFields.get_bitfield",
"Prims.squash",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let get_bitfield_partition_3
(#tot: pos)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(x y: U.uint_t tot)
: Lemma
(requires
(get_bitfield x 0 lo == get_bitfield y 0 lo /\ get_bitfield x lo hi == get_bitfield y lo hi /\
get_bitfield x hi tot == get_bitfield y hi tot)) (ensures (x == y)) =
| assert_norm (get_bitfield_partition_prop x y 0 tot [lo; hi]);
get_bitfield_partition x y 0 tot [lo; hi];
get_bitfield_full x;
get_bitfield_full y | false |
LowParse.BitFields.fsti | LowParse.BitFields.uint_get_bitfield_set_bitfield_same | val uint_get_bitfield_set_bitfield_same
(#tot #t: _)
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
: Lemma (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi == z)
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)] | val uint_get_bitfield_set_bitfield_same
(#tot #t: _)
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
: Lemma (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi == z)
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)] | let uint_get_bitfield_set_bitfield_same
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
: Lemma
(cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi == z)
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)]
= get_bitfield_set_bitfield_same (cl.v x) lo hi (cl.v z);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)) == cl.uint_to_t (cl.v z)) | {
"file_name": "src/lowparse/LowParse.BitFields.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 107,
"end_line": 298,
"start_col": 0,
"start_line": 291
} | module LowParse.BitFields
module U = FStar.UInt
type ubitfield (tot: nat) (sz: nat) = (x: U.uint_t tot { x < pow2 sz })
// IMPORTANT: these bitfield operators are defined in a least
// significant bit (LSB) first fashion.
val get_bitfield
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Tot (ubitfield tot (hi - lo))
val get_bitfield_logor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi)
val get_bitfield_logxor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi)
val set_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Tot (U.uint_t tot)
val get_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(get_bitfield (set_bitfield x lo hi v) lo hi == v)
val get_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot })
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi'))
val set_bitfield_set_bitfield_same_gen
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot })
(v' : ubitfield tot (hi' - lo'))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v'))
let set_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(v' : ubitfield tot (hi - lo))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v'))
= set_bitfield_set_bitfield_same_gen x lo hi v lo hi v'
val set_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo'))
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v))
val set_bitfield_full
(#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot)
: Lemma
(set_bitfield x 0 tot y == y)
val set_bitfield_empty
(#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0)
: Lemma
(set_bitfield x i i y == x)
val get_bitfield_zero
(tot: pos)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield #tot 0 lo hi == 0)
val get_bitfield_full
(#tot: pos)
(x: U.uint_t tot)
: Lemma
(get_bitfield x 0 tot == x)
val get_bitfield_empty
(#tot: pos)
(x: U.uint_t tot)
(i: nat { i <= tot })
: Lemma
(get_bitfield x i i == 0)
val lt_pow2_get_bitfield_hi
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (x < pow2 mi))
(ensures (get_bitfield x mi tot == 0))
val get_bitfield_hi_lt_pow2
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (get_bitfield x mi tot == 0))
(ensures (x < pow2 mi))
val get_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo })
: Lemma
(get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi'))
val get_bitfield_zero_inner
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi })
: Lemma
(ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0))
val set_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(set_bitfield x lo hi (get_bitfield x lo hi) == x)
val get_bitfield_partition_2_gen
(#tot: pos)
(lo: nat)
(mi: nat)
(hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x lo mi == get_bitfield y lo mi /\
get_bitfield x mi hi == get_bitfield y mi hi
))
(ensures (
get_bitfield x lo hi == get_bitfield y lo hi
))
val get_bitfield_partition_2
(#tot: pos)
(mid: nat { mid <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 mid == get_bitfield y 0 mid /\
get_bitfield x mid tot == get_bitfield y mid tot
))
(ensures (
x == y
))
let rec get_bitfield_partition_prop
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Tot bool
(decreases l)
= match l with
| [] ->
get_bitfield x lo hi = get_bitfield y lo hi
| mi :: q ->
lo <= mi && mi <= hi &&
get_bitfield_partition_prop x y mi hi q &&
get_bitfield x lo mi = get_bitfield y lo mi
val get_bitfield_partition
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Lemma
(requires (get_bitfield_partition_prop x y lo hi l))
(ensures (get_bitfield x lo hi == get_bitfield y lo hi))
let get_bitfield_partition_3
(#tot: pos)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 lo == get_bitfield y 0 lo /\
get_bitfield x lo hi == get_bitfield y lo hi /\
get_bitfield x hi tot == get_bitfield y hi tot
))
(ensures (x == y))
= assert_norm (get_bitfield_partition_prop x y 0 tot [lo; hi]); // does not need fuel, thanks to normalization
get_bitfield_partition x y 0 tot [lo; hi];
get_bitfield_full x;
get_bitfield_full y
val get_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
: Lemma
(x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat))
val set_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
(v: ubitfield tot1 (hi - lo))
: Lemma
(x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat))
val set_bitfield_bound
(#tot: pos)
(x: U.uint_t tot)
(bound: nat { bound <= tot /\ x < pow2 bound })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= bound })
(v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v < pow2 bound)
val set_bitfield_set_bitfield_get_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= hi - lo }) (v' : ubitfield tot (hi' - lo'))
: Lemma
( let v = set_bitfield (get_bitfield x lo hi) lo' hi' v' in
v < pow2 (hi - lo) /\
set_bitfield x lo hi v == set_bitfield x (lo + lo') (lo + hi') v' )
val get_bitfield_eq
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo))
val get_bitfield_eq_2
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo))
val set_bitfield_eq
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo))
module U32 = FStar.UInt32
inline_for_extraction
noextract
noeq
type uint_t (tot: pos) (t: Type) = {
v: (t -> Tot (U.uint_t tot));
uint_to_t: (U.uint_t tot -> Tot t);
v_uint_to_t: ((x: U.uint_t tot) -> Lemma (v (uint_to_t x) == x));
uint_to_t_v: ((x: t) -> Lemma (uint_to_t (v x) == x));
get_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) (U32.v lo) (U32.v hi) }));
set_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> (z: t { v z < pow2 (U32.v hi - U32.v lo) }) -> Tot (y : t { v y == set_bitfield (v x) (U32.v lo) (U32.v hi) (v z)}));
get_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) lo hi }));
set_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y : t { v y == set_bitfield (v x) lo hi (v z)}));
logor: ((x: t) -> (y: t) -> Tot (z: t { v z == v x `U.logor` v y }));
bitfield_eq_lhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot t);
bitfield_eq_rhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y: t { bitfield_eq_lhs x lo hi == y <==> (get_bitfield x lo hi <: t) == z }));
}
inline_for_extraction
let bitfield (#tot: pos) (#t: Type) (cl: uint_t tot t) (sz: nat { sz <= tot }) : Tot Type =
(x: t { cl.v x < pow2 sz })
let uint_t_v_uint_to_t #tot #t (cl: uint_t tot t) (x: U.uint_t tot) : Lemma
(cl.v (cl.uint_to_t x) == x)
[SMTPat (cl.v (cl.uint_to_t x))]
= cl.v_uint_to_t x
let uint_t_uint_to_t_v #tot #t (cl: uint_t tot t) (x: t) : Lemma
(cl.uint_to_t (cl.v x) == x)
[SMTPat (cl.uint_to_t (cl.v x))]
= cl.uint_to_t_v x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.BitFields.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
cl: LowParse.BitFields.uint_t tot t ->
x: t ->
lo: Prims.nat ->
hi: Prims.nat{lo <= hi /\ hi <= tot} ->
z: LowParse.BitFields.bitfield cl (hi - lo)
-> FStar.Pervasives.Lemma
(ensures Mkuint_t?.get_bitfield cl (Mkuint_t?.set_bitfield cl x lo hi z) lo hi == z)
[SMTPat (Mkuint_t?.get_bitfield cl (Mkuint_t?.set_bitfield cl x lo hi z) lo hi)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.BitFields.bitfield",
"Prims.op_Subtraction",
"Prims._assert",
"Prims.eq2",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield",
"Prims.unit",
"LowParse.BitFields.get_bitfield_set_bitfield_same",
"Prims.l_True",
"Prims.squash",
"Prims.l_or",
"FStar.UInt.uint_t",
"LowParse.BitFields.get_bitfield",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let uint_get_bitfield_set_bitfield_same
#tot
#t
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
: Lemma (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi == z)
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)] =
| get_bitfield_set_bitfield_same (cl.v x) lo hi (cl.v z);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)) ==
cl.uint_to_t (cl.v z)) | false |
Steel.FractionalPermission.fst | Steel.FractionalPermission.sum_perm | val sum_perm (p1 p2: perm) : Tot perm | val sum_perm (p1 p2: perm) : Tot perm | let sum_perm (p1 p2: perm) : Tot perm =
MkPerm (MkPerm?.v p1 +. MkPerm?.v p2) | {
"file_name": "lib/steel/Steel.FractionalPermission.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 40,
"end_line": 41,
"start_col": 0,
"start_line": 40
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.FractionalPermission
open FStar.Real
/// This module defines fractional permissions, to be used with Steel references
/// A fractional permission is a real value between 0 (excluded) and 1.
/// 1 represents full ownership, while any fraction corresponds to a shared
/// permission.
/// Note: Does not use real literals, but rather the wrappers one, zero, two, …
/// Real literals are currently not supported by Meta-F*'s reflection framework
[@@erasable]
noeq type perm : Type0 =
| MkPerm: v:real{ v >. zero } -> perm
/// A reference is only safely writeable if we have full permission
let writeable (p: perm) : GTot bool =
MkPerm?.v p = one
/// Helper around splitting a permission in half
let half_perm (p: perm) : Tot perm =
MkPerm ((MkPerm?.v p) /. two) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.FractionalPermission.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | p1: Steel.FractionalPermission.perm -> p2: Steel.FractionalPermission.perm
-> Steel.FractionalPermission.perm | Prims.Tot | [
"total"
] | [] | [
"Steel.FractionalPermission.perm",
"Steel.FractionalPermission.MkPerm",
"FStar.Real.op_Plus_Dot",
"Steel.FractionalPermission.__proj__MkPerm__item__v"
] | [] | false | false | false | true | false | let sum_perm (p1 p2: perm) : Tot perm =
| MkPerm (MkPerm?.v p1 +. MkPerm?.v p2) | false |
Vale.AsLowStar.MemoryHelpers.fst | Vale.AsLowStar.MemoryHelpers.relate_modifies | val relate_modifies (args:list arg) (m0 m1:ME.vale_full_heap)
: Lemma
(requires
ME.modifies (VSig.mloc_modified_args args) (ME.get_vale_heap m0) (ME.get_vale_heap m1))
(ensures
B.modifies (loc_modified_args args)
(hs_of_mem (as_mem m0.vf_heap))
(hs_of_mem (as_mem m1.vf_heap))) | val relate_modifies (args:list arg) (m0 m1:ME.vale_full_heap)
: Lemma
(requires
ME.modifies (VSig.mloc_modified_args args) (ME.get_vale_heap m0) (ME.get_vale_heap m1))
(ensures
B.modifies (loc_modified_args args)
(hs_of_mem (as_mem m0.vf_heap))
(hs_of_mem (as_mem m1.vf_heap))) | let relate_modifies args m0 m1 = loc_eq args | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 39,
"start_col": 0,
"start_line": 39
} | module Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module ME = Vale.X64.Memory
module VSig = Vale.AsLowStar.ValeSig
module IX64 = Vale.Interop.X64
friend Vale.X64.Memory
friend Vale.X64.Memory_Sems
friend Vale.X64.Stack_i
friend Vale.X64.Stack_Sems
friend Vale.X64.Decls
friend Vale.X64.StateLemmas
friend Vale.X64.MemoryAdapters
let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let state_eq_down_mem (va_s1:V.va_state) (s1:_) = ()
let rec loc_eq (args:list arg)
: Lemma (VSig.mloc_modified_args args == loc_modified_args args)
= match args with
| [] -> ()
| hd :: tl -> loc_eq tl | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fst.checked",
"Vale.X64.Stack_Sems.fst.checked",
"Vale.X64.Stack_i.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.Memory_Sems.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Decls.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.MemoryHelpers.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MES"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
args: Prims.list Vale.Interop.Base.arg ->
m0: Vale.X64.Memory.vale_full_heap ->
m1: Vale.X64.Memory.vale_full_heap
-> FStar.Pervasives.Lemma
(requires
Vale.X64.Memory.modifies (Vale.AsLowStar.ValeSig.mloc_modified_args args)
(Vale.X64.Memory.get_vale_heap m0)
(Vale.X64.Memory.get_vale_heap m1))
(ensures
LowStar.Monotonic.Buffer.modifies (Vale.Interop.Base.loc_modified_args args)
(Vale.Interop.Heap_s.hs_of_mem (Vale.X64.MemoryAdapters.as_mem (Mkvale_full_heap?.vf_heap m0
)))
(Vale.Interop.Heap_s.hs_of_mem (Vale.X64.MemoryAdapters.as_mem (Mkvale_full_heap?.vf_heap m1
)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Vale.Interop.Base.arg",
"Vale.X64.Memory.vale_full_heap",
"Vale.AsLowStar.MemoryHelpers.loc_eq",
"Prims.unit"
] | [] | true | false | true | false | false | let relate_modifies args m0 m1 =
| loc_eq args | false |
LowParse.BitFields.fsti | LowParse.BitFields.uint_set_bitfield_set_bitfield_same_gen | val uint_set_bitfield_set_bitfield_same_gen
(#tot #t: _)
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
(lo': nat)
(hi': nat{lo' <= lo /\ hi <= hi' /\ hi' <= tot})
(z': bitfield cl (hi' - lo'))
: Lemma (cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z' == cl.set_bitfield x lo' hi' z') | val uint_set_bitfield_set_bitfield_same_gen
(#tot #t: _)
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
(lo': nat)
(hi': nat{lo' <= lo /\ hi <= hi' /\ hi' <= tot})
(z': bitfield cl (hi' - lo'))
: Lemma (cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z' == cl.set_bitfield x lo' hi' z') | let uint_set_bitfield_set_bitfield_same_gen
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
(lo': nat) (hi': nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (z' : bitfield cl (hi' - lo'))
: Lemma
(cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z' == cl.set_bitfield x lo' hi' z')
= set_bitfield_set_bitfield_same_gen (cl.v x) lo hi (cl.v z) lo' hi' (cl.v z');
assert (cl.uint_to_t (cl.v (cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z')) == cl.uint_to_t (cl.v (cl.set_bitfield x lo' hi' z'))) | {
"file_name": "src/lowparse/LowParse.BitFields.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 141,
"end_line": 317,
"start_col": 0,
"start_line": 310
} | module LowParse.BitFields
module U = FStar.UInt
type ubitfield (tot: nat) (sz: nat) = (x: U.uint_t tot { x < pow2 sz })
// IMPORTANT: these bitfield operators are defined in a least
// significant bit (LSB) first fashion.
val get_bitfield
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Tot (ubitfield tot (hi - lo))
val get_bitfield_logor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi)
val get_bitfield_logxor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi)
val set_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Tot (U.uint_t tot)
val get_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(get_bitfield (set_bitfield x lo hi v) lo hi == v)
val get_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot })
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi'))
val set_bitfield_set_bitfield_same_gen
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot })
(v' : ubitfield tot (hi' - lo'))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v'))
let set_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(v' : ubitfield tot (hi - lo))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v'))
= set_bitfield_set_bitfield_same_gen x lo hi v lo hi v'
val set_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo'))
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v))
val set_bitfield_full
(#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot)
: Lemma
(set_bitfield x 0 tot y == y)
val set_bitfield_empty
(#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0)
: Lemma
(set_bitfield x i i y == x)
val get_bitfield_zero
(tot: pos)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield #tot 0 lo hi == 0)
val get_bitfield_full
(#tot: pos)
(x: U.uint_t tot)
: Lemma
(get_bitfield x 0 tot == x)
val get_bitfield_empty
(#tot: pos)
(x: U.uint_t tot)
(i: nat { i <= tot })
: Lemma
(get_bitfield x i i == 0)
val lt_pow2_get_bitfield_hi
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (x < pow2 mi))
(ensures (get_bitfield x mi tot == 0))
val get_bitfield_hi_lt_pow2
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (get_bitfield x mi tot == 0))
(ensures (x < pow2 mi))
val get_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo })
: Lemma
(get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi'))
val get_bitfield_zero_inner
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi })
: Lemma
(ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0))
val set_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(set_bitfield x lo hi (get_bitfield x lo hi) == x)
val get_bitfield_partition_2_gen
(#tot: pos)
(lo: nat)
(mi: nat)
(hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x lo mi == get_bitfield y lo mi /\
get_bitfield x mi hi == get_bitfield y mi hi
))
(ensures (
get_bitfield x lo hi == get_bitfield y lo hi
))
val get_bitfield_partition_2
(#tot: pos)
(mid: nat { mid <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 mid == get_bitfield y 0 mid /\
get_bitfield x mid tot == get_bitfield y mid tot
))
(ensures (
x == y
))
let rec get_bitfield_partition_prop
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Tot bool
(decreases l)
= match l with
| [] ->
get_bitfield x lo hi = get_bitfield y lo hi
| mi :: q ->
lo <= mi && mi <= hi &&
get_bitfield_partition_prop x y mi hi q &&
get_bitfield x lo mi = get_bitfield y lo mi
val get_bitfield_partition
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Lemma
(requires (get_bitfield_partition_prop x y lo hi l))
(ensures (get_bitfield x lo hi == get_bitfield y lo hi))
let get_bitfield_partition_3
(#tot: pos)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 lo == get_bitfield y 0 lo /\
get_bitfield x lo hi == get_bitfield y lo hi /\
get_bitfield x hi tot == get_bitfield y hi tot
))
(ensures (x == y))
= assert_norm (get_bitfield_partition_prop x y 0 tot [lo; hi]); // does not need fuel, thanks to normalization
get_bitfield_partition x y 0 tot [lo; hi];
get_bitfield_full x;
get_bitfield_full y
val get_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
: Lemma
(x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat))
val set_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
(v: ubitfield tot1 (hi - lo))
: Lemma
(x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat))
val set_bitfield_bound
(#tot: pos)
(x: U.uint_t tot)
(bound: nat { bound <= tot /\ x < pow2 bound })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= bound })
(v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v < pow2 bound)
val set_bitfield_set_bitfield_get_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= hi - lo }) (v' : ubitfield tot (hi' - lo'))
: Lemma
( let v = set_bitfield (get_bitfield x lo hi) lo' hi' v' in
v < pow2 (hi - lo) /\
set_bitfield x lo hi v == set_bitfield x (lo + lo') (lo + hi') v' )
val get_bitfield_eq
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo))
val get_bitfield_eq_2
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo))
val set_bitfield_eq
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo))
module U32 = FStar.UInt32
inline_for_extraction
noextract
noeq
type uint_t (tot: pos) (t: Type) = {
v: (t -> Tot (U.uint_t tot));
uint_to_t: (U.uint_t tot -> Tot t);
v_uint_to_t: ((x: U.uint_t tot) -> Lemma (v (uint_to_t x) == x));
uint_to_t_v: ((x: t) -> Lemma (uint_to_t (v x) == x));
get_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) (U32.v lo) (U32.v hi) }));
set_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> (z: t { v z < pow2 (U32.v hi - U32.v lo) }) -> Tot (y : t { v y == set_bitfield (v x) (U32.v lo) (U32.v hi) (v z)}));
get_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) lo hi }));
set_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y : t { v y == set_bitfield (v x) lo hi (v z)}));
logor: ((x: t) -> (y: t) -> Tot (z: t { v z == v x `U.logor` v y }));
bitfield_eq_lhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot t);
bitfield_eq_rhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y: t { bitfield_eq_lhs x lo hi == y <==> (get_bitfield x lo hi <: t) == z }));
}
inline_for_extraction
let bitfield (#tot: pos) (#t: Type) (cl: uint_t tot t) (sz: nat { sz <= tot }) : Tot Type =
(x: t { cl.v x < pow2 sz })
let uint_t_v_uint_to_t #tot #t (cl: uint_t tot t) (x: U.uint_t tot) : Lemma
(cl.v (cl.uint_to_t x) == x)
[SMTPat (cl.v (cl.uint_to_t x))]
= cl.v_uint_to_t x
let uint_t_uint_to_t_v #tot #t (cl: uint_t tot t) (x: t) : Lemma
(cl.uint_to_t (cl.v x) == x)
[SMTPat (cl.uint_to_t (cl.v x))]
= cl.uint_to_t_v x
let uint_get_bitfield_set_bitfield_same
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
: Lemma
(cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi == z)
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)]
= get_bitfield_set_bitfield_same (cl.v x) lo hi (cl.v z);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)) == cl.uint_to_t (cl.v z))
let uint_get_bitfield_set_bitfield_other
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo') })
: Lemma
(cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi' == cl.get_bitfield x lo' hi')
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi')]
= get_bitfield_set_bitfield_other (cl.v x) lo hi (cl.v z) lo' hi';
assert (cl.uint_to_t (cl.v (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi')) == cl.uint_to_t (cl.v (cl.get_bitfield x lo' hi'))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.BitFields.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
cl: LowParse.BitFields.uint_t tot t ->
x: t ->
lo: Prims.nat ->
hi: Prims.nat{lo <= hi /\ hi <= tot} ->
z: LowParse.BitFields.bitfield cl (hi - lo) ->
lo': Prims.nat ->
hi': Prims.nat{lo' <= lo /\ hi <= hi' /\ hi' <= tot} ->
z': LowParse.BitFields.bitfield cl (hi' - lo')
-> FStar.Pervasives.Lemma
(ensures
Mkuint_t?.set_bitfield cl (Mkuint_t?.set_bitfield cl x lo hi z) lo' hi' z' ==
Mkuint_t?.set_bitfield cl x lo' hi' z') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.BitFields.bitfield",
"Prims.op_Subtraction",
"Prims._assert",
"Prims.eq2",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield",
"Prims.unit",
"LowParse.BitFields.set_bitfield_set_bitfield_same_gen",
"Prims.l_True",
"Prims.squash",
"Prims.l_or",
"FStar.UInt.uint_t",
"LowParse.BitFields.set_bitfield",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let uint_set_bitfield_set_bitfield_same_gen
#tot
#t
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
(lo': nat)
(hi': nat{lo' <= lo /\ hi <= hi' /\ hi' <= tot})
(z': bitfield cl (hi' - lo'))
: Lemma (cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z' == cl.set_bitfield x lo' hi' z') =
| set_bitfield_set_bitfield_same_gen (cl.v x) lo hi (cl.v z) lo' hi' (cl.v z');
assert (cl.uint_to_t (cl.v (cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z')) ==
cl.uint_to_t (cl.v (cl.set_bitfield x lo' hi' z'))) | false |
FStar.Tactics.V1.SyntaxHelpers.fst | FStar.Tactics.V1.SyntaxHelpers.mk_tot_arr | val mk_tot_arr (bs: list binder) (cod: term) : Tac term | val mk_tot_arr (bs: list binder) (cod: term) : Tac term | let rec mk_tot_arr (bs: list binder) (cod : term) : Tac term =
match bs with
| [] -> cod
| (b::bs) ->
pack (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr bs cod)))) | {
"file_name": "ulib/FStar.Tactics.V1.SyntaxHelpers.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 65,
"end_line": 67,
"start_col": 0,
"start_line": 63
} | module FStar.Tactics.V1.SyntaxHelpers
open FStar.Reflection.V1
open FStar.Tactics.Effect
open FStar.Stubs.Tactics.Types
open FStar.Stubs.Tactics.V1.Builtins
(* These are fully-named variants of functions found in FStar.Reflection *)
private
let rec collect_arr' (bs : list binder) (c : comp) : Tac (list binder * comp) =
begin match inspect_comp c with
| C_Total t ->
begin match inspect t with
| Tv_Arrow b c ->
collect_arr' (b::bs) c
| _ ->
(bs, c)
end
| _ -> (bs, c)
end
val collect_arr_bs : typ -> Tac (list binder * comp)
let collect_arr_bs t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
(List.Tot.Base.rev bs, c)
val collect_arr : typ -> Tac (list typ * comp)
let collect_arr t =
let (bs, c) = collect_arr' [] (pack_comp (C_Total t)) in
let ts = List.Tot.Base.map type_of_binder bs in
(List.Tot.Base.rev ts, c)
private
let rec collect_abs' (bs : list binder) (t : term) : Tac (list binder * term) (decreases t) =
match inspect t with
| Tv_Abs b t' ->
collect_abs' (b::bs) t'
| _ -> (bs, t)
val collect_abs : term -> Tac (list binder * term)
let collect_abs t =
let (bs, t') = collect_abs' [] t in
(List.Tot.Base.rev bs, t')
(* Copied from FStar.Tactics.Derived *)
private
let fail (#a:Type) (m:string) = raise #a (TacticFailure m)
let rec mk_arr (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack (Tv_Arrow b cod)
| (b::bs) ->
pack (Tv_Arrow b (pack_comp (C_Total (mk_arr bs cod))))
let rec mk_arr_curried (bs: list binder) (cod : comp) : Tac term =
match bs with
| [] -> fail "mk_arr, empty binders"
| [b] -> pack_curried (Tv_Arrow b cod)
| (b::bs) -> pack_curried (Tv_Arrow b (pack_comp (C_Total (mk_arr_curried bs cod)))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Stubs.Tactics.V1.Builtins.fsti.checked",
"FStar.Stubs.Tactics.Types.fsti.checked",
"FStar.Reflection.V1.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V1.SyntaxHelpers.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.V1.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Stubs.Tactics.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V1",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | bs: Prims.list FStar.Stubs.Reflection.Types.binder -> cod: FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"FStar.Stubs.Reflection.Types.binder",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Tactics.V1.Builtins.pack",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Stubs.Reflection.V1.Data.Tv_Arrow",
"FStar.Stubs.Reflection.Types.comp",
"FStar.Stubs.Reflection.V1.Builtins.pack_comp",
"FStar.Stubs.Reflection.V1.Data.comp_view",
"FStar.Stubs.Reflection.V1.Data.C_Total",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Tactics.V1.SyntaxHelpers.mk_tot_arr"
] | [
"recursion"
] | false | true | false | false | false | let rec mk_tot_arr (bs: list binder) (cod: term) : Tac term =
| match bs with
| [] -> cod
| b :: bs -> pack (Tv_Arrow b (pack_comp (C_Total (mk_tot_arr bs cod)))) | false |
Steel.FractionalPermission.fst | Steel.FractionalPermission.comp_perm | val comp_perm (p: perm{p `lesser_perm` full_perm}) : GTot perm | val comp_perm (p: perm{p `lesser_perm` full_perm}) : GTot perm | let comp_perm (p:perm{p `lesser_perm` full_perm}) : GTot perm =
MkPerm (1.0R -. MkPerm?.v p) | {
"file_name": "lib/steel/Steel.FractionalPermission.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 30,
"end_line": 55,
"start_col": 0,
"start_line": 54
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.FractionalPermission
open FStar.Real
/// This module defines fractional permissions, to be used with Steel references
/// A fractional permission is a real value between 0 (excluded) and 1.
/// 1 represents full ownership, while any fraction corresponds to a shared
/// permission.
/// Note: Does not use real literals, but rather the wrappers one, zero, two, …
/// Real literals are currently not supported by Meta-F*'s reflection framework
[@@erasable]
noeq type perm : Type0 =
| MkPerm: v:real{ v >. zero } -> perm
/// A reference is only safely writeable if we have full permission
let writeable (p: perm) : GTot bool =
MkPerm?.v p = one
/// Helper around splitting a permission in half
let half_perm (p: perm) : Tot perm =
MkPerm ((MkPerm?.v p) /. two)
/// Helper to combine two permissions into one
let sum_perm (p1 p2: perm) : Tot perm =
MkPerm (MkPerm?.v p1 +. MkPerm?.v p2)
/// Helper to compare two permissions
let lesser_equal_perm (p1 p2:perm) : GTot bool =
MkPerm?.v p1 <=. MkPerm?.v p2
let lesser_perm (p1 p2:perm) : GTot bool =
MkPerm?.v p1 <. MkPerm?.v p2
/// Wrapper around the full permission value
let full_perm : perm = MkPerm one | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.FractionalPermission.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p:
Steel.FractionalPermission.perm
{Steel.FractionalPermission.lesser_perm p Steel.FractionalPermission.full_perm}
-> Prims.GTot Steel.FractionalPermission.perm | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.FractionalPermission.perm",
"Prims.b2t",
"Steel.FractionalPermission.lesser_perm",
"Steel.FractionalPermission.full_perm",
"Steel.FractionalPermission.MkPerm",
"FStar.Real.op_Subtraction_Dot",
"Steel.FractionalPermission.__proj__MkPerm__item__v"
] | [] | false | false | false | false | false | let comp_perm (p: perm{p `lesser_perm` full_perm}) : GTot perm =
| MkPerm (1.0R -. MkPerm?.v p) | false |
Steel.FractionalPermission.fst | Steel.FractionalPermission.full_perm | val full_perm:perm | val full_perm:perm | let full_perm : perm = MkPerm one | {
"file_name": "lib/steel/Steel.FractionalPermission.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 33,
"end_line": 51,
"start_col": 0,
"start_line": 51
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.FractionalPermission
open FStar.Real
/// This module defines fractional permissions, to be used with Steel references
/// A fractional permission is a real value between 0 (excluded) and 1.
/// 1 represents full ownership, while any fraction corresponds to a shared
/// permission.
/// Note: Does not use real literals, but rather the wrappers one, zero, two, …
/// Real literals are currently not supported by Meta-F*'s reflection framework
[@@erasable]
noeq type perm : Type0 =
| MkPerm: v:real{ v >. zero } -> perm
/// A reference is only safely writeable if we have full permission
let writeable (p: perm) : GTot bool =
MkPerm?.v p = one
/// Helper around splitting a permission in half
let half_perm (p: perm) : Tot perm =
MkPerm ((MkPerm?.v p) /. two)
/// Helper to combine two permissions into one
let sum_perm (p1 p2: perm) : Tot perm =
MkPerm (MkPerm?.v p1 +. MkPerm?.v p2)
/// Helper to compare two permissions
let lesser_equal_perm (p1 p2:perm) : GTot bool =
MkPerm?.v p1 <=. MkPerm?.v p2
let lesser_perm (p1 p2:perm) : GTot bool =
MkPerm?.v p1 <. MkPerm?.v p2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.FractionalPermission.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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 | Steel.FractionalPermission.perm | Prims.Tot | [
"total"
] | [] | [
"Steel.FractionalPermission.MkPerm",
"FStar.Real.one"
] | [] | false | false | false | true | false | let full_perm:perm =
| MkPerm one | false |
Vale.AsLowStar.MemoryHelpers.fst | Vale.AsLowStar.MemoryHelpers.buffer_as_seq_reveal | val buffer_as_seq_reveal
(src t:ME.base_typ)
(x:buf_t src t)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args}) : Lemma
(let y = as_vale_buffer x in
let db = get_downview x in
DV.length_eq db;
let mem = mk_mem args h0 in
Seq.equal
(LSig.nat_to_uint_seq_t t (ME.buffer_as_seq (create_initial_vale_heap mem) y))
(UV.as_seq h0 (UV.mk_buffer db (LSig.view_of_base_typ t)))) | val buffer_as_seq_reveal
(src t:ME.base_typ)
(x:buf_t src t)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args}) : Lemma
(let y = as_vale_buffer x in
let db = get_downview x in
DV.length_eq db;
let mem = mk_mem args h0 in
Seq.equal
(LSig.nat_to_uint_seq_t t (ME.buffer_as_seq (create_initial_vale_heap mem) y))
(UV.as_seq h0 (UV.mk_buffer db (LSig.view_of_base_typ t)))) | let buffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 111,
"end_line": 48,
"start_col": 0,
"start_line": 48
} | module Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module ME = Vale.X64.Memory
module VSig = Vale.AsLowStar.ValeSig
module IX64 = Vale.Interop.X64
friend Vale.X64.Memory
friend Vale.X64.Memory_Sems
friend Vale.X64.Stack_i
friend Vale.X64.Stack_Sems
friend Vale.X64.Decls
friend Vale.X64.StateLemmas
friend Vale.X64.MemoryAdapters
let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let state_eq_down_mem (va_s1:V.va_state) (s1:_) = ()
let rec loc_eq (args:list arg)
: Lemma (VSig.mloc_modified_args args == loc_modified_args args)
= match args with
| [] -> ()
| hd :: tl -> loc_eq tl
let relate_modifies args m0 m1 = loc_eq args
let reveal_readable #src #t x s = ()
let reveal_imm_readable #src #t x s = ()
let readable_live #src #t x s = ()
let readable_imm_live #src #t x s = ()
let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
//let get_heap_mk_mem_reveal args h0 = ()
let lemma_as_mem_as_vale_mem h = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fst.checked",
"Vale.X64.Stack_Sems.fst.checked",
"Vale.X64.Stack_i.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.Memory_Sems.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Decls.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.MemoryHelpers.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MES"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
src: Vale.Arch.HeapTypes_s.base_typ ->
t: Vale.Arch.HeapTypes_s.base_typ ->
x: Vale.Interop.Base.buf_t src t ->
args: Vale.Interop.X64.arg_list ->
h0: FStar.Monotonic.HyperStack.mem{Vale.Interop.Base.mem_roots_p h0 args}
-> FStar.Pervasives.Lemma
(ensures
(let y = Vale.X64.MemoryAdapters.as_vale_buffer x in
let db = Vale.Interop.Types.get_downview x in
LowStar.BufferView.Down.length_eq db;
let mem = Vale.Interop.Base.mk_mem args h0 in
FStar.Seq.Base.equal (Vale.AsLowStar.LowStarSig.nat_to_uint_seq_t t
(Vale.X64.Memory.buffer_as_seq (Vale.X64.MemoryAdapters.create_initial_vale_heap mem)
y))
(LowStar.BufferView.Up.as_seq h0
(LowStar.BufferView.Up.mk_buffer db (Vale.AsLowStar.LowStarSig.view_of_base_typ t))))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buf_t",
"Vale.Interop.X64.arg_list",
"FStar.Monotonic.HyperStack.mem",
"Vale.Interop.Base.mem_roots_p",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Memory.vale_full_heap",
"Vale.X64.Memory.vale_heap",
"Vale.X64.Memory.get_vale_heap",
"Prims.unit"
] | [] | true | false | true | false | false | let buffer_as_seq_reveal src t x args h0 =
| FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap | false |
Steel.FractionalPermission.fst | Steel.FractionalPermission.half_perm | val half_perm (p: perm) : Tot perm | val half_perm (p: perm) : Tot perm | let half_perm (p: perm) : Tot perm =
MkPerm ((MkPerm?.v p) /. two) | {
"file_name": "lib/steel/Steel.FractionalPermission.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 31,
"end_line": 37,
"start_col": 0,
"start_line": 36
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.FractionalPermission
open FStar.Real
/// This module defines fractional permissions, to be used with Steel references
/// A fractional permission is a real value between 0 (excluded) and 1.
/// 1 represents full ownership, while any fraction corresponds to a shared
/// permission.
/// Note: Does not use real literals, but rather the wrappers one, zero, two, …
/// Real literals are currently not supported by Meta-F*'s reflection framework
[@@erasable]
noeq type perm : Type0 =
| MkPerm: v:real{ v >. zero } -> perm
/// A reference is only safely writeable if we have full permission
let writeable (p: perm) : GTot bool =
MkPerm?.v p = one | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.FractionalPermission.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Steel.FractionalPermission.perm -> Steel.FractionalPermission.perm | Prims.Tot | [
"total"
] | [] | [
"Steel.FractionalPermission.perm",
"Steel.FractionalPermission.MkPerm",
"FStar.Real.op_Slash_Dot",
"Steel.FractionalPermission.__proj__MkPerm__item__v",
"FStar.Real.two"
] | [] | false | false | false | true | false | let half_perm (p: perm) : Tot perm =
| MkPerm ((MkPerm?.v p) /. two) | false |
LowParse.BitFields.fsti | LowParse.BitFields.uint_get_bitfield_set_bitfield_other | val uint_get_bitfield_set_bitfield_other
(#tot #t: _)
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
(lo': nat)
(hi': nat{lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo')})
: Lemma (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi' == cl.get_bitfield x lo' hi')
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi')] | val uint_get_bitfield_set_bitfield_other
(#tot #t: _)
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
(lo': nat)
(hi': nat{lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo')})
: Lemma (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi' == cl.get_bitfield x lo' hi')
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi')] | let uint_get_bitfield_set_bitfield_other
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo') })
: Lemma
(cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi' == cl.get_bitfield x lo' hi')
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi')]
= get_bitfield_set_bitfield_other (cl.v x) lo hi (cl.v z) lo' hi';
assert (cl.uint_to_t (cl.v (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi')) == cl.uint_to_t (cl.v (cl.get_bitfield x lo' hi'))) | {
"file_name": "src/lowparse/LowParse.BitFields.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 135,
"end_line": 308,
"start_col": 0,
"start_line": 300
} | module LowParse.BitFields
module U = FStar.UInt
type ubitfield (tot: nat) (sz: nat) = (x: U.uint_t tot { x < pow2 sz })
// IMPORTANT: these bitfield operators are defined in a least
// significant bit (LSB) first fashion.
val get_bitfield
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Tot (ubitfield tot (hi - lo))
val get_bitfield_logor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi)
val get_bitfield_logxor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi)
val set_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Tot (U.uint_t tot)
val get_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(get_bitfield (set_bitfield x lo hi v) lo hi == v)
val get_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot })
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi'))
val set_bitfield_set_bitfield_same_gen
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot })
(v' : ubitfield tot (hi' - lo'))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v'))
let set_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(v' : ubitfield tot (hi - lo))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v'))
= set_bitfield_set_bitfield_same_gen x lo hi v lo hi v'
val set_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo'))
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v))
val set_bitfield_full
(#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot)
: Lemma
(set_bitfield x 0 tot y == y)
val set_bitfield_empty
(#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0)
: Lemma
(set_bitfield x i i y == x)
val get_bitfield_zero
(tot: pos)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield #tot 0 lo hi == 0)
val get_bitfield_full
(#tot: pos)
(x: U.uint_t tot)
: Lemma
(get_bitfield x 0 tot == x)
val get_bitfield_empty
(#tot: pos)
(x: U.uint_t tot)
(i: nat { i <= tot })
: Lemma
(get_bitfield x i i == 0)
val lt_pow2_get_bitfield_hi
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (x < pow2 mi))
(ensures (get_bitfield x mi tot == 0))
val get_bitfield_hi_lt_pow2
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (get_bitfield x mi tot == 0))
(ensures (x < pow2 mi))
val get_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo })
: Lemma
(get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi'))
val get_bitfield_zero_inner
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi })
: Lemma
(ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0))
val set_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(set_bitfield x lo hi (get_bitfield x lo hi) == x)
val get_bitfield_partition_2_gen
(#tot: pos)
(lo: nat)
(mi: nat)
(hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x lo mi == get_bitfield y lo mi /\
get_bitfield x mi hi == get_bitfield y mi hi
))
(ensures (
get_bitfield x lo hi == get_bitfield y lo hi
))
val get_bitfield_partition_2
(#tot: pos)
(mid: nat { mid <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 mid == get_bitfield y 0 mid /\
get_bitfield x mid tot == get_bitfield y mid tot
))
(ensures (
x == y
))
let rec get_bitfield_partition_prop
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Tot bool
(decreases l)
= match l with
| [] ->
get_bitfield x lo hi = get_bitfield y lo hi
| mi :: q ->
lo <= mi && mi <= hi &&
get_bitfield_partition_prop x y mi hi q &&
get_bitfield x lo mi = get_bitfield y lo mi
val get_bitfield_partition
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Lemma
(requires (get_bitfield_partition_prop x y lo hi l))
(ensures (get_bitfield x lo hi == get_bitfield y lo hi))
let get_bitfield_partition_3
(#tot: pos)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 lo == get_bitfield y 0 lo /\
get_bitfield x lo hi == get_bitfield y lo hi /\
get_bitfield x hi tot == get_bitfield y hi tot
))
(ensures (x == y))
= assert_norm (get_bitfield_partition_prop x y 0 tot [lo; hi]); // does not need fuel, thanks to normalization
get_bitfield_partition x y 0 tot [lo; hi];
get_bitfield_full x;
get_bitfield_full y
val get_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
: Lemma
(x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat))
val set_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
(v: ubitfield tot1 (hi - lo))
: Lemma
(x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat))
val set_bitfield_bound
(#tot: pos)
(x: U.uint_t tot)
(bound: nat { bound <= tot /\ x < pow2 bound })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= bound })
(v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v < pow2 bound)
val set_bitfield_set_bitfield_get_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= hi - lo }) (v' : ubitfield tot (hi' - lo'))
: Lemma
( let v = set_bitfield (get_bitfield x lo hi) lo' hi' v' in
v < pow2 (hi - lo) /\
set_bitfield x lo hi v == set_bitfield x (lo + lo') (lo + hi') v' )
val get_bitfield_eq
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo))
val get_bitfield_eq_2
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo))
val set_bitfield_eq
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo))
module U32 = FStar.UInt32
inline_for_extraction
noextract
noeq
type uint_t (tot: pos) (t: Type) = {
v: (t -> Tot (U.uint_t tot));
uint_to_t: (U.uint_t tot -> Tot t);
v_uint_to_t: ((x: U.uint_t tot) -> Lemma (v (uint_to_t x) == x));
uint_to_t_v: ((x: t) -> Lemma (uint_to_t (v x) == x));
get_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) (U32.v lo) (U32.v hi) }));
set_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> (z: t { v z < pow2 (U32.v hi - U32.v lo) }) -> Tot (y : t { v y == set_bitfield (v x) (U32.v lo) (U32.v hi) (v z)}));
get_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) lo hi }));
set_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y : t { v y == set_bitfield (v x) lo hi (v z)}));
logor: ((x: t) -> (y: t) -> Tot (z: t { v z == v x `U.logor` v y }));
bitfield_eq_lhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot t);
bitfield_eq_rhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y: t { bitfield_eq_lhs x lo hi == y <==> (get_bitfield x lo hi <: t) == z }));
}
inline_for_extraction
let bitfield (#tot: pos) (#t: Type) (cl: uint_t tot t) (sz: nat { sz <= tot }) : Tot Type =
(x: t { cl.v x < pow2 sz })
let uint_t_v_uint_to_t #tot #t (cl: uint_t tot t) (x: U.uint_t tot) : Lemma
(cl.v (cl.uint_to_t x) == x)
[SMTPat (cl.v (cl.uint_to_t x))]
= cl.v_uint_to_t x
let uint_t_uint_to_t_v #tot #t (cl: uint_t tot t) (x: t) : Lemma
(cl.uint_to_t (cl.v x) == x)
[SMTPat (cl.uint_to_t (cl.v x))]
= cl.uint_to_t_v x
let uint_get_bitfield_set_bitfield_same
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
: Lemma
(cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi == z)
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)]
= get_bitfield_set_bitfield_same (cl.v x) lo hi (cl.v z);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)) == cl.uint_to_t (cl.v z)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.BitFields.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
cl: LowParse.BitFields.uint_t tot t ->
x: t ->
lo: Prims.nat ->
hi: Prims.nat{lo <= hi /\ hi <= tot} ->
z: LowParse.BitFields.bitfield cl (hi - lo) ->
lo': Prims.nat ->
hi': Prims.nat{lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo')}
-> FStar.Pervasives.Lemma
(ensures
Mkuint_t?.get_bitfield cl (Mkuint_t?.set_bitfield cl x lo hi z) lo' hi' ==
Mkuint_t?.get_bitfield cl x lo' hi')
[SMTPat (Mkuint_t?.get_bitfield cl (Mkuint_t?.set_bitfield cl x lo hi z) lo' hi')] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.BitFields.bitfield",
"Prims.op_Subtraction",
"Prims.l_or",
"Prims._assert",
"Prims.eq2",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield",
"Prims.unit",
"LowParse.BitFields.get_bitfield_set_bitfield_other",
"Prims.l_True",
"Prims.squash",
"FStar.UInt.uint_t",
"LowParse.BitFields.get_bitfield",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let uint_get_bitfield_set_bitfield_other
#tot
#t
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
(lo': nat)
(hi': nat{lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo')})
: Lemma (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi' == cl.get_bitfield x lo' hi')
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi')] =
| get_bitfield_set_bitfield_other (cl.v x) lo hi (cl.v z) lo' hi';
assert (cl.uint_to_t (cl.v (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi')) ==
cl.uint_to_t (cl.v (cl.get_bitfield x lo' hi'))) | false |
Vale.AsLowStar.MemoryHelpers.fst | Vale.AsLowStar.MemoryHelpers.loc_eq | val loc_eq (args: list arg) : Lemma (VSig.mloc_modified_args args == loc_modified_args args) | val loc_eq (args: list arg) : Lemma (VSig.mloc_modified_args args == loc_modified_args args) | let rec loc_eq (args:list arg)
: Lemma (VSig.mloc_modified_args args == loc_modified_args args)
= match args with
| [] -> ()
| hd :: tl -> loc_eq tl | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 37,
"start_col": 0,
"start_line": 33
} | module Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module ME = Vale.X64.Memory
module VSig = Vale.AsLowStar.ValeSig
module IX64 = Vale.Interop.X64
friend Vale.X64.Memory
friend Vale.X64.Memory_Sems
friend Vale.X64.Stack_i
friend Vale.X64.Stack_Sems
friend Vale.X64.Decls
friend Vale.X64.StateLemmas
friend Vale.X64.MemoryAdapters
let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let state_eq_down_mem (va_s1:V.va_state) (s1:_) = () | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fst.checked",
"Vale.X64.Stack_Sems.fst.checked",
"Vale.X64.Stack_i.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.Memory_Sems.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Decls.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.MemoryHelpers.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MES"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | args: Prims.list Vale.Interop.Base.arg
-> FStar.Pervasives.Lemma
(ensures
Vale.AsLowStar.ValeSig.mloc_modified_args args == Vale.Interop.Base.loc_modified_args args) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Vale.Interop.Base.arg",
"Vale.AsLowStar.MemoryHelpers.loc_eq",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"LowStar.Monotonic.Buffer.loc",
"Vale.AsLowStar.ValeSig.mloc_modified_args",
"Vale.Interop.Base.loc_modified_args",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec loc_eq (args: list arg) : Lemma (VSig.mloc_modified_args args == loc_modified_args args) =
| match args with
| [] -> ()
| hd :: tl -> loc_eq tl | false |
Steel.FractionalPermission.fst | Steel.FractionalPermission.sum_halves | val sum_halves (p: perm)
: Lemma (sum_perm (half_perm p) (half_perm p) == p)
[SMTPat (sum_perm (half_perm p) (half_perm p))] | val sum_halves (p: perm)
: Lemma (sum_perm (half_perm p) (half_perm p) == p)
[SMTPat (sum_perm (half_perm p) (half_perm p))] | let sum_halves (p:perm)
: Lemma (sum_perm (half_perm p) (half_perm p) == p)
[SMTPat (sum_perm (half_perm p) (half_perm p))]
= assert (forall (r:real). r /. 2.0R +. r /. 2.0R == r) | {
"file_name": "lib/steel/Steel.FractionalPermission.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 57,
"end_line": 61,
"start_col": 0,
"start_line": 58
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.FractionalPermission
open FStar.Real
/// This module defines fractional permissions, to be used with Steel references
/// A fractional permission is a real value between 0 (excluded) and 1.
/// 1 represents full ownership, while any fraction corresponds to a shared
/// permission.
/// Note: Does not use real literals, but rather the wrappers one, zero, two, …
/// Real literals are currently not supported by Meta-F*'s reflection framework
[@@erasable]
noeq type perm : Type0 =
| MkPerm: v:real{ v >. zero } -> perm
/// A reference is only safely writeable if we have full permission
let writeable (p: perm) : GTot bool =
MkPerm?.v p = one
/// Helper around splitting a permission in half
let half_perm (p: perm) : Tot perm =
MkPerm ((MkPerm?.v p) /. two)
/// Helper to combine two permissions into one
let sum_perm (p1 p2: perm) : Tot perm =
MkPerm (MkPerm?.v p1 +. MkPerm?.v p2)
/// Helper to compare two permissions
let lesser_equal_perm (p1 p2:perm) : GTot bool =
MkPerm?.v p1 <=. MkPerm?.v p2
let lesser_perm (p1 p2:perm) : GTot bool =
MkPerm?.v p1 <. MkPerm?.v p2
/// Wrapper around the full permission value
let full_perm : perm = MkPerm one
/// Complement of a permission
let comp_perm (p:perm{p `lesser_perm` full_perm}) : GTot perm =
MkPerm (1.0R -. MkPerm?.v p) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.FractionalPermission.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Real",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Steel.FractionalPermission.perm
-> FStar.Pervasives.Lemma
(ensures
Steel.FractionalPermission.sum_perm (Steel.FractionalPermission.half_perm p)
(Steel.FractionalPermission.half_perm p) ==
p)
[
SMTPat (Steel.FractionalPermission.sum_perm (Steel.FractionalPermission.half_perm p)
(Steel.FractionalPermission.half_perm p))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Steel.FractionalPermission.perm",
"Prims._assert",
"Prims.l_Forall",
"FStar.Real.real",
"Prims.eq2",
"FStar.Real.op_Plus_Dot",
"FStar.Real.op_Slash_Dot",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Steel.FractionalPermission.sum_perm",
"Steel.FractionalPermission.half_perm",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | false | false | true | false | false | let sum_halves (p: perm)
: Lemma (sum_perm (half_perm p) (half_perm p) == p)
[SMTPat (sum_perm (half_perm p) (half_perm p))] =
| assert (forall (r: real). r /. 2.0R +. r /. 2.0R == r) | false |
LowParse.BitFields.fsti | LowParse.BitFields.uint_set_bitfield_set_bitfield_same | val uint_set_bitfield_set_bitfield_same
(#tot #t: _)
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z z': bitfield cl (hi - lo))
: Lemma (cl.set_bitfield (cl.set_bitfield x lo hi z) lo hi z' == cl.set_bitfield x lo hi z') | val uint_set_bitfield_set_bitfield_same
(#tot #t: _)
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z z': bitfield cl (hi - lo))
: Lemma (cl.set_bitfield (cl.set_bitfield x lo hi z) lo hi z' == cl.set_bitfield x lo hi z') | let uint_set_bitfield_set_bitfield_same
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
(z' : bitfield cl (hi - lo))
: Lemma
(cl.set_bitfield (cl.set_bitfield x lo hi z) lo hi z' == cl.set_bitfield x lo hi z')
= set_bitfield_set_bitfield_same (cl.v x) lo hi (cl.v z) (cl.v z');
assert (cl.uint_to_t (cl.v (cl.set_bitfield (cl.set_bitfield x lo hi z) lo hi z')) == cl.uint_to_t (cl.v (cl.set_bitfield x lo hi z'))) | {
"file_name": "src/lowparse/LowParse.BitFields.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 137,
"end_line": 326,
"start_col": 0,
"start_line": 319
} | module LowParse.BitFields
module U = FStar.UInt
type ubitfield (tot: nat) (sz: nat) = (x: U.uint_t tot { x < pow2 sz })
// IMPORTANT: these bitfield operators are defined in a least
// significant bit (LSB) first fashion.
val get_bitfield
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Tot (ubitfield tot (hi - lo))
val get_bitfield_logor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi)
val get_bitfield_logxor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi)
val set_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Tot (U.uint_t tot)
val get_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(get_bitfield (set_bitfield x lo hi v) lo hi == v)
val get_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot })
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi'))
val set_bitfield_set_bitfield_same_gen
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot })
(v' : ubitfield tot (hi' - lo'))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v'))
let set_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(v' : ubitfield tot (hi - lo))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v'))
= set_bitfield_set_bitfield_same_gen x lo hi v lo hi v'
val set_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo'))
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v))
val set_bitfield_full
(#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot)
: Lemma
(set_bitfield x 0 tot y == y)
val set_bitfield_empty
(#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0)
: Lemma
(set_bitfield x i i y == x)
val get_bitfield_zero
(tot: pos)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield #tot 0 lo hi == 0)
val get_bitfield_full
(#tot: pos)
(x: U.uint_t tot)
: Lemma
(get_bitfield x 0 tot == x)
val get_bitfield_empty
(#tot: pos)
(x: U.uint_t tot)
(i: nat { i <= tot })
: Lemma
(get_bitfield x i i == 0)
val lt_pow2_get_bitfield_hi
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (x < pow2 mi))
(ensures (get_bitfield x mi tot == 0))
val get_bitfield_hi_lt_pow2
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (get_bitfield x mi tot == 0))
(ensures (x < pow2 mi))
val get_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo })
: Lemma
(get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi'))
val get_bitfield_zero_inner
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi })
: Lemma
(ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0))
val set_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(set_bitfield x lo hi (get_bitfield x lo hi) == x)
val get_bitfield_partition_2_gen
(#tot: pos)
(lo: nat)
(mi: nat)
(hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x lo mi == get_bitfield y lo mi /\
get_bitfield x mi hi == get_bitfield y mi hi
))
(ensures (
get_bitfield x lo hi == get_bitfield y lo hi
))
val get_bitfield_partition_2
(#tot: pos)
(mid: nat { mid <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 mid == get_bitfield y 0 mid /\
get_bitfield x mid tot == get_bitfield y mid tot
))
(ensures (
x == y
))
let rec get_bitfield_partition_prop
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Tot bool
(decreases l)
= match l with
| [] ->
get_bitfield x lo hi = get_bitfield y lo hi
| mi :: q ->
lo <= mi && mi <= hi &&
get_bitfield_partition_prop x y mi hi q &&
get_bitfield x lo mi = get_bitfield y lo mi
val get_bitfield_partition
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Lemma
(requires (get_bitfield_partition_prop x y lo hi l))
(ensures (get_bitfield x lo hi == get_bitfield y lo hi))
let get_bitfield_partition_3
(#tot: pos)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 lo == get_bitfield y 0 lo /\
get_bitfield x lo hi == get_bitfield y lo hi /\
get_bitfield x hi tot == get_bitfield y hi tot
))
(ensures (x == y))
= assert_norm (get_bitfield_partition_prop x y 0 tot [lo; hi]); // does not need fuel, thanks to normalization
get_bitfield_partition x y 0 tot [lo; hi];
get_bitfield_full x;
get_bitfield_full y
val get_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
: Lemma
(x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat))
val set_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
(v: ubitfield tot1 (hi - lo))
: Lemma
(x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat))
val set_bitfield_bound
(#tot: pos)
(x: U.uint_t tot)
(bound: nat { bound <= tot /\ x < pow2 bound })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= bound })
(v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v < pow2 bound)
val set_bitfield_set_bitfield_get_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= hi - lo }) (v' : ubitfield tot (hi' - lo'))
: Lemma
( let v = set_bitfield (get_bitfield x lo hi) lo' hi' v' in
v < pow2 (hi - lo) /\
set_bitfield x lo hi v == set_bitfield x (lo + lo') (lo + hi') v' )
val get_bitfield_eq
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo))
val get_bitfield_eq_2
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo))
val set_bitfield_eq
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo))
module U32 = FStar.UInt32
inline_for_extraction
noextract
noeq
type uint_t (tot: pos) (t: Type) = {
v: (t -> Tot (U.uint_t tot));
uint_to_t: (U.uint_t tot -> Tot t);
v_uint_to_t: ((x: U.uint_t tot) -> Lemma (v (uint_to_t x) == x));
uint_to_t_v: ((x: t) -> Lemma (uint_to_t (v x) == x));
get_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) (U32.v lo) (U32.v hi) }));
set_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> (z: t { v z < pow2 (U32.v hi - U32.v lo) }) -> Tot (y : t { v y == set_bitfield (v x) (U32.v lo) (U32.v hi) (v z)}));
get_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) lo hi }));
set_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y : t { v y == set_bitfield (v x) lo hi (v z)}));
logor: ((x: t) -> (y: t) -> Tot (z: t { v z == v x `U.logor` v y }));
bitfield_eq_lhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot t);
bitfield_eq_rhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y: t { bitfield_eq_lhs x lo hi == y <==> (get_bitfield x lo hi <: t) == z }));
}
inline_for_extraction
let bitfield (#tot: pos) (#t: Type) (cl: uint_t tot t) (sz: nat { sz <= tot }) : Tot Type =
(x: t { cl.v x < pow2 sz })
let uint_t_v_uint_to_t #tot #t (cl: uint_t tot t) (x: U.uint_t tot) : Lemma
(cl.v (cl.uint_to_t x) == x)
[SMTPat (cl.v (cl.uint_to_t x))]
= cl.v_uint_to_t x
let uint_t_uint_to_t_v #tot #t (cl: uint_t tot t) (x: t) : Lemma
(cl.uint_to_t (cl.v x) == x)
[SMTPat (cl.uint_to_t (cl.v x))]
= cl.uint_to_t_v x
let uint_get_bitfield_set_bitfield_same
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
: Lemma
(cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi == z)
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)]
= get_bitfield_set_bitfield_same (cl.v x) lo hi (cl.v z);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)) == cl.uint_to_t (cl.v z))
let uint_get_bitfield_set_bitfield_other
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo') })
: Lemma
(cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi' == cl.get_bitfield x lo' hi')
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi')]
= get_bitfield_set_bitfield_other (cl.v x) lo hi (cl.v z) lo' hi';
assert (cl.uint_to_t (cl.v (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi')) == cl.uint_to_t (cl.v (cl.get_bitfield x lo' hi')))
let uint_set_bitfield_set_bitfield_same_gen
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
(lo': nat) (hi': nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (z' : bitfield cl (hi' - lo'))
: Lemma
(cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z' == cl.set_bitfield x lo' hi' z')
= set_bitfield_set_bitfield_same_gen (cl.v x) lo hi (cl.v z) lo' hi' (cl.v z');
assert (cl.uint_to_t (cl.v (cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z')) == cl.uint_to_t (cl.v (cl.set_bitfield x lo' hi' z'))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.BitFields.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
cl: LowParse.BitFields.uint_t tot t ->
x: t ->
lo: Prims.nat ->
hi: Prims.nat{lo <= hi /\ hi <= tot} ->
z: LowParse.BitFields.bitfield cl (hi - lo) ->
z': LowParse.BitFields.bitfield cl (hi - lo)
-> FStar.Pervasives.Lemma
(ensures
Mkuint_t?.set_bitfield cl (Mkuint_t?.set_bitfield cl x lo hi z) lo hi z' ==
Mkuint_t?.set_bitfield cl x lo hi z') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.BitFields.bitfield",
"Prims.op_Subtraction",
"Prims._assert",
"Prims.eq2",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield",
"Prims.unit",
"LowParse.BitFields.set_bitfield_set_bitfield_same",
"Prims.l_True",
"Prims.squash",
"Prims.l_or",
"FStar.UInt.uint_t",
"LowParse.BitFields.set_bitfield",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let uint_set_bitfield_set_bitfield_same
#tot
#t
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
(z': bitfield cl (hi - lo))
: Lemma (cl.set_bitfield (cl.set_bitfield x lo hi z) lo hi z' == cl.set_bitfield x lo hi z') =
| set_bitfield_set_bitfield_same (cl.v x) lo hi (cl.v z) (cl.v z');
assert (cl.uint_to_t (cl.v (cl.set_bitfield (cl.set_bitfield x lo hi z) lo hi z')) ==
cl.uint_to_t (cl.v (cl.set_bitfield x lo hi z'))) | false |
LowParse.BitFields.fsti | LowParse.BitFields.uint_set_bitfield_set_bitfield_other | val uint_set_bitfield_set_bitfield_other
(#tot #t: _)
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
(lo': nat)
(hi': nat{lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo')})
(z': bitfield cl (hi' - lo'))
: Lemma
(cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z' ==
cl.set_bitfield (cl.set_bitfield x lo' hi' z') lo hi z) | val uint_set_bitfield_set_bitfield_other
(#tot #t: _)
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
(lo': nat)
(hi': nat{lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo')})
(z': bitfield cl (hi' - lo'))
: Lemma
(cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z' ==
cl.set_bitfield (cl.set_bitfield x lo' hi' z') lo hi z) | let uint_set_bitfield_set_bitfield_other
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo') })
(z' : bitfield cl (hi' - lo'))
: Lemma
(cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z' == cl.set_bitfield (cl.set_bitfield x lo' hi' z') lo hi z)
= set_bitfield_set_bitfield_other (cl.v x) lo hi (cl.v z) lo' hi' (cl.v z');
assert (cl.uint_to_t (cl.v (cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z')) == cl.uint_to_t (cl.v (cl.set_bitfield (cl.set_bitfield x lo' hi' z') lo hi z))) | {
"file_name": "src/lowparse/LowParse.BitFields.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 167,
"end_line": 336,
"start_col": 0,
"start_line": 328
} | module LowParse.BitFields
module U = FStar.UInt
type ubitfield (tot: nat) (sz: nat) = (x: U.uint_t tot { x < pow2 sz })
// IMPORTANT: these bitfield operators are defined in a least
// significant bit (LSB) first fashion.
val get_bitfield
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Tot (ubitfield tot (hi - lo))
val get_bitfield_logor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logor` y) lo hi == get_bitfield x lo hi `U.logor` get_bitfield y lo hi)
val get_bitfield_logxor
(#tot: pos) (x y: U.uint_t tot) (lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield (x `U.logxor` y) lo hi == get_bitfield x lo hi `U.logxor` get_bitfield y lo hi)
val set_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Tot (U.uint_t tot)
val get_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(get_bitfield (set_bitfield x lo hi v) lo hi == v)
val get_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot })
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (get_bitfield (set_bitfield x lo hi v) lo' hi' == get_bitfield x lo' hi'))
val set_bitfield_set_bitfield_same_gen
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot })
(v' : ubitfield tot (hi' - lo'))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield x lo' hi' v'))
let set_bitfield_set_bitfield_same
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(v' : ubitfield tot (hi - lo))
: Lemma
(ensures (set_bitfield (set_bitfield x lo hi v) lo hi v' == set_bitfield x lo hi v'))
= set_bitfield_set_bitfield_same_gen x lo hi v lo hi v'
val set_bitfield_set_bitfield_other
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot }) (v' : ubitfield tot (hi' - lo'))
: Lemma
(requires (hi' <= lo \/ hi <= lo'))
(ensures (set_bitfield (set_bitfield x lo hi v) lo' hi' v' == set_bitfield (set_bitfield x lo' hi' v') lo hi v))
val set_bitfield_full
(#tot: pos) (x: U.uint_t tot) (y: ubitfield tot tot)
: Lemma
(set_bitfield x 0 tot y == y)
val set_bitfield_empty
(#tot: pos) (x: U.uint_t tot) (i: nat { i <= tot }) (y: ubitfield tot 0)
: Lemma
(set_bitfield x i i y == x)
val get_bitfield_zero
(tot: pos)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield #tot 0 lo hi == 0)
val get_bitfield_full
(#tot: pos)
(x: U.uint_t tot)
: Lemma
(get_bitfield x 0 tot == x)
val get_bitfield_empty
(#tot: pos)
(x: U.uint_t tot)
(i: nat { i <= tot })
: Lemma
(get_bitfield x i i == 0)
val lt_pow2_get_bitfield_hi
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (x < pow2 mi))
(ensures (get_bitfield x mi tot == 0))
val get_bitfield_hi_lt_pow2
(#tot: pos)
(x: U.uint_t tot)
(mi: nat {mi <= tot})
: Lemma
(requires (get_bitfield x mi tot == 0))
(ensures (x < pow2 mi))
val get_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat) (hi': nat { lo' <= hi' /\ hi' <= hi - lo })
: Lemma
(get_bitfield (get_bitfield x lo hi) lo' hi' == get_bitfield x (lo + lo') (lo + hi'))
val get_bitfield_zero_inner
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo': nat { lo <= lo' }) (hi': nat { lo' <= hi' /\ hi' <= hi })
: Lemma
(ensures (get_bitfield x lo hi == 0 ==> get_bitfield x lo' hi' == 0))
val set_bitfield_get_bitfield
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(set_bitfield x lo hi (get_bitfield x lo hi) == x)
val get_bitfield_partition_2_gen
(#tot: pos)
(lo: nat)
(mi: nat)
(hi: nat { lo <= mi /\ mi <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x lo mi == get_bitfield y lo mi /\
get_bitfield x mi hi == get_bitfield y mi hi
))
(ensures (
get_bitfield x lo hi == get_bitfield y lo hi
))
val get_bitfield_partition_2
(#tot: pos)
(mid: nat { mid <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 mid == get_bitfield y 0 mid /\
get_bitfield x mid tot == get_bitfield y mid tot
))
(ensures (
x == y
))
let rec get_bitfield_partition_prop
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Tot bool
(decreases l)
= match l with
| [] ->
get_bitfield x lo hi = get_bitfield y lo hi
| mi :: q ->
lo <= mi && mi <= hi &&
get_bitfield_partition_prop x y mi hi q &&
get_bitfield x lo mi = get_bitfield y lo mi
val get_bitfield_partition
(#tot: pos)
(x y: U.uint_t tot)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(l: list nat)
: Lemma
(requires (get_bitfield_partition_prop x y lo hi l))
(ensures (get_bitfield x lo hi == get_bitfield y lo hi))
let get_bitfield_partition_3
(#tot: pos)
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot })
(x y: U.uint_t tot)
: Lemma
(requires (
get_bitfield x 0 lo == get_bitfield y 0 lo /\
get_bitfield x lo hi == get_bitfield y lo hi /\
get_bitfield x hi tot == get_bitfield y hi tot
))
(ensures (x == y))
= assert_norm (get_bitfield_partition_prop x y 0 tot [lo; hi]); // does not need fuel, thanks to normalization
get_bitfield_partition x y 0 tot [lo; hi];
get_bitfield_full x;
get_bitfield_full y
val get_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
: Lemma
(x < pow2 tot2 /\ (get_bitfield #tot1 x lo hi <: nat) == (get_bitfield #tot2 x lo hi <: nat))
val set_bitfield_size
(tot1 tot2: pos)
(x: nat { x < pow2 tot1 /\ tot1 <= tot2 })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= tot1 })
(v: ubitfield tot1 (hi - lo))
: Lemma
(x < pow2 tot2 /\ v < pow2 tot2 /\ (set_bitfield #tot1 x lo hi v <: nat) == (set_bitfield #tot2 x lo hi v <: nat))
val set_bitfield_bound
(#tot: pos)
(x: U.uint_t tot)
(bound: nat { bound <= tot /\ x < pow2 bound })
(lo: nat)
(hi: nat { lo <= hi /\ hi <= bound })
(v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v < pow2 bound)
val set_bitfield_set_bitfield_get_bitfield
(#tot: pos) (x: U.uint_t tot)
(lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= hi - lo }) (v' : ubitfield tot (hi' - lo'))
: Lemma
( let v = set_bitfield (get_bitfield x lo hi) lo' hi' v' in
v < pow2 (hi - lo) /\
set_bitfield x lo hi v == set_bitfield x (lo + lo') (lo + hi') v' )
val get_bitfield_eq
(#tot: pos)
(x: U.uint_t tot)
(lo: nat) (hi: nat {lo <= hi /\ hi <= tot})
: Lemma
(get_bitfield x lo hi == (x / pow2 lo) % pow2 (hi - lo))
val get_bitfield_eq_2
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot })
: Lemma
(get_bitfield x lo hi == (x `U.shift_left` (tot - hi)) `U.shift_right` (tot - hi + lo))
val set_bitfield_eq
(#tot: pos) (x: U.uint_t tot) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (v: ubitfield tot (hi - lo))
: Lemma
(set_bitfield x lo hi v == (x `U.logand` U.lognot ((U.lognot 0 `U.shift_right` (tot - (hi - lo))) `U.shift_left` lo)) `U.logor` (v `U.shift_left` lo))
module U32 = FStar.UInt32
inline_for_extraction
noextract
noeq
type uint_t (tot: pos) (t: Type) = {
v: (t -> Tot (U.uint_t tot));
uint_to_t: (U.uint_t tot -> Tot t);
v_uint_to_t: ((x: U.uint_t tot) -> Lemma (v (uint_to_t x) == x));
uint_to_t_v: ((x: t) -> Lemma (uint_to_t (v x) == x));
get_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) (U32.v lo) (U32.v hi) }));
set_bitfield_gen: ((x: t) -> (lo: U32.t) -> (hi: U32.t { U32.v lo < U32.v hi /\ U32.v hi <= tot }) -> (z: t { v z < pow2 (U32.v hi - U32.v lo) }) -> Tot (y : t { v y == set_bitfield (v x) (U32.v lo) (U32.v hi) (v z)}));
get_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot (y: t { v y == get_bitfield (v x) lo hi }));
set_bitfield: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y : t { v y == set_bitfield (v x) lo hi (v z)}));
logor: ((x: t) -> (y: t) -> Tot (z: t { v z == v x `U.logor` v y }));
bitfield_eq_lhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> Tot t);
bitfield_eq_rhs: ((x: t) -> (lo: nat) -> (hi: nat { lo <= hi /\ hi <= tot }) -> (z: t { v z < pow2 (hi - lo) }) -> Tot (y: t { bitfield_eq_lhs x lo hi == y <==> (get_bitfield x lo hi <: t) == z }));
}
inline_for_extraction
let bitfield (#tot: pos) (#t: Type) (cl: uint_t tot t) (sz: nat { sz <= tot }) : Tot Type =
(x: t { cl.v x < pow2 sz })
let uint_t_v_uint_to_t #tot #t (cl: uint_t tot t) (x: U.uint_t tot) : Lemma
(cl.v (cl.uint_to_t x) == x)
[SMTPat (cl.v (cl.uint_to_t x))]
= cl.v_uint_to_t x
let uint_t_uint_to_t_v #tot #t (cl: uint_t tot t) (x: t) : Lemma
(cl.uint_to_t (cl.v x) == x)
[SMTPat (cl.uint_to_t (cl.v x))]
= cl.uint_to_t_v x
let uint_get_bitfield_set_bitfield_same
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
: Lemma
(cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi == z)
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)]
= get_bitfield_set_bitfield_same (cl.v x) lo hi (cl.v z);
assert (cl.uint_to_t (cl.v (cl.get_bitfield (cl.set_bitfield x lo hi z) lo hi)) == cl.uint_to_t (cl.v z))
let uint_get_bitfield_set_bitfield_other
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
(lo' : nat) (hi' : nat { lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo') })
: Lemma
(cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi' == cl.get_bitfield x lo' hi')
[SMTPat (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi')]
= get_bitfield_set_bitfield_other (cl.v x) lo hi (cl.v z) lo' hi';
assert (cl.uint_to_t (cl.v (cl.get_bitfield (cl.set_bitfield x lo hi z) lo' hi')) == cl.uint_to_t (cl.v (cl.get_bitfield x lo' hi')))
let uint_set_bitfield_set_bitfield_same_gen
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
(lo': nat) (hi': nat { lo' <= lo /\ hi <= hi' /\ hi' <= tot }) (z' : bitfield cl (hi' - lo'))
: Lemma
(cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z' == cl.set_bitfield x lo' hi' z')
= set_bitfield_set_bitfield_same_gen (cl.v x) lo hi (cl.v z) lo' hi' (cl.v z');
assert (cl.uint_to_t (cl.v (cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z')) == cl.uint_to_t (cl.v (cl.set_bitfield x lo' hi' z')))
let uint_set_bitfield_set_bitfield_same
#tot #t (cl: uint_t tot t)
(x: t) (lo: nat) (hi: nat { lo <= hi /\ hi <= tot }) (z: bitfield cl (hi - lo))
(z' : bitfield cl (hi - lo))
: Lemma
(cl.set_bitfield (cl.set_bitfield x lo hi z) lo hi z' == cl.set_bitfield x lo hi z')
= set_bitfield_set_bitfield_same (cl.v x) lo hi (cl.v z) (cl.v z');
assert (cl.uint_to_t (cl.v (cl.set_bitfield (cl.set_bitfield x lo hi z) lo hi z')) == cl.uint_to_t (cl.v (cl.set_bitfield x lo hi z'))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.BitFields.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt",
"short_module": "U"
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
cl: LowParse.BitFields.uint_t tot t ->
x: t ->
lo: Prims.nat ->
hi: Prims.nat{lo <= hi /\ hi <= tot} ->
z: LowParse.BitFields.bitfield cl (hi - lo) ->
lo': Prims.nat ->
hi': Prims.nat{lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo')} ->
z': LowParse.BitFields.bitfield cl (hi' - lo')
-> FStar.Pervasives.Lemma
(ensures
Mkuint_t?.set_bitfield cl (Mkuint_t?.set_bitfield cl x lo hi z) lo' hi' z' ==
Mkuint_t?.set_bitfield cl (Mkuint_t?.set_bitfield cl x lo' hi' z') lo hi z) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"LowParse.BitFields.uint_t",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.BitFields.bitfield",
"Prims.op_Subtraction",
"Prims.l_or",
"Prims._assert",
"Prims.eq2",
"LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t",
"LowParse.BitFields.__proj__Mkuint_t__item__v",
"LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield",
"Prims.unit",
"LowParse.BitFields.set_bitfield_set_bitfield_other",
"Prims.l_True",
"Prims.squash",
"FStar.UInt.uint_t",
"LowParse.BitFields.set_bitfield",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let uint_set_bitfield_set_bitfield_other
#tot
#t
(cl: uint_t tot t)
(x: t)
(lo: nat)
(hi: nat{lo <= hi /\ hi <= tot})
(z: bitfield cl (hi - lo))
(lo': nat)
(hi': nat{lo' <= hi' /\ hi' <= tot /\ (hi' <= lo \/ hi <= lo')})
(z': bitfield cl (hi' - lo'))
: Lemma
(cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z' ==
cl.set_bitfield (cl.set_bitfield x lo' hi' z') lo hi z) =
| set_bitfield_set_bitfield_other (cl.v x) lo hi (cl.v z) lo' hi' (cl.v z');
assert (cl.uint_to_t (cl.v (cl.set_bitfield (cl.set_bitfield x lo hi z) lo' hi' z')) ==
cl.uint_to_t (cl.v (cl.set_bitfield (cl.set_bitfield x lo' hi' z') lo hi z))) | false |
Vale.AsLowStar.MemoryHelpers.fst | Vale.AsLowStar.MemoryHelpers.bounded_buffer_addrs_all | val bounded_buffer_addrs_all (src t:base_typ) (m:HS.mem) (b:buf_t src t{B.live m b}) : Lemma
(forall (h:ME.vale_heap) (vb:ME.buffer t).{:pattern ME.buffer_addr #t vb h}
vb == as_vale_buffer b ==>
ME.buffer_addr #t vb h + DV.length (get_downview b) < Vale.Def.Words_s.pow2_64) | val bounded_buffer_addrs_all (src t:base_typ) (m:HS.mem) (b:buf_t src t{B.live m b}) : Lemma
(forall (h:ME.vale_heap) (vb:ME.buffer t).{:pattern ME.buffer_addr #t vb h}
vb == as_vale_buffer b ==>
ME.buffer_addr #t vb h + DV.length (get_downview b) < Vale.Def.Words_s.pow2_64) | let bounded_buffer_addrs_all src t h b = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 103,
"end_line": 119,
"start_col": 0,
"start_line": 119
} | module Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module ME = Vale.X64.Memory
module VSig = Vale.AsLowStar.ValeSig
module IX64 = Vale.Interop.X64
friend Vale.X64.Memory
friend Vale.X64.Memory_Sems
friend Vale.X64.Stack_i
friend Vale.X64.Stack_Sems
friend Vale.X64.Decls
friend Vale.X64.StateLemmas
friend Vale.X64.MemoryAdapters
let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let state_eq_down_mem (va_s1:V.va_state) (s1:_) = ()
let rec loc_eq (args:list arg)
: Lemma (VSig.mloc_modified_args args == loc_modified_args args)
= match args with
| [] -> ()
| hd :: tl -> loc_eq tl
let relate_modifies args m0 m1 = loc_eq args
let reveal_readable #src #t x s = ()
let reveal_imm_readable #src #t x s = ()
let readable_live #src #t x s = ()
let readable_imm_live #src #t x s = ()
let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
//let get_heap_mk_mem_reveal args h0 = ()
let lemma_as_mem_as_vale_mem h = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let mk_stack_reveal stack = ()
let buffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let immbuffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let buffer_as_seq_reveal2 src t x va_s = ()
let immbuffer_as_seq_reveal2 src t x va_s = ()
let buffer_addr_reveal src t x args h0 = ()
let immbuffer_addr_reveal src t x args h0 = ()
let fuel_eq = ()
let decls_eval_code_reveal c va_s0 va_s1 f = ()
let as_vale_buffer_disjoint #src1 #src2 #t1 #t2 x y = ()
let as_vale_buffer_imm_disjoint #src1 #src2 #t1 #t2 x y = ()
let as_vale_immbuffer_imm_disjoint #src1 #src2 #t1 #t2 x y = ()
let modifies_same_roots s h0 h1 = ()
let modifies_equal_domains s h0 h1 = ()
let loc_disjoint_sym x y = ()
#set-options "--z3rlimit 20"
let core_create_lemma_taint_hyp
#max_arity
#arg_reg
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
LSig.taint_hyp args va_s))
=
FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap;
let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
let taint_map = full_heap_taint va_s.VS.vs_heap in
let mem = ME.get_vale_heap va_s.VS.vs_heap in
// assert (mem == mk_mem args h0);
let raw_taint = IX64.(mk_taint args IX64.init_taint) in
// assert (taint_map == create_memtaint (_ih mem) (args_b8 args) raw_taint);
ME.valid_memtaint mem (args_b8 args) raw_taint;
// assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x));
assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x));
Classical.forall_intro (IX64.mk_taint_equiv args);
assert (forall (a:arg). List.memP a args /\ Some? (IX64.taint_of_arg a) ==>
Some?.v (IX64.taint_of_arg a) == raw_taint (IX64.taint_arg_b8 a));
Classical.forall_intro (args_b8_mem args);
assert (forall x. List.memP x args /\ Some? (IX64.taint_of_arg x) ==>
LSig.taint_hyp_arg mem taint_map x);
BigOps.big_and'_forall (LSig.taint_hyp_arg mem taint_map) args
let buffer_writeable_reveal src t x = ()
let buffer_read_reveal src t h s b i =
let db = get_downview b in
DV.length_eq db;
let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in
UV.as_seq_sel h b_v i
let imm_buffer_read_reveal src t h s b i =
let db = get_downview b in
DV.length_eq db;
let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in
UV.as_seq_sel h b_v i
let buffer_as_seq_invert src t h s b =
let db = get_downview b in
DV.length_eq db;
assert (Seq.equal
(ME.buffer_as_seq s (as_vale_buffer b))
(LSig.uint_to_nat_seq_t t (UV.as_seq h (UV.mk_buffer db (LSig.view_of_base_typ t)))))
let buffer_as_seq_reveal_tuint128 src x va_s = ()
let immbuffer_as_seq_reveal_tuint128 src x va_s = ()
let bounded_buffer_addrs_one src t h b s = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fst.checked",
"Vale.X64.Stack_Sems.fst.checked",
"Vale.X64.Stack_i.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.Memory_Sems.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Decls.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.MemoryHelpers.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MES"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
src: Vale.Arch.HeapTypes_s.base_typ ->
t: Vale.Arch.HeapTypes_s.base_typ ->
m: FStar.Monotonic.HyperStack.mem ->
b: Vale.Interop.Base.buf_t src t {LowStar.Monotonic.Buffer.live m b}
-> FStar.Pervasives.Lemma
(ensures
forall (h: Vale.X64.Memory.vale_heap) (vb: Vale.X64.Memory.buffer t).
{:pattern Vale.X64.Memory.buffer_addr vb h}
vb == Vale.X64.MemoryAdapters.as_vale_buffer b ==>
Vale.X64.Memory.buffer_addr vb h +
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) <
Vale.Def.Words_s.pow2_64) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"FStar.Monotonic.HyperStack.mem",
"Vale.Interop.Base.buf_t",
"LowStar.Monotonic.Buffer.live",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.Buffer.trivial_preorder",
"FStar.Pervasives.reveal_opaque",
"Vale.Interop.Types.b8",
"Vale.Def.Words_s.nat64",
"Prims.logical",
"Vale.Interop.Types.addr_map_pred",
"Prims.unit"
] | [] | true | false | true | false | false | let bounded_buffer_addrs_all src t h b =
| FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred | false |
Vale.AsLowStar.MemoryHelpers.fst | Vale.AsLowStar.MemoryHelpers.lemma_valid_layout_buffer_id | val lemma_valid_layout_buffer_id (t:base_typ) (b:ME.buffer t) (layout:vale_heap_layout) (write:bool) : Lemma
(requires True)
(ensures ME.valid_layout_buffer_id t b layout None write)
[SMTPat (ME.valid_layout_buffer_id t b layout None write)] | val lemma_valid_layout_buffer_id (t:base_typ) (b:ME.buffer t) (layout:vale_heap_layout) (write:bool) : Lemma
(requires True)
(ensures ME.valid_layout_buffer_id t b layout None write)
[SMTPat (ME.valid_layout_buffer_id t b layout None write)] | let lemma_valid_layout_buffer_id t b layout write =
reveal_opaque (`%ME.valid_layout_buffer_id) ME.valid_layout_buffer_id | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 175,
"start_col": 0,
"start_line": 174
} | module Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module ME = Vale.X64.Memory
module VSig = Vale.AsLowStar.ValeSig
module IX64 = Vale.Interop.X64
friend Vale.X64.Memory
friend Vale.X64.Memory_Sems
friend Vale.X64.Stack_i
friend Vale.X64.Stack_Sems
friend Vale.X64.Decls
friend Vale.X64.StateLemmas
friend Vale.X64.MemoryAdapters
let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let state_eq_down_mem (va_s1:V.va_state) (s1:_) = ()
let rec loc_eq (args:list arg)
: Lemma (VSig.mloc_modified_args args == loc_modified_args args)
= match args with
| [] -> ()
| hd :: tl -> loc_eq tl
let relate_modifies args m0 m1 = loc_eq args
let reveal_readable #src #t x s = ()
let reveal_imm_readable #src #t x s = ()
let readable_live #src #t x s = ()
let readable_imm_live #src #t x s = ()
let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
//let get_heap_mk_mem_reveal args h0 = ()
let lemma_as_mem_as_vale_mem h = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let mk_stack_reveal stack = ()
let buffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let immbuffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let buffer_as_seq_reveal2 src t x va_s = ()
let immbuffer_as_seq_reveal2 src t x va_s = ()
let buffer_addr_reveal src t x args h0 = ()
let immbuffer_addr_reveal src t x args h0 = ()
let fuel_eq = ()
let decls_eval_code_reveal c va_s0 va_s1 f = ()
let as_vale_buffer_disjoint #src1 #src2 #t1 #t2 x y = ()
let as_vale_buffer_imm_disjoint #src1 #src2 #t1 #t2 x y = ()
let as_vale_immbuffer_imm_disjoint #src1 #src2 #t1 #t2 x y = ()
let modifies_same_roots s h0 h1 = ()
let modifies_equal_domains s h0 h1 = ()
let loc_disjoint_sym x y = ()
#set-options "--z3rlimit 20"
let core_create_lemma_taint_hyp
#max_arity
#arg_reg
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
LSig.taint_hyp args va_s))
=
FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap;
let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
let taint_map = full_heap_taint va_s.VS.vs_heap in
let mem = ME.get_vale_heap va_s.VS.vs_heap in
// assert (mem == mk_mem args h0);
let raw_taint = IX64.(mk_taint args IX64.init_taint) in
// assert (taint_map == create_memtaint (_ih mem) (args_b8 args) raw_taint);
ME.valid_memtaint mem (args_b8 args) raw_taint;
// assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x));
assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x));
Classical.forall_intro (IX64.mk_taint_equiv args);
assert (forall (a:arg). List.memP a args /\ Some? (IX64.taint_of_arg a) ==>
Some?.v (IX64.taint_of_arg a) == raw_taint (IX64.taint_arg_b8 a));
Classical.forall_intro (args_b8_mem args);
assert (forall x. List.memP x args /\ Some? (IX64.taint_of_arg x) ==>
LSig.taint_hyp_arg mem taint_map x);
BigOps.big_and'_forall (LSig.taint_hyp_arg mem taint_map) args
let buffer_writeable_reveal src t x = ()
let buffer_read_reveal src t h s b i =
let db = get_downview b in
DV.length_eq db;
let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in
UV.as_seq_sel h b_v i
let imm_buffer_read_reveal src t h s b i =
let db = get_downview b in
DV.length_eq db;
let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in
UV.as_seq_sel h b_v i
let buffer_as_seq_invert src t h s b =
let db = get_downview b in
DV.length_eq db;
assert (Seq.equal
(ME.buffer_as_seq s (as_vale_buffer b))
(LSig.uint_to_nat_seq_t t (UV.as_seq h (UV.mk_buffer db (LSig.view_of_base_typ t)))))
let buffer_as_seq_reveal_tuint128 src x va_s = ()
let immbuffer_as_seq_reveal_tuint128 src x va_s = ()
let bounded_buffer_addrs_one src t h b s = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred
let bounded_buffer_addrs_all src t h b = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred
let same_down_up_buffer_length src b =
let db = get_downview b in
DV.length_eq db;
FStar.Math.Lemmas.cancel_mul_div (B.length b) (view_n src)
#push-options "--z3rlimit 80"
let down_up_buffer_read_reveal src h s b i =
let db = get_downview b in
let n:pos = view_n src in
let up_view = (LSig.view_of_base_typ src) in
let ub = UV.mk_buffer db up_view in
same_down_up_buffer_length src b;
UV.length_eq ub;
UV.get_sel h ub i;
FStar.Math.Lemmas.lemma_mult_lt_right n i (DV.length db / n);
FStar.Math.Lemmas.multiply_fractions (DV.length db) n;
FStar.Math.Lemmas.nat_times_nat_is_nat i n;
assert (low_buffer_read src src h b i ==
UV.View?.get up_view (Seq.slice (DV.as_seq h db) (i*n) (i*n + n)));
DV.put_sel h db (i*n);
let aux () : Lemma (n * ((i*n)/n) == i*n) =
FStar.Math.Lemmas.cancel_mul_div i n
in aux()
#pop-options
let same_buffer_same_upviews #src #bt b h0 h1 =
let dv = get_downview b in
let s0 = DV.as_seq h0 dv in
let s1 = DV.as_seq h1 dv in
let aux (i:nat{i < DV.length dv}) : Lemma (Seq.index s0 i == Seq.index s1 i) =
DV.as_seq_sel h0 dv i;
DV.as_seq_sel h1 dv i;
DV.get_sel h0 dv i;
DV.get_sel h1 dv i
in Classical.forall_intro aux;
Seq.lemma_eq_intro s0 s1;
DV.length_eq dv;
Vale.Lib.BufferViewHelpers.lemma_uv_equal (LSig.view_of_base_typ bt) dv h0 h1
let same_immbuffer_same_upviews #src #bt b h0 h1 =
let dv = get_downview b in
let s0 = DV.as_seq h0 dv in
let s1 = DV.as_seq h1 dv in
let aux (i:nat{i < DV.length dv}) : Lemma (Seq.index s0 i == Seq.index s1 i) =
DV.as_seq_sel h0 dv i;
DV.as_seq_sel h1 dv i;
DV.get_sel h0 dv i;
DV.get_sel h1 dv i
in Classical.forall_intro aux;
Seq.lemma_eq_intro s0 s1;
DV.length_eq dv;
Vale.Lib.BufferViewHelpers.lemma_uv_equal (LSig.view_of_base_typ bt) dv h0 h1 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fst.checked",
"Vale.X64.Stack_Sems.fst.checked",
"Vale.X64.Stack_i.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.Memory_Sems.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Decls.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.MemoryHelpers.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MES"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
t: Vale.Arch.HeapTypes_s.base_typ ->
b: Vale.X64.Memory.buffer t ->
layout: Vale.Arch.HeapImpl.vale_heap_layout ->
write: Prims.bool
-> FStar.Pervasives.Lemma
(ensures Vale.X64.Memory.valid_layout_buffer_id t b layout FStar.Pervasives.Native.None write)
[
SMTPat (Vale.X64.Memory.valid_layout_buffer_id t b layout FStar.Pervasives.Native.None write
)
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.X64.Memory.buffer",
"Vale.Arch.HeapImpl.vale_heap_layout",
"Prims.bool",
"FStar.Pervasives.reveal_opaque",
"FStar.Pervasives.Native.option",
"Vale.Arch.HeapImpl.heaplet_id",
"Vale.Def.Prop_s.prop0",
"Vale.X64.Memory.valid_layout_buffer_id",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_valid_layout_buffer_id t b layout write =
| reveal_opaque (`%ME.valid_layout_buffer_id) ME.valid_layout_buffer_id | false |
Vale.AsLowStar.MemoryHelpers.fst | Vale.AsLowStar.MemoryHelpers.immbuffer_as_seq_reveal | val immbuffer_as_seq_reveal
(src t:ME.base_typ)
(x:ibuf_t src t)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args}) : Lemma
(let y = as_vale_immbuffer x in
let db = get_downview x in
DV.length_eq db;
let mem = mk_mem args h0 in
Seq.equal
(LSig.nat_to_uint_seq_t t (ME.buffer_as_seq (create_initial_vale_heap mem) y))
(UV.as_seq h0 (UV.mk_buffer db (LSig.view_of_base_typ t)))) | val immbuffer_as_seq_reveal
(src t:ME.base_typ)
(x:ibuf_t src t)
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args}) : Lemma
(let y = as_vale_immbuffer x in
let db = get_downview x in
DV.length_eq db;
let mem = mk_mem args h0 in
Seq.equal
(LSig.nat_to_uint_seq_t t (ME.buffer_as_seq (create_initial_vale_heap mem) y))
(UV.as_seq h0 (UV.mk_buffer db (LSig.view_of_base_typ t)))) | let immbuffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 114,
"end_line": 49,
"start_col": 0,
"start_line": 49
} | module Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module ME = Vale.X64.Memory
module VSig = Vale.AsLowStar.ValeSig
module IX64 = Vale.Interop.X64
friend Vale.X64.Memory
friend Vale.X64.Memory_Sems
friend Vale.X64.Stack_i
friend Vale.X64.Stack_Sems
friend Vale.X64.Decls
friend Vale.X64.StateLemmas
friend Vale.X64.MemoryAdapters
let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let state_eq_down_mem (va_s1:V.va_state) (s1:_) = ()
let rec loc_eq (args:list arg)
: Lemma (VSig.mloc_modified_args args == loc_modified_args args)
= match args with
| [] -> ()
| hd :: tl -> loc_eq tl
let relate_modifies args m0 m1 = loc_eq args
let reveal_readable #src #t x s = ()
let reveal_imm_readable #src #t x s = ()
let readable_live #src #t x s = ()
let readable_imm_live #src #t x s = ()
let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
//let get_heap_mk_mem_reveal args h0 = ()
let lemma_as_mem_as_vale_mem h = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let mk_stack_reveal stack = () | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fst.checked",
"Vale.X64.Stack_Sems.fst.checked",
"Vale.X64.Stack_i.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.Memory_Sems.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Decls.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.MemoryHelpers.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MES"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
src: Vale.Arch.HeapTypes_s.base_typ ->
t: Vale.Arch.HeapTypes_s.base_typ ->
x: Vale.Interop.Base.ibuf_t src t ->
args: Vale.Interop.X64.arg_list ->
h0: FStar.Monotonic.HyperStack.mem{Vale.Interop.Base.mem_roots_p h0 args}
-> FStar.Pervasives.Lemma
(ensures
(let y = Vale.X64.MemoryAdapters.as_vale_immbuffer x in
let db = Vale.Interop.Types.get_downview x in
LowStar.BufferView.Down.length_eq db;
let mem = Vale.Interop.Base.mk_mem args h0 in
FStar.Seq.Base.equal (Vale.AsLowStar.LowStarSig.nat_to_uint_seq_t t
(Vale.X64.Memory.buffer_as_seq (Vale.X64.MemoryAdapters.create_initial_vale_heap mem)
y))
(LowStar.BufferView.Up.as_seq h0
(LowStar.BufferView.Up.mk_buffer db (Vale.AsLowStar.LowStarSig.view_of_base_typ t))))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.ibuf_t",
"Vale.Interop.X64.arg_list",
"FStar.Monotonic.HyperStack.mem",
"Vale.Interop.Base.mem_roots_p",
"FStar.Pervasives.reveal_opaque",
"Vale.X64.Memory.vale_full_heap",
"Vale.X64.Memory.vale_heap",
"Vale.X64.Memory.get_vale_heap",
"Prims.unit"
] | [] | true | false | true | false | false | let immbuffer_as_seq_reveal src t x args h0 =
| FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap | false |
Vale.AsLowStar.MemoryHelpers.fst | Vale.AsLowStar.MemoryHelpers.same_down_up_buffer_length | val same_down_up_buffer_length (src:base_typ) (b:buf_t src src) : Lemma
(B.length b == DV.length (get_downview b) / view_n src) | val same_down_up_buffer_length (src:base_typ) (b:buf_t src src) : Lemma
(B.length b == DV.length (get_downview b) / view_n src) | let same_down_up_buffer_length src b =
let db = get_downview b in
DV.length_eq db;
FStar.Math.Lemmas.cancel_mul_div (B.length b) (view_n src) | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 124,
"start_col": 0,
"start_line": 121
} | module Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module ME = Vale.X64.Memory
module VSig = Vale.AsLowStar.ValeSig
module IX64 = Vale.Interop.X64
friend Vale.X64.Memory
friend Vale.X64.Memory_Sems
friend Vale.X64.Stack_i
friend Vale.X64.Stack_Sems
friend Vale.X64.Decls
friend Vale.X64.StateLemmas
friend Vale.X64.MemoryAdapters
let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let state_eq_down_mem (va_s1:V.va_state) (s1:_) = ()
let rec loc_eq (args:list arg)
: Lemma (VSig.mloc_modified_args args == loc_modified_args args)
= match args with
| [] -> ()
| hd :: tl -> loc_eq tl
let relate_modifies args m0 m1 = loc_eq args
let reveal_readable #src #t x s = ()
let reveal_imm_readable #src #t x s = ()
let readable_live #src #t x s = ()
let readable_imm_live #src #t x s = ()
let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
//let get_heap_mk_mem_reveal args h0 = ()
let lemma_as_mem_as_vale_mem h = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let mk_stack_reveal stack = ()
let buffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let immbuffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let buffer_as_seq_reveal2 src t x va_s = ()
let immbuffer_as_seq_reveal2 src t x va_s = ()
let buffer_addr_reveal src t x args h0 = ()
let immbuffer_addr_reveal src t x args h0 = ()
let fuel_eq = ()
let decls_eval_code_reveal c va_s0 va_s1 f = ()
let as_vale_buffer_disjoint #src1 #src2 #t1 #t2 x y = ()
let as_vale_buffer_imm_disjoint #src1 #src2 #t1 #t2 x y = ()
let as_vale_immbuffer_imm_disjoint #src1 #src2 #t1 #t2 x y = ()
let modifies_same_roots s h0 h1 = ()
let modifies_equal_domains s h0 h1 = ()
let loc_disjoint_sym x y = ()
#set-options "--z3rlimit 20"
let core_create_lemma_taint_hyp
#max_arity
#arg_reg
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
LSig.taint_hyp args va_s))
=
FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap;
let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
let taint_map = full_heap_taint va_s.VS.vs_heap in
let mem = ME.get_vale_heap va_s.VS.vs_heap in
// assert (mem == mk_mem args h0);
let raw_taint = IX64.(mk_taint args IX64.init_taint) in
// assert (taint_map == create_memtaint (_ih mem) (args_b8 args) raw_taint);
ME.valid_memtaint mem (args_b8 args) raw_taint;
// assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x));
assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x));
Classical.forall_intro (IX64.mk_taint_equiv args);
assert (forall (a:arg). List.memP a args /\ Some? (IX64.taint_of_arg a) ==>
Some?.v (IX64.taint_of_arg a) == raw_taint (IX64.taint_arg_b8 a));
Classical.forall_intro (args_b8_mem args);
assert (forall x. List.memP x args /\ Some? (IX64.taint_of_arg x) ==>
LSig.taint_hyp_arg mem taint_map x);
BigOps.big_and'_forall (LSig.taint_hyp_arg mem taint_map) args
let buffer_writeable_reveal src t x = ()
let buffer_read_reveal src t h s b i =
let db = get_downview b in
DV.length_eq db;
let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in
UV.as_seq_sel h b_v i
let imm_buffer_read_reveal src t h s b i =
let db = get_downview b in
DV.length_eq db;
let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in
UV.as_seq_sel h b_v i
let buffer_as_seq_invert src t h s b =
let db = get_downview b in
DV.length_eq db;
assert (Seq.equal
(ME.buffer_as_seq s (as_vale_buffer b))
(LSig.uint_to_nat_seq_t t (UV.as_seq h (UV.mk_buffer db (LSig.view_of_base_typ t)))))
let buffer_as_seq_reveal_tuint128 src x va_s = ()
let immbuffer_as_seq_reveal_tuint128 src x va_s = ()
let bounded_buffer_addrs_one src t h b s = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred
let bounded_buffer_addrs_all src t h b = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fst.checked",
"Vale.X64.Stack_Sems.fst.checked",
"Vale.X64.Stack_i.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.Memory_Sems.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Decls.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.MemoryHelpers.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MES"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | src: Vale.Arch.HeapTypes_s.base_typ -> b: Vale.Interop.Base.buf_t src src
-> FStar.Pervasives.Lemma
(ensures
LowStar.Monotonic.Buffer.length b ==
LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) /
Vale.Interop.Types.view_n src) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buf_t",
"FStar.Math.Lemmas.cancel_mul_div",
"LowStar.Monotonic.Buffer.length",
"Vale.Interop.Types.base_typ_as_type",
"LowStar.Buffer.trivial_preorder",
"Vale.Interop.Types.view_n",
"Prims.unit",
"LowStar.BufferView.Down.length_eq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview"
] | [] | true | false | true | false | false | let same_down_up_buffer_length src b =
| let db = get_downview b in
DV.length_eq db;
FStar.Math.Lemmas.cancel_mul_div (B.length b) (view_n src) | false |
MerkleTree.Low.VectorExtras.fst | MerkleTree.Low.VectorExtras.rv_flush_inplace | val rv_flush_inplace:
#a:Type0 -> #rst:Type -> #rg:regional rst a ->
rv:rvector rg -> i:uint32_t{i <= size_of rv} ->
HST.ST (rvector rg)
(requires (fun h0 -> rv_inv h0 rv))
(ensures (fun h0 frv h1 ->
V.size_of frv = V.size_of rv - i /\
V.frameOf rv = V.frameOf frv /\
modifies (loc_rvector rv) h0 h1 /\
rv_inv h1 frv /\
S.equal (as_seq h1 frv)
(S.slice (as_seq h0 rv) (U32.v i) (U32.v (V.size_of rv))))) | val rv_flush_inplace:
#a:Type0 -> #rst:Type -> #rg:regional rst a ->
rv:rvector rg -> i:uint32_t{i <= size_of rv} ->
HST.ST (rvector rg)
(requires (fun h0 -> rv_inv h0 rv))
(ensures (fun h0 frv h1 ->
V.size_of frv = V.size_of rv - i /\
V.frameOf rv = V.frameOf frv /\
modifies (loc_rvector rv) h0 h1 /\
rv_inv h1 frv /\
S.equal (as_seq h1 frv)
(S.slice (as_seq h0 rv) (U32.v i) (U32.v (V.size_of rv))))) | let rv_flush_inplace #a #rst #rg rv i =
let hh0 = HST.get () in
(if i = 0ul then () else free_elems rv (i - 1ul));
rv_loc_elems_included hh0 rv 0ul i;
let hh1 = HST.get () in
assert (modifies (rs_loc_elems rg (V.as_seq hh0 rv) 0 (U32.v i)) hh0 hh1);
let frv = flush_inplace rv i in
let hh2 = HST.get () in
assert (modifies (loc_region_only false (V.frameOf rv)) hh1 hh2);
// Safety
rs_loc_elems_disj
rg (V.as_seq hh0 rv) (V.frameOf rv) 0 (U32.v (V.size_of rv))
0 (U32.v i) (U32.v i) (U32.v (V.size_of rv));
rs_loc_elems_parent_disj
rg (V.as_seq hh0 rv) (V.frameOf rv)
(U32.v i) (U32.v (V.size_of rv));
rs_elems_inv_preserved
rg (V.as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv))
(loc_union (rs_loc_elems rg (V.as_seq hh0 rv) 0 (U32.v i))
(loc_region_only false (V.frameOf rv)))
hh0 hh2;
assert (rv_inv #a #rst #rg hh2 frv);
// Correctness
as_seq_seq_preserved
rg (V.as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv))
(loc_union (rs_loc_elems rg (V.as_seq hh0 rv) 0 (U32.v i))
(loc_region_only false (V.frameOf rv)))
hh0 hh2;
as_seq_seq_slice
rg hh0 (V.as_seq hh0 rv) 0 (U32.v (V.size_of rv))
(U32.v i) (U32.v (V.size_of rv));
assert (S.equal (S.slice (as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv)))
(as_seq_seq rg hh2 (V.as_seq hh0 rv)
(U32.v i) (U32.v (V.size_of rv))));
as_seq_seq_eq
rg hh2 (V.as_seq hh0 rv) (V.as_seq hh2 frv)
(U32.v i) (U32.v (V.size_of rv)) 0 (U32.v (V.size_of frv));
assert (S.equal (as_seq_seq rg hh2 (V.as_seq hh2 frv)
0 (U32.v (V.size_of frv)))
(as_seq_seq rg hh2 (V.as_seq hh0 rv)
(U32.v i) (U32.v (V.size_of rv))));
assert (S.equal (S.slice (as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv)))
(as_seq hh2 frv));
frv | {
"file_name": "src/MerkleTree.Low.VectorExtras.fst",
"git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | {
"end_col": 5,
"end_line": 220,
"start_col": 0,
"start_line": 173
} | module MerkleTree.Low.VectorExtras
module B = LowStar.Buffer
module S = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
open LowStar.BufferOps
open Hacl.Hash.Lemmas
open FStar.Integers
open LowStar.Modifies
open LowStar.Regional
open LowStar.Vector
open LowStar.RVector
module V = LowStar.Vector
module RV = LowStar.RVector
(** Some extra functions on top of LowStar.Vector... used for Merkle Tree. *)
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
inline_for_extraction
let move_left #a (b: B.buffer a) (dst src: U32.t) (l: U32.t): HST.Stack unit
(requires fun h0 ->
B.live h0 b /\
U32.v src + U32.v l <= B.length b /\
U32.v dst <= U32.v src)
(ensures fun h0 _ h1 ->
B.(modifies (loc_buffer b) h0 h1) /\ (
let b0 = B.as_seq h0 b in
let b1 = B.as_seq h1 b in
let src = U32.v src in
let dst = U32.v dst in
let l = U32.v l in
S.slice b1 dst (dst + l) `S.equal` S.slice b0 src (src + l)))
=
let h0 = HST.get () in
[@inline_let]
let inv (h: HS.mem) (i: nat) =
let b0 = B.as_seq h0 b in
let b1 = B.as_seq h b in
let src = U32.v src in
let dst = U32.v dst in
let l = U32.v l in
i <= l /\
B.(modifies (loc_buffer b) h0 h) /\
S.slice b1 dst (dst + i) `S.equal` S.slice b0 src (src + i) /\
S.slice b1 (src + i) (src + l) `S.equal` S.slice b0 (src + i) (src + l)
in
let f (i: U32.t { U32.(0 <= v i /\ v i < v l) }): HST.Stack unit
(requires fun h0 -> inv h0 (U32.v i))
(ensures fun h0 _ h1 -> U32.(inv h0 (v i) /\ inv h1 (v i + 1)))
=
let h00 = HST.get () in
calc (==) {
S.index (B.as_seq h0 b) U32.(v src + v i);
(==) {}
S.index (S.slice (B.as_seq h0 b) U32.(v src + v i) U32.(v src + v l)) 0;
(==) {}
S.index (S.slice (B.as_seq h00 b) U32.(v src + v i) U32.(v src + v l)) 0;
(==) {}
S.index (B.as_seq h00 b) U32.(v src + v i);
};
b.(dst `U32.add` i) <- b.(src `U32.add` i);
let h = HST.get () in
let b0 = B.as_seq h0 b in
let b1 = B.as_seq h b in
let src = U32.v src in
let dst = U32.v dst in
let l = U32.v l in
let i = U32.v i in
calc (S.equal) {
S.slice b1 dst (dst + (i + 1));
(S.equal) { lemma_slice_ijk b1 dst (dst + i) (dst + i + 1) }
S.slice b1 dst (dst + i) `S.append` S.slice b1 (dst + i) (dst + i + 1);
(S.equal) { }
S.slice b0 src (src + i) `S.append` S.slice b1 (dst + i) (dst + i + 1);
(S.equal) { }
S.slice b0 src (src + i) `S.append` S.cons (S.index b1 (dst + i)) S.empty;
(S.equal) { }
S.slice b0 src (src + i) `S.append` S.cons (S.index b0 (src + i)) S.empty;
(S.equal) { }
S.slice b0 src (src + i) `S.append` S.slice b0 (src + i) (src + i + 1);
(S.equal) { lemma_slice_ijk b0 src (src + i) (src + i + 1) }
S.slice b0 src (src + (i + 1));
};
let s1 = S.slice b1 (src + (i + 1)) (src + l) in
let s0 = S.slice b0 (src + (i + 1)) (src + l) in
let aux (j: nat { j < S.length s0 }): Lemma (S.index s0 j == S.index s1 j)
[ SMTPat (S.index s0 j); SMTPat (S.index s1 j) ]
=
calc (==) {
S.index s0 j;
(==) {}
S.index (S.slice b0 (src + i) (src + l)) (j + 1);
(==) {}
S.index (S.slice b1 (src + i) (src + l)) (j + 1);
(==) {}
S.index s1 j;
}
in
()
in
C.Loops.for 0ul l inv f
inline_for_extraction
val shrink:
#a:Type -> vec:vector a ->
new_size:uint32_t{new_size <= size_of vec} ->
HST.ST (vector a)
(requires (fun h0 -> live h0 vec /\ freeable vec))
(ensures (fun h0 r h1 ->
live h1 vec /\ live h1 r /\ size_of r = new_size /\
frameOf r = frameOf vec /\
hmap_dom_eq h0 h1 /\
freeable r /\
modifies (loc_vector vec) h0 h1 /\
loc_vector vec == loc_vector r /\
S.equal (S.slice (V.as_seq h0 vec) 0 (U32.v new_size))
(S.slice (V.as_seq h1 r) 0 (U32.v new_size))))
let shrink #a vec new_size =
Vec new_size (Vec?.cap vec) (Vec?.vs vec)
inline_for_extraction
val flush_inplace:
#a:Type -> vec:vector a ->
i:uint32_t{i <= size_of vec} ->
HST.ST (vector a)
(requires (fun h0 ->
live h0 vec /\ freeable vec /\
HST.is_eternal_region (frameOf vec)))
(ensures (fun h0 fvec h1 ->
frameOf vec = frameOf fvec /\
hmap_dom_eq h0 h1 /\
live h1 fvec /\ freeable fvec /\
modifies (loc_vector vec) h0 h1 /\
loc_vector vec == loc_vector fvec /\
size_of fvec = size_of vec - i /\
S.equal (V.as_seq h1 fvec)
(S.slice (V.as_seq h0 vec) (U32.v i) (U32.v (size_of vec)))))
let flush_inplace #a vec i =
let h0 = HST.get() in
if i >= size_of vec then
shrink vec 0ul
else if i = 0ul then
vec
else begin
let n_shifted = size_of vec - i in
move_left (Vec?.vs vec) 0ul i n_shifted;
shrink vec n_shifted
end
inline_for_extraction
val rv_flush_inplace:
#a:Type0 -> #rst:Type -> #rg:regional rst a ->
rv:rvector rg -> i:uint32_t{i <= size_of rv} ->
HST.ST (rvector rg)
(requires (fun h0 -> rv_inv h0 rv))
(ensures (fun h0 frv h1 ->
V.size_of frv = V.size_of rv - i /\
V.frameOf rv = V.frameOf frv /\
modifies (loc_rvector rv) h0 h1 /\
rv_inv h1 frv /\
S.equal (as_seq h1 frv) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Hacl.Hash.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Calc.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "MerkleTree.Low.VectorExtras.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Modifies",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "MerkleTree.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | rv: LowStar.RVector.rvector rg -> i: LowStar.Vector.uint32_t{i <= LowStar.Vector.size_of rv}
-> FStar.HyperStack.ST.ST (LowStar.RVector.rvector rg) | FStar.HyperStack.ST.ST | [] | [] | [
"LowStar.Regional.regional",
"LowStar.RVector.rvector",
"LowStar.Vector.uint32_t",
"Prims.b2t",
"FStar.Integers.op_Less_Equals",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"LowStar.Vector.size_of",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"LowStar.Regional.__proj__Rgl__item__repr",
"FStar.Seq.Base.slice",
"LowStar.RVector.as_seq",
"FStar.UInt32.v",
"LowStar.RVector.as_seq_seq",
"LowStar.Vector.as_seq",
"LowStar.RVector.as_seq_seq_eq",
"LowStar.RVector.as_seq_seq_slice",
"LowStar.RVector.as_seq_seq_preserved",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.RVector.rs_loc_elems",
"LowStar.Monotonic.Buffer.loc_region_only",
"LowStar.Vector.frameOf",
"LowStar.RVector.rv_inv",
"LowStar.RVector.rs_elems_inv_preserved",
"LowStar.RVector.rs_loc_elems_parent_disj",
"LowStar.RVector.rs_loc_elems_disj",
"LowStar.Monotonic.Buffer.modifies",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowStar.Vector.vector",
"MerkleTree.Low.VectorExtras.flush_inplace",
"LowStar.RVector.rv_loc_elems_included",
"FStar.UInt32.__uint_to_t",
"Prims.op_Equality",
"FStar.UInt32.t",
"Prims.bool",
"LowStar.RVector.free_elems",
"FStar.Integers.op_Subtraction"
] | [] | false | true | false | false | false | let rv_flush_inplace #a #rst #rg rv i =
| let hh0 = HST.get () in
(if i = 0ul then () else free_elems rv (i - 1ul));
rv_loc_elems_included hh0 rv 0ul i;
let hh1 = HST.get () in
assert (modifies (rs_loc_elems rg (V.as_seq hh0 rv) 0 (U32.v i)) hh0 hh1);
let frv = flush_inplace rv i in
let hh2 = HST.get () in
assert (modifies (loc_region_only false (V.frameOf rv)) hh1 hh2);
rs_loc_elems_disj rg
(V.as_seq hh0 rv)
(V.frameOf rv)
0
(U32.v (V.size_of rv))
0
(U32.v i)
(U32.v i)
(U32.v (V.size_of rv));
rs_loc_elems_parent_disj rg (V.as_seq hh0 rv) (V.frameOf rv) (U32.v i) (U32.v (V.size_of rv));
rs_elems_inv_preserved rg
(V.as_seq hh0 rv)
(U32.v i)
(U32.v (V.size_of rv))
(loc_union (rs_loc_elems rg (V.as_seq hh0 rv) 0 (U32.v i)) (loc_region_only false (V.frameOf rv)))
hh0
hh2;
assert (rv_inv #a #rst #rg hh2 frv);
as_seq_seq_preserved rg
(V.as_seq hh0 rv)
(U32.v i)
(U32.v (V.size_of rv))
(loc_union (rs_loc_elems rg (V.as_seq hh0 rv) 0 (U32.v i)) (loc_region_only false (V.frameOf rv)))
hh0
hh2;
as_seq_seq_slice rg hh0 (V.as_seq hh0 rv) 0 (U32.v (V.size_of rv)) (U32.v i) (U32.v (V.size_of rv));
assert (S.equal (S.slice (as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv)))
(as_seq_seq rg hh2 (V.as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv))));
as_seq_seq_eq rg
hh2
(V.as_seq hh0 rv)
(V.as_seq hh2 frv)
(U32.v i)
(U32.v (V.size_of rv))
0
(U32.v (V.size_of frv));
assert (S.equal (as_seq_seq rg hh2 (V.as_seq hh2 frv) 0 (U32.v (V.size_of frv)))
(as_seq_seq rg hh2 (V.as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv))));
assert (S.equal (S.slice (as_seq hh0 rv) (U32.v i) (U32.v (V.size_of rv))) (as_seq hh2 frv));
frv | false |
MerkleTree.Low.VectorExtras.fst | MerkleTree.Low.VectorExtras.flush_inplace | val flush_inplace:
#a:Type -> vec:vector a ->
i:uint32_t{i <= size_of vec} ->
HST.ST (vector a)
(requires (fun h0 ->
live h0 vec /\ freeable vec /\
HST.is_eternal_region (frameOf vec)))
(ensures (fun h0 fvec h1 ->
frameOf vec = frameOf fvec /\
hmap_dom_eq h0 h1 /\
live h1 fvec /\ freeable fvec /\
modifies (loc_vector vec) h0 h1 /\
loc_vector vec == loc_vector fvec /\
size_of fvec = size_of vec - i /\
S.equal (V.as_seq h1 fvec)
(S.slice (V.as_seq h0 vec) (U32.v i) (U32.v (size_of vec))))) | val flush_inplace:
#a:Type -> vec:vector a ->
i:uint32_t{i <= size_of vec} ->
HST.ST (vector a)
(requires (fun h0 ->
live h0 vec /\ freeable vec /\
HST.is_eternal_region (frameOf vec)))
(ensures (fun h0 fvec h1 ->
frameOf vec = frameOf fvec /\
hmap_dom_eq h0 h1 /\
live h1 fvec /\ freeable fvec /\
modifies (loc_vector vec) h0 h1 /\
loc_vector vec == loc_vector fvec /\
size_of fvec = size_of vec - i /\
S.equal (V.as_seq h1 fvec)
(S.slice (V.as_seq h0 vec) (U32.v i) (U32.v (size_of vec))))) | let flush_inplace #a vec i =
let h0 = HST.get() in
if i >= size_of vec then
shrink vec 0ul
else if i = 0ul then
vec
else begin
let n_shifted = size_of vec - i in
move_left (Vec?.vs vec) 0ul i n_shifted;
shrink vec n_shifted
end | {
"file_name": "src/MerkleTree.Low.VectorExtras.fst",
"git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | {
"end_col": 5,
"end_line": 157,
"start_col": 0,
"start_line": 147
} | module MerkleTree.Low.VectorExtras
module B = LowStar.Buffer
module S = FStar.Seq
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module U32 = FStar.UInt32
open LowStar.BufferOps
open Hacl.Hash.Lemmas
open FStar.Integers
open LowStar.Modifies
open LowStar.Regional
open LowStar.Vector
open LowStar.RVector
module V = LowStar.Vector
module RV = LowStar.RVector
(** Some extra functions on top of LowStar.Vector... used for Merkle Tree. *)
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
inline_for_extraction
let move_left #a (b: B.buffer a) (dst src: U32.t) (l: U32.t): HST.Stack unit
(requires fun h0 ->
B.live h0 b /\
U32.v src + U32.v l <= B.length b /\
U32.v dst <= U32.v src)
(ensures fun h0 _ h1 ->
B.(modifies (loc_buffer b) h0 h1) /\ (
let b0 = B.as_seq h0 b in
let b1 = B.as_seq h1 b in
let src = U32.v src in
let dst = U32.v dst in
let l = U32.v l in
S.slice b1 dst (dst + l) `S.equal` S.slice b0 src (src + l)))
=
let h0 = HST.get () in
[@inline_let]
let inv (h: HS.mem) (i: nat) =
let b0 = B.as_seq h0 b in
let b1 = B.as_seq h b in
let src = U32.v src in
let dst = U32.v dst in
let l = U32.v l in
i <= l /\
B.(modifies (loc_buffer b) h0 h) /\
S.slice b1 dst (dst + i) `S.equal` S.slice b0 src (src + i) /\
S.slice b1 (src + i) (src + l) `S.equal` S.slice b0 (src + i) (src + l)
in
let f (i: U32.t { U32.(0 <= v i /\ v i < v l) }): HST.Stack unit
(requires fun h0 -> inv h0 (U32.v i))
(ensures fun h0 _ h1 -> U32.(inv h0 (v i) /\ inv h1 (v i + 1)))
=
let h00 = HST.get () in
calc (==) {
S.index (B.as_seq h0 b) U32.(v src + v i);
(==) {}
S.index (S.slice (B.as_seq h0 b) U32.(v src + v i) U32.(v src + v l)) 0;
(==) {}
S.index (S.slice (B.as_seq h00 b) U32.(v src + v i) U32.(v src + v l)) 0;
(==) {}
S.index (B.as_seq h00 b) U32.(v src + v i);
};
b.(dst `U32.add` i) <- b.(src `U32.add` i);
let h = HST.get () in
let b0 = B.as_seq h0 b in
let b1 = B.as_seq h b in
let src = U32.v src in
let dst = U32.v dst in
let l = U32.v l in
let i = U32.v i in
calc (S.equal) {
S.slice b1 dst (dst + (i + 1));
(S.equal) { lemma_slice_ijk b1 dst (dst + i) (dst + i + 1) }
S.slice b1 dst (dst + i) `S.append` S.slice b1 (dst + i) (dst + i + 1);
(S.equal) { }
S.slice b0 src (src + i) `S.append` S.slice b1 (dst + i) (dst + i + 1);
(S.equal) { }
S.slice b0 src (src + i) `S.append` S.cons (S.index b1 (dst + i)) S.empty;
(S.equal) { }
S.slice b0 src (src + i) `S.append` S.cons (S.index b0 (src + i)) S.empty;
(S.equal) { }
S.slice b0 src (src + i) `S.append` S.slice b0 (src + i) (src + i + 1);
(S.equal) { lemma_slice_ijk b0 src (src + i) (src + i + 1) }
S.slice b0 src (src + (i + 1));
};
let s1 = S.slice b1 (src + (i + 1)) (src + l) in
let s0 = S.slice b0 (src + (i + 1)) (src + l) in
let aux (j: nat { j < S.length s0 }): Lemma (S.index s0 j == S.index s1 j)
[ SMTPat (S.index s0 j); SMTPat (S.index s1 j) ]
=
calc (==) {
S.index s0 j;
(==) {}
S.index (S.slice b0 (src + i) (src + l)) (j + 1);
(==) {}
S.index (S.slice b1 (src + i) (src + l)) (j + 1);
(==) {}
S.index s1 j;
}
in
()
in
C.Loops.for 0ul l inv f
inline_for_extraction
val shrink:
#a:Type -> vec:vector a ->
new_size:uint32_t{new_size <= size_of vec} ->
HST.ST (vector a)
(requires (fun h0 -> live h0 vec /\ freeable vec))
(ensures (fun h0 r h1 ->
live h1 vec /\ live h1 r /\ size_of r = new_size /\
frameOf r = frameOf vec /\
hmap_dom_eq h0 h1 /\
freeable r /\
modifies (loc_vector vec) h0 h1 /\
loc_vector vec == loc_vector r /\
S.equal (S.slice (V.as_seq h0 vec) 0 (U32.v new_size))
(S.slice (V.as_seq h1 r) 0 (U32.v new_size))))
let shrink #a vec new_size =
Vec new_size (Vec?.cap vec) (Vec?.vs vec)
inline_for_extraction
val flush_inplace:
#a:Type -> vec:vector a ->
i:uint32_t{i <= size_of vec} ->
HST.ST (vector a)
(requires (fun h0 ->
live h0 vec /\ freeable vec /\
HST.is_eternal_region (frameOf vec)))
(ensures (fun h0 fvec h1 ->
frameOf vec = frameOf fvec /\
hmap_dom_eq h0 h1 /\
live h1 fvec /\ freeable fvec /\
modifies (loc_vector vec) h0 h1 /\
loc_vector vec == loc_vector fvec /\
size_of fvec = size_of vec - i /\
S.equal (V.as_seq h1 fvec) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Vector.fst.checked",
"LowStar.RVector.fst.checked",
"LowStar.Regional.fst.checked",
"LowStar.Modifies.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Hacl.Hash.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Calc.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "MerkleTree.Low.VectorExtras.fst"
} | [
{
"abbrev": true,
"full_module": "LowStar.RVector",
"short_module": "RV"
},
{
"abbrev": true,
"full_module": "LowStar.Vector",
"short_module": "V"
},
{
"abbrev": false,
"full_module": "LowStar.RVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Vector",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Regional",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Modifies",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "MerkleTree.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | vec: LowStar.Vector.vector a -> i: LowStar.Vector.uint32_t{i <= LowStar.Vector.size_of vec}
-> FStar.HyperStack.ST.ST (LowStar.Vector.vector a) | FStar.HyperStack.ST.ST | [] | [] | [
"LowStar.Vector.vector",
"LowStar.Vector.uint32_t",
"Prims.b2t",
"FStar.Integers.op_Less_Equals",
"FStar.Integers.Unsigned",
"FStar.Integers.W32",
"LowStar.Vector.size_of",
"FStar.Integers.op_Greater_Equals",
"MerkleTree.Low.VectorExtras.shrink",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"Prims.op_Equality",
"FStar.UInt32.t",
"Prims.unit",
"MerkleTree.Low.VectorExtras.move_left",
"LowStar.Vector.__proj__Vec__item__vs",
"FStar.Integers.int_t",
"FStar.Integers.op_Subtraction",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let flush_inplace #a vec i =
| let h0 = HST.get () in
if i >= size_of vec
then shrink vec 0ul
else
if i = 0ul
then vec
else
let n_shifted = size_of vec - i in
move_left (Vec?.vs vec) 0ul i n_shifted;
shrink vec n_shifted | false |
Vale.AsLowStar.MemoryHelpers.fst | Vale.AsLowStar.MemoryHelpers.same_buffer_same_upviews | val same_buffer_same_upviews (#src #bt:base_typ) (b:buf_t src bt) (h0 h1:HS.mem) : Lemma
(requires Seq.equal (B.as_seq h0 b) (B.as_seq h1 b))
(ensures (
let db = get_downview b in
DV.length_eq db;
let ub = UV.mk_buffer db (LSig.view_of_base_typ bt) in
Seq.equal (UV.as_seq h0 ub) (UV.as_seq h1 ub))) | val same_buffer_same_upviews (#src #bt:base_typ) (b:buf_t src bt) (h0 h1:HS.mem) : Lemma
(requires Seq.equal (B.as_seq h0 b) (B.as_seq h1 b))
(ensures (
let db = get_downview b in
DV.length_eq db;
let ub = UV.mk_buffer db (LSig.view_of_base_typ bt) in
Seq.equal (UV.as_seq h0 ub) (UV.as_seq h1 ub))) | let same_buffer_same_upviews #src #bt b h0 h1 =
let dv = get_downview b in
let s0 = DV.as_seq h0 dv in
let s1 = DV.as_seq h1 dv in
let aux (i:nat{i < DV.length dv}) : Lemma (Seq.index s0 i == Seq.index s1 i) =
DV.as_seq_sel h0 dv i;
DV.as_seq_sel h1 dv i;
DV.get_sel h0 dv i;
DV.get_sel h1 dv i
in Classical.forall_intro aux;
Seq.lemma_eq_intro s0 s1;
DV.length_eq dv;
Vale.Lib.BufferViewHelpers.lemma_uv_equal (LSig.view_of_base_typ bt) dv h0 h1 | {
"file_name": "vale/code/arch/x64/interop/Vale.AsLowStar.MemoryHelpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 158,
"start_col": 0,
"start_line": 146
} | module Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Arch.HeapImpl
open Vale.X64.MemoryAdapters
open Vale.Interop.Base
module B = LowStar.Buffer
module UV = LowStar.BufferView.Up
module DV = LowStar.BufferView.Down
module ME = Vale.X64.Memory
module VSig = Vale.AsLowStar.ValeSig
module IX64 = Vale.Interop.X64
friend Vale.X64.Memory
friend Vale.X64.Memory_Sems
friend Vale.X64.Stack_i
friend Vale.X64.Stack_Sems
friend Vale.X64.Decls
friend Vale.X64.StateLemmas
friend Vale.X64.MemoryAdapters
let as_vale_buffer_len (#src #t:base_typ) (x:buf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let as_vale_immbuffer_len (#src #t:base_typ) (x:ibuf_t src t)
= let db = get_downview x in
DV.length_eq db;
UV.length_eq (UV.mk_buffer db (ME.uint_view t))
let state_eq_down_mem (va_s1:V.va_state) (s1:_) = ()
let rec loc_eq (args:list arg)
: Lemma (VSig.mloc_modified_args args == loc_modified_args args)
= match args with
| [] -> ()
| hd :: tl -> loc_eq tl
let relate_modifies args m0 m1 = loc_eq args
let reveal_readable #src #t x s = ()
let reveal_imm_readable #src #t x s = ()
let readable_live #src #t x s = ()
let readable_imm_live #src #t x s = ()
let buffer_readable_reveal #max_arity src bt x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
//let get_heap_mk_mem_reveal args h0 = ()
let lemma_as_mem_as_vale_mem h = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let mk_stack_reveal stack = ()
let buffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let immbuffer_as_seq_reveal src t x args h0 = FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap
let buffer_as_seq_reveal2 src t x va_s = ()
let immbuffer_as_seq_reveal2 src t x va_s = ()
let buffer_addr_reveal src t x args h0 = ()
let immbuffer_addr_reveal src t x args h0 = ()
let fuel_eq = ()
let decls_eval_code_reveal c va_s0 va_s1 f = ()
let as_vale_buffer_disjoint #src1 #src2 #t1 #t2 x y = ()
let as_vale_buffer_imm_disjoint #src1 #src2 #t1 #t2 x y = ()
let as_vale_immbuffer_imm_disjoint #src1 #src2 #t1 #t2 x y = ()
let modifies_same_roots s h0 h1 = ()
let modifies_equal_domains s h0 h1 = ()
let loc_disjoint_sym x y = ()
#set-options "--z3rlimit 20"
let core_create_lemma_taint_hyp
#max_arity
#arg_reg
(args:IX64.arg_list)
(h0:HS.mem{mem_roots_p h0 args})
: Lemma
(ensures (let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
LSig.taint_hyp args va_s))
=
FStar.Pervasives.reveal_opaque (`%ME.get_vale_heap) ME.get_vale_heap;
let va_s = LSig.create_initial_vale_state #max_arity #arg_reg args h0 in
let taint_map = full_heap_taint va_s.VS.vs_heap in
let mem = ME.get_vale_heap va_s.VS.vs_heap in
// assert (mem == mk_mem args h0);
let raw_taint = IX64.(mk_taint args IX64.init_taint) in
// assert (taint_map == create_memtaint (_ih mem) (args_b8 args) raw_taint);
ME.valid_memtaint mem (args_b8 args) raw_taint;
// assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x));
assert (forall x. List.memP x (args_b8 args) ==> ME.valid_taint_b8 x mem taint_map (raw_taint x));
Classical.forall_intro (IX64.mk_taint_equiv args);
assert (forall (a:arg). List.memP a args /\ Some? (IX64.taint_of_arg a) ==>
Some?.v (IX64.taint_of_arg a) == raw_taint (IX64.taint_arg_b8 a));
Classical.forall_intro (args_b8_mem args);
assert (forall x. List.memP x args /\ Some? (IX64.taint_of_arg x) ==>
LSig.taint_hyp_arg mem taint_map x);
BigOps.big_and'_forall (LSig.taint_hyp_arg mem taint_map) args
let buffer_writeable_reveal src t x = ()
let buffer_read_reveal src t h s b i =
let db = get_downview b in
DV.length_eq db;
let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in
UV.as_seq_sel h b_v i
let imm_buffer_read_reveal src t h s b i =
let db = get_downview b in
DV.length_eq db;
let b_v = UV.mk_buffer db (LSig.view_of_base_typ t) in
UV.as_seq_sel h b_v i
let buffer_as_seq_invert src t h s b =
let db = get_downview b in
DV.length_eq db;
assert (Seq.equal
(ME.buffer_as_seq s (as_vale_buffer b))
(LSig.uint_to_nat_seq_t t (UV.as_seq h (UV.mk_buffer db (LSig.view_of_base_typ t)))))
let buffer_as_seq_reveal_tuint128 src x va_s = ()
let immbuffer_as_seq_reveal_tuint128 src x va_s = ()
let bounded_buffer_addrs_one src t h b s = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred
let bounded_buffer_addrs_all src t h b = FStar.Pervasives.reveal_opaque (`%addr_map_pred) addr_map_pred
let same_down_up_buffer_length src b =
let db = get_downview b in
DV.length_eq db;
FStar.Math.Lemmas.cancel_mul_div (B.length b) (view_n src)
#push-options "--z3rlimit 80"
let down_up_buffer_read_reveal src h s b i =
let db = get_downview b in
let n:pos = view_n src in
let up_view = (LSig.view_of_base_typ src) in
let ub = UV.mk_buffer db up_view in
same_down_up_buffer_length src b;
UV.length_eq ub;
UV.get_sel h ub i;
FStar.Math.Lemmas.lemma_mult_lt_right n i (DV.length db / n);
FStar.Math.Lemmas.multiply_fractions (DV.length db) n;
FStar.Math.Lemmas.nat_times_nat_is_nat i n;
assert (low_buffer_read src src h b i ==
UV.View?.get up_view (Seq.slice (DV.as_seq h db) (i*n) (i*n + n)));
DV.put_sel h db (i*n);
let aux () : Lemma (n * ((i*n)/n) == i*n) =
FStar.Math.Lemmas.cancel_mul_div i n
in aux()
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.StateLemmas.fst.checked",
"Vale.X64.Stack_Sems.fst.checked",
"Vale.X64.Stack_i.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.MemoryAdapters.fst.checked",
"Vale.X64.Memory_Sems.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Memory.fst.checked",
"Vale.X64.Decls.fst.checked",
"Vale.Lib.BufferViewHelpers.fst.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.AsLowStar.MemoryHelpers.fst"
} | [
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Heap",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Interop",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Vale.X64.Lemmas",
"short_module": "VL"
},
{
"abbrev": true,
"full_module": "Vale.X64.StateLemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_Sems",
"short_module": "VSS"
},
{
"abbrev": true,
"full_module": "Vale.X64.Stack_i",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory_Sems",
"short_module": "MES"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": "BS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: Vale.Interop.Base.buf_t src bt ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.equal (LowStar.Monotonic.Buffer.as_seq h0 b)
(LowStar.Monotonic.Buffer.as_seq h1 b))
(ensures
(let db = Vale.Interop.Types.get_downview b in
LowStar.BufferView.Down.length_eq db;
let ub =
LowStar.BufferView.Up.mk_buffer db (Vale.AsLowStar.LowStarSig.view_of_base_typ bt)
in
FStar.Seq.Base.equal (LowStar.BufferView.Up.as_seq h0 ub)
(LowStar.BufferView.Up.as_seq h1 ub))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Arch.HeapTypes_s.base_typ",
"Vale.Interop.Base.buf_t",
"FStar.Monotonic.HyperStack.mem",
"Vale.Lib.BufferViewHelpers.lemma_uv_equal",
"FStar.UInt8.t",
"Vale.Interop.Types.base_typ_as_type",
"Vale.AsLowStar.LowStarSig.view_of_base_typ",
"Prims.unit",
"LowStar.BufferView.Down.length_eq",
"FStar.Seq.Base.lemma_eq_intro",
"FStar.Classical.forall_intro",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"LowStar.BufferView.Down.length",
"Prims.eq2",
"FStar.Seq.Base.index",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"LowStar.BufferView.Down.get_sel",
"LowStar.BufferView.Down.as_seq_sel",
"FStar.Seq.Properties.lseq",
"LowStar.BufferView.Down.as_seq",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"LowStar.Buffer.trivial_preorder"
] | [] | false | false | true | false | false | let same_buffer_same_upviews #src #bt b h0 h1 =
| let dv = get_downview b in
let s0 = DV.as_seq h0 dv in
let s1 = DV.as_seq h1 dv in
let aux (i: nat{i < DV.length dv}) : Lemma (Seq.index s0 i == Seq.index s1 i) =
DV.as_seq_sel h0 dv i;
DV.as_seq_sel h1 dv i;
DV.get_sel h0 dv i;
DV.get_sel h1 dv i
in
Classical.forall_intro aux;
Seq.lemma_eq_intro s0 s1;
DV.length_eq dv;
Vale.Lib.BufferViewHelpers.lemma_uv_equal (LSig.view_of_base_typ bt) dv h0 h1 | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.