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.Impl.SHA3.fst
Hacl.Impl.SHA3.set
val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v)
val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v)
let set s x y v = s.(x +! 5ul *! y) <- v
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 65, "start_col": 0, "start_line": 65 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Hacl.Impl.SHA3.state -> x: Hacl.Impl.SHA3.index -> y: Hacl.Impl.SHA3.index -> v: Lib.IntTypes.uint64 -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.SHA3.state", "Hacl.Impl.SHA3.index", "Lib.IntTypes.uint64", "Lib.Buffer.op_Array_Assignment", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.op_Star_Bang", "Prims.unit" ]
[]
false
true
false
false
false
let set s x y v =
s.(x +! 5ul *! y) <- v
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.state_theta0
val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C))
val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C))
let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul )
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 93, "start_col": 0, "start_line": 80 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Hacl.Impl.SHA3.state -> _C: Lib.Buffer.lbuffer Lib.IntTypes.uint64 5ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.SHA3.state", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.Buffer.loop1", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.op_Array_Assignment", "Prims.unit", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Hat_Dot", "Hacl.Impl.SHA3.get", "Lib.LoopCombinators.unfold_repeati", "Lib.Sequence.lseq", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Prims.nat", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Spec.SHA3.state_theta_inner_C" ]
[]
false
true
false
false
false
let state_theta0 s _C =
[@@ inline_let ]let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul)
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.index_map
val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i))
val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i))
let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1)
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 161, "start_col": 0, "start_line": 156 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} ->
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: a -> b) -> l: Prims.list a -> i: Prims.nat{i < FStar.List.Tot.Base.length l} -> FStar.Pervasives.Lemma (ensures FStar.List.Tot.Base.index (FStar.List.Tot.Base.map f l) i == f (FStar.List.Tot.Base.index l i) )
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "Prims.op_Equality", "Prims.int", "Prims.bool", "Hacl.Impl.SHA3.index_map", "Prims.op_Subtraction", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec index_map #a #b f l i =
if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1)
false
Pulse.Soundness.Common.fst
Pulse.Soundness.Common.elab_comp_post
val elab_comp_post (c: comp_st) : R.term
val elab_comp_post (c: comp_st) : R.term
let elab_comp_post (c:comp_st) : R.term = let t = elab_term (comp_res c) in let post = elab_term (comp_post c) in mk_abs t R.Q_Explicit post
{ "file_name": "lib/steel/pulse/Pulse.Soundness.Common.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 28, "end_line": 353, "start_col": 0, "start_line": 350 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Soundness.Common module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Reflection.Util open Pulse.Typing open Pulse.Elaborate let ln_comp = c:comp_st { ln_c c } let rec extend_env_l_lookup_fvar (g:R.env) (sg:env_bindings) (fv:R.fv) (us:R.universes) : Lemma (ensures RT.lookup_fvar_uinst (extend_env_l g sg) fv us == RT.lookup_fvar_uinst g fv us) [SMTPat (RT.lookup_fvar_uinst (extend_env_l g sg) fv us)] = match sg with | [] -> () | hd::tl -> extend_env_l_lookup_fvar g tl fv us let elab_term_opt (b:option term) = match b with | Some b -> Some (elab_term b) | None -> None // let rec extend_env_l_lookup_bvar (g:R.env) (sg:env_bindings) (x:var) // : Lemma // (requires (forall x. RT.lookup_bvar g x == None)) // (ensures (RT.lookup_bvar (extend_env_l g sg) x == elab_term_opt (lookup sg x))) // (decreases sg) // [SMTPat (RT.lookup_bvar (extend_env_l g sg) x)] // = match sg with // | [] -> () // | hd :: tl -> extend_env_l_lookup_bvar g tl x let lookup_elab_env (g:env) (x:var) : Lemma (ensures (RT.lookup_bvar (elab_env g) x == elab_term_opt (lookup g x))) [SMTPat (RT.lookup_bvar (elab_env g) x)] = admit () // TODO: FIX ME!!!! let tot_typing_soundness (#g:env) (#e:term) (#t:term) (d:tot_typing g e t) : GTot (RT.tot_typing (elab_env g) (elab_term e) (elab_term t)) = let E d = d in d let ghost_typing_soundness (#g:env) (#e:term) (#t:term) (d:ghost_typing g e t) : GTot (RT.ghost_typing (elab_env g) (elab_term e) (elab_term t)) = let E d = d in d #push-options "--z3rlimit_factor 4" let mk_t_abs_tot (g:env) (#u:universe) (#q:option qualifier) (#ty:term) (ppname:ppname) (t_typing:tot_typing g ty (tm_type u)) (#body:term) (#body_ty:term) (#x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars body) }) (body_typing:tot_typing (push_binding g x ppname ty) (open_term body x) body_ty) : GTot (RT.tot_typing (elab_env g) (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (elab_term body)) (elab_term (tm_arrow (mk_binder_ppname ty ppname) q (close_comp (C_Tot body_ty) x)))) = let c = C_Tot body_ty in let r_ty = elab_term ty in let r_body = elab_term (open_term body x) in let r_c = elab_comp c in let r_t_typing = tot_typing_soundness t_typing in let r_body_typing = tot_typing_soundness body_typing in RT.well_typed_terms_are_ln _ _ _ r_body_typing; RT.open_close_inverse r_body x; elab_comp_close_commute c x; elab_freevars body; assert (~ (x `Set.mem` RT.freevars (elab_term body))); assume (~ (x `Set.mem` RT.freevars (RT.close_term r_body x))); RT.close_term_spec (elab_comp c) x; assert (elab_term (tm_type u) == RT.tm_type u); let r_t_typing : RT.tot_typing (elab_env g) r_ty (RT.tm_type u) = coerce_eq () r_t_typing //strange that this coercion is needed in let d : RT.tot_typing (elab_env g) (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (RT.close_term (elab_term (open_term body x)) x)) (elab_term (tm_arrow (mk_binder_ppname ty ppname) q (close_comp (C_Tot body_ty) x))) = RT.T_Abs (elab_env g) x r_ty (RT.close_term r_body x) (T.E_Total, r_c) u ppname.name (elab_qual q) _ r_t_typing r_body_typing in elab_open_commute' body (null_var x) 0; RT.open_term_spec (elab_term body) x; assert (elab_term (open_term body x) == RT.open_term (elab_term body) x); let d : RT.typing _ (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (RT.close_term (RT.open_term (elab_term body) x) x)) _ = d in RT.close_open_inverse (elab_term body) x; d let mk_t_abs (g:env) (#u:universe) (#ty:term) (#q:option qualifier) (#t_typing:typing g ty T.E_Total (tm_type u)) (ppname:ppname) (r_t_typing:RT.tot_typing (elab_env g) (elab_term ty) (elab_comp (C_Tot (tm_type u)))) (#body:st_term) (#x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) }) (#c:comp) (#body_typing:st_typing (push_binding g x ppname ty) (open_st_term body x) c) (r_body_typing:RT.tot_typing (elab_env (push_binding g x ppname ty)) (elab_st_typing body_typing) (elab_comp c)) : GTot (RT.tot_typing (elab_env g) (mk_abs_with_name ppname.name (elab_term ty) (elab_qual q) (RT.close_term (elab_st_typing body_typing) x)) (elab_term (tm_arrow (mk_binder_ppname ty ppname) q (close_comp c x)))) = let r_ty = elab_term ty in let r_body = elab_st_typing body_typing in let r_c = elab_comp c in RT.well_typed_terms_are_ln _ _ _ r_body_typing; RT.open_close_inverse r_body x; elab_comp_close_commute c x; assume (~ (x `Set.mem` RT.freevars (RT.close_term r_body x))); RT.close_term_spec (elab_comp c) x; RT.T_Abs (elab_env g) x r_ty (RT.close_term r_body x) (T.E_Total, r_c) u ppname.name (elab_qual q) _ r_t_typing r_body_typing (*** Typing of combinators used in the elaboration **) (** Type of bind **) let bind_res (u2:R.universe) (t2 pre post2:R.term) = mk_stt_comp u2 t2 pre post2 let g_type_bind (u2:R.universe) (t1 t2 post1 post2:R.term) = mk_arrow (t1, R.Q_Explicit) (bind_res u2 t2 (R.mk_app post1 [bound_var 0 (* x *), R.Q_Explicit]) post2) let bind_type_t1_t2_pre_post1_post2_f (u1 u2:R.universe) (t1 t2 pre post1 post2:R.term) = mk_arrow (g_type_bind u2 t1 t2 post1 post2, R.Q_Explicit) (bind_res u2 t2 pre post2) let bind_type_t1_t2_pre_post1_post2 (u1 u2:R.universe) (t1 t2 pre post1 post2:R.term) = let f_type = mk_stt_comp u1 t1 pre post1 in mk_arrow (f_type, R.Q_Explicit) (bind_type_t1_t2_pre_post1_post2_f u1 u2 t1 t2 pre post1 post2) let post2_type_bind t2 = mk_arrow (t2, R.Q_Explicit) vprop_tm let bind_type_t1_t2_pre_post1 (u1 u2:R.universe) (t1 t2 pre post1:R.term) = let var = 0 in let post2 = mk_name var in mk_arrow (post2_type_bind t2, R.Q_Implicit) (RT.subst_term (bind_type_t1_t2_pre_post1_post2 u1 u2 t1 t2 pre post1 post2) [ RT.ND var 0 ]) let post1_type_bind t1 = mk_arrow (t1, R.Q_Explicit) vprop_tm let bind_type_t1_t2_pre (u1 u2:R.universe) (t1 t2 pre:R.term) = let var = 1 in let post1 = mk_name var in mk_arrow (post1_type_bind t1, R.Q_Implicit) (RT.subst_term (bind_type_t1_t2_pre_post1 u1 u2 t1 t2 pre post1) [ RT.ND var 0 ]) let bind_type_t1_t2 (u1 u2:R.universe) (t1 t2:R.term) = let var = 2 in let pre = mk_name var in let pre_type = vprop_tm in mk_arrow (pre_type, R.Q_Implicit) (RT.subst_term (bind_type_t1_t2_pre u1 u2 t1 t2 pre) [ RT.ND var 0 ]) let bind_type_t1 (u1 u2:R.universe) (t1:R.term) = let var = 3 in let t2 = mk_name var in let t2_type = RT.tm_type u2 in mk_arrow (t2_type, R.Q_Implicit) (RT.subst_term (bind_type_t1_t2 u1 u2 t1 t2) [ RT.ND var 0 ]) let bind_type (u1 u2:R.universe) = let var = 4 in let t1 = mk_name var in let t1_type = RT.tm_type u1 in mk_arrow (t1_type, R.Q_Implicit) (RT.subst_term (bind_type_t1 u1 u2 t1) [ RT.ND var 0 ]) (** Type of frame **) let mk_star (l r:R.term) = let open R in let head = pack_ln (Tv_FVar (pack_fv star_lid)) in R.mk_app head [(l, Q_Explicit); (r, Q_Explicit)] let frame_res (u:R.universe) (t pre post frame:R.term) = mk_stt_comp u t (mk_star pre frame) (mk_abs t R.Q_Explicit (mk_star (R.mk_app post [bound_var 0, R.Q_Explicit]) frame)) let frame_type_t_pre_post_frame (u:R.universe) (t pre post frame:R.term) = let open R in let f_type = mk_stt_comp u t pre post in mk_arrow (f_type, Q_Explicit) (frame_res u t pre post frame) let frame_type_t_pre_post (u:R.universe) (t pre post:R.term) = let var = 0 in let frame = mk_name var in mk_arrow (vprop_tm, R.Q_Explicit) (RT.close_term (frame_res u t pre post frame) var) let frame_type_t_pre (u:R.universe) (t pre:R.term) = let var = 1 in let post = mk_name var in let post_type = mk_arrow (t, R.Q_Explicit) vprop_tm in mk_arrow (post_type, R.Q_Implicit) (RT.close_term (frame_type_t_pre_post u t pre post) var) let frame_type_t (u:R.universe) (t:R.term) = let var = 2 in let pre = mk_name var in let pre_type = vprop_tm in mk_arrow (pre_type, R.Q_Implicit) (RT.close_term (frame_type_t_pre u t pre) var) let frame_type (u:R.universe) = let var = 3 in let t = mk_name var in let t_type = RT.tm_type u in mk_arrow (t_type, R.Q_Implicit) (RT.close_term (frame_type_t u t) var) (** Type of sub_stt **) let stt_vprop_post_equiv_fv = R.pack_fv (mk_pulse_lib_core_lid "vprop_post_equiv") let stt_vprop_post_equiv_univ_inst u = R.pack_ln (R.Tv_UInst stt_vprop_post_equiv_fv [u]) let stt_vprop_post_equiv (u:R.universe) (t t1 t2:R.term) = R.mk_app (stt_vprop_post_equiv_univ_inst u) [(t, R.Q_Implicit); (t1, R.Q_Explicit); (t2, R.Q_Explicit)] let sub_stt_res u t pre post = mk_stt_comp u t pre post let sub_stt_equiv_post u t pre1 post1 pre2 post2 = mk_arrow (stt_vprop_post_equiv u t post1 post2, R.Q_Explicit) (sub_stt_res u t pre2 post2) let sub_stt_equiv_pre u t pre1 post1 pre2 post2 = mk_arrow (stt_vprop_equiv pre1 pre2, R.Q_Explicit) (sub_stt_equiv_post u t pre1 pre2 post1 post2) let sub_stt_post2 u t pre1 post1 pre2 = let var = 0 in let post2 = mk_name var in let post2_type = mk_arrow (t, R.Q_Explicit) vprop_tm in mk_arrow (post2_type, R.Q_Explicit) (RT.close_term (sub_stt_equiv_pre u t pre1 pre2 post1 post2) var) let sub_stt_pre2 u t pre1 post1 = let var = 1 in let pre2 = mk_name var in let pre2_type = vprop_tm in mk_arrow (pre2_type, R.Q_Explicit) (RT.close_term (sub_stt_post2 u t pre1 post1 pre2) var) let sub_stt_post1 u t pre1 = let var = 2 in let post1 = mk_name var in let post1_type = mk_arrow (t, R.Q_Explicit) vprop_tm in mk_arrow (post1_type, R.Q_Explicit) (RT.close_term (sub_stt_pre2 u t pre1 post1) var) let sub_stt_pre1 u t = let var = 3 in let pre1 = mk_name var in let pre1_type = vprop_tm in mk_arrow (pre1_type, R.Q_Explicit) (RT.close_term (sub_stt_post1 u t pre1) var) let sub_stt_type u = let var = 4 in let t = mk_name var in let ty_typ = RT.tm_type u in mk_arrow (ty_typ, R.Q_Explicit) (RT.close_term (sub_stt_pre1 u t) var) (** Properties of environments suitable for elaboration **) let has_stt_bindings (f:RT.fstar_top_env) = RT.lookup_fvar f RT.bool_fv == Some (RT.tm_type RT.u_zero) /\ RT.lookup_fvar f vprop_fv == Some (RT.tm_type u2) /\ True //(forall (u1 u2:R.universe). RT.lookup_fvar_uinst f bind_fv [u1; u2] == Some (bind_type u1 u2)) /\ //(forall (u:R.universe). RT.lookup_fvar_uinst f frame_fv [u] == Some (frame_type u)) /\ //(forall (u:R.universe). RT.lookup_fvar_uinst f subsumption_fv [u] == Some (sub_stt_type u)) let stt_env = e:env { has_stt_bindings (fstar_env e) } let check_top_level_environment (f:RT.fstar_top_env) : option stt_env = admit(); Some (mk_env f) //we should implement this as a runtime check
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Elaborate.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Soundness.Common.fst" }
[ { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse.Soundness", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Soundness", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 4, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Pulse.Syntax.Base.comp_st -> FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.comp_st", "Pulse.Reflection.Util.mk_abs", "FStar.Stubs.Reflection.V2.Data.Q_Explicit", "FStar.Stubs.Reflection.Types.term", "Pulse.Elaborate.Pure.elab_term", "Pulse.Syntax.Base.comp_post", "Pulse.Syntax.Base.comp_res" ]
[]
false
false
false
true
false
let elab_comp_post (c: comp_st) : R.term =
let t = elab_term (comp_res c) in let post = elab_term (comp_post c) in mk_abs t R.Q_Explicit post
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.keccak_rotc
val keccak_rotc:x: glbuffer rotc_t 24ul {witnessed x keccak_rotc /\ recallable x}
val keccak_rotc:x: glbuffer rotc_t 24ul {witnessed x keccak_rotc /\ recallable x}
let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 26, "start_col": 8, "start_line": 25 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: (c: Lib.Buffer.lbuffer_t Lib.Buffer.CONST Spec.SHA3.Constants.rotc_t (24ul <: FStar.UInt32.t) {LowStar.ConstBuffer.qual_of c == LowStar.ConstBuffer.IMMUTABLE}) {Lib.Buffer.witnessed x Spec.SHA3.Constants.keccak_rotc /\ Lib.Buffer.recallable x}
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_global", "Spec.SHA3.Constants.rotc_t", "Spec.SHA3.Constants.rotc_list", "Lib.Buffer.glbuffer", "Lib.IntTypes.size", "FStar.Pervasives.normalize_term", "Lib.IntTypes.size_nat", "FStar.List.Tot.Base.length" ]
[]
false
false
false
false
false
let keccak_rotc:x: glbuffer rotc_t 24ul {witnessed x keccak_rotc /\ recallable x} =
createL_global rotc_list
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.keccak_piln
val keccak_piln:x: glbuffer piln_t 24ul {witnessed x keccak_piln /\ recallable x}
val keccak_piln:x: glbuffer piln_t 24ul {witnessed x keccak_piln /\ recallable x}
let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 29, "start_col": 8, "start_line": 28 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: (c: Lib.Buffer.lbuffer_t Lib.Buffer.CONST Spec.SHA3.Constants.piln_t (24ul <: FStar.UInt32.t) {LowStar.ConstBuffer.qual_of c == LowStar.ConstBuffer.IMMUTABLE}) {Lib.Buffer.witnessed x Spec.SHA3.Constants.keccak_piln /\ Lib.Buffer.recallable x}
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_global", "Spec.SHA3.Constants.piln_t", "Spec.SHA3.Constants.piln_list", "Lib.Buffer.glbuffer", "Lib.IntTypes.size", "FStar.Pervasives.normalize_term", "Lib.IntTypes.size_nat", "FStar.List.Tot.Base.length" ]
[]
false
false
false
false
false
let keccak_piln:x: glbuffer piln_t 24ul {witnessed x keccak_piln /\ recallable x} =
createL_global piln_list
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.state_theta
val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s))
val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s))
let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame()
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 148, "start_col": 0, "start_line": 143 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Hacl.Impl.SHA3.state -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.SHA3.state", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.SHA3.state_theta1", "Hacl.Impl.SHA3.state_theta0", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u64", "Lib.Buffer.lbuffer", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let state_theta s =
push_frame (); let h0 = ST.get () in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame ()
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.storeState_inner
val storeState_inner: s:state -> j:size_t{v j < 25} -> block:lbuffer uint8 200ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc block) h0 h1 /\ as_seq h1 block == S.storeState_inner (as_seq h0 s) (v j) (as_seq h0 block))
val storeState_inner: s:state -> j:size_t{v j < 25} -> block:lbuffer uint8 200ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc block) h0 h1 /\ as_seq h1 block == S.storeState_inner (as_seq h0 s) (v j) (as_seq h0 block))
let storeState_inner s j block = let sj = s.(j) in let h0 = ST.get () in update_sub_f h0 block (j *! 8ul) 8ul (fun h -> Lib.ByteSequence.uint_to_bytes_le sj) (fun _ -> uint_to_bytes_le #U64 (sub block (j *! 8ul) 8ul) sj)
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 340, "start_col": 0, "start_line": 335 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s')) let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp inline_for_extraction noextract val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s)) let state_pi_rho s = push_frame(); let x = get s 1ul 0ul in let h0 = ST.get() in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@ inline_let] let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@ inline_let] let footprint i = loc_union (loc current) (loc s) in [@ inline_let] let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s ); pop_frame() inline_for_extraction noextract val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) let state_chi_inner st y = let h0 = ST.get() in let v0 = get st 0ul y ^. ((lognot (get st 1ul y)) &. get st 2ul y) in let v1 = get st 1ul y ^. ((lognot (get st 2ul y)) &. get st 3ul y) in let v2 = get st 2ul y ^. ((lognot (get st 3ul y)) &. get st 4ul y) in let v3 = get st 3ul y ^. ((lognot (get st 4ul y)) &. get st 0ul y) in let v4 = get st 4ul y ^. ((lognot (get st 0ul y)) &. get st 1ul y) in set st 0ul y v0; set st 1ul y v1; set st 2ul y v2; set st 3ul y v3; set st 4ul y v4; let h1 = ST.get() in assert (modifies (loc st) h0 h1); assert (as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) inline_for_extraction noextract val state_chi: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_chi (as_seq h0 s)) let state_chi st = let h0 = ST.get() in [@ inline_let] let spec h0 = Equiv.state_chi_inner in let h0 = ST.get () in loop1 h0 5ul st spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 st) (v y); state_chi_inner st y ); let h1 = ST.get() in assert(as_seq h1 st == Equiv.state_chi (as_seq h0 st)); Equiv.state_chi_equivalence (as_seq h0 st) inline_for_extraction noextract val state_iota: s:state -> round:size_t{v round < 24} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_iota (as_seq h0 s) (v round)) let state_iota s round = recall_contents keccak_rndc Spec.SHA3.Constants.keccak_rndc; let c = keccak_rndc.(round) in set s 0ul 0ul (get s 0ul 0ul ^. secret c) private val state_permute: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_permute (as_seq h0 s)) let state_permute s = [@ inline_let] let spec h0 = S.state_permute1 in let h0 = ST.get () in loop1 h0 24ul s spec (fun round -> Loop.unfold_repeati 24 (spec h0) (as_seq h0 s) (v round); state_theta s; state_pi_rho s; state_chi s; state_iota s round) private val loadState: rateInBytes:size_t{v rateInBytes <= 200} -> input:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h -> live h input /\ live h s /\ disjoint input s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.loadState (v rateInBytes) (as_seq h0 input) (as_seq h0 s)) let loadState rateInBytes input s = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in update_sub block 0ul rateInBytes input; [@ inline_let] let spec h0 = S.loadState_inner (as_seq h0 block) in let h0 = ST.get () in loop1 h0 25ul s spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 s) (v j); let h0 = ST.get() in let x = uint_from_bytes_le #U64 (sub block (j *! 8ul) 8ul) in s.(j) <- s.(j) ^. x ); pop_frame() inline_for_extraction noextract val storeState_inner: s:state -> j:size_t{v j < 25} -> block:lbuffer uint8 200ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc block) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Hacl.Impl.SHA3.state -> j: Lib.IntTypes.size_t{Lib.IntTypes.v j < 25} -> block: Lib.Buffer.lbuffer Lib.IntTypes.uint8 200ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.SHA3.state", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.Buffer.update_sub_f", "Lib.IntTypes.op_Star_Bang", "FStar.Monotonic.HyperStack.mem", "Lib.ByteSequence.uint_to_bytes_le", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Sequence.lseq", "Prims.unit", "Lib.ByteBuffer.uint_to_bytes_le", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.mk_int", "Lib.Buffer.sub", "FStar.HyperStack.ST.get", "Lib.Buffer.op_Array_Access", "Lib.IntTypes.uint64" ]
[]
false
true
false
false
false
let storeState_inner s j block =
let sj = s.(j) in let h0 = ST.get () in update_sub_f h0 block (j *! 8ul) 8ul (fun h -> Lib.ByteSequence.uint_to_bytes_le sj) (fun _ -> uint_to_bytes_le #U64 (sub block (j *! 8ul) 8ul) sj)
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.keccak_rndc
val keccak_rndc:x: glbuffer pub_uint64 24ul {witnessed x keccak_rndc /\ recallable x}
val keccak_rndc:x: glbuffer pub_uint64 24ul {witnessed x keccak_rndc /\ recallable x}
let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 32, "start_col": 8, "start_line": 31 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: (c: Lib.Buffer.lbuffer_t Lib.Buffer.CONST (Lib.IntTypes.int_t Lib.IntTypes.U64 Lib.IntTypes.PUB) (24ul <: FStar.UInt32.t) {LowStar.ConstBuffer.qual_of c == LowStar.ConstBuffer.IMMUTABLE}) {Lib.Buffer.witnessed x Spec.SHA3.Constants.keccak_rndc /\ Lib.Buffer.recallable x}
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_global", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.PUB", "Spec.SHA3.Constants.rndc_list", "Lib.Buffer.glbuffer", "Lib.IntTypes.size", "FStar.Pervasives.normalize_term", "Lib.IntTypes.size_nat", "FStar.List.Tot.Base.length" ]
[]
false
false
false
false
false
let keccak_rndc:x: glbuffer pub_uint64 24ul {witnessed x keccak_rndc /\ recallable x} =
createL_global rndc_list
false
Pulse.Soundness.Common.fst
Pulse.Soundness.Common.elab_term_opt
val elab_term_opt : b: FStar.Pervasives.Native.option Pulse.Syntax.Base.term -> FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.term
let elab_term_opt (b:option term) = match b with | Some b -> Some (elab_term b) | None -> None
{ "file_name": "lib/steel/pulse/Pulse.Soundness.Common.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 16, "end_line": 44, "start_col": 0, "start_line": 41 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Soundness.Common module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 open FStar.List.Tot open Pulse.Syntax open Pulse.Reflection.Util open Pulse.Typing open Pulse.Elaborate let ln_comp = c:comp_st { ln_c c } let rec extend_env_l_lookup_fvar (g:R.env) (sg:env_bindings) (fv:R.fv) (us:R.universes) : Lemma (ensures RT.lookup_fvar_uinst (extend_env_l g sg) fv us == RT.lookup_fvar_uinst g fv us) [SMTPat (RT.lookup_fvar_uinst (extend_env_l g sg) fv us)] = match sg with | [] -> () | hd::tl -> extend_env_l_lookup_fvar g tl fv us
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.Reflection.Util.fst.checked", "Pulse.Elaborate.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Soundness.Common.fst" }
[ { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse.Soundness", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Soundness", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: FStar.Pervasives.Native.option Pulse.Syntax.Base.term -> FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.term
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.option", "Pulse.Syntax.Base.term", "FStar.Pervasives.Native.Some", "FStar.Stubs.Reflection.Types.term", "Pulse.Elaborate.Pure.elab_term", "FStar.Pervasives.Native.None" ]
[]
false
false
false
true
false
let elab_term_opt (b: option term) =
match b with | Some b -> Some (elab_term b) | None -> None
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.squeeze_inner
val squeeze_inner: rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> outputByteLen:size_t -> s:state -> output:lbuffer uint8 rateInBytes -> i:size_t{v i < v (outputByteLen /. rateInBytes)} -> Stack unit (requires fun h0 -> live h0 s /\ live h0 output /\ disjoint s output) (ensures fun h0 _ h1 -> modifies2 s output h0 h1 /\ (as_seq h1 s, as_seq h1 output) == S.squeeze_inner (v rateInBytes) (v outputByteLen) (v i) (as_seq h0 s))
val squeeze_inner: rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> outputByteLen:size_t -> s:state -> output:lbuffer uint8 rateInBytes -> i:size_t{v i < v (outputByteLen /. rateInBytes)} -> Stack unit (requires fun h0 -> live h0 s /\ live h0 output /\ disjoint s output) (ensures fun h0 _ h1 -> modifies2 s output h0 h1 /\ (as_seq h1 s, as_seq h1 output) == S.squeeze_inner (v rateInBytes) (v outputByteLen) (v i) (as_seq h0 s))
let squeeze_inner rateInBytes outputByteLen s output i = storeState rateInBytes s output; state_permute s
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 474, "start_col": 0, "start_line": 472 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s')) let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp inline_for_extraction noextract val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s)) let state_pi_rho s = push_frame(); let x = get s 1ul 0ul in let h0 = ST.get() in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@ inline_let] let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@ inline_let] let footprint i = loc_union (loc current) (loc s) in [@ inline_let] let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s ); pop_frame() inline_for_extraction noextract val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) let state_chi_inner st y = let h0 = ST.get() in let v0 = get st 0ul y ^. ((lognot (get st 1ul y)) &. get st 2ul y) in let v1 = get st 1ul y ^. ((lognot (get st 2ul y)) &. get st 3ul y) in let v2 = get st 2ul y ^. ((lognot (get st 3ul y)) &. get st 4ul y) in let v3 = get st 3ul y ^. ((lognot (get st 4ul y)) &. get st 0ul y) in let v4 = get st 4ul y ^. ((lognot (get st 0ul y)) &. get st 1ul y) in set st 0ul y v0; set st 1ul y v1; set st 2ul y v2; set st 3ul y v3; set st 4ul y v4; let h1 = ST.get() in assert (modifies (loc st) h0 h1); assert (as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) inline_for_extraction noextract val state_chi: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_chi (as_seq h0 s)) let state_chi st = let h0 = ST.get() in [@ inline_let] let spec h0 = Equiv.state_chi_inner in let h0 = ST.get () in loop1 h0 5ul st spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 st) (v y); state_chi_inner st y ); let h1 = ST.get() in assert(as_seq h1 st == Equiv.state_chi (as_seq h0 st)); Equiv.state_chi_equivalence (as_seq h0 st) inline_for_extraction noextract val state_iota: s:state -> round:size_t{v round < 24} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_iota (as_seq h0 s) (v round)) let state_iota s round = recall_contents keccak_rndc Spec.SHA3.Constants.keccak_rndc; let c = keccak_rndc.(round) in set s 0ul 0ul (get s 0ul 0ul ^. secret c) private val state_permute: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_permute (as_seq h0 s)) let state_permute s = [@ inline_let] let spec h0 = S.state_permute1 in let h0 = ST.get () in loop1 h0 24ul s spec (fun round -> Loop.unfold_repeati 24 (spec h0) (as_seq h0 s) (v round); state_theta s; state_pi_rho s; state_chi s; state_iota s round) private val loadState: rateInBytes:size_t{v rateInBytes <= 200} -> input:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h -> live h input /\ live h s /\ disjoint input s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.loadState (v rateInBytes) (as_seq h0 input) (as_seq h0 s)) let loadState rateInBytes input s = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in update_sub block 0ul rateInBytes input; [@ inline_let] let spec h0 = S.loadState_inner (as_seq h0 block) in let h0 = ST.get () in loop1 h0 25ul s spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 s) (v j); let h0 = ST.get() in let x = uint_from_bytes_le #U64 (sub block (j *! 8ul) 8ul) in s.(j) <- s.(j) ^. x ); pop_frame() inline_for_extraction noextract val storeState_inner: s:state -> j:size_t{v j < 25} -> block:lbuffer uint8 200ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc block) h0 h1 /\ as_seq h1 block == S.storeState_inner (as_seq h0 s) (v j) (as_seq h0 block)) let storeState_inner s j block = let sj = s.(j) in let h0 = ST.get () in update_sub_f h0 block (j *! 8ul) 8ul (fun h -> Lib.ByteSequence.uint_to_bytes_le sj) (fun _ -> uint_to_bytes_le #U64 (sub block (j *! 8ul) 8ul) sj) private val storeState: rateInBytes:size_t{v rateInBytes <= 200} -> s:state -> res:lbuffer uint8 rateInBytes -> Stack unit (requires fun h0 -> live h0 s /\ live h0 res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.storeState (v rateInBytes) (as_seq h0 s)) let storeState rateInBytes s res = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in [@ inline_let] let spec h0 = S.storeState_inner (as_seq h0 s) in let h0 = ST.get () in loop1 h0 25ul block spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 block) (v j); storeState_inner s j block ); copy res (sub block 0ul rateInBytes); pop_frame() #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract val absorb_next: s:state -> rateInBytes:size_t{v rateInBytes > 0 /\ v rateInBytes <= 200} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_next (as_seq h0 s) (v rateInBytes)) let absorb_next s rateInBytes = push_frame(); let h0 = ST.get() in let nextBlock_ = create 200ul (u8 0) in let nextBlock = sub nextBlock_ 0ul rateInBytes in let h1 = ST.get () in assert (as_seq h1 nextBlock `Seq.equal` Lib.Sequence.create (v rateInBytes) (u8 0)); nextBlock.(rateInBytes -! 1ul) <- u8 0x80; loadState rateInBytes nextBlock s; state_permute s; pop_frame() inline_for_extraction noextract val absorb_last: delimitedSuffix:byte_t -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> rem:size_t{v rem < v rateInBytes} -> input:lbuffer uint8 rem -> s:state -> Stack unit (requires fun h -> live h s /\ live h input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_last delimitedSuffix (v rateInBytes) (v rem) (as_seq h0 input) (as_seq h0 s)) let absorb_last delimitedSuffix rateInBytes rem input s = push_frame(); let h0 = ST.get() in let lastBlock_ = create 200ul (u8 0) in let lastBlock = sub lastBlock_ 0ul rateInBytes in let h1 = ST.get () in assert (as_seq h1 lastBlock `Seq.equal` Lib.Sequence.create (v rateInBytes) (u8 0)); let open Lib.RawIntTypes in update_sub lastBlock (size 0) rem input; lastBlock.(rem) <- byte_to_uint8 delimitedSuffix; loadState rateInBytes lastBlock s; if not ((delimitedSuffix &. byte 0x80) =. byte 0) && (size_to_UInt32 rem = size_to_UInt32 (rateInBytes -. 1ul)) then state_permute s; absorb_next s rateInBytes; pop_frame() val absorb_inner: rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> block:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_inner (v rateInBytes) (as_seq h0 block) (as_seq h0 s)) let absorb_inner rateInBytes block s = loadState rateInBytes block s; state_permute s #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" private val absorb: s:state -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> inputByteLen:size_t -> input:lbuffer uint8 inputByteLen -> delimitedSuffix:byte_t -> Stack unit (requires fun h0 -> live h0 s /\ live h0 input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb (as_seq h0 s) (v rateInBytes) (v inputByteLen) (as_seq h0 input) delimitedSuffix) let absorb s rateInBytes inputByteLen input delimitedSuffix = let n_blocks = inputByteLen /. rateInBytes in let rem = inputByteLen %. rateInBytes in loop_blocks rateInBytes n_blocks rem input (S.absorb_inner (v rateInBytes)) (S.absorb_last delimitedSuffix (v rateInBytes)) (absorb_inner rateInBytes) (absorb_last delimitedSuffix rateInBytes) s inline_for_extraction noextract val squeeze_inner: rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> outputByteLen:size_t -> s:state -> output:lbuffer uint8 rateInBytes -> i:size_t{v i < v (outputByteLen /. rateInBytes)} -> Stack unit (requires fun h0 -> live h0 s /\ live h0 output /\ disjoint s output) (ensures fun h0 _ h1 -> modifies2 s output h0 h1 /\ (as_seq h1 s, as_seq h1 output) ==
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
rateInBytes: Lib.IntTypes.size_t{0 < Lib.IntTypes.v rateInBytes /\ Lib.IntTypes.v rateInBytes <= 200} -> outputByteLen: Lib.IntTypes.size_t -> s: Hacl.Impl.SHA3.state -> output: Lib.Buffer.lbuffer Lib.IntTypes.uint8 rateInBytes -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i < Lib.IntTypes.v (outputByteLen /. rateInBytes)} -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "Hacl.Impl.SHA3.state", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Lib.IntTypes.op_Slash_Dot", "Hacl.Impl.SHA3.state_permute", "Prims.unit", "Hacl.Impl.SHA3.storeState" ]
[]
false
true
false
false
false
let squeeze_inner rateInBytes outputByteLen s output i =
storeState rateInBytes s output; state_permute s
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.state_chi
val state_chi: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_chi (as_seq h0 s))
val state_chi: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_chi (as_seq h0 s))
let state_chi st = let h0 = ST.get() in [@ inline_let] let spec h0 = Equiv.state_chi_inner in let h0 = ST.get () in loop1 h0 5ul st spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 st) (v y); state_chi_inner st y ); let h1 = ST.get() in assert(as_seq h1 st == Equiv.state_chi (as_seq h0 st)); Equiv.state_chi_equivalence (as_seq h0 st)
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 264, "start_col": 0, "start_line": 252 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s')) let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp inline_for_extraction noextract val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s)) let state_pi_rho s = push_frame(); let x = get s 1ul 0ul in let h0 = ST.get() in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@ inline_let] let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@ inline_let] let footprint i = loc_union (loc current) (loc s) in [@ inline_let] let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s ); pop_frame() inline_for_extraction noextract val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) let state_chi_inner st y = let h0 = ST.get() in let v0 = get st 0ul y ^. ((lognot (get st 1ul y)) &. get st 2ul y) in let v1 = get st 1ul y ^. ((lognot (get st 2ul y)) &. get st 3ul y) in let v2 = get st 2ul y ^. ((lognot (get st 3ul y)) &. get st 4ul y) in let v3 = get st 3ul y ^. ((lognot (get st 4ul y)) &. get st 0ul y) in let v4 = get st 4ul y ^. ((lognot (get st 0ul y)) &. get st 1ul y) in set st 0ul y v0; set st 1ul y v1; set st 2ul y v2; set st 3ul y v3; set st 4ul y v4; let h1 = ST.get() in assert (modifies (loc st) h0 h1); assert (as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) inline_for_extraction noextract val state_chi: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Hacl.Impl.SHA3.state -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.SHA3.state", "Spec.SHA3.Equivalence.state_chi_equivalence", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Prims.unit", "Prims._assert", "Prims.eq2", "Lib.Sequence.lseq", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Spec.SHA3.Equivalence.state_chi", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.loop1", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Hacl.Impl.SHA3.state_chi_inner", "Lib.LoopCombinators.unfold_repeati", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.nat", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Spec.SHA3.Equivalence.state_chi_inner" ]
[]
false
true
false
false
false
let state_chi st =
let h0 = ST.get () in [@@ inline_let ]let spec h0 = Equiv.state_chi_inner in let h0 = ST.get () in loop1 h0 5ul st spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 st) (v y); state_chi_inner st y); let h1 = ST.get () in assert (as_seq h1 st == Equiv.state_chi (as_seq h0 st)); Equiv.state_chi_equivalence (as_seq h0 st)
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.absorb
val absorb: s:state -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> inputByteLen:size_t -> input:lbuffer uint8 inputByteLen -> delimitedSuffix:byte_t -> Stack unit (requires fun h0 -> live h0 s /\ live h0 input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb (as_seq h0 s) (v rateInBytes) (v inputByteLen) (as_seq h0 input) delimitedSuffix)
val absorb: s:state -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> inputByteLen:size_t -> input:lbuffer uint8 inputByteLen -> delimitedSuffix:byte_t -> Stack unit (requires fun h0 -> live h0 s /\ live h0 input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb (as_seq h0 s) (v rateInBytes) (v inputByteLen) (as_seq h0 input) delimitedSuffix)
let absorb s rateInBytes inputByteLen input delimitedSuffix = let n_blocks = inputByteLen /. rateInBytes in let rem = inputByteLen %. rateInBytes in loop_blocks rateInBytes n_blocks rem input (S.absorb_inner (v rateInBytes)) (S.absorb_last delimitedSuffix (v rateInBytes)) (absorb_inner rateInBytes) (absorb_last delimitedSuffix rateInBytes) s
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 457, "start_col": 0, "start_line": 450 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s')) let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp inline_for_extraction noextract val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s)) let state_pi_rho s = push_frame(); let x = get s 1ul 0ul in let h0 = ST.get() in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@ inline_let] let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@ inline_let] let footprint i = loc_union (loc current) (loc s) in [@ inline_let] let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s ); pop_frame() inline_for_extraction noextract val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) let state_chi_inner st y = let h0 = ST.get() in let v0 = get st 0ul y ^. ((lognot (get st 1ul y)) &. get st 2ul y) in let v1 = get st 1ul y ^. ((lognot (get st 2ul y)) &. get st 3ul y) in let v2 = get st 2ul y ^. ((lognot (get st 3ul y)) &. get st 4ul y) in let v3 = get st 3ul y ^. ((lognot (get st 4ul y)) &. get st 0ul y) in let v4 = get st 4ul y ^. ((lognot (get st 0ul y)) &. get st 1ul y) in set st 0ul y v0; set st 1ul y v1; set st 2ul y v2; set st 3ul y v3; set st 4ul y v4; let h1 = ST.get() in assert (modifies (loc st) h0 h1); assert (as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) inline_for_extraction noextract val state_chi: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_chi (as_seq h0 s)) let state_chi st = let h0 = ST.get() in [@ inline_let] let spec h0 = Equiv.state_chi_inner in let h0 = ST.get () in loop1 h0 5ul st spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 st) (v y); state_chi_inner st y ); let h1 = ST.get() in assert(as_seq h1 st == Equiv.state_chi (as_seq h0 st)); Equiv.state_chi_equivalence (as_seq h0 st) inline_for_extraction noextract val state_iota: s:state -> round:size_t{v round < 24} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_iota (as_seq h0 s) (v round)) let state_iota s round = recall_contents keccak_rndc Spec.SHA3.Constants.keccak_rndc; let c = keccak_rndc.(round) in set s 0ul 0ul (get s 0ul 0ul ^. secret c) private val state_permute: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_permute (as_seq h0 s)) let state_permute s = [@ inline_let] let spec h0 = S.state_permute1 in let h0 = ST.get () in loop1 h0 24ul s spec (fun round -> Loop.unfold_repeati 24 (spec h0) (as_seq h0 s) (v round); state_theta s; state_pi_rho s; state_chi s; state_iota s round) private val loadState: rateInBytes:size_t{v rateInBytes <= 200} -> input:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h -> live h input /\ live h s /\ disjoint input s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.loadState (v rateInBytes) (as_seq h0 input) (as_seq h0 s)) let loadState rateInBytes input s = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in update_sub block 0ul rateInBytes input; [@ inline_let] let spec h0 = S.loadState_inner (as_seq h0 block) in let h0 = ST.get () in loop1 h0 25ul s spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 s) (v j); let h0 = ST.get() in let x = uint_from_bytes_le #U64 (sub block (j *! 8ul) 8ul) in s.(j) <- s.(j) ^. x ); pop_frame() inline_for_extraction noextract val storeState_inner: s:state -> j:size_t{v j < 25} -> block:lbuffer uint8 200ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc block) h0 h1 /\ as_seq h1 block == S.storeState_inner (as_seq h0 s) (v j) (as_seq h0 block)) let storeState_inner s j block = let sj = s.(j) in let h0 = ST.get () in update_sub_f h0 block (j *! 8ul) 8ul (fun h -> Lib.ByteSequence.uint_to_bytes_le sj) (fun _ -> uint_to_bytes_le #U64 (sub block (j *! 8ul) 8ul) sj) private val storeState: rateInBytes:size_t{v rateInBytes <= 200} -> s:state -> res:lbuffer uint8 rateInBytes -> Stack unit (requires fun h0 -> live h0 s /\ live h0 res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.storeState (v rateInBytes) (as_seq h0 s)) let storeState rateInBytes s res = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in [@ inline_let] let spec h0 = S.storeState_inner (as_seq h0 s) in let h0 = ST.get () in loop1 h0 25ul block spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 block) (v j); storeState_inner s j block ); copy res (sub block 0ul rateInBytes); pop_frame() #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract val absorb_next: s:state -> rateInBytes:size_t{v rateInBytes > 0 /\ v rateInBytes <= 200} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_next (as_seq h0 s) (v rateInBytes)) let absorb_next s rateInBytes = push_frame(); let h0 = ST.get() in let nextBlock_ = create 200ul (u8 0) in let nextBlock = sub nextBlock_ 0ul rateInBytes in let h1 = ST.get () in assert (as_seq h1 nextBlock `Seq.equal` Lib.Sequence.create (v rateInBytes) (u8 0)); nextBlock.(rateInBytes -! 1ul) <- u8 0x80; loadState rateInBytes nextBlock s; state_permute s; pop_frame() inline_for_extraction noextract val absorb_last: delimitedSuffix:byte_t -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> rem:size_t{v rem < v rateInBytes} -> input:lbuffer uint8 rem -> s:state -> Stack unit (requires fun h -> live h s /\ live h input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_last delimitedSuffix (v rateInBytes) (v rem) (as_seq h0 input) (as_seq h0 s)) let absorb_last delimitedSuffix rateInBytes rem input s = push_frame(); let h0 = ST.get() in let lastBlock_ = create 200ul (u8 0) in let lastBlock = sub lastBlock_ 0ul rateInBytes in let h1 = ST.get () in assert (as_seq h1 lastBlock `Seq.equal` Lib.Sequence.create (v rateInBytes) (u8 0)); let open Lib.RawIntTypes in update_sub lastBlock (size 0) rem input; lastBlock.(rem) <- byte_to_uint8 delimitedSuffix; loadState rateInBytes lastBlock s; if not ((delimitedSuffix &. byte 0x80) =. byte 0) && (size_to_UInt32 rem = size_to_UInt32 (rateInBytes -. 1ul)) then state_permute s; absorb_next s rateInBytes; pop_frame() val absorb_inner: rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> block:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_inner (v rateInBytes) (as_seq h0 block) (as_seq h0 s)) let absorb_inner rateInBytes block s = loadState rateInBytes block s; state_permute s #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" private val absorb: s:state -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> inputByteLen:size_t -> input:lbuffer uint8 inputByteLen -> delimitedSuffix:byte_t -> Stack unit (requires fun h0 -> live h0 s /\ live h0 input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb (as_seq h0 s) (v rateInBytes) (v inputByteLen)
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Hacl.Impl.SHA3.state -> rateInBytes: Lib.IntTypes.size_t{0 < Lib.IntTypes.v rateInBytes /\ Lib.IntTypes.v rateInBytes <= 200} -> inputByteLen: Lib.IntTypes.size_t -> input: Lib.Buffer.lbuffer Lib.IntTypes.uint8 inputByteLen -> delimitedSuffix: Lib.IntTypes.byte_t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.SHA3.state", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Lib.IntTypes.byte_t", "Lib.Buffer.loop_blocks", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Spec.SHA3.absorb_inner", "Spec.SHA3.absorb_last", "Hacl.Impl.SHA3.absorb_inner", "Hacl.Impl.SHA3.absorb_last", "Prims.unit", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Percent_Dot", "Lib.IntTypes.op_Slash_Dot" ]
[]
false
true
false
false
false
let absorb s rateInBytes inputByteLen input delimitedSuffix =
let n_blocks = inputByteLen /. rateInBytes in let rem = inputByteLen %. rateInBytes in loop_blocks rateInBytes n_blocks rem input (S.absorb_inner (v rateInBytes)) (S.absorb_last delimitedSuffix (v rateInBytes)) (absorb_inner rateInBytes) (absorb_last delimitedSuffix rateInBytes) s
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.state_theta_inner_s
val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s))
val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s))
let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) )
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 114, "start_col": 0, "start_line": 105 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_C: Lib.Buffer.lbuffer Lib.IntTypes.uint64 5ul -> x: Hacl.Impl.SHA3.index -> s: Hacl.Impl.SHA3.state -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Hacl.Impl.SHA3.index", "Hacl.Impl.SHA3.state", "Lib.Buffer.loop1", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.SHA3.set", "Prims.unit", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Hat_Dot", "Hacl.Impl.SHA3.get", "Lib.LoopCombinators.unfold_repeati", "Lib.Sequence.lseq", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Prims.nat", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Spec.SHA3.state_theta_inner_s_inner", "Hacl.Impl.SHA3.rotl", "Lib.Buffer.op_Array_Access", "Lib.IntTypes.op_Percent_Dot", "Lib.IntTypes.op_Plus_Dot" ]
[]
false
true
false
false
false
let state_theta_inner_s _C x s =
let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@@ inline_let ]let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D))
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.storeState
val storeState: rateInBytes:size_t{v rateInBytes <= 200} -> s:state -> res:lbuffer uint8 rateInBytes -> Stack unit (requires fun h0 -> live h0 s /\ live h0 res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.storeState (v rateInBytes) (as_seq h0 s))
val storeState: rateInBytes:size_t{v rateInBytes <= 200} -> s:state -> res:lbuffer uint8 rateInBytes -> Stack unit (requires fun h0 -> live h0 s /\ live h0 res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.storeState (v rateInBytes) (as_seq h0 s))
let storeState rateInBytes s res = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in [@ inline_let] let spec h0 = S.storeState_inner (as_seq h0 s) in let h0 = ST.get () in loop1 h0 25ul block spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 block) (v j); storeState_inner s j block ); copy res (sub block 0ul rateInBytes); pop_frame()
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 364, "start_col": 0, "start_line": 351 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s')) let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp inline_for_extraction noextract val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s)) let state_pi_rho s = push_frame(); let x = get s 1ul 0ul in let h0 = ST.get() in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@ inline_let] let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@ inline_let] let footprint i = loc_union (loc current) (loc s) in [@ inline_let] let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s ); pop_frame() inline_for_extraction noextract val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) let state_chi_inner st y = let h0 = ST.get() in let v0 = get st 0ul y ^. ((lognot (get st 1ul y)) &. get st 2ul y) in let v1 = get st 1ul y ^. ((lognot (get st 2ul y)) &. get st 3ul y) in let v2 = get st 2ul y ^. ((lognot (get st 3ul y)) &. get st 4ul y) in let v3 = get st 3ul y ^. ((lognot (get st 4ul y)) &. get st 0ul y) in let v4 = get st 4ul y ^. ((lognot (get st 0ul y)) &. get st 1ul y) in set st 0ul y v0; set st 1ul y v1; set st 2ul y v2; set st 3ul y v3; set st 4ul y v4; let h1 = ST.get() in assert (modifies (loc st) h0 h1); assert (as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) inline_for_extraction noextract val state_chi: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_chi (as_seq h0 s)) let state_chi st = let h0 = ST.get() in [@ inline_let] let spec h0 = Equiv.state_chi_inner in let h0 = ST.get () in loop1 h0 5ul st spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 st) (v y); state_chi_inner st y ); let h1 = ST.get() in assert(as_seq h1 st == Equiv.state_chi (as_seq h0 st)); Equiv.state_chi_equivalence (as_seq h0 st) inline_for_extraction noextract val state_iota: s:state -> round:size_t{v round < 24} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_iota (as_seq h0 s) (v round)) let state_iota s round = recall_contents keccak_rndc Spec.SHA3.Constants.keccak_rndc; let c = keccak_rndc.(round) in set s 0ul 0ul (get s 0ul 0ul ^. secret c) private val state_permute: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_permute (as_seq h0 s)) let state_permute s = [@ inline_let] let spec h0 = S.state_permute1 in let h0 = ST.get () in loop1 h0 24ul s spec (fun round -> Loop.unfold_repeati 24 (spec h0) (as_seq h0 s) (v round); state_theta s; state_pi_rho s; state_chi s; state_iota s round) private val loadState: rateInBytes:size_t{v rateInBytes <= 200} -> input:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h -> live h input /\ live h s /\ disjoint input s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.loadState (v rateInBytes) (as_seq h0 input) (as_seq h0 s)) let loadState rateInBytes input s = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in update_sub block 0ul rateInBytes input; [@ inline_let] let spec h0 = S.loadState_inner (as_seq h0 block) in let h0 = ST.get () in loop1 h0 25ul s spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 s) (v j); let h0 = ST.get() in let x = uint_from_bytes_le #U64 (sub block (j *! 8ul) 8ul) in s.(j) <- s.(j) ^. x ); pop_frame() inline_for_extraction noextract val storeState_inner: s:state -> j:size_t{v j < 25} -> block:lbuffer uint8 200ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc block) h0 h1 /\ as_seq h1 block == S.storeState_inner (as_seq h0 s) (v j) (as_seq h0 block)) let storeState_inner s j block = let sj = s.(j) in let h0 = ST.get () in update_sub_f h0 block (j *! 8ul) 8ul (fun h -> Lib.ByteSequence.uint_to_bytes_le sj) (fun _ -> uint_to_bytes_le #U64 (sub block (j *! 8ul) 8ul) sj) private val storeState: rateInBytes:size_t{v rateInBytes <= 200} -> s:state -> res:lbuffer uint8 rateInBytes -> Stack unit (requires fun h0 -> live h0 s /\ live h0 res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
rateInBytes: Lib.IntTypes.size_t{Lib.IntTypes.v rateInBytes <= 200} -> s: Hacl.Impl.SHA3.state -> res: Lib.Buffer.lbuffer Lib.IntTypes.uint8 rateInBytes -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.SHA3.state", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Lib.Buffer.copy", "Lib.Buffer.MUT", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.sub", "FStar.UInt32.__uint_to_t", "Lib.Buffer.loop1", "Prims.op_LessThan", "Hacl.Impl.SHA3.storeState_inner", "Lib.LoopCombinators.unfold_repeati", "Lib.Sequence.lseq", "Lib.Buffer.as_seq", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Prims.nat", "Prims.op_Subtraction", "Prims.pow2", "Spec.SHA3.storeState_inner", "Lib.IntTypes.uint64", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.u8", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let storeState rateInBytes s res =
push_frame (); let h0 = ST.get () in let block = create 200ul (u8 0) in [@@ inline_let ]let spec h0 = S.storeState_inner (as_seq h0 s) in let h0 = ST.get () in loop1 h0 25ul block spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 block) (v j); storeState_inner s j block); copy res (sub block 0ul rateInBytes); pop_frame ()
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.state_pi_rho_inner
val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s'))
val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s'))
let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 23, "end_line": 187, "start_col": 0, "start_line": 177 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Lib.IntTypes.size_t{Lib.IntTypes.v i < 24} -> current: Lib.Buffer.lbuffer Lib.IntTypes.uint64 1ul -> s: Hacl.Impl.SHA3.state -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Hacl.Impl.SHA3.state", "Lib.Buffer.op_Array_Assignment", "Prims.unit", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Impl.SHA3.rotl", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Spec.SHA3.Constants.rotc_t", "Lib.Buffer.CONST", "FStar.UInt32.uint_to_t", "Hacl.Impl.SHA3.keccak_rotc", "Spec.SHA3.Constants.piln_t", "Hacl.Impl.SHA3.keccak_piln", "Hacl.Impl.SHA3.index_map", "Lib.IntTypes.range_t", "Spec.SHA3.Constants.piln_list", "Lib.Buffer.recall_contents", "Spec.SHA3.Constants.keccak_piln", "Spec.SHA3.Constants.keccak_rotc", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "FStar.List.Tot.Base.length" ]
[]
false
true
false
false
false
let state_pi_rho_inner i current s =
assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.keccak
val keccak: rate:size_t{v rate % 8 == 0 /\ v rate / 8 > 0 /\ v rate <= 1600} -> capacity:size_t{v capacity + v rate == 1600} -> inputByteLen:size_t -> input:lbuffer uint8 inputByteLen -> delimitedSuffix:byte_t -> outputByteLen:size_t -> output:lbuffer uint8 outputByteLen -> Stack unit (requires fun h -> live h input /\ live h output /\ disjoint input output) (ensures fun h0 _ h1 -> modifies1 output h0 h1 /\ as_seq h1 output == S.keccak (v rate) (v capacity) (v inputByteLen) (as_seq h0 input) delimitedSuffix (v outputByteLen))
val keccak: rate:size_t{v rate % 8 == 0 /\ v rate / 8 > 0 /\ v rate <= 1600} -> capacity:size_t{v capacity + v rate == 1600} -> inputByteLen:size_t -> input:lbuffer uint8 inputByteLen -> delimitedSuffix:byte_t -> outputByteLen:size_t -> output:lbuffer uint8 outputByteLen -> Stack unit (requires fun h -> live h input /\ live h output /\ disjoint input output) (ensures fun h0 _ h1 -> modifies1 output h0 h1 /\ as_seq h1 output == S.keccak (v rate) (v capacity) (v inputByteLen) (as_seq h0 input) delimitedSuffix (v outputByteLen))
let keccak rate capacity inputByteLen input delimitedSuffix outputByteLen output = push_frame(); let rateInBytes = rate /. size 8 in let s:state = create 25ul (u64 0) in absorb s rateInBytes inputByteLen input delimitedSuffix; squeeze s rateInBytes outputByteLen output; pop_frame()
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 532, "start_col": 0, "start_line": 526 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s')) let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp inline_for_extraction noextract val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s)) let state_pi_rho s = push_frame(); let x = get s 1ul 0ul in let h0 = ST.get() in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@ inline_let] let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@ inline_let] let footprint i = loc_union (loc current) (loc s) in [@ inline_let] let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s ); pop_frame() inline_for_extraction noextract val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) let state_chi_inner st y = let h0 = ST.get() in let v0 = get st 0ul y ^. ((lognot (get st 1ul y)) &. get st 2ul y) in let v1 = get st 1ul y ^. ((lognot (get st 2ul y)) &. get st 3ul y) in let v2 = get st 2ul y ^. ((lognot (get st 3ul y)) &. get st 4ul y) in let v3 = get st 3ul y ^. ((lognot (get st 4ul y)) &. get st 0ul y) in let v4 = get st 4ul y ^. ((lognot (get st 0ul y)) &. get st 1ul y) in set st 0ul y v0; set st 1ul y v1; set st 2ul y v2; set st 3ul y v3; set st 4ul y v4; let h1 = ST.get() in assert (modifies (loc st) h0 h1); assert (as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) inline_for_extraction noextract val state_chi: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_chi (as_seq h0 s)) let state_chi st = let h0 = ST.get() in [@ inline_let] let spec h0 = Equiv.state_chi_inner in let h0 = ST.get () in loop1 h0 5ul st spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 st) (v y); state_chi_inner st y ); let h1 = ST.get() in assert(as_seq h1 st == Equiv.state_chi (as_seq h0 st)); Equiv.state_chi_equivalence (as_seq h0 st) inline_for_extraction noextract val state_iota: s:state -> round:size_t{v round < 24} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_iota (as_seq h0 s) (v round)) let state_iota s round = recall_contents keccak_rndc Spec.SHA3.Constants.keccak_rndc; let c = keccak_rndc.(round) in set s 0ul 0ul (get s 0ul 0ul ^. secret c) private val state_permute: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_permute (as_seq h0 s)) let state_permute s = [@ inline_let] let spec h0 = S.state_permute1 in let h0 = ST.get () in loop1 h0 24ul s spec (fun round -> Loop.unfold_repeati 24 (spec h0) (as_seq h0 s) (v round); state_theta s; state_pi_rho s; state_chi s; state_iota s round) private val loadState: rateInBytes:size_t{v rateInBytes <= 200} -> input:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h -> live h input /\ live h s /\ disjoint input s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.loadState (v rateInBytes) (as_seq h0 input) (as_seq h0 s)) let loadState rateInBytes input s = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in update_sub block 0ul rateInBytes input; [@ inline_let] let spec h0 = S.loadState_inner (as_seq h0 block) in let h0 = ST.get () in loop1 h0 25ul s spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 s) (v j); let h0 = ST.get() in let x = uint_from_bytes_le #U64 (sub block (j *! 8ul) 8ul) in s.(j) <- s.(j) ^. x ); pop_frame() inline_for_extraction noextract val storeState_inner: s:state -> j:size_t{v j < 25} -> block:lbuffer uint8 200ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc block) h0 h1 /\ as_seq h1 block == S.storeState_inner (as_seq h0 s) (v j) (as_seq h0 block)) let storeState_inner s j block = let sj = s.(j) in let h0 = ST.get () in update_sub_f h0 block (j *! 8ul) 8ul (fun h -> Lib.ByteSequence.uint_to_bytes_le sj) (fun _ -> uint_to_bytes_le #U64 (sub block (j *! 8ul) 8ul) sj) private val storeState: rateInBytes:size_t{v rateInBytes <= 200} -> s:state -> res:lbuffer uint8 rateInBytes -> Stack unit (requires fun h0 -> live h0 s /\ live h0 res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.storeState (v rateInBytes) (as_seq h0 s)) let storeState rateInBytes s res = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in [@ inline_let] let spec h0 = S.storeState_inner (as_seq h0 s) in let h0 = ST.get () in loop1 h0 25ul block spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 block) (v j); storeState_inner s j block ); copy res (sub block 0ul rateInBytes); pop_frame() #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract val absorb_next: s:state -> rateInBytes:size_t{v rateInBytes > 0 /\ v rateInBytes <= 200} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_next (as_seq h0 s) (v rateInBytes)) let absorb_next s rateInBytes = push_frame(); let h0 = ST.get() in let nextBlock_ = create 200ul (u8 0) in let nextBlock = sub nextBlock_ 0ul rateInBytes in let h1 = ST.get () in assert (as_seq h1 nextBlock `Seq.equal` Lib.Sequence.create (v rateInBytes) (u8 0)); nextBlock.(rateInBytes -! 1ul) <- u8 0x80; loadState rateInBytes nextBlock s; state_permute s; pop_frame() inline_for_extraction noextract val absorb_last: delimitedSuffix:byte_t -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> rem:size_t{v rem < v rateInBytes} -> input:lbuffer uint8 rem -> s:state -> Stack unit (requires fun h -> live h s /\ live h input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_last delimitedSuffix (v rateInBytes) (v rem) (as_seq h0 input) (as_seq h0 s)) let absorb_last delimitedSuffix rateInBytes rem input s = push_frame(); let h0 = ST.get() in let lastBlock_ = create 200ul (u8 0) in let lastBlock = sub lastBlock_ 0ul rateInBytes in let h1 = ST.get () in assert (as_seq h1 lastBlock `Seq.equal` Lib.Sequence.create (v rateInBytes) (u8 0)); let open Lib.RawIntTypes in update_sub lastBlock (size 0) rem input; lastBlock.(rem) <- byte_to_uint8 delimitedSuffix; loadState rateInBytes lastBlock s; if not ((delimitedSuffix &. byte 0x80) =. byte 0) && (size_to_UInt32 rem = size_to_UInt32 (rateInBytes -. 1ul)) then state_permute s; absorb_next s rateInBytes; pop_frame() val absorb_inner: rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> block:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_inner (v rateInBytes) (as_seq h0 block) (as_seq h0 s)) let absorb_inner rateInBytes block s = loadState rateInBytes block s; state_permute s #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" private val absorb: s:state -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> inputByteLen:size_t -> input:lbuffer uint8 inputByteLen -> delimitedSuffix:byte_t -> Stack unit (requires fun h0 -> live h0 s /\ live h0 input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb (as_seq h0 s) (v rateInBytes) (v inputByteLen) (as_seq h0 input) delimitedSuffix) let absorb s rateInBytes inputByteLen input delimitedSuffix = let n_blocks = inputByteLen /. rateInBytes in let rem = inputByteLen %. rateInBytes in loop_blocks rateInBytes n_blocks rem input (S.absorb_inner (v rateInBytes)) (S.absorb_last delimitedSuffix (v rateInBytes)) (absorb_inner rateInBytes) (absorb_last delimitedSuffix rateInBytes) s inline_for_extraction noextract val squeeze_inner: rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> outputByteLen:size_t -> s:state -> output:lbuffer uint8 rateInBytes -> i:size_t{v i < v (outputByteLen /. rateInBytes)} -> Stack unit (requires fun h0 -> live h0 s /\ live h0 output /\ disjoint s output) (ensures fun h0 _ h1 -> modifies2 s output h0 h1 /\ (as_seq h1 s, as_seq h1 output) == S.squeeze_inner (v rateInBytes) (v outputByteLen) (v i) (as_seq h0 s)) let squeeze_inner rateInBytes outputByteLen s output i = storeState rateInBytes s output; state_permute s private let mult_plus_lt (i a b:nat) : Lemma (requires i < a) (ensures i * b + b <= a * b) = assert (i <= a - 1) val squeeze: s:state -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> outputByteLen:size_t -> output:lbuffer uint8 outputByteLen -> Stack unit (requires fun h0 -> live h0 s /\ live h0 output /\ disjoint s output) (ensures fun h0 _ h1 -> modifies2 s output h0 h1 /\ as_seq h1 output == S.squeeze (as_seq h0 s) (v rateInBytes) (v outputByteLen)) let squeeze s rateInBytes outputByteLen output = let outBlocks = outputByteLen /. rateInBytes in let remOut = outputByteLen %. rateInBytes in assert_spinoff (v outputByteLen - v remOut == v outBlocks * v rateInBytes); let last = sub output (outputByteLen -. remOut) remOut in [@ inline_let] let a_spec (i:nat{i <= v outputByteLen / v rateInBytes}) = S.state in let blocks = sub output (size 0) (outBlocks *! rateInBytes) in let h0 = ST.get() in fill_blocks h0 rateInBytes outBlocks blocks a_spec (fun h i -> as_seq h s) (fun _ -> loc s) (fun h0 -> S.squeeze_inner (v rateInBytes) (v outputByteLen)) (fun i -> mult_plus_lt (v i) (v outBlocks) (v rateInBytes); squeeze_inner rateInBytes outputByteLen s (sub blocks (i *! rateInBytes) rateInBytes) i); storeState remOut s last; let h1 = ST.get() in Seq.lemma_split (as_seq h1 output) (v outBlocks * v rateInBytes); norm_spec [delta_only [`%S.squeeze]] (S.squeeze (as_seq h0 s) (v rateInBytes) (v outputByteLen)) val keccak: rate:size_t{v rate % 8 == 0 /\ v rate / 8 > 0 /\ v rate <= 1600} -> capacity:size_t{v capacity + v rate == 1600} -> inputByteLen:size_t -> input:lbuffer uint8 inputByteLen -> delimitedSuffix:byte_t -> outputByteLen:size_t -> output:lbuffer uint8 outputByteLen -> Stack unit (requires fun h -> live h input /\ live h output /\ disjoint input output) (ensures fun h0 _ h1 -> modifies1 output h0 h1 /\ as_seq h1 output ==
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
rate: Lib.IntTypes.size_t {Lib.IntTypes.v rate % 8 == 0 /\ Lib.IntTypes.v rate / 8 > 0 /\ Lib.IntTypes.v rate <= 1600} -> capacity: Lib.IntTypes.size_t{Lib.IntTypes.v capacity + Lib.IntTypes.v rate == 1600} -> inputByteLen: Lib.IntTypes.size_t -> input: Lib.Buffer.lbuffer Lib.IntTypes.uint8 inputByteLen -> delimitedSuffix: Lib.IntTypes.byte_t -> outputByteLen: Lib.IntTypes.size_t -> output: Lib.Buffer.lbuffer Lib.IntTypes.uint8 outputByteLen -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.IntTypes.size_t", "Prims.l_and", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_Division", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Lib.IntTypes.byte_t", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.SHA3.squeeze", "Hacl.Impl.SHA3.absorb", "Hacl.Impl.SHA3.state", "Lib.Buffer.create", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u64", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Slash_Dot", "Lib.IntTypes.size", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let keccak rate capacity inputByteLen input delimitedSuffix outputByteLen output =
push_frame (); let rateInBytes = rate /. size 8 in let s:state = create 25ul (u64 0) in absorb s rateInBytes inputByteLen input delimitedSuffix; squeeze s rateInBytes outputByteLen output; pop_frame ()
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.loadState
val loadState: rateInBytes:size_t{v rateInBytes <= 200} -> input:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h -> live h input /\ live h s /\ disjoint input s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.loadState (v rateInBytes) (as_seq h0 input) (as_seq h0 s))
val loadState: rateInBytes:size_t{v rateInBytes <= 200} -> input:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h -> live h input /\ live h s /\ disjoint input s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.loadState (v rateInBytes) (as_seq h0 input) (as_seq h0 s))
let loadState rateInBytes input s = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in update_sub block 0ul rateInBytes input; [@ inline_let] let spec h0 = S.loadState_inner (as_seq h0 block) in let h0 = ST.get () in loop1 h0 25ul s spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 s) (v j); let h0 = ST.get() in let x = uint_from_bytes_le #U64 (sub block (j *! 8ul) 8ul) in s.(j) <- s.(j) ^. x ); pop_frame()
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 323, "start_col": 0, "start_line": 308 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s')) let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp inline_for_extraction noextract val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s)) let state_pi_rho s = push_frame(); let x = get s 1ul 0ul in let h0 = ST.get() in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@ inline_let] let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@ inline_let] let footprint i = loc_union (loc current) (loc s) in [@ inline_let] let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s ); pop_frame() inline_for_extraction noextract val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) let state_chi_inner st y = let h0 = ST.get() in let v0 = get st 0ul y ^. ((lognot (get st 1ul y)) &. get st 2ul y) in let v1 = get st 1ul y ^. ((lognot (get st 2ul y)) &. get st 3ul y) in let v2 = get st 2ul y ^. ((lognot (get st 3ul y)) &. get st 4ul y) in let v3 = get st 3ul y ^. ((lognot (get st 4ul y)) &. get st 0ul y) in let v4 = get st 4ul y ^. ((lognot (get st 0ul y)) &. get st 1ul y) in set st 0ul y v0; set st 1ul y v1; set st 2ul y v2; set st 3ul y v3; set st 4ul y v4; let h1 = ST.get() in assert (modifies (loc st) h0 h1); assert (as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) inline_for_extraction noextract val state_chi: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_chi (as_seq h0 s)) let state_chi st = let h0 = ST.get() in [@ inline_let] let spec h0 = Equiv.state_chi_inner in let h0 = ST.get () in loop1 h0 5ul st spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 st) (v y); state_chi_inner st y ); let h1 = ST.get() in assert(as_seq h1 st == Equiv.state_chi (as_seq h0 st)); Equiv.state_chi_equivalence (as_seq h0 st) inline_for_extraction noextract val state_iota: s:state -> round:size_t{v round < 24} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_iota (as_seq h0 s) (v round)) let state_iota s round = recall_contents keccak_rndc Spec.SHA3.Constants.keccak_rndc; let c = keccak_rndc.(round) in set s 0ul 0ul (get s 0ul 0ul ^. secret c) private val state_permute: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_permute (as_seq h0 s)) let state_permute s = [@ inline_let] let spec h0 = S.state_permute1 in let h0 = ST.get () in loop1 h0 24ul s spec (fun round -> Loop.unfold_repeati 24 (spec h0) (as_seq h0 s) (v round); state_theta s; state_pi_rho s; state_chi s; state_iota s round) private val loadState: rateInBytes:size_t{v rateInBytes <= 200} -> input:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h -> live h input /\ live h s /\ disjoint input s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
rateInBytes: Lib.IntTypes.size_t{Lib.IntTypes.v rateInBytes <= 200} -> input: Lib.Buffer.lbuffer Lib.IntTypes.uint8 rateInBytes -> s: Hacl.Impl.SHA3.state -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.Impl.SHA3.state", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Lib.Buffer.loop1", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Prims.op_LessThan", "Lib.Buffer.op_Array_Assignment", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Hat_Dot", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Lib.ByteBuffer.uint_from_bytes_le", "Lib.IntTypes.uint_t", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.U8", "Lib.IntTypes.mk_int", "Lib.Buffer.sub", "Lib.IntTypes.op_Star_Bang", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.LoopCombinators.unfold_repeati", "Lib.Sequence.lseq", "Lib.Buffer.as_seq", "Prims.nat", "Prims.op_Subtraction", "Prims.pow2", "Spec.SHA3.loadState_inner", "Lib.Buffer.update_sub", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.u8", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let loadState rateInBytes input s =
push_frame (); let h0 = ST.get () in let block = create 200ul (u8 0) in update_sub block 0ul rateInBytes input; [@@ inline_let ]let spec h0 = S.loadState_inner (as_seq h0 block) in let h0 = ST.get () in loop1 h0 25ul s spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 s) (v j); let h0 = ST.get () in let x = uint_from_bytes_le #U64 (sub block (j *! 8ul) 8ul) in s.(j) <- s.(j) ^. x); pop_frame ()
false
Spec.SHA3.Equivalence.fst
Spec.SHA3.Equivalence.state_chi_inner_equivalence0
val state_chi_inner_equivalence0 (st_old: state) (y: index) (st: state) : Lemma (requires (forall y'. (y' >= y /\ y' < 5) ==> get st_old 0 y' == get st 0 y' /\ get st_old 1 y' == get st 1 y' /\ get st_old 2 y' == get st 2 y' /\ get st_old 3 y' == get st 3 y' /\ get st_old 4 y' == get st 4 y')) (ensures (let st_new = state_chi_inner1 st_old y st in st_new == state_chi_inner y st))
val state_chi_inner_equivalence0 (st_old: state) (y: index) (st: state) : Lemma (requires (forall y'. (y' >= y /\ y' < 5) ==> get st_old 0 y' == get st 0 y' /\ get st_old 1 y' == get st 1 y' /\ get st_old 2 y' == get st 2 y' /\ get st_old 3 y' == get st 3 y' /\ get st_old 4 y' == get st 4 y')) (ensures (let st_new = state_chi_inner1 st_old y st in st_new == state_chi_inner y st))
let state_chi_inner_equivalence0 (st_old:state) (y:index) (st:state) : Lemma (requires (forall y'. (y' >= y /\ y' < 5) ==> get st_old 0 y' == get st 0 y' /\ get st_old 1 y' == get st 1 y' /\ get st_old 2 y' == get st 2 y' /\ get st_old 3 y' == get st 3 y' /\ get st_old 4 y' == get st 4 y')) (ensures (let st_new = state_chi_inner1 st_old y st in st_new == state_chi_inner y st)) = Lib.LoopCombinators.eq_repeati0 5 (state_chi_inner0 st_old y) st; Lib.LoopCombinators.unfold_repeati 5 (state_chi_inner0 st_old y) st 0; Lib.LoopCombinators.unfold_repeati 5 (state_chi_inner0 st_old y) st 1; Lib.LoopCombinators.unfold_repeati 5 (state_chi_inner0 st_old y) st 2; Lib.LoopCombinators.unfold_repeati 5 (state_chi_inner0 st_old y) st 3; Lib.LoopCombinators.unfold_repeati 5 (state_chi_inner0 st_old y) st 4; assert (repeati 5 (state_chi_inner0 st_old y) st == state_chi_inner0 st_old y 4 (state_chi_inner0 st_old y 3 (state_chi_inner0 st_old y 2 (state_chi_inner0 st_old y 1 (state_chi_inner0 st_old y 0 st))))); ()
{ "file_name": "specs/lemmas/Spec.SHA3.Equivalence.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 11, "end_line": 48, "start_col": 0, "start_line": 30 }
module Spec.SHA3.Equivalence open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open FStar.Mul open Lib.LoopCombinators open Spec.SHA3.Constants open Spec.SHA3 #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" let state_chi_inner (y:index) (s:state) : Tot state = let v0 = get s 0 y ^. ((lognot (get s 1 y)) &. get s 2 y) in let v1 = get s 1 y ^. ((lognot (get s 2 y)) &. get s 3 y) in let v2 = get s 2 y ^. ((lognot (get s 3 y)) &. get s 4 y) in let v3 = get s 3 y ^. ((lognot (get s 4 y)) &. get s 0 y) in let v4 = get s 4 y ^. ((lognot (get s 0 y)) &. get s 1 y) in let s = set s 0 y v0 in let s = set s 1 y v1 in let s = set s 2 y v2 in let s = set s 3 y v3 in let s = set s 4 y v4 in s let state_chi (s_pi_rho:state) : Tot state = repeati 5 state_chi_inner s_pi_rho
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.SHA3.Equivalence.fst" }
[ { "abbrev": false, "full_module": "Spec.SHA3", "short_module": null }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Spec.SHA3", "short_module": null }, { "abbrev": false, "full_module": "Spec.SHA3", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
st_old: Spec.SHA3.state -> y: Spec.SHA3.index -> st: Spec.SHA3.state -> FStar.Pervasives.Lemma (requires forall (y': i: Prims.int { i >= 0 /\ i <= Lib.IntTypes.max_size_t /\ i < 5 /\ (i >= 0) /\ (i <= Lib.IntTypes.max_size_t) /\ (i < 5) /\ (i >= 0) /\ (i <= Lib.IntTypes.max_size_t) /\ (i < 5) /\ (i >= 0) /\ (i <= Lib.IntTypes.max_size_t) /\ (i < 5) /\ (i >= 0) /\ (i <= Lib.IntTypes.max_size_t) /\ (i < 5) /\ (i >= 0) /\ (i <= Lib.IntTypes.max_size_t) /\ (i < 5) /\ (i >= 0) /\ (i <= Lib.IntTypes.max_size_t) /\ (i < 5) /\ (i >= 0) /\ (i <= Lib.IntTypes.max_size_t) /\ (i < 5) /\ (i >= 0) /\ (i <= Lib.IntTypes.max_size_t) /\ (i < 5) /\ (i >= 0) /\ (i <= Lib.IntTypes.max_size_t) /\ (i < 5) }). y' >= y /\ y' < 5 ==> Spec.SHA3.get st_old 0 y' == Spec.SHA3.get st 0 y' /\ Spec.SHA3.get st_old 1 y' == Spec.SHA3.get st 1 y' /\ Spec.SHA3.get st_old 2 y' == Spec.SHA3.get st 2 y' /\ Spec.SHA3.get st_old 3 y' == Spec.SHA3.get st 3 y' /\ Spec.SHA3.get st_old 4 y' == Spec.SHA3.get st 4 y') (ensures (let st_new = Spec.SHA3.state_chi_inner1 st_old y st in st_new == Spec.SHA3.Equivalence.state_chi_inner y st))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.SHA3.state", "Spec.SHA3.index", "Prims.unit", "Prims._assert", "Prims.eq2", "Lib.LoopCombinators.repeati", "Spec.SHA3.state_chi_inner0", "Lib.LoopCombinators.unfold_repeati", "Lib.LoopCombinators.eq_repeati0", "Prims.l_Forall", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "Prims.op_LessThan", "Prims.l_imp", "Lib.IntTypes.uint64", "Spec.SHA3.get", "Prims.squash", "Spec.SHA3.Equivalence.state_chi_inner", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Spec.SHA3.state_chi_inner1", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let state_chi_inner_equivalence0 (st_old: state) (y: index) (st: state) : Lemma (requires (forall y'. (y' >= y /\ y' < 5) ==> get st_old 0 y' == get st 0 y' /\ get st_old 1 y' == get st 1 y' /\ get st_old 2 y' == get st 2 y' /\ get st_old 3 y' == get st 3 y' /\ get st_old 4 y' == get st 4 y')) (ensures (let st_new = state_chi_inner1 st_old y st in st_new == state_chi_inner y st)) =
Lib.LoopCombinators.eq_repeati0 5 (state_chi_inner0 st_old y) st; Lib.LoopCombinators.unfold_repeati 5 (state_chi_inner0 st_old y) st 0; Lib.LoopCombinators.unfold_repeati 5 (state_chi_inner0 st_old y) st 1; Lib.LoopCombinators.unfold_repeati 5 (state_chi_inner0 st_old y) st 2; Lib.LoopCombinators.unfold_repeati 5 (state_chi_inner0 st_old y) st 3; Lib.LoopCombinators.unfold_repeati 5 (state_chi_inner0 st_old y) st 4; assert (repeati 5 (state_chi_inner0 st_old y) st == state_chi_inner0 st_old y 4 (state_chi_inner0 st_old y 3 (state_chi_inner0 st_old y 2 (state_chi_inner0 st_old y 1 (state_chi_inner0 st_old y 0 st))))); ()
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.absorb_next
val absorb_next: s:state -> rateInBytes:size_t{v rateInBytes > 0 /\ v rateInBytes <= 200} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_next (as_seq h0 s) (v rateInBytes))
val absorb_next: s:state -> rateInBytes:size_t{v rateInBytes > 0 /\ v rateInBytes <= 200} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_next (as_seq h0 s) (v rateInBytes))
let absorb_next s rateInBytes = push_frame(); let h0 = ST.get() in let nextBlock_ = create 200ul (u8 0) in let nextBlock = sub nextBlock_ 0ul rateInBytes in let h1 = ST.get () in assert (as_seq h1 nextBlock `Seq.equal` Lib.Sequence.create (v rateInBytes) (u8 0)); nextBlock.(rateInBytes -! 1ul) <- u8 0x80; loadState rateInBytes nextBlock s; state_permute s; pop_frame()
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 388, "start_col": 0, "start_line": 378 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s')) let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp inline_for_extraction noextract val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s)) let state_pi_rho s = push_frame(); let x = get s 1ul 0ul in let h0 = ST.get() in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@ inline_let] let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@ inline_let] let footprint i = loc_union (loc current) (loc s) in [@ inline_let] let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s ); pop_frame() inline_for_extraction noextract val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) let state_chi_inner st y = let h0 = ST.get() in let v0 = get st 0ul y ^. ((lognot (get st 1ul y)) &. get st 2ul y) in let v1 = get st 1ul y ^. ((lognot (get st 2ul y)) &. get st 3ul y) in let v2 = get st 2ul y ^. ((lognot (get st 3ul y)) &. get st 4ul y) in let v3 = get st 3ul y ^. ((lognot (get st 4ul y)) &. get st 0ul y) in let v4 = get st 4ul y ^. ((lognot (get st 0ul y)) &. get st 1ul y) in set st 0ul y v0; set st 1ul y v1; set st 2ul y v2; set st 3ul y v3; set st 4ul y v4; let h1 = ST.get() in assert (modifies (loc st) h0 h1); assert (as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) inline_for_extraction noextract val state_chi: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_chi (as_seq h0 s)) let state_chi st = let h0 = ST.get() in [@ inline_let] let spec h0 = Equiv.state_chi_inner in let h0 = ST.get () in loop1 h0 5ul st spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 st) (v y); state_chi_inner st y ); let h1 = ST.get() in assert(as_seq h1 st == Equiv.state_chi (as_seq h0 st)); Equiv.state_chi_equivalence (as_seq h0 st) inline_for_extraction noextract val state_iota: s:state -> round:size_t{v round < 24} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_iota (as_seq h0 s) (v round)) let state_iota s round = recall_contents keccak_rndc Spec.SHA3.Constants.keccak_rndc; let c = keccak_rndc.(round) in set s 0ul 0ul (get s 0ul 0ul ^. secret c) private val state_permute: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_permute (as_seq h0 s)) let state_permute s = [@ inline_let] let spec h0 = S.state_permute1 in let h0 = ST.get () in loop1 h0 24ul s spec (fun round -> Loop.unfold_repeati 24 (spec h0) (as_seq h0 s) (v round); state_theta s; state_pi_rho s; state_chi s; state_iota s round) private val loadState: rateInBytes:size_t{v rateInBytes <= 200} -> input:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h -> live h input /\ live h s /\ disjoint input s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.loadState (v rateInBytes) (as_seq h0 input) (as_seq h0 s)) let loadState rateInBytes input s = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in update_sub block 0ul rateInBytes input; [@ inline_let] let spec h0 = S.loadState_inner (as_seq h0 block) in let h0 = ST.get () in loop1 h0 25ul s spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 s) (v j); let h0 = ST.get() in let x = uint_from_bytes_le #U64 (sub block (j *! 8ul) 8ul) in s.(j) <- s.(j) ^. x ); pop_frame() inline_for_extraction noextract val storeState_inner: s:state -> j:size_t{v j < 25} -> block:lbuffer uint8 200ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc block) h0 h1 /\ as_seq h1 block == S.storeState_inner (as_seq h0 s) (v j) (as_seq h0 block)) let storeState_inner s j block = let sj = s.(j) in let h0 = ST.get () in update_sub_f h0 block (j *! 8ul) 8ul (fun h -> Lib.ByteSequence.uint_to_bytes_le sj) (fun _ -> uint_to_bytes_le #U64 (sub block (j *! 8ul) 8ul) sj) private val storeState: rateInBytes:size_t{v rateInBytes <= 200} -> s:state -> res:lbuffer uint8 rateInBytes -> Stack unit (requires fun h0 -> live h0 s /\ live h0 res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.storeState (v rateInBytes) (as_seq h0 s)) let storeState rateInBytes s res = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in [@ inline_let] let spec h0 = S.storeState_inner (as_seq h0 s) in let h0 = ST.get () in loop1 h0 25ul block spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 block) (v j); storeState_inner s j block ); copy res (sub block 0ul rateInBytes); pop_frame() #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract val absorb_next: s:state -> rateInBytes:size_t{v rateInBytes > 0 /\ v rateInBytes <= 200} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Hacl.Impl.SHA3.state -> rateInBytes: Lib.IntTypes.size_t{Lib.IntTypes.v rateInBytes > 0 /\ Lib.IntTypes.v rateInBytes <= 200} -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.SHA3.state", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.SHA3.state_permute", "Hacl.Impl.SHA3.loadState", "Lib.Buffer.op_Array_Assignment", "Lib.IntTypes.uint8", "Lib.IntTypes.op_Subtraction_Bang", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u8", "Prims._assert", "FStar.Seq.Base.equal", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Lib.Sequence.create", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.sub", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let absorb_next s rateInBytes =
push_frame (); let h0 = ST.get () in let nextBlock_ = create 200ul (u8 0) in let nextBlock = sub nextBlock_ 0ul rateInBytes in let h1 = ST.get () in assert ((as_seq h1 nextBlock) `Seq.equal` (Lib.Sequence.create (v rateInBytes) (u8 0))); nextBlock.(rateInBytes -! 1ul) <- u8 0x80; loadState rateInBytes nextBlock s; state_permute s; pop_frame ()
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.state_chi_inner
val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st))
val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st))
let state_chi_inner st y = let h0 = ST.get() in let v0 = get st 0ul y ^. ((lognot (get st 1ul y)) &. get st 2ul y) in let v1 = get st 1ul y ^. ((lognot (get st 2ul y)) &. get st 3ul y) in let v2 = get st 2ul y ^. ((lognot (get st 3ul y)) &. get st 4ul y) in let v3 = get st 3ul y ^. ((lognot (get st 4ul y)) &. get st 0ul y) in let v4 = get st 4ul y ^. ((lognot (get st 0ul y)) &. get st 1ul y) in set st 0ul y v0; set st 1ul y v1; set st 2ul y v2; set st 3ul y v3; set st 4ul y v4; let h1 = ST.get() in assert (modifies (loc st) h0 h1); assert (as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st))
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 69, "end_line": 242, "start_col": 0, "start_line": 228 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s')) let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp inline_for_extraction noextract val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s)) let state_pi_rho s = push_frame(); let x = get s 1ul 0ul in let h0 = ST.get() in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@ inline_let] let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@ inline_let] let footprint i = loc_union (loc current) (loc s) in [@ inline_let] let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s ); pop_frame() inline_for_extraction noextract val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
st: Hacl.Impl.SHA3.state -> y: Hacl.Impl.SHA3.index -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.SHA3.state", "Hacl.Impl.SHA3.index", "Prims._assert", "Prims.eq2", "Lib.Sequence.lseq", "Lib.IntTypes.uint64", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.__uint_to_t", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Spec.SHA3.Equivalence.state_chi_inner", "Prims.unit", "Lib.Buffer.modifies", "Lib.Buffer.loc", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.SHA3.set", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Hat_Dot", "Lib.IntTypes.op_Amp_Dot", "Hacl.Impl.SHA3.get", "Lib.IntTypes.lognot" ]
[]
false
true
false
false
false
let state_chi_inner st y =
let h0 = ST.get () in let v0 = get st 0ul y ^. ((lognot (get st 1ul y)) &. get st 2ul y) in let v1 = get st 1ul y ^. ((lognot (get st 2ul y)) &. get st 3ul y) in let v2 = get st 2ul y ^. ((lognot (get st 3ul y)) &. get st 4ul y) in let v3 = get st 3ul y ^. ((lognot (get st 4ul y)) &. get st 0ul y) in let v4 = get st 4ul y ^. ((lognot (get st 0ul y)) &. get st 1ul y) in set st 0ul y v0; set st 1ul y v1; set st 2ul y v2; set st 3ul y v3; set st 4ul y v4; let h1 = ST.get () in assert (modifies (loc st) h0 h1); assert (as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st))
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.state_pi_rho
val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s))
val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s))
let state_pi_rho s = push_frame(); let x = get s 1ul 0ul in let h0 = ST.get() in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@ inline_let] let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@ inline_let] let footprint i = loc_union (loc current) (loc s) in [@ inline_let] let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s ); pop_frame()
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 216, "start_col": 0, "start_line": 197 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s')) let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp inline_for_extraction noextract val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Hacl.Impl.SHA3.state -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.SHA3.state", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Lib.Buffer.loop", "FStar.UInt32.__uint_to_t", "Spec.SHA3.state_pi_rho_s", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.SHA3.state_pi_rho_inner", "Lib.LoopCombinators.unfold_repeat_gen", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Prims.nat", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "FStar.Pervasives.Native.tuple2", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Sequence.lseq", "Spec.SHA3.state_pi_rho_inner", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.loc", "Lib.IntTypes.size_nat", "LowStar.Monotonic.Buffer.loc_union", "Lib.Buffer.loc", "Lib.Buffer.MUT", "Lib.IntTypes.uint64", "Prims.int", "FStar.Pervasives.Native.Mktuple2", "Spec.SHA3.state", "Lib.Buffer.bget", "Lib.Buffer.as_seq", "Prims._assert", "Prims.eq2", "Spec.SHA3.get", "Lib.Buffer.lbuffer_t", "Lib.Buffer.create", "Lib.Buffer.lbuffer", "Hacl.Impl.SHA3.get", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let state_pi_rho s =
push_frame (); let x = get s 1ul 0ul in let h0 = ST.get () in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@@ inline_let ]let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@@ inline_let ]let footprint i = loc_union (loc current) (loc s) in [@@ inline_let ]let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s); pop_frame ()
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.squeeze
val squeeze: s:state -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> outputByteLen:size_t -> output:lbuffer uint8 outputByteLen -> Stack unit (requires fun h0 -> live h0 s /\ live h0 output /\ disjoint s output) (ensures fun h0 _ h1 -> modifies2 s output h0 h1 /\ as_seq h1 output == S.squeeze (as_seq h0 s) (v rateInBytes) (v outputByteLen))
val squeeze: s:state -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> outputByteLen:size_t -> output:lbuffer uint8 outputByteLen -> Stack unit (requires fun h0 -> live h0 s /\ live h0 output /\ disjoint s output) (ensures fun h0 _ h1 -> modifies2 s output h0 h1 /\ as_seq h1 output == S.squeeze (as_seq h0 s) (v rateInBytes) (v outputByteLen))
let squeeze s rateInBytes outputByteLen output = let outBlocks = outputByteLen /. rateInBytes in let remOut = outputByteLen %. rateInBytes in assert_spinoff (v outputByteLen - v remOut == v outBlocks * v rateInBytes); let last = sub output (outputByteLen -. remOut) remOut in [@ inline_let] let a_spec (i:nat{i <= v outputByteLen / v rateInBytes}) = S.state in let blocks = sub output (size 0) (outBlocks *! rateInBytes) in let h0 = ST.get() in fill_blocks h0 rateInBytes outBlocks blocks a_spec (fun h i -> as_seq h s) (fun _ -> loc s) (fun h0 -> S.squeeze_inner (v rateInBytes) (v outputByteLen)) (fun i -> mult_plus_lt (v i) (v outBlocks) (v rateInBytes); squeeze_inner rateInBytes outputByteLen s (sub blocks (i *! rateInBytes) rateInBytes) i); storeState remOut s last; let h1 = ST.get() in Seq.lemma_split (as_seq h1 output) (v outBlocks * v rateInBytes); norm_spec [delta_only [`%S.squeeze]] (S.squeeze (as_seq h0 s) (v rateInBytes) (v outputByteLen))
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 98, "end_line": 510, "start_col": 0, "start_line": 491 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s')) let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp inline_for_extraction noextract val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s)) let state_pi_rho s = push_frame(); let x = get s 1ul 0ul in let h0 = ST.get() in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@ inline_let] let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@ inline_let] let footprint i = loc_union (loc current) (loc s) in [@ inline_let] let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s ); pop_frame() inline_for_extraction noextract val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) let state_chi_inner st y = let h0 = ST.get() in let v0 = get st 0ul y ^. ((lognot (get st 1ul y)) &. get st 2ul y) in let v1 = get st 1ul y ^. ((lognot (get st 2ul y)) &. get st 3ul y) in let v2 = get st 2ul y ^. ((lognot (get st 3ul y)) &. get st 4ul y) in let v3 = get st 3ul y ^. ((lognot (get st 4ul y)) &. get st 0ul y) in let v4 = get st 4ul y ^. ((lognot (get st 0ul y)) &. get st 1ul y) in set st 0ul y v0; set st 1ul y v1; set st 2ul y v2; set st 3ul y v3; set st 4ul y v4; let h1 = ST.get() in assert (modifies (loc st) h0 h1); assert (as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) inline_for_extraction noextract val state_chi: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_chi (as_seq h0 s)) let state_chi st = let h0 = ST.get() in [@ inline_let] let spec h0 = Equiv.state_chi_inner in let h0 = ST.get () in loop1 h0 5ul st spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 st) (v y); state_chi_inner st y ); let h1 = ST.get() in assert(as_seq h1 st == Equiv.state_chi (as_seq h0 st)); Equiv.state_chi_equivalence (as_seq h0 st) inline_for_extraction noextract val state_iota: s:state -> round:size_t{v round < 24} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_iota (as_seq h0 s) (v round)) let state_iota s round = recall_contents keccak_rndc Spec.SHA3.Constants.keccak_rndc; let c = keccak_rndc.(round) in set s 0ul 0ul (get s 0ul 0ul ^. secret c) private val state_permute: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_permute (as_seq h0 s)) let state_permute s = [@ inline_let] let spec h0 = S.state_permute1 in let h0 = ST.get () in loop1 h0 24ul s spec (fun round -> Loop.unfold_repeati 24 (spec h0) (as_seq h0 s) (v round); state_theta s; state_pi_rho s; state_chi s; state_iota s round) private val loadState: rateInBytes:size_t{v rateInBytes <= 200} -> input:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h -> live h input /\ live h s /\ disjoint input s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.loadState (v rateInBytes) (as_seq h0 input) (as_seq h0 s)) let loadState rateInBytes input s = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in update_sub block 0ul rateInBytes input; [@ inline_let] let spec h0 = S.loadState_inner (as_seq h0 block) in let h0 = ST.get () in loop1 h0 25ul s spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 s) (v j); let h0 = ST.get() in let x = uint_from_bytes_le #U64 (sub block (j *! 8ul) 8ul) in s.(j) <- s.(j) ^. x ); pop_frame() inline_for_extraction noextract val storeState_inner: s:state -> j:size_t{v j < 25} -> block:lbuffer uint8 200ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc block) h0 h1 /\ as_seq h1 block == S.storeState_inner (as_seq h0 s) (v j) (as_seq h0 block)) let storeState_inner s j block = let sj = s.(j) in let h0 = ST.get () in update_sub_f h0 block (j *! 8ul) 8ul (fun h -> Lib.ByteSequence.uint_to_bytes_le sj) (fun _ -> uint_to_bytes_le #U64 (sub block (j *! 8ul) 8ul) sj) private val storeState: rateInBytes:size_t{v rateInBytes <= 200} -> s:state -> res:lbuffer uint8 rateInBytes -> Stack unit (requires fun h0 -> live h0 s /\ live h0 res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.storeState (v rateInBytes) (as_seq h0 s)) let storeState rateInBytes s res = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in [@ inline_let] let spec h0 = S.storeState_inner (as_seq h0 s) in let h0 = ST.get () in loop1 h0 25ul block spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 block) (v j); storeState_inner s j block ); copy res (sub block 0ul rateInBytes); pop_frame() #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract val absorb_next: s:state -> rateInBytes:size_t{v rateInBytes > 0 /\ v rateInBytes <= 200} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_next (as_seq h0 s) (v rateInBytes)) let absorb_next s rateInBytes = push_frame(); let h0 = ST.get() in let nextBlock_ = create 200ul (u8 0) in let nextBlock = sub nextBlock_ 0ul rateInBytes in let h1 = ST.get () in assert (as_seq h1 nextBlock `Seq.equal` Lib.Sequence.create (v rateInBytes) (u8 0)); nextBlock.(rateInBytes -! 1ul) <- u8 0x80; loadState rateInBytes nextBlock s; state_permute s; pop_frame() inline_for_extraction noextract val absorb_last: delimitedSuffix:byte_t -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> rem:size_t{v rem < v rateInBytes} -> input:lbuffer uint8 rem -> s:state -> Stack unit (requires fun h -> live h s /\ live h input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_last delimitedSuffix (v rateInBytes) (v rem) (as_seq h0 input) (as_seq h0 s)) let absorb_last delimitedSuffix rateInBytes rem input s = push_frame(); let h0 = ST.get() in let lastBlock_ = create 200ul (u8 0) in let lastBlock = sub lastBlock_ 0ul rateInBytes in let h1 = ST.get () in assert (as_seq h1 lastBlock `Seq.equal` Lib.Sequence.create (v rateInBytes) (u8 0)); let open Lib.RawIntTypes in update_sub lastBlock (size 0) rem input; lastBlock.(rem) <- byte_to_uint8 delimitedSuffix; loadState rateInBytes lastBlock s; if not ((delimitedSuffix &. byte 0x80) =. byte 0) && (size_to_UInt32 rem = size_to_UInt32 (rateInBytes -. 1ul)) then state_permute s; absorb_next s rateInBytes; pop_frame() val absorb_inner: rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> block:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_inner (v rateInBytes) (as_seq h0 block) (as_seq h0 s)) let absorb_inner rateInBytes block s = loadState rateInBytes block s; state_permute s #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" private val absorb: s:state -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> inputByteLen:size_t -> input:lbuffer uint8 inputByteLen -> delimitedSuffix:byte_t -> Stack unit (requires fun h0 -> live h0 s /\ live h0 input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb (as_seq h0 s) (v rateInBytes) (v inputByteLen) (as_seq h0 input) delimitedSuffix) let absorb s rateInBytes inputByteLen input delimitedSuffix = let n_blocks = inputByteLen /. rateInBytes in let rem = inputByteLen %. rateInBytes in loop_blocks rateInBytes n_blocks rem input (S.absorb_inner (v rateInBytes)) (S.absorb_last delimitedSuffix (v rateInBytes)) (absorb_inner rateInBytes) (absorb_last delimitedSuffix rateInBytes) s inline_for_extraction noextract val squeeze_inner: rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> outputByteLen:size_t -> s:state -> output:lbuffer uint8 rateInBytes -> i:size_t{v i < v (outputByteLen /. rateInBytes)} -> Stack unit (requires fun h0 -> live h0 s /\ live h0 output /\ disjoint s output) (ensures fun h0 _ h1 -> modifies2 s output h0 h1 /\ (as_seq h1 s, as_seq h1 output) == S.squeeze_inner (v rateInBytes) (v outputByteLen) (v i) (as_seq h0 s)) let squeeze_inner rateInBytes outputByteLen s output i = storeState rateInBytes s output; state_permute s private let mult_plus_lt (i a b:nat) : Lemma (requires i < a) (ensures i * b + b <= a * b) = assert (i <= a - 1) val squeeze: s:state -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> outputByteLen:size_t -> output:lbuffer uint8 outputByteLen -> Stack unit (requires fun h0 -> live h0 s /\ live h0 output /\ disjoint s output) (ensures fun h0 _ h1 -> modifies2 s output h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Hacl.Impl.SHA3.state -> rateInBytes: Lib.IntTypes.size_t{0 < Lib.IntTypes.v rateInBytes /\ Lib.IntTypes.v rateInBytes <= 200} -> outputByteLen: Lib.IntTypes.size_t -> output: Lib.Buffer.lbuffer Lib.IntTypes.uint8 outputByteLen -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.SHA3.state", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.Pervasives.norm_spec", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_only", "Prims.string", "Prims.Nil", "Lib.ByteSequence.lbytes", "Spec.SHA3.squeeze", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Seq.Properties.lemma_split", "FStar.Mul.op_Star", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.SHA3.storeState", "Lib.Buffer.fill_blocks", "Lib.IntTypes.size_nat", "Lib.Buffer.loc", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "Spec.SHA3.squeeze_inner", "FStar.Pervasives.Native.tuple2", "Prims.op_Addition", "Lib.Sequence.lseq", "Hacl.Impl.SHA3.squeeze_inner", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.sub", "Lib.IntTypes.op_Star_Bang", "Hacl.Impl.SHA3.mult_plus_lt", "Lib.IntTypes.mul", "Lib.IntTypes.size", "Prims.nat", "Prims.op_Division", "Spec.SHA3.state", "Lib.IntTypes.op_Subtraction_Dot", "FStar.Pervasives.assert_spinoff", "Prims.eq2", "Prims.int", "Prims.op_Subtraction", "Lib.IntTypes.op_Percent_Dot", "Lib.IntTypes.op_Slash_Dot" ]
[]
false
true
false
false
false
let squeeze s rateInBytes outputByteLen output =
let outBlocks = outputByteLen /. rateInBytes in let remOut = outputByteLen %. rateInBytes in assert_spinoff (v outputByteLen - v remOut == v outBlocks * v rateInBytes); let last = sub output (outputByteLen -. remOut) remOut in [@@ inline_let ]let a_spec (i: nat{i <= v outputByteLen / v rateInBytes}) = S.state in let blocks = sub output (size 0) (outBlocks *! rateInBytes) in let h0 = ST.get () in fill_blocks h0 rateInBytes outBlocks blocks a_spec (fun h i -> as_seq h s) (fun _ -> loc s) (fun h0 -> S.squeeze_inner (v rateInBytes) (v outputByteLen)) (fun i -> mult_plus_lt (v i) (v outBlocks) (v rateInBytes); squeeze_inner rateInBytes outputByteLen s (sub blocks (i *! rateInBytes) rateInBytes) i); storeState remOut s last; let h1 = ST.get () in Seq.lemma_split (as_seq h1 output) (v outBlocks * v rateInBytes); norm_spec [delta_only [`%S.squeeze]] (S.squeeze (as_seq h0 s) (v rateInBytes) (v outputByteLen))
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.nat_mod_comm_monoid
val nat_mod_comm_monoid : Lib.Exponentiation.Definition.comm_monoid (Lib.NatMod.nat_mod Spec.K256.PointOps.q)
let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 12, "start_col": 0, "start_line": 12 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Lib.Exponentiation.Definition.comm_monoid (Lib.NatMod.nat_mod Spec.K256.PointOps.q)
Prims.Tot
[ "total" ]
[]
[ "Lib.NatMod.mk_nat_mod_comm_monoid", "Spec.K256.PointOps.q" ]
[]
false
false
false
true
false
let nat_mod_comm_monoid =
M.mk_nat_mod_comm_monoid S.q
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.qsquare_times
val qsquare_times (a: S.qelem) (b: nat) : S.qelem
val qsquare_times (a: S.qelem) (b: nat) : S.qelem
let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 37, "start_col": 0, "start_line": 36 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; }
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.K256.PointOps.qelem -> b: Prims.nat -> Spec.K256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.K256.PointOps.qelem", "Prims.nat", "Spec.Exponentiation.exp_pow2", "Hacl.Spec.K256.Qinv.mk_nat_mod_concrete_ops" ]
[]
false
false
false
true
false
let qsquare_times (a: S.qelem) (b: nat) : S.qelem =
SE.exp_pow2 mk_nat_mod_concrete_ops a b
false
Hacl.Impl.Curve25519.Fields.fst
Hacl.Impl.Curve25519.Fields.set_one
val set_one: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 1)
val set_one: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 1)
let set_one #s f = match s with | M51 -> F51.set_one f | M64 -> F64.set_one f
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 95, "start_col": 0, "start_line": 92 }
module Hacl.Impl.Curve25519.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer include Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module BSeq = Lib.ByteSequence module LSeq = Lib.Sequence module P = Spec.Curve25519 module F51 = Hacl.Impl.Curve25519.Field51 module F64 = Hacl.Impl.Curve25519.Field64 #set-options "--z3rlimit 50 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --record_options" inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create (v (nlimb s)) (limb_zero s)) /\ as_nat h1 f == 0) let create_felem s = match s with | M51 -> (F51.create_felem ()) <: felem s | M64 -> (F64.create_felem ()) <: felem s inline_for_extraction noextract val load_felem: #s:field_spec -> f:felem s -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint f u64s /\ v (LSeq.index (as_seq h u64s) 3) < pow2 63) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ state_inv_t h1 f /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s)) let load_felem #s f b = match s with | M51 -> F51.load_felem f b | M64 -> F64.load_felem f b val store_felem: #s:field_spec -> b:lbuffer uint64 4ul -> f:felem s -> Stack unit (requires fun h -> live h f /\ live h b /\ disjoint f b /\ state_inv_t h f) (ensures fun h0 _ h1 -> modifies (loc b |+| loc f) h0 h1 /\ as_seq h1 b == BSeq.nat_to_intseq_le 4 (feval h0 f)) [@ Meta.Attribute.specialize ] let store_felem #s b f = match s with | M51 -> F51.store_felem b f | M64 -> F64.store_felem b f inline_for_extraction noextract val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 0) let set_zero #s f = match s with | M51 -> F51.set_zero f | M64 -> F64.set_zero f inline_for_extraction noextract val set_one: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "Hacl.Impl.Curve25519.Field64.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field64", "short_module": "F64" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Impl.Curve25519.Fields.Core.felem s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.field_spec", "Hacl.Impl.Curve25519.Fields.Core.felem", "Hacl.Impl.Curve25519.Field51.set_one", "Prims.unit", "Hacl.Impl.Curve25519.Field64.set_one" ]
[]
false
true
false
false
false
let set_one #s f =
match s with | M51 -> F51.set_one f | M64 -> F64.set_one f
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.qinv_r0_r1
val qinv_r0_r1 (x14: S.qelem) : S.qelem
val qinv_r0_r1 (x14: S.qelem) : S.qelem
let qinv_r0_r1 x14 = let x28 = S.qmul (qsquare_times x14 14) x14 in let x56 = S.qmul (qsquare_times x28 28) x28 in let r0 = S.qmul (qsquare_times x56 56) x56 in let r1 = S.qmul (qsquare_times r0 14) x14 in r1
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 59, "start_col": 0, "start_line": 54 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b) (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *)
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x14: Spec.K256.PointOps.qelem -> Spec.K256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.K256.PointOps.qelem", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv_r0_r1 x14 =
let x28 = S.qmul (qsquare_times x14 14) x14 in let x56 = S.qmul (qsquare_times x28 28) x28 in let r0 = S.qmul (qsquare_times x56 56) x56 in let r1 = S.qmul (qsquare_times r0 14) x14 in r1
false
Hacl.Impl.Curve25519.Fields.fst
Hacl.Impl.Curve25519.Fields.set_zero
val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 0)
val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 0)
let set_zero #s f = match s with | M51 -> F51.set_zero f | M64 -> F64.set_zero f
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 81, "start_col": 0, "start_line": 78 }
module Hacl.Impl.Curve25519.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer include Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module BSeq = Lib.ByteSequence module LSeq = Lib.Sequence module P = Spec.Curve25519 module F51 = Hacl.Impl.Curve25519.Field51 module F64 = Hacl.Impl.Curve25519.Field64 #set-options "--z3rlimit 50 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --record_options" inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create (v (nlimb s)) (limb_zero s)) /\ as_nat h1 f == 0) let create_felem s = match s with | M51 -> (F51.create_felem ()) <: felem s | M64 -> (F64.create_felem ()) <: felem s inline_for_extraction noextract val load_felem: #s:field_spec -> f:felem s -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint f u64s /\ v (LSeq.index (as_seq h u64s) 3) < pow2 63) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ state_inv_t h1 f /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s)) let load_felem #s f b = match s with | M51 -> F51.load_felem f b | M64 -> F64.load_felem f b val store_felem: #s:field_spec -> b:lbuffer uint64 4ul -> f:felem s -> Stack unit (requires fun h -> live h f /\ live h b /\ disjoint f b /\ state_inv_t h f) (ensures fun h0 _ h1 -> modifies (loc b |+| loc f) h0 h1 /\ as_seq h1 b == BSeq.nat_to_intseq_le 4 (feval h0 f)) [@ Meta.Attribute.specialize ] let store_felem #s b f = match s with | M51 -> F51.store_felem b f | M64 -> F64.store_felem b f inline_for_extraction noextract val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "Hacl.Impl.Curve25519.Field64.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field64", "short_module": "F64" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Impl.Curve25519.Fields.Core.felem s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.field_spec", "Hacl.Impl.Curve25519.Fields.Core.felem", "Hacl.Impl.Curve25519.Field51.set_zero", "Prims.unit", "Hacl.Impl.Curve25519.Field64.set_zero" ]
[]
false
true
false
false
false
let set_zero #s f =
match s with | M51 -> F51.set_zero f | M64 -> F64.set_zero f
false
Spec.Frodo.KEM.Encaps.fst
Spec.Frodo.KEM.Encaps.crypto_kem_enc_ss
val crypto_kem_enc_ss: a:frodo_alg -> k:lbytes (crypto_bytes a) -> ct:lbytes (crypto_ciphertextbytes a) -> lbytes (crypto_bytes a)
val crypto_kem_enc_ss: a:frodo_alg -> k:lbytes (crypto_bytes a) -> ct:lbytes (crypto_ciphertextbytes a) -> lbytes (crypto_bytes a)
let crypto_kem_enc_ss a k ct = let shake_input_ss = concat ct k in let ss = frodo_shake a (crypto_ciphertextbytes a + crypto_bytes a) shake_input_ss (crypto_bytes a) in ss
{ "file_name": "specs/frodo/Spec.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 136, "start_col": 0, "start_line": 133 }
module Spec.Frodo.KEM.Encaps open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Matrix open Spec.Frodo.Lemmas open Spec.Frodo.Params open Spec.Frodo.Encode open Spec.Frodo.Pack open Spec.Frodo.Sample module LSeq = Lib.Sequence module Matrix = Spec.Matrix module KG = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val frodo_mul_add_sa_plus_e: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> matrix params_nbar (params_n a) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix = let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in let b_matrix = Matrix.add (Matrix.mul sp_matrix a_matrix) ep_matrix in b_matrix val crypto_kem_enc_ct_pack_c1: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> lbytes (ct1bytes_len a) let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix = let bp_matrix = frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix in let ct1 = frodo_pack (params_logq a) bp_matrix in ct1 val frodo_mul_add_sb_plus_e: a:frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix = let b_matrix = frodo_unpack #(params_n a) #params_nbar (params_logq a) b in let v_matrix = Matrix.add (Matrix.mul sp_matrix b_matrix) epp_matrix in v_matrix val frodo_mul_add_sb_plus_e_plus_mu: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix in let mu_encode = frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu in let v_matrix = Matrix.add v_matrix mu_encode in v_matrix val crypto_kem_enc_ct_pack_c2: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> lbytes (ct2bytes_len a) let crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix in let ct2 = frodo_pack (params_logq a) v_matrix in ct2 val get_sp_ep_epp_matrices: a:frodo_alg -> seed_se:lbytes (crypto_bytes a) -> matrix params_nbar (params_n a) & matrix params_nbar (params_n a) & matrix params_nbar params_nbar let get_sp_ep_epp_matrices a seed_se = let s_bytes_len = secretmatrixbytes_len a in let r = KG.frodo_shake_r a (u8 0x96) seed_se (2 * s_bytes_len + 2 * params_nbar * params_nbar) in let sp_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r 0 s_bytes_len) in let ep_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r s_bytes_len s_bytes_len) in let epp_matrix = frodo_sample_matrix a params_nbar params_nbar (LSeq.sub r (2 * s_bytes_len) (2 * params_nbar * params_nbar)) in sp_matrix, ep_matrix, epp_matrix val crypto_kem_enc_ct: a:frodo_alg -> gen_a:frodo_gen_a -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> seed_se:lbytes (crypto_bytes a) -> lbytes (crypto_ciphertextbytes a) let crypto_kem_enc_ct a gen_a mu pk seed_se = expand_crypto_publickeybytes a; let seed_a = LSeq.sub pk 0 bytes_seed_a in let b = LSeq.sub pk bytes_seed_a (publicmatrixbytes_len a) in let sp_matrix, ep_matrix, epp_matrix = get_sp_ep_epp_matrices a seed_se in let c1 = crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix in let c2 = crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix in expand_crypto_ciphertextbytes a; let ct = concat c1 c2 in ct val crypto_kem_enc_ss: a:frodo_alg -> k:lbytes (crypto_bytes a) -> ct:lbytes (crypto_ciphertextbytes a) -> lbytes (crypto_bytes a)
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Sample.fst.checked", "Spec.Frodo.Random.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.Pack.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "Spec.Frodo.Encode.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "Matrix" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Spec.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Spec.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Spec.Frodo.Params.frodo_alg -> k: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_bytes a) -> ct: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_ciphertextbytes a) -> Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_bytes a)
Prims.Tot
[ "total" ]
[]
[ "Spec.Frodo.Params.frodo_alg", "Lib.ByteSequence.lbytes", "Spec.Frodo.Params.crypto_bytes", "Spec.Frodo.Params.crypto_ciphertextbytes", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Spec.Frodo.Params.frodo_shake", "Prims.op_Addition", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.append", "Lib.Sequence.concat", "Lib.IntTypes.uint_t" ]
[]
false
false
false
false
false
let crypto_kem_enc_ss a k ct =
let shake_input_ss = concat ct k in let ss = frodo_shake a (crypto_ciphertextbytes a + crypto_bytes a) shake_input_ss (crypto_bytes a) in ss
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.mul_mod
val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid
val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid
let mul_mod x y = S.qmul x y
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 24, "start_col": 0, "start_line": 24 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Spec.Exponentiation.mul_st Spec.K256.PointOps.qelem Hacl.Spec.K256.Qinv.mk_to_nat_mod_comm_monoid
Prims.Tot
[ "total" ]
[]
[ "Spec.K256.PointOps.qelem", "Spec.K256.PointOps.qmul" ]
[]
false
false
false
true
false
let mul_mod x y =
S.qmul x y
false
Spec.Frodo.KEM.Encaps.fst
Spec.Frodo.KEM.Encaps.crypto_kem_enc
val crypto_kem_enc: a:frodo_alg -> gen_a:frodo_gen_a -> state:Spec.Frodo.Random.state_t -> pk:lbytes (crypto_publickeybytes a) -> lbytes (crypto_ciphertextbytes a) & lbytes (crypto_bytes a)
val crypto_kem_enc: a:frodo_alg -> gen_a:frodo_gen_a -> state:Spec.Frodo.Random.state_t -> pk:lbytes (crypto_publickeybytes a) -> lbytes (crypto_ciphertextbytes a) & lbytes (crypto_bytes a)
let crypto_kem_enc a gen_a state pk = let mu, _ = Spec.Frodo.Random.randombytes_ state (bytes_mu a) in crypto_kem_enc_ a gen_a mu pk
{ "file_name": "specs/frodo/Spec.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 178, "start_col": 0, "start_line": 176 }
module Spec.Frodo.KEM.Encaps open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Matrix open Spec.Frodo.Lemmas open Spec.Frodo.Params open Spec.Frodo.Encode open Spec.Frodo.Pack open Spec.Frodo.Sample module LSeq = Lib.Sequence module Matrix = Spec.Matrix module KG = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val frodo_mul_add_sa_plus_e: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> matrix params_nbar (params_n a) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix = let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in let b_matrix = Matrix.add (Matrix.mul sp_matrix a_matrix) ep_matrix in b_matrix val crypto_kem_enc_ct_pack_c1: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> lbytes (ct1bytes_len a) let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix = let bp_matrix = frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix in let ct1 = frodo_pack (params_logq a) bp_matrix in ct1 val frodo_mul_add_sb_plus_e: a:frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix = let b_matrix = frodo_unpack #(params_n a) #params_nbar (params_logq a) b in let v_matrix = Matrix.add (Matrix.mul sp_matrix b_matrix) epp_matrix in v_matrix val frodo_mul_add_sb_plus_e_plus_mu: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix in let mu_encode = frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu in let v_matrix = Matrix.add v_matrix mu_encode in v_matrix val crypto_kem_enc_ct_pack_c2: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> lbytes (ct2bytes_len a) let crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix in let ct2 = frodo_pack (params_logq a) v_matrix in ct2 val get_sp_ep_epp_matrices: a:frodo_alg -> seed_se:lbytes (crypto_bytes a) -> matrix params_nbar (params_n a) & matrix params_nbar (params_n a) & matrix params_nbar params_nbar let get_sp_ep_epp_matrices a seed_se = let s_bytes_len = secretmatrixbytes_len a in let r = KG.frodo_shake_r a (u8 0x96) seed_se (2 * s_bytes_len + 2 * params_nbar * params_nbar) in let sp_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r 0 s_bytes_len) in let ep_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r s_bytes_len s_bytes_len) in let epp_matrix = frodo_sample_matrix a params_nbar params_nbar (LSeq.sub r (2 * s_bytes_len) (2 * params_nbar * params_nbar)) in sp_matrix, ep_matrix, epp_matrix val crypto_kem_enc_ct: a:frodo_alg -> gen_a:frodo_gen_a -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> seed_se:lbytes (crypto_bytes a) -> lbytes (crypto_ciphertextbytes a) let crypto_kem_enc_ct a gen_a mu pk seed_se = expand_crypto_publickeybytes a; let seed_a = LSeq.sub pk 0 bytes_seed_a in let b = LSeq.sub pk bytes_seed_a (publicmatrixbytes_len a) in let sp_matrix, ep_matrix, epp_matrix = get_sp_ep_epp_matrices a seed_se in let c1 = crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix in let c2 = crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix in expand_crypto_ciphertextbytes a; let ct = concat c1 c2 in ct val crypto_kem_enc_ss: a:frodo_alg -> k:lbytes (crypto_bytes a) -> ct:lbytes (crypto_ciphertextbytes a) -> lbytes (crypto_bytes a) let crypto_kem_enc_ss a k ct = let shake_input_ss = concat ct k in let ss = frodo_shake a (crypto_ciphertextbytes a + crypto_bytes a) shake_input_ss (crypto_bytes a) in ss val crypto_kem_enc_seed_se_k: a:frodo_alg -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> lbytes (2 * crypto_bytes a) let crypto_kem_enc_seed_se_k a mu pk = let pkh = frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) in let pkh_mu = concat pkh mu in let seed_se_k = frodo_shake a (bytes_pkhash a + bytes_mu a) pkh_mu (2 * crypto_bytes a) in seed_se_k val crypto_kem_enc_: a:frodo_alg -> gen_a:frodo_gen_a -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> lbytes (crypto_ciphertextbytes a) & lbytes (crypto_bytes a) let crypto_kem_enc_ a gen_a mu pk = let seed_se_k = crypto_kem_enc_seed_se_k a mu pk in let seed_se = LSeq.sub seed_se_k 0 (crypto_bytes a) in let k = LSeq.sub seed_se_k (crypto_bytes a) (crypto_bytes a) in let ct = crypto_kem_enc_ct a gen_a mu pk seed_se in let ss = crypto_kem_enc_ss a k ct in ct, ss val crypto_kem_enc: a:frodo_alg -> gen_a:frodo_gen_a -> state:Spec.Frodo.Random.state_t -> pk:lbytes (crypto_publickeybytes a) -> lbytes (crypto_ciphertextbytes a) & lbytes (crypto_bytes a)
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Sample.fst.checked", "Spec.Frodo.Random.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.Pack.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "Spec.Frodo.Encode.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "Matrix" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Spec.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Spec.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Spec.Frodo.Params.frodo_alg -> gen_a: Spec.Frodo.Params.frodo_gen_a -> state: Spec.Frodo.Random.state_t -> pk: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_publickeybytes a) -> Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_ciphertextbytes a) * Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_bytes a)
Prims.Tot
[ "total" ]
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Spec.Frodo.Random.state_t", "Lib.ByteSequence.lbytes", "Spec.Frodo.Params.crypto_publickeybytes", "Lib.Sequence.lseq", "Lib.IntTypes.uint8", "Spec.Frodo.Params.bytes_mu", "Spec.Frodo.KEM.Encaps.crypto_kem_enc_", "FStar.Pervasives.Native.tuple2", "Spec.Frodo.Params.crypto_ciphertextbytes", "Spec.Frodo.Params.crypto_bytes", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Spec.Frodo.Random.randombytes_" ]
[]
false
false
false
false
false
let crypto_kem_enc a gen_a state pk =
let mu, _ = Spec.Frodo.Random.randombytes_ state (bytes_mu a) in crypto_kem_enc_ a gen_a mu pk
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.qinv_r24_r25
val qinv_r24_r25 (r23 x_1 x6: S.qelem) : S.qelem
val qinv_r24_r25 (r23 x_1 x6: S.qelem) : S.qelem
let qinv_r24_r25 r23 x_1 x6 = let r24 = S.qmul (qsquare_times r23 6) x_1 in let r25 = S.qmul (qsquare_times r24 8) x6 in r25
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 103, "start_col": 0, "start_line": 100 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b) (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv_r0_r1 (x14: S.qelem) : S.qelem let qinv_r0_r1 x14 = let x28 = S.qmul (qsquare_times x14 14) x14 in let x56 = S.qmul (qsquare_times x28 28) x28 in let r0 = S.qmul (qsquare_times x56 56) x56 in let r1 = S.qmul (qsquare_times r0 14) x14 in r1 val qinv_r2_r8 (r1 x_101 x_111 x_1011: S.qelem) : S.qelem let qinv_r2_r8 r1 x_101 x_111 x_1011 = let r2 = S.qmul (qsquare_times r1 3) x_101 in let r3 = S.qmul (qsquare_times r2 4) x_111 in let r4 = S.qmul (qsquare_times r3 4) x_101 in let r5 = S.qmul (qsquare_times r4 5) x_1011 in let r6 = S.qmul (qsquare_times r5 4) x_1011 in let r7 = S.qmul (qsquare_times r6 4) x_111 in let r8 = S.qmul (qsquare_times r7 5) x_111 in r8 val qinv_r9_r15 (r8 x_101 x_111 x_1001 x_1101: S.qelem) : S.qelem let qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 = let r9 = S.qmul (qsquare_times r8 6) x_1101 in let r10 = S.qmul (qsquare_times r9 4) x_101 in let r11 = S.qmul (qsquare_times r10 3) x_111 in let r12 = S.qmul (qsquare_times r11 5) x_1001 in let r13 = S.qmul (qsquare_times r12 6) x_101 in let r14 = S.qmul (qsquare_times r13 10) x_111 in let r15 = S.qmul (qsquare_times r14 4) x_111 in r15 val qinv_r16_r23 (r15 x8 x_11 x_1001 x_1011 x_1101: S.qelem) : S.qelem let qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 = let r16 = S.qmul (qsquare_times r15 9) x8 in let r17 = S.qmul (qsquare_times r16 5) x_1001 in let r18 = S.qmul (qsquare_times r17 6) x_1011 in let r19 = S.qmul (qsquare_times r18 4) x_1101 in let r20 = S.qmul (qsquare_times r19 5) x_11 in let r21 = S.qmul (qsquare_times r20 6) x_1101 in let r22 = S.qmul (qsquare_times r21 10) x_1101 in let r23 = S.qmul (qsquare_times r22 4) x_1001 in r23
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r23: Spec.K256.PointOps.qelem -> x_1: Spec.K256.PointOps.qelem -> x6: Spec.K256.PointOps.qelem -> Spec.K256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.K256.PointOps.qelem", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv_r24_r25 r23 x_1 x6 =
let r24 = S.qmul (qsquare_times r23 6) x_1 in let r25 = S.qmul (qsquare_times r24 8) x6 in r25
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.qinv_r2_r8
val qinv_r2_r8 (r1 x_101 x_111 x_1011: S.qelem) : S.qelem
val qinv_r2_r8 (r1 x_101 x_111 x_1011: S.qelem) : S.qelem
let qinv_r2_r8 r1 x_101 x_111 x_1011 = let r2 = S.qmul (qsquare_times r1 3) x_101 in let r3 = S.qmul (qsquare_times r2 4) x_111 in let r4 = S.qmul (qsquare_times r3 4) x_101 in let r5 = S.qmul (qsquare_times r4 5) x_1011 in let r6 = S.qmul (qsquare_times r5 4) x_1011 in let r7 = S.qmul (qsquare_times r6 4) x_111 in let r8 = S.qmul (qsquare_times r7 5) x_111 in r8
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 71, "start_col": 0, "start_line": 63 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b) (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv_r0_r1 (x14: S.qelem) : S.qelem let qinv_r0_r1 x14 = let x28 = S.qmul (qsquare_times x14 14) x14 in let x56 = S.qmul (qsquare_times x28 28) x28 in let r0 = S.qmul (qsquare_times x56 56) x56 in let r1 = S.qmul (qsquare_times r0 14) x14 in r1
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r1: Spec.K256.PointOps.qelem -> x_101: Spec.K256.PointOps.qelem -> x_111: Spec.K256.PointOps.qelem -> x_1011: Spec.K256.PointOps.qelem -> Spec.K256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.K256.PointOps.qelem", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv_r2_r8 r1 x_101 x_111 x_1011 =
let r2 = S.qmul (qsquare_times r1 3) x_101 in let r3 = S.qmul (qsquare_times r2 4) x_111 in let r4 = S.qmul (qsquare_times r3 4) x_101 in let r5 = S.qmul (qsquare_times r4 5) x_1011 in let r6 = S.qmul (qsquare_times r5 4) x_1011 in let r7 = S.qmul (qsquare_times r6 4) x_111 in let r8 = S.qmul (qsquare_times r7 5) x_111 in r8
false
Spec.Frodo.KEM.Encaps.fst
Spec.Frodo.KEM.Encaps.frodo_mul_add_sb_plus_e_plus_mu
val frodo_mul_add_sb_plus_e_plus_mu: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar
val frodo_mul_add_sb_plus_e_plus_mu: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar
let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix in let mu_encode = frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu in let v_matrix = Matrix.add v_matrix mu_encode in v_matrix
{ "file_name": "specs/frodo/Spec.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 75, "start_col": 0, "start_line": 71 }
module Spec.Frodo.KEM.Encaps open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Matrix open Spec.Frodo.Lemmas open Spec.Frodo.Params open Spec.Frodo.Encode open Spec.Frodo.Pack open Spec.Frodo.Sample module LSeq = Lib.Sequence module Matrix = Spec.Matrix module KG = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val frodo_mul_add_sa_plus_e: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> matrix params_nbar (params_n a) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix = let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in let b_matrix = Matrix.add (Matrix.mul sp_matrix a_matrix) ep_matrix in b_matrix val crypto_kem_enc_ct_pack_c1: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> lbytes (ct1bytes_len a) let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix = let bp_matrix = frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix in let ct1 = frodo_pack (params_logq a) bp_matrix in ct1 val frodo_mul_add_sb_plus_e: a:frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix = let b_matrix = frodo_unpack #(params_n a) #params_nbar (params_logq a) b in let v_matrix = Matrix.add (Matrix.mul sp_matrix b_matrix) epp_matrix in v_matrix val frodo_mul_add_sb_plus_e_plus_mu: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Sample.fst.checked", "Spec.Frodo.Random.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.Pack.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "Spec.Frodo.Encode.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "Matrix" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Spec.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Spec.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Spec.Frodo.Params.frodo_alg -> mu: Lib.ByteSequence.lbytes (Spec.Frodo.Params.bytes_mu a) -> b: Lib.ByteSequence.lbytes (Spec.Frodo.Params.publicmatrixbytes_len a) -> sp_matrix: Spec.Matrix.matrix Spec.Frodo.Params.params_nbar (Spec.Frodo.Params.params_n a) -> epp_matrix: Spec.Matrix.matrix Spec.Frodo.Params.params_nbar Spec.Frodo.Params.params_nbar -> Spec.Matrix.matrix Spec.Frodo.Params.params_nbar Spec.Frodo.Params.params_nbar
Prims.Tot
[ "total" ]
[]
[ "Spec.Frodo.Params.frodo_alg", "Lib.ByteSequence.lbytes", "Spec.Frodo.Params.bytes_mu", "Spec.Frodo.Params.publicmatrixbytes_len", "Spec.Matrix.matrix", "Spec.Frodo.Params.params_nbar", "Spec.Frodo.Params.params_n", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Prims.op_Multiply", "Prims.l_Forall", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Prims.l_and", "Prims.op_LessThan", "Prims.eq2", "Spec.Matrix.mget", "Lib.IntTypes.add_mod", "Spec.Matrix.add", "Spec.Frodo.Encode.frodo_key_encode", "Spec.Frodo.Params.params_logq", "Spec.Frodo.Params.params_extracted_bits", "Spec.Frodo.KEM.Encaps.frodo_mul_add_sb_plus_e" ]
[]
false
false
false
false
false
let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix =
let v_matrix = frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix in let mu_encode = frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu in let v_matrix = Matrix.add v_matrix mu_encode in v_matrix
false
Spec.Frodo.KEM.Encaps.fst
Spec.Frodo.KEM.Encaps.frodo_mul_add_sa_plus_e
val frodo_mul_add_sa_plus_e: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> matrix params_nbar (params_n a)
val frodo_mul_add_sa_plus_e: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> matrix params_nbar (params_n a)
let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix = let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in let b_matrix = Matrix.add (Matrix.mul sp_matrix a_matrix) ep_matrix in b_matrix
{ "file_name": "specs/frodo/Spec.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 33, "start_col": 0, "start_line": 30 }
module Spec.Frodo.KEM.Encaps open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Matrix open Spec.Frodo.Lemmas open Spec.Frodo.Params open Spec.Frodo.Encode open Spec.Frodo.Pack open Spec.Frodo.Sample module LSeq = Lib.Sequence module Matrix = Spec.Matrix module KG = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val frodo_mul_add_sa_plus_e: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> matrix params_nbar (params_n a)
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Sample.fst.checked", "Spec.Frodo.Random.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.Pack.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "Spec.Frodo.Encode.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "Matrix" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Spec.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Spec.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Spec.Frodo.Params.frodo_alg -> gen_a: Spec.Frodo.Params.frodo_gen_a -> seed_a: Lib.ByteSequence.lbytes Spec.Frodo.Params.bytes_seed_a -> sp_matrix: Spec.Matrix.matrix Spec.Frodo.Params.params_nbar (Spec.Frodo.Params.params_n a) -> ep_matrix: Spec.Matrix.matrix Spec.Frodo.Params.params_nbar (Spec.Frodo.Params.params_n a) -> Spec.Matrix.matrix Spec.Frodo.Params.params_nbar (Spec.Frodo.Params.params_n a)
Prims.Tot
[ "total" ]
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Lib.ByteSequence.lbytes", "Spec.Frodo.Params.bytes_seed_a", "Spec.Matrix.matrix", "Spec.Frodo.Params.params_nbar", "Spec.Frodo.Params.params_n", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Prims.op_Multiply", "Prims.l_Forall", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Prims.l_and", "Prims.op_LessThan", "Prims.eq2", "Spec.Matrix.mget", "Lib.IntTypes.add_mod", "Spec.Matrix.mul", "Spec.Matrix.add", "Spec.Frodo.Params.frodo_gen_matrix" ]
[]
false
false
false
false
false
let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix =
let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in let b_matrix = Matrix.add (Matrix.mul sp_matrix a_matrix) ep_matrix in b_matrix
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.sqr_mod
val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid
val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid
let sqr_mod x = S.qmul x x
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 27, "start_col": 0, "start_line": 27 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Spec.Exponentiation.sqr_st Spec.K256.PointOps.qelem Hacl.Spec.K256.Qinv.mk_to_nat_mod_comm_monoid
Prims.Tot
[ "total" ]
[]
[ "Spec.K256.PointOps.qelem", "Spec.K256.PointOps.qmul" ]
[]
false
false
false
true
false
let sqr_mod x =
S.qmul x x
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.qinv_r16_r23
val qinv_r16_r23 (r15 x8 x_11 x_1001 x_1011 x_1101: S.qelem) : S.qelem
val qinv_r16_r23 (r15 x8 x_11 x_1001 x_1011 x_1101: S.qelem) : S.qelem
let qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 = let r16 = S.qmul (qsquare_times r15 9) x8 in let r17 = S.qmul (qsquare_times r16 5) x_1001 in let r18 = S.qmul (qsquare_times r17 6) x_1011 in let r19 = S.qmul (qsquare_times r18 4) x_1101 in let r20 = S.qmul (qsquare_times r19 5) x_11 in let r21 = S.qmul (qsquare_times r20 6) x_1101 in let r22 = S.qmul (qsquare_times r21 10) x_1101 in let r23 = S.qmul (qsquare_times r22 4) x_1001 in r23
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 96, "start_col": 0, "start_line": 87 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b) (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv_r0_r1 (x14: S.qelem) : S.qelem let qinv_r0_r1 x14 = let x28 = S.qmul (qsquare_times x14 14) x14 in let x56 = S.qmul (qsquare_times x28 28) x28 in let r0 = S.qmul (qsquare_times x56 56) x56 in let r1 = S.qmul (qsquare_times r0 14) x14 in r1 val qinv_r2_r8 (r1 x_101 x_111 x_1011: S.qelem) : S.qelem let qinv_r2_r8 r1 x_101 x_111 x_1011 = let r2 = S.qmul (qsquare_times r1 3) x_101 in let r3 = S.qmul (qsquare_times r2 4) x_111 in let r4 = S.qmul (qsquare_times r3 4) x_101 in let r5 = S.qmul (qsquare_times r4 5) x_1011 in let r6 = S.qmul (qsquare_times r5 4) x_1011 in let r7 = S.qmul (qsquare_times r6 4) x_111 in let r8 = S.qmul (qsquare_times r7 5) x_111 in r8 val qinv_r9_r15 (r8 x_101 x_111 x_1001 x_1101: S.qelem) : S.qelem let qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 = let r9 = S.qmul (qsquare_times r8 6) x_1101 in let r10 = S.qmul (qsquare_times r9 4) x_101 in let r11 = S.qmul (qsquare_times r10 3) x_111 in let r12 = S.qmul (qsquare_times r11 5) x_1001 in let r13 = S.qmul (qsquare_times r12 6) x_101 in let r14 = S.qmul (qsquare_times r13 10) x_111 in let r15 = S.qmul (qsquare_times r14 4) x_111 in r15
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r15: Spec.K256.PointOps.qelem -> x8: Spec.K256.PointOps.qelem -> x_11: Spec.K256.PointOps.qelem -> x_1001: Spec.K256.PointOps.qelem -> x_1011: Spec.K256.PointOps.qelem -> x_1101: Spec.K256.PointOps.qelem -> Spec.K256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.K256.PointOps.qelem", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 =
let r16 = S.qmul (qsquare_times r15 9) x8 in let r17 = S.qmul (qsquare_times r16 5) x_1001 in let r18 = S.qmul (qsquare_times r17 6) x_1011 in let r19 = S.qmul (qsquare_times r18 4) x_1101 in let r20 = S.qmul (qsquare_times r19 5) x_11 in let r21 = S.qmul (qsquare_times r20 6) x_1101 in let r22 = S.qmul (qsquare_times r21 10) x_1101 in let r23 = S.qmul (qsquare_times r22 4) x_1001 in r23
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.qinv_r0_r25
val qinv_r0_r25 (x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101: S.qelem) : S.qelem
val qinv_r0_r25 (x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101: S.qelem) : S.qelem
let qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let x6 = S.qmul (qsquare_times x_1101 2) x_1011 in let x8 = S.qmul (qsquare_times x6 2) x_11 in let x14 = S.qmul (qsquare_times x8 6) x6 in let r1 = qinv_r0_r1 x14 in let r8 = qinv_r2_r8 r1 x_101 x_111 x_1011 in let r15 = qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 in let r23 = qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 in qinv_r24_r25 r23 x_1 x6
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 116, "start_col": 0, "start_line": 107 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b) (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv_r0_r1 (x14: S.qelem) : S.qelem let qinv_r0_r1 x14 = let x28 = S.qmul (qsquare_times x14 14) x14 in let x56 = S.qmul (qsquare_times x28 28) x28 in let r0 = S.qmul (qsquare_times x56 56) x56 in let r1 = S.qmul (qsquare_times r0 14) x14 in r1 val qinv_r2_r8 (r1 x_101 x_111 x_1011: S.qelem) : S.qelem let qinv_r2_r8 r1 x_101 x_111 x_1011 = let r2 = S.qmul (qsquare_times r1 3) x_101 in let r3 = S.qmul (qsquare_times r2 4) x_111 in let r4 = S.qmul (qsquare_times r3 4) x_101 in let r5 = S.qmul (qsquare_times r4 5) x_1011 in let r6 = S.qmul (qsquare_times r5 4) x_1011 in let r7 = S.qmul (qsquare_times r6 4) x_111 in let r8 = S.qmul (qsquare_times r7 5) x_111 in r8 val qinv_r9_r15 (r8 x_101 x_111 x_1001 x_1101: S.qelem) : S.qelem let qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 = let r9 = S.qmul (qsquare_times r8 6) x_1101 in let r10 = S.qmul (qsquare_times r9 4) x_101 in let r11 = S.qmul (qsquare_times r10 3) x_111 in let r12 = S.qmul (qsquare_times r11 5) x_1001 in let r13 = S.qmul (qsquare_times r12 6) x_101 in let r14 = S.qmul (qsquare_times r13 10) x_111 in let r15 = S.qmul (qsquare_times r14 4) x_111 in r15 val qinv_r16_r23 (r15 x8 x_11 x_1001 x_1011 x_1101: S.qelem) : S.qelem let qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 = let r16 = S.qmul (qsquare_times r15 9) x8 in let r17 = S.qmul (qsquare_times r16 5) x_1001 in let r18 = S.qmul (qsquare_times r17 6) x_1011 in let r19 = S.qmul (qsquare_times r18 4) x_1101 in let r20 = S.qmul (qsquare_times r19 5) x_11 in let r21 = S.qmul (qsquare_times r20 6) x_1101 in let r22 = S.qmul (qsquare_times r21 10) x_1101 in let r23 = S.qmul (qsquare_times r22 4) x_1001 in r23 val qinv_r24_r25 (r23 x_1 x6: S.qelem) : S.qelem let qinv_r24_r25 r23 x_1 x6 = let r24 = S.qmul (qsquare_times r23 6) x_1 in let r25 = S.qmul (qsquare_times r24 8) x6 in r25
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x_1: Spec.K256.PointOps.qelem -> x_11: Spec.K256.PointOps.qelem -> x_101: Spec.K256.PointOps.qelem -> x_111: Spec.K256.PointOps.qelem -> x_1001: Spec.K256.PointOps.qelem -> x_1011: Spec.K256.PointOps.qelem -> x_1101: Spec.K256.PointOps.qelem -> Spec.K256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.K256.PointOps.qelem", "Hacl.Spec.K256.Qinv.qinv_r24_r25", "Hacl.Spec.K256.Qinv.qinv_r16_r23", "Hacl.Spec.K256.Qinv.qinv_r9_r15", "Hacl.Spec.K256.Qinv.qinv_r2_r8", "Hacl.Spec.K256.Qinv.qinv_r0_r1", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101 =
let x6 = S.qmul (qsquare_times x_1101 2) x_1011 in let x8 = S.qmul (qsquare_times x6 2) x_11 in let x14 = S.qmul (qsquare_times x8 6) x6 in let r1 = qinv_r0_r1 x14 in let r8 = qinv_r2_r8 r1 x_101 x_111 x_1011 in let r15 = qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 in let r23 = qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 in qinv_r24_r25 r23 x_1 x6
false
Hacl.Impl.Curve25519.Fields.fst
Hacl.Impl.Curve25519.Fields.copy_felem
val copy_felem: #s:field_spec -> f:felem s -> f':felem s -> Stack unit (requires fun h -> live h f /\ live h f' /\ disjoint f f') (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_seq h1 f == as_seq h0 f')
val copy_felem: #s:field_spec -> f:felem s -> f':felem s -> Stack unit (requires fun h -> live h f /\ live h f' /\ disjoint f f') (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_seq h1 f == as_seq h0 f')
let copy_felem #s f f' = match s with | M51 -> F51.copy_felem f f' | M64 -> F64.copy_felem f f'
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 111, "start_col": 0, "start_line": 108 }
module Hacl.Impl.Curve25519.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer include Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module BSeq = Lib.ByteSequence module LSeq = Lib.Sequence module P = Spec.Curve25519 module F51 = Hacl.Impl.Curve25519.Field51 module F64 = Hacl.Impl.Curve25519.Field64 #set-options "--z3rlimit 50 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --record_options" inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create (v (nlimb s)) (limb_zero s)) /\ as_nat h1 f == 0) let create_felem s = match s with | M51 -> (F51.create_felem ()) <: felem s | M64 -> (F64.create_felem ()) <: felem s inline_for_extraction noextract val load_felem: #s:field_spec -> f:felem s -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint f u64s /\ v (LSeq.index (as_seq h u64s) 3) < pow2 63) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ state_inv_t h1 f /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s)) let load_felem #s f b = match s with | M51 -> F51.load_felem f b | M64 -> F64.load_felem f b val store_felem: #s:field_spec -> b:lbuffer uint64 4ul -> f:felem s -> Stack unit (requires fun h -> live h f /\ live h b /\ disjoint f b /\ state_inv_t h f) (ensures fun h0 _ h1 -> modifies (loc b |+| loc f) h0 h1 /\ as_seq h1 b == BSeq.nat_to_intseq_le 4 (feval h0 f)) [@ Meta.Attribute.specialize ] let store_felem #s b f = match s with | M51 -> F51.store_felem b f | M64 -> F64.store_felem b f inline_for_extraction noextract val set_zero: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 0) let set_zero #s f = match s with | M51 -> F51.set_zero f | M64 -> F64.set_zero f inline_for_extraction noextract val set_one: #s:field_spec -> f:felem s -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 1) let set_one #s f = match s with | M51 -> F51.set_one f | M64 -> F64.set_one f inline_for_extraction noextract val copy_felem: #s:field_spec -> f:felem s -> f':felem s -> Stack unit (requires fun h -> live h f /\ live h f' /\ disjoint f f') (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "Hacl.Impl.Curve25519.Field64.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field64", "short_module": "F64" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Impl.Curve25519.Fields.Core.felem s -> f': Hacl.Impl.Curve25519.Fields.Core.felem s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.field_spec", "Hacl.Impl.Curve25519.Fields.Core.felem", "Hacl.Impl.Curve25519.Field51.copy_felem", "Prims.unit", "Hacl.Impl.Curve25519.Field64.copy_felem" ]
[]
false
true
false
false
false
let copy_felem #s f f' =
match s with | M51 -> F51.copy_felem f f' | M64 -> F64.copy_felem f f'
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.one_mod
val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid
val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid
let one_mod _ = 1
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 21, "start_col": 0, "start_line": 21 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); }
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Spec.Exponentiation.one_st Spec.K256.PointOps.qelem Hacl.Spec.K256.Qinv.mk_to_nat_mod_comm_monoid
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Spec.K256.PointOps.qelem" ]
[]
false
false
false
true
false
let one_mod _ =
1
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.qinv
val qinv: f:S.qelem -> S.qelem
val qinv: f:S.qelem -> S.qelem
let qinv f = let x_1 = f in let x_10 = qsquare_times f 1 in let x_11 = S.qmul x_10 x_1 in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1001 = S.qmul x_10 x_111 in let x_1011 = S.qmul x_10 x_1001 in let x_1101 = S.qmul x_10 x_1011 in qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 130, "start_col": 0, "start_line": 120 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b) (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv_r0_r1 (x14: S.qelem) : S.qelem let qinv_r0_r1 x14 = let x28 = S.qmul (qsquare_times x14 14) x14 in let x56 = S.qmul (qsquare_times x28 28) x28 in let r0 = S.qmul (qsquare_times x56 56) x56 in let r1 = S.qmul (qsquare_times r0 14) x14 in r1 val qinv_r2_r8 (r1 x_101 x_111 x_1011: S.qelem) : S.qelem let qinv_r2_r8 r1 x_101 x_111 x_1011 = let r2 = S.qmul (qsquare_times r1 3) x_101 in let r3 = S.qmul (qsquare_times r2 4) x_111 in let r4 = S.qmul (qsquare_times r3 4) x_101 in let r5 = S.qmul (qsquare_times r4 5) x_1011 in let r6 = S.qmul (qsquare_times r5 4) x_1011 in let r7 = S.qmul (qsquare_times r6 4) x_111 in let r8 = S.qmul (qsquare_times r7 5) x_111 in r8 val qinv_r9_r15 (r8 x_101 x_111 x_1001 x_1101: S.qelem) : S.qelem let qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 = let r9 = S.qmul (qsquare_times r8 6) x_1101 in let r10 = S.qmul (qsquare_times r9 4) x_101 in let r11 = S.qmul (qsquare_times r10 3) x_111 in let r12 = S.qmul (qsquare_times r11 5) x_1001 in let r13 = S.qmul (qsquare_times r12 6) x_101 in let r14 = S.qmul (qsquare_times r13 10) x_111 in let r15 = S.qmul (qsquare_times r14 4) x_111 in r15 val qinv_r16_r23 (r15 x8 x_11 x_1001 x_1011 x_1101: S.qelem) : S.qelem let qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 = let r16 = S.qmul (qsquare_times r15 9) x8 in let r17 = S.qmul (qsquare_times r16 5) x_1001 in let r18 = S.qmul (qsquare_times r17 6) x_1011 in let r19 = S.qmul (qsquare_times r18 4) x_1101 in let r20 = S.qmul (qsquare_times r19 5) x_11 in let r21 = S.qmul (qsquare_times r20 6) x_1101 in let r22 = S.qmul (qsquare_times r21 10) x_1101 in let r23 = S.qmul (qsquare_times r22 4) x_1001 in r23 val qinv_r24_r25 (r23 x_1 x6: S.qelem) : S.qelem let qinv_r24_r25 r23 x_1 x6 = let r24 = S.qmul (qsquare_times r23 6) x_1 in let r25 = S.qmul (qsquare_times r24 8) x6 in r25 val qinv_r0_r25 (x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101: S.qelem) : S.qelem let qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let x6 = S.qmul (qsquare_times x_1101 2) x_1011 in let x8 = S.qmul (qsquare_times x6 2) x_11 in let x14 = S.qmul (qsquare_times x8 6) x6 in let r1 = qinv_r0_r1 x14 in let r8 = qinv_r2_r8 r1 x_101 x_111 x_1011 in let r15 = qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 in let r23 = qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 in qinv_r24_r25 r23 x_1 x6
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.K256.PointOps.qelem -> Spec.K256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.K256.PointOps.qelem", "Hacl.Spec.K256.Qinv.qinv_r0_r25", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv f =
let x_1 = f in let x_10 = qsquare_times f 1 in let x_11 = S.qmul x_10 x_1 in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1001 = S.qmul x_10 x_111 in let x_1011 = S.qmul x_10 x_1001 in let x_1101 = S.qmul x_10 x_1011 in qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101
false
Spec.Frodo.KEM.Encaps.fst
Spec.Frodo.KEM.Encaps.frodo_mul_add_sb_plus_e
val frodo_mul_add_sb_plus_e: a:frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar
val frodo_mul_add_sb_plus_e: a:frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar
let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix = let b_matrix = frodo_unpack #(params_n a) #params_nbar (params_logq a) b in let v_matrix = Matrix.add (Matrix.mul sp_matrix b_matrix) epp_matrix in v_matrix
{ "file_name": "specs/frodo/Spec.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 60, "start_col": 0, "start_line": 57 }
module Spec.Frodo.KEM.Encaps open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Matrix open Spec.Frodo.Lemmas open Spec.Frodo.Params open Spec.Frodo.Encode open Spec.Frodo.Pack open Spec.Frodo.Sample module LSeq = Lib.Sequence module Matrix = Spec.Matrix module KG = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val frodo_mul_add_sa_plus_e: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> matrix params_nbar (params_n a) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix = let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in let b_matrix = Matrix.add (Matrix.mul sp_matrix a_matrix) ep_matrix in b_matrix val crypto_kem_enc_ct_pack_c1: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> lbytes (ct1bytes_len a) let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix = let bp_matrix = frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix in let ct1 = frodo_pack (params_logq a) bp_matrix in ct1 val frodo_mul_add_sb_plus_e: a:frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Sample.fst.checked", "Spec.Frodo.Random.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.Pack.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "Spec.Frodo.Encode.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "Matrix" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Spec.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Spec.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Spec.Frodo.Params.frodo_alg -> b: Lib.ByteSequence.lbytes (Spec.Frodo.Params.publicmatrixbytes_len a) -> sp_matrix: Spec.Matrix.matrix Spec.Frodo.Params.params_nbar (Spec.Frodo.Params.params_n a) -> epp_matrix: Spec.Matrix.matrix Spec.Frodo.Params.params_nbar Spec.Frodo.Params.params_nbar -> Spec.Matrix.matrix Spec.Frodo.Params.params_nbar Spec.Frodo.Params.params_nbar
Prims.Tot
[ "total" ]
[]
[ "Spec.Frodo.Params.frodo_alg", "Lib.ByteSequence.lbytes", "Spec.Frodo.Params.publicmatrixbytes_len", "Spec.Matrix.matrix", "Spec.Frodo.Params.params_nbar", "Spec.Frodo.Params.params_n", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Prims.op_Multiply", "Prims.l_Forall", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Prims.l_and", "Prims.op_LessThan", "Prims.eq2", "Spec.Matrix.mget", "Lib.IntTypes.add_mod", "Spec.Matrix.mul", "Spec.Matrix.add", "Spec.Frodo.Pack.frodo_unpack", "Spec.Frodo.Params.params_logq" ]
[]
false
false
false
false
false
let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix =
let b_matrix = frodo_unpack #(params_n a) #params_nbar (params_logq a) b in let v_matrix = Matrix.add (Matrix.mul sp_matrix b_matrix) epp_matrix in v_matrix
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.qinv_r9_r15
val qinv_r9_r15 (r8 x_101 x_111 x_1001 x_1101: S.qelem) : S.qelem
val qinv_r9_r15 (r8 x_101 x_111 x_1001 x_1101: S.qelem) : S.qelem
let qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 = let r9 = S.qmul (qsquare_times r8 6) x_1101 in let r10 = S.qmul (qsquare_times r9 4) x_101 in let r11 = S.qmul (qsquare_times r10 3) x_111 in let r12 = S.qmul (qsquare_times r11 5) x_1001 in let r13 = S.qmul (qsquare_times r12 6) x_101 in let r14 = S.qmul (qsquare_times r13 10) x_111 in let r15 = S.qmul (qsquare_times r14 4) x_111 in r15
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 83, "start_col": 0, "start_line": 75 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b) (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv_r0_r1 (x14: S.qelem) : S.qelem let qinv_r0_r1 x14 = let x28 = S.qmul (qsquare_times x14 14) x14 in let x56 = S.qmul (qsquare_times x28 28) x28 in let r0 = S.qmul (qsquare_times x56 56) x56 in let r1 = S.qmul (qsquare_times r0 14) x14 in r1 val qinv_r2_r8 (r1 x_101 x_111 x_1011: S.qelem) : S.qelem let qinv_r2_r8 r1 x_101 x_111 x_1011 = let r2 = S.qmul (qsquare_times r1 3) x_101 in let r3 = S.qmul (qsquare_times r2 4) x_111 in let r4 = S.qmul (qsquare_times r3 4) x_101 in let r5 = S.qmul (qsquare_times r4 5) x_1011 in let r6 = S.qmul (qsquare_times r5 4) x_1011 in let r7 = S.qmul (qsquare_times r6 4) x_111 in let r8 = S.qmul (qsquare_times r7 5) x_111 in r8
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r8: Spec.K256.PointOps.qelem -> x_101: Spec.K256.PointOps.qelem -> x_111: Spec.K256.PointOps.qelem -> x_1001: Spec.K256.PointOps.qelem -> x_1101: Spec.K256.PointOps.qelem -> Spec.K256.PointOps.qelem
Prims.Tot
[ "total" ]
[]
[ "Spec.K256.PointOps.qelem", "Spec.K256.PointOps.qmul", "Hacl.Spec.K256.Qinv.qsquare_times" ]
[]
false
false
false
true
false
let qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 =
let r9 = S.qmul (qsquare_times r8 6) x_1101 in let r10 = S.qmul (qsquare_times r9 4) x_101 in let r11 = S.qmul (qsquare_times r10 3) x_111 in let r12 = S.qmul (qsquare_times r11 5) x_1001 in let r13 = S.qmul (qsquare_times r12 6) x_101 in let r14 = S.qmul (qsquare_times r13 10) x_111 in let r15 = S.qmul (qsquare_times r14 4) x_111 in r15
false
Spec.Frodo.KEM.Encaps.fst
Spec.Frodo.KEM.Encaps.crypto_kem_enc_
val crypto_kem_enc_: a:frodo_alg -> gen_a:frodo_gen_a -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> lbytes (crypto_ciphertextbytes a) & lbytes (crypto_bytes a)
val crypto_kem_enc_: a:frodo_alg -> gen_a:frodo_gen_a -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> lbytes (crypto_ciphertextbytes a) & lbytes (crypto_bytes a)
let crypto_kem_enc_ a gen_a mu pk = let seed_se_k = crypto_kem_enc_seed_se_k a mu pk in let seed_se = LSeq.sub seed_se_k 0 (crypto_bytes a) in let k = LSeq.sub seed_se_k (crypto_bytes a) (crypto_bytes a) in let ct = crypto_kem_enc_ct a gen_a mu pk seed_se in let ss = crypto_kem_enc_ss a k ct in ct, ss
{ "file_name": "specs/frodo/Spec.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 8, "end_line": 166, "start_col": 0, "start_line": 159 }
module Spec.Frodo.KEM.Encaps open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Matrix open Spec.Frodo.Lemmas open Spec.Frodo.Params open Spec.Frodo.Encode open Spec.Frodo.Pack open Spec.Frodo.Sample module LSeq = Lib.Sequence module Matrix = Spec.Matrix module KG = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val frodo_mul_add_sa_plus_e: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> matrix params_nbar (params_n a) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix = let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in let b_matrix = Matrix.add (Matrix.mul sp_matrix a_matrix) ep_matrix in b_matrix val crypto_kem_enc_ct_pack_c1: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> lbytes (ct1bytes_len a) let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix = let bp_matrix = frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix in let ct1 = frodo_pack (params_logq a) bp_matrix in ct1 val frodo_mul_add_sb_plus_e: a:frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix = let b_matrix = frodo_unpack #(params_n a) #params_nbar (params_logq a) b in let v_matrix = Matrix.add (Matrix.mul sp_matrix b_matrix) epp_matrix in v_matrix val frodo_mul_add_sb_plus_e_plus_mu: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix in let mu_encode = frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu in let v_matrix = Matrix.add v_matrix mu_encode in v_matrix val crypto_kem_enc_ct_pack_c2: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> lbytes (ct2bytes_len a) let crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix in let ct2 = frodo_pack (params_logq a) v_matrix in ct2 val get_sp_ep_epp_matrices: a:frodo_alg -> seed_se:lbytes (crypto_bytes a) -> matrix params_nbar (params_n a) & matrix params_nbar (params_n a) & matrix params_nbar params_nbar let get_sp_ep_epp_matrices a seed_se = let s_bytes_len = secretmatrixbytes_len a in let r = KG.frodo_shake_r a (u8 0x96) seed_se (2 * s_bytes_len + 2 * params_nbar * params_nbar) in let sp_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r 0 s_bytes_len) in let ep_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r s_bytes_len s_bytes_len) in let epp_matrix = frodo_sample_matrix a params_nbar params_nbar (LSeq.sub r (2 * s_bytes_len) (2 * params_nbar * params_nbar)) in sp_matrix, ep_matrix, epp_matrix val crypto_kem_enc_ct: a:frodo_alg -> gen_a:frodo_gen_a -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> seed_se:lbytes (crypto_bytes a) -> lbytes (crypto_ciphertextbytes a) let crypto_kem_enc_ct a gen_a mu pk seed_se = expand_crypto_publickeybytes a; let seed_a = LSeq.sub pk 0 bytes_seed_a in let b = LSeq.sub pk bytes_seed_a (publicmatrixbytes_len a) in let sp_matrix, ep_matrix, epp_matrix = get_sp_ep_epp_matrices a seed_se in let c1 = crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix in let c2 = crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix in expand_crypto_ciphertextbytes a; let ct = concat c1 c2 in ct val crypto_kem_enc_ss: a:frodo_alg -> k:lbytes (crypto_bytes a) -> ct:lbytes (crypto_ciphertextbytes a) -> lbytes (crypto_bytes a) let crypto_kem_enc_ss a k ct = let shake_input_ss = concat ct k in let ss = frodo_shake a (crypto_ciphertextbytes a + crypto_bytes a) shake_input_ss (crypto_bytes a) in ss val crypto_kem_enc_seed_se_k: a:frodo_alg -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> lbytes (2 * crypto_bytes a) let crypto_kem_enc_seed_se_k a mu pk = let pkh = frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) in let pkh_mu = concat pkh mu in let seed_se_k = frodo_shake a (bytes_pkhash a + bytes_mu a) pkh_mu (2 * crypto_bytes a) in seed_se_k val crypto_kem_enc_: a:frodo_alg -> gen_a:frodo_gen_a -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> lbytes (crypto_ciphertextbytes a) & lbytes (crypto_bytes a)
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Sample.fst.checked", "Spec.Frodo.Random.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.Pack.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "Spec.Frodo.Encode.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "Matrix" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Spec.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Spec.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Spec.Frodo.Params.frodo_alg -> gen_a: Spec.Frodo.Params.frodo_gen_a -> mu: Lib.ByteSequence.lbytes (Spec.Frodo.Params.bytes_mu a) -> pk: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_publickeybytes a) -> Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_ciphertextbytes a) * Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_bytes a)
Prims.Tot
[ "total" ]
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Lib.ByteSequence.lbytes", "Spec.Frodo.Params.bytes_mu", "Spec.Frodo.Params.crypto_publickeybytes", "FStar.Pervasives.Native.Mktuple2", "Spec.Frodo.Params.crypto_ciphertextbytes", "Spec.Frodo.Params.crypto_bytes", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Spec.Frodo.KEM.Encaps.crypto_kem_enc_ss", "Spec.Frodo.KEM.Encaps.crypto_kem_enc_ct", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.slice", "Prims.op_Multiply", "Prims.op_Addition", "Prims.l_Forall", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.index", "Lib.Sequence.sub", "Lib.IntTypes.uint_t", "FStar.Mul.op_Star", "Spec.Frodo.KEM.Encaps.crypto_kem_enc_seed_se_k", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let crypto_kem_enc_ a gen_a mu pk =
let seed_se_k = crypto_kem_enc_seed_se_k a mu pk in let seed_se = LSeq.sub seed_se_k 0 (crypto_bytes a) in let k = LSeq.sub seed_se_k (crypto_bytes a) (crypto_bytes a) in let ct = crypto_kem_enc_ct a gen_a mu pk seed_se in let ss = crypto_kem_enc_ss a k ct in ct, ss
false
Spec.Frodo.KEM.Encaps.fst
Spec.Frodo.KEM.Encaps.get_sp_ep_epp_matrices
val get_sp_ep_epp_matrices: a:frodo_alg -> seed_se:lbytes (crypto_bytes a) -> matrix params_nbar (params_n a) & matrix params_nbar (params_n a) & matrix params_nbar params_nbar
val get_sp_ep_epp_matrices: a:frodo_alg -> seed_se:lbytes (crypto_bytes a) -> matrix params_nbar (params_n a) & matrix params_nbar (params_n a) & matrix params_nbar params_nbar
let get_sp_ep_epp_matrices a seed_se = let s_bytes_len = secretmatrixbytes_len a in let r = KG.frodo_shake_r a (u8 0x96) seed_se (2 * s_bytes_len + 2 * params_nbar * params_nbar) in let sp_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r 0 s_bytes_len) in let ep_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r s_bytes_len s_bytes_len) in let epp_matrix = frodo_sample_matrix a params_nbar params_nbar (LSeq.sub r (2 * s_bytes_len) (2 * params_nbar * params_nbar)) in sp_matrix, ep_matrix, epp_matrix
{ "file_name": "specs/frodo/Spec.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 103, "start_col": 0, "start_line": 97 }
module Spec.Frodo.KEM.Encaps open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Matrix open Spec.Frodo.Lemmas open Spec.Frodo.Params open Spec.Frodo.Encode open Spec.Frodo.Pack open Spec.Frodo.Sample module LSeq = Lib.Sequence module Matrix = Spec.Matrix module KG = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val frodo_mul_add_sa_plus_e: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> matrix params_nbar (params_n a) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix = let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in let b_matrix = Matrix.add (Matrix.mul sp_matrix a_matrix) ep_matrix in b_matrix val crypto_kem_enc_ct_pack_c1: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> lbytes (ct1bytes_len a) let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix = let bp_matrix = frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix in let ct1 = frodo_pack (params_logq a) bp_matrix in ct1 val frodo_mul_add_sb_plus_e: a:frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix = let b_matrix = frodo_unpack #(params_n a) #params_nbar (params_logq a) b in let v_matrix = Matrix.add (Matrix.mul sp_matrix b_matrix) epp_matrix in v_matrix val frodo_mul_add_sb_plus_e_plus_mu: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix in let mu_encode = frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu in let v_matrix = Matrix.add v_matrix mu_encode in v_matrix val crypto_kem_enc_ct_pack_c2: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> lbytes (ct2bytes_len a) let crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix in let ct2 = frodo_pack (params_logq a) v_matrix in ct2 val get_sp_ep_epp_matrices: a:frodo_alg -> seed_se:lbytes (crypto_bytes a) -> matrix params_nbar (params_n a) & matrix params_nbar (params_n a) & matrix params_nbar params_nbar
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Sample.fst.checked", "Spec.Frodo.Random.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.Pack.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "Spec.Frodo.Encode.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "Matrix" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Spec.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Spec.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Spec.Frodo.Params.frodo_alg -> seed_se: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_bytes a) -> (Spec.Matrix.matrix Spec.Frodo.Params.params_nbar (Spec.Frodo.Params.params_n a) * Spec.Matrix.matrix Spec.Frodo.Params.params_nbar (Spec.Frodo.Params.params_n a)) * Spec.Matrix.matrix Spec.Frodo.Params.params_nbar Spec.Frodo.Params.params_nbar
Prims.Tot
[ "total" ]
[]
[ "Spec.Frodo.Params.frodo_alg", "Lib.ByteSequence.lbytes", "Spec.Frodo.Params.crypto_bytes", "FStar.Pervasives.Native.Mktuple3", "Spec.Matrix.matrix", "Spec.Frodo.Params.params_nbar", "Spec.Frodo.Params.params_n", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Prims.op_Multiply", "Spec.Frodo.Sample.frodo_sample_matrix", "Lib.Sequence.sub", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Prims.op_Addition", "FStar.Mul.op_Star", "Spec.Frodo.KEM.KeyGen.frodo_shake_r", "Lib.IntTypes.u8", "Prims.pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "Prims.pow2", "Spec.Frodo.Params.secretmatrixbytes_len", "FStar.Pervasives.Native.tuple3" ]
[]
false
false
false
false
false
let get_sp_ep_epp_matrices a seed_se =
let s_bytes_len = secretmatrixbytes_len a in let r = KG.frodo_shake_r a (u8 0x96) seed_se (2 * s_bytes_len + (2 * params_nbar) * params_nbar) in let sp_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r 0 s_bytes_len) in let ep_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r s_bytes_len s_bytes_len) in let epp_matrix = frodo_sample_matrix a params_nbar params_nbar (LSeq.sub r (2 * s_bytes_len) ((2 * params_nbar) * params_nbar)) in sp_matrix, ep_matrix, epp_matrix
false
Platform.Error.fst
Platform.Error.correct
val correct (#a #r: Type) (x: r) : Tot (optResult a r)
val correct (#a #r: Type) (x: r) : Tot (optResult a r)
let correct (#a:Type) (#r:Type) (x:r) : Tot (optResult a r) = Correct x
{ "file_name": "ucontrib/Platform/fst/Platform.Error.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 71, "end_line": 32, "start_col": 0, "start_line": 32 }
(* Copyright 2008-2018 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 Platform.Error type optResult 'a 'b = | Error of 'a | Correct of 'b //allowing inverting optResult without having to globally increase the fuel just for this val invertOptResult : a:Type -> b:Type -> Lemma (requires True) (ensures (forall (x:optResult a b). Error? x \/ Correct? x)) [SMTPat (optResult a b)] let invertOptResult a b = allow_inversion (optResult a b) assume val perror: string -> int -> string -> Tot string
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.IO.fst.checked" ], "interface_file": false, "source_file": "Platform.Error.fst" }
[ { "abbrev": false, "full_module": "Platform", "short_module": null }, { "abbrev": false, "full_module": "Platform", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: r -> Platform.Error.optResult a r
Prims.Tot
[ "total" ]
[]
[ "Platform.Error.Correct", "Platform.Error.optResult" ]
[]
false
false
false
true
false
let correct (#a #r: Type) (x: r) : Tot (optResult a r) =
Correct x
false
Platform.Error.fst
Platform.Error.unreachable
val unreachable (#a: Type) (s: string) : Div a (requires False) (ensures (fun _ -> False))
val unreachable (#a: Type) (s: string) : Div a (requires False) (ensures (fun _ -> False))
let rec unreachable (#a:Type) (s:string) : Div a (requires False) (ensures (fun _ -> False)) = let _ = FStar.IO.debug_print_string ("Platform.Error.unreachable: " ^ s) in unreachable s
{ "file_name": "ucontrib/Platform/fst/Platform.Error.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 49, "start_col": 0, "start_line": 45 }
(* Copyright 2008-2018 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 Platform.Error type optResult 'a 'b = | Error of 'a | Correct of 'b //allowing inverting optResult without having to globally increase the fuel just for this val invertOptResult : a:Type -> b:Type -> Lemma (requires True) (ensures (forall (x:optResult a b). Error? x \/ Correct? x)) [SMTPat (optResult a b)] let invertOptResult a b = allow_inversion (optResult a b) assume val perror: string -> int -> string -> Tot string //assume val correct: #a:Type -> #b:Type -> x:a -> Tot (y:(optResult b a){y = Correct(x)}) let correct (#a:Type) (#r:Type) (x:r) : Tot (optResult a r) = Correct x (* Both unexpected and unreachable are aliases for failwith; they indicate code that should never be executed at runtime. This is verified by typing only for the unreachable function; this matters e.g. when dynamic errors are security-critical *) let rec unexpected (#a:Type) (s:string) : Div a (requires True) (ensures (fun _ -> True)) = let _ = FStar.IO.debug_print_string ("Platform.Error.unexpected: " ^ s) in unexpected s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.IO.fst.checked" ], "interface_file": false, "source_file": "Platform.Error.fst" }
[ { "abbrev": false, "full_module": "Platform", "short_module": null }, { "abbrev": false, "full_module": "Platform", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Prims.string -> FStar.Pervasives.Div a
FStar.Pervasives.Div
[]
[]
[ "Prims.string", "Platform.Error.unreachable", "Prims.bool", "FStar.IO.debug_print_string", "Prims.op_Hat", "Prims.l_False" ]
[ "recursion" ]
false
true
false
false
false
let rec unreachable (#a: Type) (s: string) : Div a (requires False) (ensures (fun _ -> False)) =
let _ = FStar.IO.debug_print_string ("Platform.Error.unreachable: " ^ s) in unreachable s
false
Spec.Frodo.KEM.Encaps.fst
Spec.Frodo.KEM.Encaps.crypto_kem_enc_ct_pack_c1
val crypto_kem_enc_ct_pack_c1: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> lbytes (ct1bytes_len a)
val crypto_kem_enc_ct_pack_c1: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> lbytes (ct1bytes_len a)
let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix = let bp_matrix = frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix in let ct1 = frodo_pack (params_logq a) bp_matrix in ct1
{ "file_name": "specs/frodo/Spec.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 47, "start_col": 0, "start_line": 44 }
module Spec.Frodo.KEM.Encaps open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Matrix open Spec.Frodo.Lemmas open Spec.Frodo.Params open Spec.Frodo.Encode open Spec.Frodo.Pack open Spec.Frodo.Sample module LSeq = Lib.Sequence module Matrix = Spec.Matrix module KG = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val frodo_mul_add_sa_plus_e: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> matrix params_nbar (params_n a) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix = let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in let b_matrix = Matrix.add (Matrix.mul sp_matrix a_matrix) ep_matrix in b_matrix val crypto_kem_enc_ct_pack_c1: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> lbytes (ct1bytes_len a)
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Sample.fst.checked", "Spec.Frodo.Random.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.Pack.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "Spec.Frodo.Encode.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "Matrix" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Spec.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Spec.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Spec.Frodo.Params.frodo_alg -> gen_a: Spec.Frodo.Params.frodo_gen_a -> seed_a: Lib.ByteSequence.lbytes Spec.Frodo.Params.bytes_seed_a -> sp_matrix: Spec.Matrix.matrix Spec.Frodo.Params.params_nbar (Spec.Frodo.Params.params_n a) -> ep_matrix: Spec.Matrix.matrix Spec.Frodo.Params.params_nbar (Spec.Frodo.Params.params_n a) -> Lib.ByteSequence.lbytes (Spec.Frodo.Params.ct1bytes_len a)
Prims.Tot
[ "total" ]
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Lib.ByteSequence.lbytes", "Spec.Frodo.Params.bytes_seed_a", "Spec.Matrix.matrix", "Spec.Frodo.Params.params_nbar", "Spec.Frodo.Params.params_n", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Prims.op_Multiply", "Spec.Frodo.Params.params_logq", "Prims.op_Division", "Spec.Frodo.Pack.frodo_pack", "Lib.IntTypes.U16", "Spec.Frodo.KEM.Encaps.frodo_mul_add_sa_plus_e", "Spec.Frodo.Params.ct1bytes_len" ]
[]
false
false
false
false
false
let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix =
let bp_matrix = frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix in let ct1 = frodo_pack (params_logq a) bp_matrix in ct1
false
Hacl.Impl.Curve25519.Fields.fst
Hacl.Impl.Curve25519.Fields.create_felem
val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create (v (nlimb s)) (limb_zero s)) /\ as_nat h1 f == 0)
val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create (v (nlimb s)) (limb_zero s)) /\ as_nat h1 f == 0)
let create_felem s = match s with | M51 -> (F51.create_felem ()) <: felem s | M64 -> (F64.create_felem ()) <: felem s
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 34, "start_col": 0, "start_line": 31 }
module Hacl.Impl.Curve25519.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer include Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module BSeq = Lib.ByteSequence module LSeq = Lib.Sequence module P = Spec.Curve25519 module F51 = Hacl.Impl.Curve25519.Field51 module F64 = Hacl.Impl.Curve25519.Field64 #set-options "--z3rlimit 50 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --record_options" inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create (v (nlimb s)) (limb_zero s)) /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "Hacl.Impl.Curve25519.Field64.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field64", "short_module": "F64" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Hacl.Impl.Curve25519.Fields.Core.field_spec -> FStar.HyperStack.ST.StackInline (Hacl.Impl.Curve25519.Fields.Core.felem s)
FStar.HyperStack.ST.StackInline
[]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.field_spec", "Hacl.Impl.Curve25519.Field51.create_felem", "Hacl.Impl.Curve25519.Field51.felem", "Hacl.Impl.Curve25519.Fields.Core.felem", "Hacl.Impl.Curve25519.Field64.create_felem", "Hacl.Impl.Curve25519.Field64.felem" ]
[]
false
true
false
false
false
let create_felem s =
match s with | M51 -> (F51.create_felem ()) <: felem s | M64 -> (F64.create_felem ()) <: felem s
false
Platform.Error.fst
Platform.Error.unexpected
val unexpected (#a: Type) (s: string) : Div a (requires True) (ensures (fun _ -> True))
val unexpected (#a: Type) (s: string) : Div a (requires True) (ensures (fun _ -> True))
let rec unexpected (#a:Type) (s:string) : Div a (requires True) (ensures (fun _ -> True)) = let _ = FStar.IO.debug_print_string ("Platform.Error.unexpected: " ^ s) in unexpected s
{ "file_name": "ucontrib/Platform/fst/Platform.Error.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 14, "end_line": 43, "start_col": 0, "start_line": 39 }
(* Copyright 2008-2018 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 Platform.Error type optResult 'a 'b = | Error of 'a | Correct of 'b //allowing inverting optResult without having to globally increase the fuel just for this val invertOptResult : a:Type -> b:Type -> Lemma (requires True) (ensures (forall (x:optResult a b). Error? x \/ Correct? x)) [SMTPat (optResult a b)] let invertOptResult a b = allow_inversion (optResult a b) assume val perror: string -> int -> string -> Tot string //assume val correct: #a:Type -> #b:Type -> x:a -> Tot (y:(optResult b a){y = Correct(x)}) let correct (#a:Type) (#r:Type) (x:r) : Tot (optResult a r) = Correct x (* Both unexpected and unreachable are aliases for failwith; they indicate code that should never be executed at runtime. This is verified by typing only for the unreachable function; this matters e.g. when dynamic errors are security-critical *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.IO.fst.checked" ], "interface_file": false, "source_file": "Platform.Error.fst" }
[ { "abbrev": false, "full_module": "Platform", "short_module": null }, { "abbrev": false, "full_module": "Platform", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Prims.string -> FStar.Pervasives.Div a
FStar.Pervasives.Div
[]
[]
[ "Prims.string", "Platform.Error.unexpected", "Prims.bool", "FStar.IO.debug_print_string", "Prims.op_Hat", "Prims.l_True" ]
[ "recursion" ]
false
true
false
false
false
let rec unexpected (#a: Type) (s: string) : Div a (requires True) (ensures (fun _ -> True)) =
let _ = FStar.IO.debug_print_string ("Platform.Error.unexpected: " ^ s) in unexpected s
false
Spec.Frodo.KEM.Encaps.fst
Spec.Frodo.KEM.Encaps.crypto_kem_enc_seed_se_k
val crypto_kem_enc_seed_se_k: a:frodo_alg -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> lbytes (2 * crypto_bytes a)
val crypto_kem_enc_seed_se_k: a:frodo_alg -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> lbytes (2 * crypto_bytes a)
let crypto_kem_enc_seed_se_k a mu pk = let pkh = frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) in let pkh_mu = concat pkh mu in let seed_se_k = frodo_shake a (bytes_pkhash a + bytes_mu a) pkh_mu (2 * crypto_bytes a) in seed_se_k
{ "file_name": "specs/frodo/Spec.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 11, "end_line": 149, "start_col": 0, "start_line": 145 }
module Spec.Frodo.KEM.Encaps open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Matrix open Spec.Frodo.Lemmas open Spec.Frodo.Params open Spec.Frodo.Encode open Spec.Frodo.Pack open Spec.Frodo.Sample module LSeq = Lib.Sequence module Matrix = Spec.Matrix module KG = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val frodo_mul_add_sa_plus_e: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> matrix params_nbar (params_n a) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix = let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in let b_matrix = Matrix.add (Matrix.mul sp_matrix a_matrix) ep_matrix in b_matrix val crypto_kem_enc_ct_pack_c1: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> lbytes (ct1bytes_len a) let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix = let bp_matrix = frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix in let ct1 = frodo_pack (params_logq a) bp_matrix in ct1 val frodo_mul_add_sb_plus_e: a:frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix = let b_matrix = frodo_unpack #(params_n a) #params_nbar (params_logq a) b in let v_matrix = Matrix.add (Matrix.mul sp_matrix b_matrix) epp_matrix in v_matrix val frodo_mul_add_sb_plus_e_plus_mu: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix in let mu_encode = frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu in let v_matrix = Matrix.add v_matrix mu_encode in v_matrix val crypto_kem_enc_ct_pack_c2: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> lbytes (ct2bytes_len a) let crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix in let ct2 = frodo_pack (params_logq a) v_matrix in ct2 val get_sp_ep_epp_matrices: a:frodo_alg -> seed_se:lbytes (crypto_bytes a) -> matrix params_nbar (params_n a) & matrix params_nbar (params_n a) & matrix params_nbar params_nbar let get_sp_ep_epp_matrices a seed_se = let s_bytes_len = secretmatrixbytes_len a in let r = KG.frodo_shake_r a (u8 0x96) seed_se (2 * s_bytes_len + 2 * params_nbar * params_nbar) in let sp_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r 0 s_bytes_len) in let ep_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r s_bytes_len s_bytes_len) in let epp_matrix = frodo_sample_matrix a params_nbar params_nbar (LSeq.sub r (2 * s_bytes_len) (2 * params_nbar * params_nbar)) in sp_matrix, ep_matrix, epp_matrix val crypto_kem_enc_ct: a:frodo_alg -> gen_a:frodo_gen_a -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> seed_se:lbytes (crypto_bytes a) -> lbytes (crypto_ciphertextbytes a) let crypto_kem_enc_ct a gen_a mu pk seed_se = expand_crypto_publickeybytes a; let seed_a = LSeq.sub pk 0 bytes_seed_a in let b = LSeq.sub pk bytes_seed_a (publicmatrixbytes_len a) in let sp_matrix, ep_matrix, epp_matrix = get_sp_ep_epp_matrices a seed_se in let c1 = crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix in let c2 = crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix in expand_crypto_ciphertextbytes a; let ct = concat c1 c2 in ct val crypto_kem_enc_ss: a:frodo_alg -> k:lbytes (crypto_bytes a) -> ct:lbytes (crypto_ciphertextbytes a) -> lbytes (crypto_bytes a) let crypto_kem_enc_ss a k ct = let shake_input_ss = concat ct k in let ss = frodo_shake a (crypto_ciphertextbytes a + crypto_bytes a) shake_input_ss (crypto_bytes a) in ss val crypto_kem_enc_seed_se_k: a:frodo_alg -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> lbytes (2 * crypto_bytes a)
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Sample.fst.checked", "Spec.Frodo.Random.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.Pack.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "Spec.Frodo.Encode.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "Matrix" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Spec.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Spec.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Spec.Frodo.Params.frodo_alg -> mu: Lib.ByteSequence.lbytes (Spec.Frodo.Params.bytes_mu a) -> pk: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_publickeybytes a) -> Lib.ByteSequence.lbytes (2 * Spec.Frodo.Params.crypto_bytes a)
Prims.Tot
[ "total" ]
[]
[ "Spec.Frodo.Params.frodo_alg", "Lib.ByteSequence.lbytes", "Spec.Frodo.Params.bytes_mu", "Spec.Frodo.Params.crypto_publickeybytes", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Prims.op_Multiply", "Spec.Frodo.Params.crypto_bytes", "Spec.Frodo.Params.frodo_shake", "Prims.op_Addition", "Spec.Frodo.Params.bytes_pkhash", "FStar.Mul.op_Star", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.append", "Lib.Sequence.concat", "Lib.IntTypes.uint_t" ]
[]
false
false
false
false
false
let crypto_kem_enc_seed_se_k a mu pk =
let pkh = frodo_shake a (crypto_publickeybytes a) pk (bytes_pkhash a) in let pkh_mu = concat pkh mu in let seed_se_k = frodo_shake a (bytes_pkhash a + bytes_mu a) pkh_mu (2 * crypto_bytes a) in seed_se_k
false
Spec.Frodo.KEM.Encaps.fst
Spec.Frodo.KEM.Encaps.crypto_kem_enc_ct
val crypto_kem_enc_ct: a:frodo_alg -> gen_a:frodo_gen_a -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> seed_se:lbytes (crypto_bytes a) -> lbytes (crypto_ciphertextbytes a)
val crypto_kem_enc_ct: a:frodo_alg -> gen_a:frodo_gen_a -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> seed_se:lbytes (crypto_bytes a) -> lbytes (crypto_ciphertextbytes a)
let crypto_kem_enc_ct a gen_a mu pk seed_se = expand_crypto_publickeybytes a; let seed_a = LSeq.sub pk 0 bytes_seed_a in let b = LSeq.sub pk bytes_seed_a (publicmatrixbytes_len a) in let sp_matrix, ep_matrix, epp_matrix = get_sp_ep_epp_matrices a seed_se in let c1 = crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix in let c2 = crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix in expand_crypto_ciphertextbytes a; let ct = concat c1 c2 in ct
{ "file_name": "specs/frodo/Spec.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 124, "start_col": 0, "start_line": 114 }
module Spec.Frodo.KEM.Encaps open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Spec.Matrix open Spec.Frodo.Lemmas open Spec.Frodo.Params open Spec.Frodo.Encode open Spec.Frodo.Pack open Spec.Frodo.Sample module LSeq = Lib.Sequence module Matrix = Spec.Matrix module KG = Spec.Frodo.KEM.KeyGen #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val frodo_mul_add_sa_plus_e: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> matrix params_nbar (params_n a) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix = let a_matrix = frodo_gen_matrix gen_a (params_n a) seed_a in let b_matrix = Matrix.add (Matrix.mul sp_matrix a_matrix) ep_matrix in b_matrix val crypto_kem_enc_ct_pack_c1: a:frodo_alg -> gen_a:frodo_gen_a -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix params_nbar (params_n a) -> ep_matrix:matrix params_nbar (params_n a) -> lbytes (ct1bytes_len a) let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix = let bp_matrix = frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix in let ct1 = frodo_pack (params_logq a) bp_matrix in ct1 val frodo_mul_add_sb_plus_e: a:frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix = let b_matrix = frodo_unpack #(params_n a) #params_nbar (params_logq a) b in let v_matrix = Matrix.add (Matrix.mul sp_matrix b_matrix) epp_matrix in v_matrix val frodo_mul_add_sb_plus_e_plus_mu: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> matrix params_nbar params_nbar let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix in let mu_encode = frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu in let v_matrix = Matrix.add v_matrix mu_encode in v_matrix val crypto_kem_enc_ct_pack_c2: a:frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix params_nbar (params_n a) -> epp_matrix:matrix params_nbar params_nbar -> lbytes (ct2bytes_len a) let crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix = let v_matrix = frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix in let ct2 = frodo_pack (params_logq a) v_matrix in ct2 val get_sp_ep_epp_matrices: a:frodo_alg -> seed_se:lbytes (crypto_bytes a) -> matrix params_nbar (params_n a) & matrix params_nbar (params_n a) & matrix params_nbar params_nbar let get_sp_ep_epp_matrices a seed_se = let s_bytes_len = secretmatrixbytes_len a in let r = KG.frodo_shake_r a (u8 0x96) seed_se (2 * s_bytes_len + 2 * params_nbar * params_nbar) in let sp_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r 0 s_bytes_len) in let ep_matrix = frodo_sample_matrix a params_nbar (params_n a) (LSeq.sub r s_bytes_len s_bytes_len) in let epp_matrix = frodo_sample_matrix a params_nbar params_nbar (LSeq.sub r (2 * s_bytes_len) (2 * params_nbar * params_nbar)) in sp_matrix, ep_matrix, epp_matrix val crypto_kem_enc_ct: a:frodo_alg -> gen_a:frodo_gen_a -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> seed_se:lbytes (crypto_bytes a) -> lbytes (crypto_ciphertextbytes a)
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Sample.fst.checked", "Spec.Frodo.Random.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.Pack.fst.checked", "Spec.Frodo.Lemmas.fst.checked", "Spec.Frodo.KEM.KeyGen.fst.checked", "Spec.Frodo.Encode.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Spec.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "Matrix" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": false, "full_module": "Spec.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Spec.Matrix", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Spec.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Spec.Frodo.Params.frodo_alg -> gen_a: Spec.Frodo.Params.frodo_gen_a -> mu: Lib.ByteSequence.lbytes (Spec.Frodo.Params.bytes_mu a) -> pk: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_publickeybytes a) -> seed_se: Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_bytes a) -> Lib.ByteSequence.lbytes (Spec.Frodo.Params.crypto_ciphertextbytes a)
Prims.Tot
[ "total" ]
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Lib.ByteSequence.lbytes", "Spec.Frodo.Params.bytes_mu", "Spec.Frodo.Params.crypto_publickeybytes", "Spec.Frodo.Params.crypto_bytes", "Spec.Matrix.matrix", "Spec.Frodo.Params.params_nbar", "Spec.Frodo.Params.params_n", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Prims.op_Addition", "Spec.Frodo.Params.ct1bytes_len", "Spec.Frodo.Params.ct2bytes_len", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.append", "Lib.Sequence.concat", "Lib.IntTypes.uint_t", "Prims.unit", "Spec.Frodo.Params.expand_crypto_ciphertextbytes", "Spec.Frodo.KEM.Encaps.crypto_kem_enc_ct_pack_c2", "Spec.Frodo.KEM.Encaps.crypto_kem_enc_ct_pack_c1", "Spec.Frodo.Params.crypto_ciphertextbytes", "FStar.Pervasives.Native.tuple3", "Lib.IntTypes.U16", "Prims.op_Multiply", "Spec.Frodo.KEM.Encaps.get_sp_ep_epp_matrices", "Spec.Frodo.Params.publicmatrixbytes_len", "Prims.l_and", "FStar.Seq.Base.slice", "Spec.Frodo.Params.bytes_seed_a", "Prims.l_Forall", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.index", "Lib.Sequence.sub", "Spec.Frodo.Params.expand_crypto_publickeybytes" ]
[]
false
false
false
false
false
let crypto_kem_enc_ct a gen_a mu pk seed_se =
expand_crypto_publickeybytes a; let seed_a = LSeq.sub pk 0 bytes_seed_a in let b = LSeq.sub pk bytes_seed_a (publicmatrixbytes_len a) in let sp_matrix, ep_matrix, epp_matrix = get_sp_ep_epp_matrices a seed_se in let c1 = crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix in let c2 = crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix in expand_crypto_ciphertextbytes a; let ct = concat c1 c2 in ct
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.qsquare_times_lemma
val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q)
val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q)
let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b)
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 45, "start_col": 0, "start_line": 41 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat ->
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.K256.PointOps.qelem -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Hacl.Spec.K256.Qinv.qsquare_times a b == Lib.NatMod.pow a (Prims.pow2 b) % Spec.K256.PointOps.q)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.K256.PointOps.qelem", "Prims.nat", "Lib.NatMod.lemma_pow_nat_mod_is_pow", "Spec.K256.PointOps.q", "Prims.pow2", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.l_or", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.K256.Qinv.qsquare_times", "Lib.Exponentiation.Definition.pow", "Lib.NatMod.nat_mod", "Hacl.Spec.K256.Qinv.nat_mod_comm_monoid", "Lib.Exponentiation.exp_pow2_lemma", "Spec.Exponentiation.exp_pow2_lemma", "Hacl.Spec.K256.Qinv.mk_nat_mod_concrete_ops" ]
[]
true
false
true
false
false
let qsquare_times_lemma a b =
SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b)
false
Platform.Error.fst
Platform.Error.invertOptResult
val invertOptResult : a:Type -> b:Type -> Lemma (requires True) (ensures (forall (x:optResult a b). Error? x \/ Correct? x)) [SMTPat (optResult a b)]
val invertOptResult : a:Type -> b:Type -> Lemma (requires True) (ensures (forall (x:optResult a b). Error? x \/ Correct? x)) [SMTPat (optResult a b)]
let invertOptResult a b = allow_inversion (optResult a b)
{ "file_name": "ucontrib/Platform/fst/Platform.Error.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 57, "end_line": 27, "start_col": 0, "start_line": 27 }
(* Copyright 2008-2018 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 Platform.Error type optResult 'a 'b = | Error of 'a | Correct of 'b //allowing inverting optResult without having to globally increase the fuel just for this val invertOptResult : a:Type -> b:Type -> Lemma (requires True) (ensures (forall (x:optResult a b). Error? x \/ Correct? x))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.IO.fst.checked" ], "interface_file": false, "source_file": "Platform.Error.fst" }
[ { "abbrev": false, "full_module": "Platform", "short_module": null }, { "abbrev": false, "full_module": "Platform", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> b: Type -> FStar.Pervasives.Lemma (ensures forall (x: Platform.Error.optResult a b). Error? x \/ Correct? x) [SMTPat (Platform.Error.optResult a b)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Pervasives.allow_inversion", "Platform.Error.optResult", "Prims.unit" ]
[]
true
false
true
false
false
let invertOptResult a b =
allow_inversion (optResult a b)
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.lemma_pow_mod_1
val lemma_pow_mod_1: f:S.qelem -> Lemma (f == M.pow f 1 % S.q)
val lemma_pow_mod_1: f:S.qelem -> Lemma (f == M.pow f 1 % S.q)
let lemma_pow_mod_1 f = M.lemma_pow1 f; Math.Lemmas.small_mod f S.q; assert_norm (pow2 0 = 1); assert (f == M.pow f 1 % S.q)
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 138, "start_col": 0, "start_line": 134 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b) (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv_r0_r1 (x14: S.qelem) : S.qelem let qinv_r0_r1 x14 = let x28 = S.qmul (qsquare_times x14 14) x14 in let x56 = S.qmul (qsquare_times x28 28) x28 in let r0 = S.qmul (qsquare_times x56 56) x56 in let r1 = S.qmul (qsquare_times r0 14) x14 in r1 val qinv_r2_r8 (r1 x_101 x_111 x_1011: S.qelem) : S.qelem let qinv_r2_r8 r1 x_101 x_111 x_1011 = let r2 = S.qmul (qsquare_times r1 3) x_101 in let r3 = S.qmul (qsquare_times r2 4) x_111 in let r4 = S.qmul (qsquare_times r3 4) x_101 in let r5 = S.qmul (qsquare_times r4 5) x_1011 in let r6 = S.qmul (qsquare_times r5 4) x_1011 in let r7 = S.qmul (qsquare_times r6 4) x_111 in let r8 = S.qmul (qsquare_times r7 5) x_111 in r8 val qinv_r9_r15 (r8 x_101 x_111 x_1001 x_1101: S.qelem) : S.qelem let qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 = let r9 = S.qmul (qsquare_times r8 6) x_1101 in let r10 = S.qmul (qsquare_times r9 4) x_101 in let r11 = S.qmul (qsquare_times r10 3) x_111 in let r12 = S.qmul (qsquare_times r11 5) x_1001 in let r13 = S.qmul (qsquare_times r12 6) x_101 in let r14 = S.qmul (qsquare_times r13 10) x_111 in let r15 = S.qmul (qsquare_times r14 4) x_111 in r15 val qinv_r16_r23 (r15 x8 x_11 x_1001 x_1011 x_1101: S.qelem) : S.qelem let qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 = let r16 = S.qmul (qsquare_times r15 9) x8 in let r17 = S.qmul (qsquare_times r16 5) x_1001 in let r18 = S.qmul (qsquare_times r17 6) x_1011 in let r19 = S.qmul (qsquare_times r18 4) x_1101 in let r20 = S.qmul (qsquare_times r19 5) x_11 in let r21 = S.qmul (qsquare_times r20 6) x_1101 in let r22 = S.qmul (qsquare_times r21 10) x_1101 in let r23 = S.qmul (qsquare_times r22 4) x_1001 in r23 val qinv_r24_r25 (r23 x_1 x6: S.qelem) : S.qelem let qinv_r24_r25 r23 x_1 x6 = let r24 = S.qmul (qsquare_times r23 6) x_1 in let r25 = S.qmul (qsquare_times r24 8) x6 in r25 val qinv_r0_r25 (x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101: S.qelem) : S.qelem let qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let x6 = S.qmul (qsquare_times x_1101 2) x_1011 in let x8 = S.qmul (qsquare_times x6 2) x_11 in let x14 = S.qmul (qsquare_times x8 6) x6 in let r1 = qinv_r0_r1 x14 in let r8 = qinv_r2_r8 r1 x_101 x_111 x_1011 in let r15 = qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 in let r23 = qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 in qinv_r24_r25 r23 x_1 x6 val qinv: f:S.qelem -> S.qelem let qinv f = let x_1 = f in let x_10 = qsquare_times f 1 in let x_11 = S.qmul x_10 x_1 in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1001 = S.qmul x_10 x_111 in let x_1011 = S.qmul x_10 x_1001 in let x_1101 = S.qmul x_10 x_1011 in qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.K256.PointOps.qelem -> FStar.Pervasives.Lemma (ensures f == Lib.NatMod.pow f 1 % Spec.K256.PointOps.q)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.K256.PointOps.qelem", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Lib.NatMod.pow", "Spec.K256.PointOps.q", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.pow2", "FStar.Math.Lemmas.small_mod", "Lib.NatMod.lemma_pow1" ]
[]
true
false
true
false
false
let lemma_pow_mod_1 f =
M.lemma_pow1 f; Math.Lemmas.small_mod f S.q; assert_norm (pow2 0 = 1); assert (f == M.pow f 1 % S.q)
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.qinv_is_qinv_lemma
val qinv_is_qinv_lemma: f:S.qelem -> Lemma (qinv f == S.qinv f)
val qinv_is_qinv_lemma: f:S.qelem -> Lemma (qinv f == S.qinv f)
let qinv_is_qinv_lemma f = qinv_lemma f; assert (qinv f == M.pow f (S.q - 2) % S.q); M.lemma_pow_mod #S.q f (S.q - 2)
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 378, "start_col": 0, "start_line": 375 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b) (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv_r0_r1 (x14: S.qelem) : S.qelem let qinv_r0_r1 x14 = let x28 = S.qmul (qsquare_times x14 14) x14 in let x56 = S.qmul (qsquare_times x28 28) x28 in let r0 = S.qmul (qsquare_times x56 56) x56 in let r1 = S.qmul (qsquare_times r0 14) x14 in r1 val qinv_r2_r8 (r1 x_101 x_111 x_1011: S.qelem) : S.qelem let qinv_r2_r8 r1 x_101 x_111 x_1011 = let r2 = S.qmul (qsquare_times r1 3) x_101 in let r3 = S.qmul (qsquare_times r2 4) x_111 in let r4 = S.qmul (qsquare_times r3 4) x_101 in let r5 = S.qmul (qsquare_times r4 5) x_1011 in let r6 = S.qmul (qsquare_times r5 4) x_1011 in let r7 = S.qmul (qsquare_times r6 4) x_111 in let r8 = S.qmul (qsquare_times r7 5) x_111 in r8 val qinv_r9_r15 (r8 x_101 x_111 x_1001 x_1101: S.qelem) : S.qelem let qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 = let r9 = S.qmul (qsquare_times r8 6) x_1101 in let r10 = S.qmul (qsquare_times r9 4) x_101 in let r11 = S.qmul (qsquare_times r10 3) x_111 in let r12 = S.qmul (qsquare_times r11 5) x_1001 in let r13 = S.qmul (qsquare_times r12 6) x_101 in let r14 = S.qmul (qsquare_times r13 10) x_111 in let r15 = S.qmul (qsquare_times r14 4) x_111 in r15 val qinv_r16_r23 (r15 x8 x_11 x_1001 x_1011 x_1101: S.qelem) : S.qelem let qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 = let r16 = S.qmul (qsquare_times r15 9) x8 in let r17 = S.qmul (qsquare_times r16 5) x_1001 in let r18 = S.qmul (qsquare_times r17 6) x_1011 in let r19 = S.qmul (qsquare_times r18 4) x_1101 in let r20 = S.qmul (qsquare_times r19 5) x_11 in let r21 = S.qmul (qsquare_times r20 6) x_1101 in let r22 = S.qmul (qsquare_times r21 10) x_1101 in let r23 = S.qmul (qsquare_times r22 4) x_1001 in r23 val qinv_r24_r25 (r23 x_1 x6: S.qelem) : S.qelem let qinv_r24_r25 r23 x_1 x6 = let r24 = S.qmul (qsquare_times r23 6) x_1 in let r25 = S.qmul (qsquare_times r24 8) x6 in r25 val qinv_r0_r25 (x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101: S.qelem) : S.qelem let qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let x6 = S.qmul (qsquare_times x_1101 2) x_1011 in let x8 = S.qmul (qsquare_times x6 2) x_11 in let x14 = S.qmul (qsquare_times x8 6) x6 in let r1 = qinv_r0_r1 x14 in let r8 = qinv_r2_r8 r1 x_101 x_111 x_1011 in let r15 = qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 in let r23 = qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 in qinv_r24_r25 r23 x_1 x6 val qinv: f:S.qelem -> S.qelem let qinv f = let x_1 = f in let x_10 = qsquare_times f 1 in let x_11 = S.qmul x_10 x_1 in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1001 = S.qmul x_10 x_111 in let x_1011 = S.qmul x_10 x_1001 in let x_1101 = S.qmul x_10 x_1011 in qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101 val lemma_pow_mod_1: f:S.qelem -> Lemma (f == M.pow f 1 % S.q) let lemma_pow_mod_1 f = M.lemma_pow1 f; Math.Lemmas.small_mod f S.q; assert_norm (pow2 0 = 1); assert (f == M.pow f 1 % S.q) val lemma_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> Lemma (S.qmul (M.pow f a % S.q) (M.pow f b % S.q) == M.pow f (a + b) % S.q) let lemma_pow_mod_mul f a b = calc (==) { S.qmul (M.pow f a % S.q) (M.pow f b % S.q); (==) { Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.q) S.q; Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.q } M.pow f a * M.pow f b % S.q; (==) { M.lemma_pow_add f a b } M.pow f (a + b) % S.q; } val lemma_pow_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> c:nat -> Lemma (S.qmul (M.pow (M.pow f a % S.q) b % S.q) (M.pow f c % S.q) == M.pow f (a * b + c) % S.q) let lemma_pow_pow_mod_mul f a b c = calc (==) { S.qmul (M.pow (M.pow f a % S.q) b % S.q) (M.pow f c % S.q); (==) { M.lemma_pow_mod_base (M.pow f a) b S.q; Math.Lemmas.lemma_mod_mul_distr_l (M.pow (M.pow f a) b) (M.pow f c % S.q) S.q; Math.Lemmas.lemma_mod_mul_distr_r (M.pow (M.pow f a) b) (M.pow f c) S.q } M.pow (M.pow f a) b * M.pow f c % S.q; (==) { M.lemma_pow_mul f a b } M.pow f (a * b) * M.pow f c % S.q; (==) { M.lemma_pow_add f (a * b) c } M.pow f (a * b + c) % S.q; } // S.q - 2 = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413f val qinv_lemma: f:S.qelem -> Lemma (qinv f == M.pow f (S.q - 2) % S.q) let qinv_lemma f = let x_1 = f in let x_10 = qsquare_times f 1 in qsquare_times_lemma f 1; assert_norm (pow2 1 = 0x2); assert (x_10 == M.pow f 0x2 % S.q); let x_11 = S.qmul x_10 x_1 in lemma_pow_mod_1 f; lemma_pow_mod_mul f 0x2 0x1; assert (x_11 == M.pow f 0x3 % S.q); let x_101 = S.qmul x_10 x_11 in lemma_pow_mod_mul f 0x2 0x3; assert (x_101 == M.pow f 0x5 % S.q); let x_111 = S.qmul x_10 x_101 in lemma_pow_mod_mul f 0x2 0x5; assert (x_111 == M.pow f 0x7 % S.q); let x_1001 = S.qmul x_10 x_111 in lemma_pow_mod_mul f 0x2 0x7; assert (x_1001 == M.pow f 0x9 % S.q); let x_1011 = S.qmul x_10 x_1001 in lemma_pow_mod_mul f 0x2 0x9; assert (x_1011 == M.pow f 0xb % S.q); let x_1101 = S.qmul x_10 x_1011 in lemma_pow_mod_mul f 0x2 0xb; assert (x_1101 == M.pow f 0xd % S.q); let x6 = S.qmul (qsquare_times x_1101 2) x_1011 in qsquare_times_lemma x_1101 2; assert_norm (pow2 2 = 0x4); lemma_pow_pow_mod_mul f 0xd 0x4 0xb; assert (x6 == M.pow f 0x3f % S.q); let x8 = S.qmul (qsquare_times x6 2) x_11 in qsquare_times_lemma x6 2; lemma_pow_pow_mod_mul f 0x3f 0x4 0x3; assert (x8 == M.pow f 0xff % S.q); let x14 = S.qmul (qsquare_times x8 6) x6 in qsquare_times_lemma x8 6; assert_norm (pow2 6 = 0x40); lemma_pow_pow_mod_mul f 0xff 0x40 0x3f; assert (x14 == M.pow f 0x3fff % S.q); let x28 = S.qmul (qsquare_times x14 14) x14 in qsquare_times_lemma x14 14; assert_norm (pow2 14 = 0x4000); lemma_pow_pow_mod_mul f 0x3fff 0x4000 0x3fff; assert (x28 == M.pow f 0xfffffff % S.q); let x56 = S.qmul (qsquare_times x28 28) x28 in qsquare_times_lemma x28 28; assert_norm (pow2 28 = 0x10000000); lemma_pow_pow_mod_mul f 0xfffffff 0x10000000 0xfffffff; assert (x56 == M.pow f 0xffffffffffffff % S.q); let r0 = S.qmul (qsquare_times x56 56) x56 in qsquare_times_lemma x56 56; assert_norm (pow2 56 = 0x100000000000000); lemma_pow_pow_mod_mul f 0xffffffffffffff 0x100000000000000 0xffffffffffffff; assert (r0 == M.pow f 0xffffffffffffffffffffffffffff % S.q); let r1 = S.qmul (qsquare_times r0 14) x14 in qsquare_times_lemma r0 14; lemma_pow_pow_mod_mul f 0xffffffffffffffffffffffffffff 0x4000 0x3fff; assert (r1 == M.pow f 0x3fffffffffffffffffffffffffffffff % S.q); let r2 = S.qmul (qsquare_times r1 3) x_101 in qsquare_times_lemma r1 3; assert_norm (pow2 3 = 0x8); lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffff 0x8 0x5; assert (r2 == M.pow f 0x1fffffffffffffffffffffffffffffffd % S.q); let r3 = S.qmul (qsquare_times r2 4) x_111 in qsquare_times_lemma r2 4; assert_norm (pow2 4 = 0x10); lemma_pow_pow_mod_mul f 0x1fffffffffffffffffffffffffffffffd 0x10 0x7; assert (r3 == M.pow f 0x1fffffffffffffffffffffffffffffffd7 % S.q); let r4 = S.qmul (qsquare_times r3 4) x_101 in qsquare_times_lemma r3 4; lemma_pow_pow_mod_mul f 0x1fffffffffffffffffffffffffffffffd7 0x10 0x5; assert (r4 == M.pow f 0x1fffffffffffffffffffffffffffffffd75 % S.q); let r5 = S.qmul (qsquare_times r4 5) x_1011 in qsquare_times_lemma r4 5; assert_norm (pow2 5 = 0x20); lemma_pow_pow_mod_mul f 0x1fffffffffffffffffffffffffffffffd75 0x20 0xb; assert (r5 == M.pow f 0x3fffffffffffffffffffffffffffffffaeab % S.q); let r6 = S.qmul (qsquare_times r5 4) x_1011 in qsquare_times_lemma r5 4; lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffaeab 0x10 0xb; assert (r6 == M.pow f 0x3fffffffffffffffffffffffffffffffaeabb % S.q); let r7 = S.qmul (qsquare_times r6 4) x_111 in qsquare_times_lemma r6 4; lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffaeabb 0x10 0x7; assert (r7 == M.pow f 0x3fffffffffffffffffffffffffffffffaeabb7 % S.q); let r8 = S.qmul (qsquare_times r7 5) x_111 in qsquare_times_lemma r7 5; lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffaeabb7 0x20 0x7; assert (r8 == M.pow f 0x7fffffffffffffffffffffffffffffff5d576e7 % S.q); let r9 = S.qmul (qsquare_times r8 6) x_1101 in qsquare_times_lemma r8 6; lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffff5d576e7 0x40 0xd; assert (r9 == M.pow f 0x1fffffffffffffffffffffffffffffffd755db9cd % S.q); let r10 = S.qmul (qsquare_times r9 4) x_101 in qsquare_times_lemma r9 4; lemma_pow_pow_mod_mul f 0x1fffffffffffffffffffffffffffffffd755db9cd 0x10 0x5; assert (r10 == M.pow f 0x1fffffffffffffffffffffffffffffffd755db9cd5 % S.q); let r11 = S.qmul (qsquare_times r10 3) x_111 in qsquare_times_lemma r10 3; lemma_pow_pow_mod_mul f 0x1fffffffffffffffffffffffffffffffd755db9cd5 0x8 0x7; assert (r11 == M.pow f 0xfffffffffffffffffffffffffffffffebaaedce6af % S.q); let r12 = S.qmul (qsquare_times r11 5) x_1001 in qsquare_times_lemma r11 5; lemma_pow_pow_mod_mul f 0xfffffffffffffffffffffffffffffffebaaedce6af 0x20 0x9; assert (r12 == M.pow f 0x1fffffffffffffffffffffffffffffffd755db9cd5e9 % S.q); let r13 = S.qmul (qsquare_times r12 6) x_101 in qsquare_times_lemma r12 6; lemma_pow_pow_mod_mul f 0x1fffffffffffffffffffffffffffffffd755db9cd5e9 0x40 0x5; assert (r13 == M.pow f 0x7fffffffffffffffffffffffffffffff5d576e7357a45 % S.q); let r14 = S.qmul (qsquare_times r13 10) x_111 in qsquare_times_lemma r13 10; assert_norm (pow2 10 = 0x400); lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffff5d576e7357a45 0x400 0x7; assert (r14 == M.pow f 0x1fffffffffffffffffffffffffffffffd755db9cd5e91407 % S.q); let r15 = S.qmul (qsquare_times r14 4) x_111 in qsquare_times_lemma r14 4; lemma_pow_pow_mod_mul f 0x1fffffffffffffffffffffffffffffffd755db9cd5e91407 0x10 0x7; assert (r15 == M.pow f 0x1fffffffffffffffffffffffffffffffd755db9cd5e914077 % S.q); let r16 = S.qmul (qsquare_times r15 9) x8 in qsquare_times_lemma r15 9; assert_norm (pow2 9 = 0x200); lemma_pow_pow_mod_mul f 0x1fffffffffffffffffffffffffffffffd755db9cd5e914077 0x200 0xff; assert (r16 == M.pow f 0x3fffffffffffffffffffffffffffffffaeabb739abd2280eeff % S.q); let r17 = S.qmul (qsquare_times r16 5) x_1001 in qsquare_times_lemma r16 5; lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffaeabb739abd2280eeff 0x20 0x9; assert (r17 == M.pow f 0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe9 % S.q); let r18 = S.qmul (qsquare_times r17 6) x_1011 in qsquare_times_lemma r17 6; lemma_pow_pow_mod_mul f 0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe9 0x40 0xb; assert (r18 == M.pow f 0x1fffffffffffffffffffffffffffffffd755db9cd5e9140777fa4b % S.q); let r19 = S.qmul (qsquare_times r18 4) x_1101 in qsquare_times_lemma r18 4; lemma_pow_pow_mod_mul f 0x1fffffffffffffffffffffffffffffffd755db9cd5e9140777fa4b 0x10 0xd; assert (r19 == M.pow f 0x1fffffffffffffffffffffffffffffffd755db9cd5e9140777fa4bd % S.q); let r20 = S.qmul (qsquare_times r19 5) x_11 in qsquare_times_lemma r19 5; lemma_pow_pow_mod_mul f 0x1fffffffffffffffffffffffffffffffd755db9cd5e9140777fa4bd 0x20 0x3; assert (r20 == M.pow f 0x3fffffffffffffffffffffffffffffffaeabb739abd2280eeff497a3 % S.q); let r21 = S.qmul (qsquare_times r20 6) x_1101 in qsquare_times_lemma r20 6; lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffaeabb739abd2280eeff497a3 0x40 0xd; assert (r21 == M.pow f 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd % S.q); let r22 = S.qmul (qsquare_times r21 10) x_1101 in qsquare_times_lemma r21 10; lemma_pow_pow_mod_mul f 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd 0x400 0xd; assert (r22 == M.pow f 0x3fffffffffffffffffffffffffffffffaeabb739abd2280eeff497a3340d % S.q); let r23 = S.qmul (qsquare_times r22 4) x_1001 in qsquare_times_lemma r22 4; lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffaeabb739abd2280eeff497a3340d 0x10 0x9; assert (r23 == M.pow f 0x3fffffffffffffffffffffffffffffffaeabb739abd2280eeff497a3340d9 % S.q); let r24 = S.qmul (qsquare_times r23 6) x_1 in qsquare_times_lemma r23 6; lemma_pow_pow_mod_mul f 0x3fffffffffffffffffffffffffffffffaeabb739abd2280eeff497a3340d9 0x40 0x1; assert (r24 == M.pow f 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641 % S.q); let r25 = S.qmul (qsquare_times r24 8) x6 in qsquare_times_lemma r24 8; assert_norm (pow2 8 = 0x100); lemma_pow_pow_mod_mul f 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd03641 0x100 0x3f; assert (r25 == M.pow f 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413f % S.q)
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.K256.PointOps.qelem -> FStar.Pervasives.Lemma (ensures Hacl.Spec.K256.Qinv.qinv f == Spec.K256.PointOps.qinv f)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.K256.PointOps.qelem", "Lib.NatMod.lemma_pow_mod", "Spec.K256.PointOps.q", "Prims.op_Subtraction", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.K256.Qinv.qinv", "Prims.op_Modulus", "Lib.NatMod.pow", "Hacl.Spec.K256.Qinv.qinv_lemma" ]
[]
true
false
true
false
false
let qinv_is_qinv_lemma f =
qinv_lemma f; assert (qinv f == M.pow f (S.q - 2) % S.q); M.lemma_pow_mod #S.q f (S.q - 2)
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.lemma_pow_mod_mul
val lemma_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> Lemma (S.qmul (M.pow f a % S.q) (M.pow f b % S.q) == M.pow f (a + b) % S.q)
val lemma_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> Lemma (S.qmul (M.pow f a % S.q) (M.pow f b % S.q) == M.pow f (a + b) % S.q)
let lemma_pow_mod_mul f a b = calc (==) { S.qmul (M.pow f a % S.q) (M.pow f b % S.q); (==) { Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.q) S.q; Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.q } M.pow f a * M.pow f b % S.q; (==) { M.lemma_pow_add f a b } M.pow f (a + b) % S.q; }
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 152, "start_col": 0, "start_line": 143 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b) (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv_r0_r1 (x14: S.qelem) : S.qelem let qinv_r0_r1 x14 = let x28 = S.qmul (qsquare_times x14 14) x14 in let x56 = S.qmul (qsquare_times x28 28) x28 in let r0 = S.qmul (qsquare_times x56 56) x56 in let r1 = S.qmul (qsquare_times r0 14) x14 in r1 val qinv_r2_r8 (r1 x_101 x_111 x_1011: S.qelem) : S.qelem let qinv_r2_r8 r1 x_101 x_111 x_1011 = let r2 = S.qmul (qsquare_times r1 3) x_101 in let r3 = S.qmul (qsquare_times r2 4) x_111 in let r4 = S.qmul (qsquare_times r3 4) x_101 in let r5 = S.qmul (qsquare_times r4 5) x_1011 in let r6 = S.qmul (qsquare_times r5 4) x_1011 in let r7 = S.qmul (qsquare_times r6 4) x_111 in let r8 = S.qmul (qsquare_times r7 5) x_111 in r8 val qinv_r9_r15 (r8 x_101 x_111 x_1001 x_1101: S.qelem) : S.qelem let qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 = let r9 = S.qmul (qsquare_times r8 6) x_1101 in let r10 = S.qmul (qsquare_times r9 4) x_101 in let r11 = S.qmul (qsquare_times r10 3) x_111 in let r12 = S.qmul (qsquare_times r11 5) x_1001 in let r13 = S.qmul (qsquare_times r12 6) x_101 in let r14 = S.qmul (qsquare_times r13 10) x_111 in let r15 = S.qmul (qsquare_times r14 4) x_111 in r15 val qinv_r16_r23 (r15 x8 x_11 x_1001 x_1011 x_1101: S.qelem) : S.qelem let qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 = let r16 = S.qmul (qsquare_times r15 9) x8 in let r17 = S.qmul (qsquare_times r16 5) x_1001 in let r18 = S.qmul (qsquare_times r17 6) x_1011 in let r19 = S.qmul (qsquare_times r18 4) x_1101 in let r20 = S.qmul (qsquare_times r19 5) x_11 in let r21 = S.qmul (qsquare_times r20 6) x_1101 in let r22 = S.qmul (qsquare_times r21 10) x_1101 in let r23 = S.qmul (qsquare_times r22 4) x_1001 in r23 val qinv_r24_r25 (r23 x_1 x6: S.qelem) : S.qelem let qinv_r24_r25 r23 x_1 x6 = let r24 = S.qmul (qsquare_times r23 6) x_1 in let r25 = S.qmul (qsquare_times r24 8) x6 in r25 val qinv_r0_r25 (x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101: S.qelem) : S.qelem let qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let x6 = S.qmul (qsquare_times x_1101 2) x_1011 in let x8 = S.qmul (qsquare_times x6 2) x_11 in let x14 = S.qmul (qsquare_times x8 6) x6 in let r1 = qinv_r0_r1 x14 in let r8 = qinv_r2_r8 r1 x_101 x_111 x_1011 in let r15 = qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 in let r23 = qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 in qinv_r24_r25 r23 x_1 x6 val qinv: f:S.qelem -> S.qelem let qinv f = let x_1 = f in let x_10 = qsquare_times f 1 in let x_11 = S.qmul x_10 x_1 in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1001 = S.qmul x_10 x_111 in let x_1011 = S.qmul x_10 x_1001 in let x_1101 = S.qmul x_10 x_1011 in qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101 val lemma_pow_mod_1: f:S.qelem -> Lemma (f == M.pow f 1 % S.q) let lemma_pow_mod_1 f = M.lemma_pow1 f; Math.Lemmas.small_mod f S.q; assert_norm (pow2 0 = 1); assert (f == M.pow f 1 % S.q) val lemma_pow_mod_mul: f:S.qelem -> a:nat -> b:nat ->
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.K256.PointOps.qelem -> a: Prims.nat -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Spec.K256.PointOps.qmul (Lib.NatMod.pow f a % Spec.K256.PointOps.q) (Lib.NatMod.pow f b % Spec.K256.PointOps.q) == Lib.NatMod.pow f (a + b) % Spec.K256.PointOps.q)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.K256.PointOps.qelem", "Prims.nat", "FStar.Calc.calc_finish", "Prims.eq2", "Spec.K256.PointOps.qmul", "Prims.op_Modulus", "Lib.NatMod.pow", "Spec.K256.PointOps.q", "Prims.op_Addition", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Mul.op_Star", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Prims.squash", "Lib.NatMod.lemma_pow_add" ]
[]
false
false
true
false
false
let lemma_pow_mod_mul f a b =
calc ( == ) { S.qmul (M.pow f a % S.q) (M.pow f b % S.q); ( == ) { (Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.q) S.q; Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.q) } M.pow f a * M.pow f b % S.q; ( == ) { M.lemma_pow_add f a b } M.pow f (a + b) % S.q; }
false
Hacl.Spec.K256.Qinv.fst
Hacl.Spec.K256.Qinv.lemma_pow_pow_mod_mul
val lemma_pow_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> c:nat -> Lemma (S.qmul (M.pow (M.pow f a % S.q) b % S.q) (M.pow f c % S.q) == M.pow f (a * b + c) % S.q)
val lemma_pow_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> c:nat -> Lemma (S.qmul (M.pow (M.pow f a % S.q) b % S.q) (M.pow f c % S.q) == M.pow f (a * b + c) % S.q)
let lemma_pow_pow_mod_mul f a b c = calc (==) { S.qmul (M.pow (M.pow f a % S.q) b % S.q) (M.pow f c % S.q); (==) { M.lemma_pow_mod_base (M.pow f a) b S.q; Math.Lemmas.lemma_mod_mul_distr_l (M.pow (M.pow f a) b) (M.pow f c % S.q) S.q; Math.Lemmas.lemma_mod_mul_distr_r (M.pow (M.pow f a) b) (M.pow f c) S.q } M.pow (M.pow f a) b * M.pow f c % S.q; (==) { M.lemma_pow_mul f a b } M.pow f (a * b) * M.pow f c % S.q; (==) { M.lemma_pow_add f (a * b) c } M.pow f (a * b + c) % S.q; }
{ "file_name": "code/k256/Hacl.Spec.K256.Qinv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 169, "start_col": 0, "start_line": 157 }
module Hacl.Spec.K256.Qinv open FStar.Mul module SE = Spec.Exponentiation module LE = Lib.Exponentiation module M = Lib.NatMod module S = Spec.K256 #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let nat_mod_comm_monoid = M.mk_nat_mod_comm_monoid S.q let mk_to_nat_mod_comm_monoid : SE.to_comm_monoid S.qelem = { SE.a_spec = S.qelem; SE.comm_monoid = nat_mod_comm_monoid; SE.refl = (fun (x:S.qelem) -> x); } val one_mod : SE.one_st S.qelem mk_to_nat_mod_comm_monoid let one_mod _ = 1 val mul_mod : SE.mul_st S.qelem mk_to_nat_mod_comm_monoid let mul_mod x y = S.qmul x y val sqr_mod : SE.sqr_st S.qelem mk_to_nat_mod_comm_monoid let sqr_mod x = S.qmul x x let mk_nat_mod_concrete_ops : SE.concrete_ops S.qelem = { SE.to = mk_to_nat_mod_comm_monoid; SE.one = one_mod; SE.mul = mul_mod; SE.sqr = sqr_mod; } let qsquare_times (a:S.qelem) (b:nat) : S.qelem = SE.exp_pow2 mk_nat_mod_concrete_ops a b val qsquare_times_lemma: a:S.qelem -> b:nat -> Lemma (qsquare_times a b == M.pow a (pow2 b) % S.q) let qsquare_times_lemma a b = SE.exp_pow2_lemma mk_nat_mod_concrete_ops a b; LE.exp_pow2_lemma nat_mod_comm_monoid a b; assert (qsquare_times a b == LE.pow nat_mod_comm_monoid a (pow2 b)); M.lemma_pow_nat_mod_is_pow #S.q a (pow2 b) (** The algorithm is taken from https://briansmith.org/ecc-inversion-addition-chains-01 *) val qinv_r0_r1 (x14: S.qelem) : S.qelem let qinv_r0_r1 x14 = let x28 = S.qmul (qsquare_times x14 14) x14 in let x56 = S.qmul (qsquare_times x28 28) x28 in let r0 = S.qmul (qsquare_times x56 56) x56 in let r1 = S.qmul (qsquare_times r0 14) x14 in r1 val qinv_r2_r8 (r1 x_101 x_111 x_1011: S.qelem) : S.qelem let qinv_r2_r8 r1 x_101 x_111 x_1011 = let r2 = S.qmul (qsquare_times r1 3) x_101 in let r3 = S.qmul (qsquare_times r2 4) x_111 in let r4 = S.qmul (qsquare_times r3 4) x_101 in let r5 = S.qmul (qsquare_times r4 5) x_1011 in let r6 = S.qmul (qsquare_times r5 4) x_1011 in let r7 = S.qmul (qsquare_times r6 4) x_111 in let r8 = S.qmul (qsquare_times r7 5) x_111 in r8 val qinv_r9_r15 (r8 x_101 x_111 x_1001 x_1101: S.qelem) : S.qelem let qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 = let r9 = S.qmul (qsquare_times r8 6) x_1101 in let r10 = S.qmul (qsquare_times r9 4) x_101 in let r11 = S.qmul (qsquare_times r10 3) x_111 in let r12 = S.qmul (qsquare_times r11 5) x_1001 in let r13 = S.qmul (qsquare_times r12 6) x_101 in let r14 = S.qmul (qsquare_times r13 10) x_111 in let r15 = S.qmul (qsquare_times r14 4) x_111 in r15 val qinv_r16_r23 (r15 x8 x_11 x_1001 x_1011 x_1101: S.qelem) : S.qelem let qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 = let r16 = S.qmul (qsquare_times r15 9) x8 in let r17 = S.qmul (qsquare_times r16 5) x_1001 in let r18 = S.qmul (qsquare_times r17 6) x_1011 in let r19 = S.qmul (qsquare_times r18 4) x_1101 in let r20 = S.qmul (qsquare_times r19 5) x_11 in let r21 = S.qmul (qsquare_times r20 6) x_1101 in let r22 = S.qmul (qsquare_times r21 10) x_1101 in let r23 = S.qmul (qsquare_times r22 4) x_1001 in r23 val qinv_r24_r25 (r23 x_1 x6: S.qelem) : S.qelem let qinv_r24_r25 r23 x_1 x6 = let r24 = S.qmul (qsquare_times r23 6) x_1 in let r25 = S.qmul (qsquare_times r24 8) x6 in r25 val qinv_r0_r25 (x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101: S.qelem) : S.qelem let qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101 = let x6 = S.qmul (qsquare_times x_1101 2) x_1011 in let x8 = S.qmul (qsquare_times x6 2) x_11 in let x14 = S.qmul (qsquare_times x8 6) x6 in let r1 = qinv_r0_r1 x14 in let r8 = qinv_r2_r8 r1 x_101 x_111 x_1011 in let r15 = qinv_r9_r15 r8 x_101 x_111 x_1001 x_1101 in let r23 = qinv_r16_r23 r15 x8 x_11 x_1001 x_1011 x_1101 in qinv_r24_r25 r23 x_1 x6 val qinv: f:S.qelem -> S.qelem let qinv f = let x_1 = f in let x_10 = qsquare_times f 1 in let x_11 = S.qmul x_10 x_1 in let x_101 = S.qmul x_10 x_11 in let x_111 = S.qmul x_10 x_101 in let x_1001 = S.qmul x_10 x_111 in let x_1011 = S.qmul x_10 x_1001 in let x_1101 = S.qmul x_10 x_1011 in qinv_r0_r25 x_1 x_11 x_101 x_111 x_1001 x_1011 x_1101 val lemma_pow_mod_1: f:S.qelem -> Lemma (f == M.pow f 1 % S.q) let lemma_pow_mod_1 f = M.lemma_pow1 f; Math.Lemmas.small_mod f S.q; assert_norm (pow2 0 = 1); assert (f == M.pow f 1 % S.q) val lemma_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> Lemma (S.qmul (M.pow f a % S.q) (M.pow f b % S.q) == M.pow f (a + b) % S.q) let lemma_pow_mod_mul f a b = calc (==) { S.qmul (M.pow f a % S.q) (M.pow f b % S.q); (==) { Math.Lemmas.lemma_mod_mul_distr_l (M.pow f a) (M.pow f b % S.q) S.q; Math.Lemmas.lemma_mod_mul_distr_r (M.pow f a) (M.pow f b) S.q } M.pow f a * M.pow f b % S.q; (==) { M.lemma_pow_add f a b } M.pow f (a + b) % S.q; } val lemma_pow_pow_mod_mul: f:S.qelem -> a:nat -> b:nat -> c:nat ->
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.Exponentiation.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Qinv.fst" }
[ { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Spec.K256.PointOps.qelem -> a: Prims.nat -> b: Prims.nat -> c: Prims.nat -> FStar.Pervasives.Lemma (ensures Spec.K256.PointOps.qmul (Lib.NatMod.pow (Lib.NatMod.pow f a % Spec.K256.PointOps.q) b % Spec.K256.PointOps.q) (Lib.NatMod.pow f c % Spec.K256.PointOps.q) == Lib.NatMod.pow f (a * b + c) % Spec.K256.PointOps.q)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.K256.PointOps.qelem", "Prims.nat", "FStar.Calc.calc_finish", "Prims.eq2", "Spec.K256.PointOps.qmul", "Prims.op_Modulus", "Lib.NatMod.pow", "Spec.K256.PointOps.q", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Lib.NatMod.lemma_pow_mod_base", "Prims.squash", "Lib.NatMod.lemma_pow_mul", "Lib.NatMod.lemma_pow_add" ]
[]
false
false
true
false
false
let lemma_pow_pow_mod_mul f a b c =
calc ( == ) { S.qmul (M.pow (M.pow f a % S.q) b % S.q) (M.pow f c % S.q); ( == ) { (M.lemma_pow_mod_base (M.pow f a) b S.q; Math.Lemmas.lemma_mod_mul_distr_l (M.pow (M.pow f a) b) (M.pow f c % S.q) S.q; Math.Lemmas.lemma_mod_mul_distr_r (M.pow (M.pow f a) b) (M.pow f c) S.q) } M.pow (M.pow f a) b * M.pow f c % S.q; ( == ) { M.lemma_pow_mul f a b } M.pow f (a * b) * M.pow f c % S.q; ( == ) { M.lemma_pow_add f (a * b) c } M.pow f (a * b + c) % S.q; }
false
Hacl.Impl.Curve25519.Fields.fst
Hacl.Impl.Curve25519.Fields.load_felem
val load_felem: #s:field_spec -> f:felem s -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint f u64s /\ v (LSeq.index (as_seq h u64s) 3) < pow2 63) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ state_inv_t h1 f /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s))
val load_felem: #s:field_spec -> f:felem s -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint f u64s /\ v (LSeq.index (as_seq h u64s) 3) < pow2 63) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ state_inv_t h1 f /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s))
let load_felem #s f b = match s with | M51 -> F51.load_felem f b | M64 -> F64.load_felem f b
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 51, "start_col": 0, "start_line": 48 }
module Hacl.Impl.Curve25519.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer include Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module BSeq = Lib.ByteSequence module LSeq = Lib.Sequence module P = Spec.Curve25519 module F51 = Hacl.Impl.Curve25519.Field51 module F64 = Hacl.Impl.Curve25519.Field64 #set-options "--z3rlimit 50 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --record_options" inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create (v (nlimb s)) (limb_zero s)) /\ as_nat h1 f == 0) let create_felem s = match s with | M51 -> (F51.create_felem ()) <: felem s | M64 -> (F64.create_felem ()) <: felem s inline_for_extraction noextract val load_felem: #s:field_spec -> f:felem s -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint f u64s /\ v (LSeq.index (as_seq h u64s) 3) < pow2 63) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ state_inv_t h1 f /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "Hacl.Impl.Curve25519.Field64.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field64", "short_module": "F64" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Impl.Curve25519.Fields.Core.felem s -> u64s: Lib.Buffer.lbuffer Lib.IntTypes.uint64 4ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.field_spec", "Hacl.Impl.Curve25519.Fields.Core.felem", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Curve25519.Field51.load_felem", "Prims.unit", "Hacl.Impl.Curve25519.Field64.load_felem" ]
[]
false
true
false
false
false
let load_felem #s f b =
match s with | M51 -> F51.load_felem f b | M64 -> F64.load_felem f b
false
Fibonacci.fst
Fibonacci.fib
val fib (n: nat) : nat
val fib (n: nat) : nat
let rec fib (n:nat) : nat = if n <= 1 then 1 else fib (n - 1) + fib (n - 2)
{ "file_name": "share/steel/examples/pulse/Fibonacci.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 32, "end_line": 24, "start_col": 0, "start_line": 22 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Fibonacci open Pulse.Lib.Pervasives module U32 = FStar.UInt32 #push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection' --ext 'pulse:rvalues'"
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.Lib.BoundedIntegers.fst.checked", "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Fibonacci.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
n: Prims.nat -> Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.op_LessThanOrEqual", "Prims.bool", "Prims.op_Addition", "Fibonacci.fib", "Prims.op_Subtraction" ]
[ "recursion" ]
false
false
false
true
false
let rec fib (n: nat) : nat =
if n <= 1 then 1 else fib (n - 1) + fib (n - 2)
false
Fibonacci.fst
Fibonacci.fib_mono
val fib_mono (n: nat) (m: nat{m <= n}) : Lemma (ensures fib m <= fib n)
val fib_mono (n: nat) (m: nat{m <= n}) : Lemma (ensures fib m <= fib n)
let rec fib_mono (n:nat) (m:nat { m <= n}) : Lemma (ensures fib m <= fib n) = if n = m then () else fib_mono (n - 1) m
{ "file_name": "share/steel/examples/pulse/Fibonacci.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 27, "end_line": 30, "start_col": 0, "start_line": 26 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Fibonacci open Pulse.Lib.Pervasives module U32 = FStar.UInt32 #push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection' --ext 'pulse:rvalues'" let rec fib (n:nat) : nat = if n <= 1 then 1 else fib (n - 1) + fib (n - 2)
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Pervasives.fst.checked", "Pulse.Lib.BoundedIntegers.fst.checked", "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Fibonacci.fst" }
[ { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
n: Prims.nat -> m: Prims.nat{m <= n} -> FStar.Pervasives.Lemma (ensures Fibonacci.fib m <= Fibonacci.fib n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Equality", "Prims.bool", "Fibonacci.fib_mono", "Prims.op_Subtraction", "Prims.unit", "Prims.l_True", "Prims.squash", "Fibonacci.fib", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec fib_mono (n: nat) (m: nat{m <= n}) : Lemma (ensures fib m <= fib n) =
if n = m then () else fib_mono (n - 1) m
false
Hacl.Impl.Curve25519.Fields.fst
Hacl.Impl.Curve25519.Fields.store_felem
val store_felem: #s:field_spec -> b:lbuffer uint64 4ul -> f:felem s -> Stack unit (requires fun h -> live h f /\ live h b /\ disjoint f b /\ state_inv_t h f) (ensures fun h0 _ h1 -> modifies (loc b |+| loc f) h0 h1 /\ as_seq h1 b == BSeq.nat_to_intseq_le 4 (feval h0 f))
val store_felem: #s:field_spec -> b:lbuffer uint64 4ul -> f:felem s -> Stack unit (requires fun h -> live h f /\ live h b /\ disjoint f b /\ state_inv_t h f) (ensures fun h0 _ h1 -> modifies (loc b |+| loc f) h0 h1 /\ as_seq h1 b == BSeq.nat_to_intseq_le 4 (feval h0 f))
let store_felem #s b f = match s with | M51 -> F51.store_felem b f | M64 -> F64.store_felem b f
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Fields.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 67, "start_col": 0, "start_line": 64 }
module Hacl.Impl.Curve25519.Fields open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer include Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module BSeq = Lib.ByteSequence module LSeq = Lib.Sequence module P = Spec.Curve25519 module F51 = Hacl.Impl.Curve25519.Field51 module F64 = Hacl.Impl.Curve25519.Field64 #set-options "--z3rlimit 50 --max_fuel 0 --initial_ifuel 1 --max_ifuel 1 --record_options" inline_for_extraction noextract val create_felem: s:field_spec -> StackInline (felem s) (requires fun h -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create (v (nlimb s)) (limb_zero s)) /\ as_nat h1 f == 0) let create_felem s = match s with | M51 -> (F51.create_felem ()) <: felem s | M64 -> (F64.create_felem ()) <: felem s inline_for_extraction noextract val load_felem: #s:field_spec -> f:felem s -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint f u64s /\ v (LSeq.index (as_seq h u64s) 3) < pow2 63) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ state_inv_t h1 f /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s)) let load_felem #s f b = match s with | M51 -> F51.load_felem f b | M64 -> F64.load_felem f b val store_felem: #s:field_spec -> b:lbuffer uint64 4ul -> f:felem s -> Stack unit (requires fun h -> live h f /\ live h b /\ disjoint f b /\ state_inv_t h f) (ensures fun h0 _ h1 -> modifies (loc b |+| loc f) h0 h1 /\ as_seq h1 b == BSeq.nat_to_intseq_le 4 (feval h0 f))
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "Hacl.Impl.Curve25519.Field64.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Fields.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field64", "short_module": "F64" }, { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.Buffer.lbuffer Lib.IntTypes.uint64 4ul -> f: Hacl.Impl.Curve25519.Fields.Core.felem s -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.field_spec", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Curve25519.Fields.Core.felem", "Hacl.Impl.Curve25519.Field51.store_felem", "Prims.unit", "Hacl.Impl.Curve25519.Field64.store_felem" ]
[]
false
true
false
false
false
let store_felem #s b f =
match s with | M51 -> F51.store_felem b f | M64 -> F64.store_felem b f
false
Hacl.Impl.SHA3.fst
Hacl.Impl.SHA3.absorb_last
val absorb_last: delimitedSuffix:byte_t -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> rem:size_t{v rem < v rateInBytes} -> input:lbuffer uint8 rem -> s:state -> Stack unit (requires fun h -> live h s /\ live h input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_last delimitedSuffix (v rateInBytes) (v rem) (as_seq h0 input) (as_seq h0 s))
val absorb_last: delimitedSuffix:byte_t -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> rem:size_t{v rem < v rateInBytes} -> input:lbuffer uint8 rem -> s:state -> Stack unit (requires fun h -> live h s /\ live h input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_last delimitedSuffix (v rateInBytes) (v rem) (as_seq h0 input) (as_seq h0 s))
let absorb_last delimitedSuffix rateInBytes rem input s = push_frame(); let h0 = ST.get() in let lastBlock_ = create 200ul (u8 0) in let lastBlock = sub lastBlock_ 0ul rateInBytes in let h1 = ST.get () in assert (as_seq h1 lastBlock `Seq.equal` Lib.Sequence.create (v rateInBytes) (u8 0)); let open Lib.RawIntTypes in update_sub lastBlock (size 0) rem input; lastBlock.(rem) <- byte_to_uint8 delimitedSuffix; loadState rateInBytes lastBlock s; if not ((delimitedSuffix &. byte 0x80) =. byte 0) && (size_to_UInt32 rem = size_to_UInt32 (rateInBytes -. 1ul)) then state_permute s; absorb_next s rateInBytes; pop_frame()
{ "file_name": "code/sha3/Hacl.Impl.SHA3.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 419, "start_col": 0, "start_line": 404 }
module Hacl.Impl.SHA3 open FStar.HyperStack.All open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open LowStar.BufferOps open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Spec.SHA3.Constants module ST = FStar.HyperStack.ST module B = LowStar.Buffer module LSeq = Lib.Sequence module LB = Lib.ByteSequence module Loop = Lib.LoopCombinators module S = Spec.SHA3 module Equiv = Spec.SHA3.Equivalence private let keccak_rotc :x:glbuffer rotc_t 24ul{witnessed x keccak_rotc /\ recallable x} = createL_global rotc_list private let keccak_piln :x:glbuffer piln_t 24ul{witnessed x keccak_piln /\ recallable x} = createL_global piln_list private let keccak_rndc :x:glbuffer pub_uint64 24ul{witnessed x keccak_rndc /\ recallable x} = createL_global rndc_list #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract let state = lbuffer uint64 25ul inline_for_extraction noextract let index = n:size_t{v n < 5} inline_for_extraction noextract val get: s:state -> x:index -> y:index -> Stack uint64 (requires fun h -> live h s) (ensures fun h0 r h1 -> modifies loc_none h0 h1 /\ r == S.get (as_seq h0 s) (v x) (v y)) let get s x y = s.(x +! 5ul *! y) inline_for_extraction noextract val set: s:state -> x:index -> y:index -> v:uint64 -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.set (as_seq h0 s) (size_v x) (size_v y) v) let set s x y v = s.(x +! 5ul *! y) <- v inline_for_extraction noextract let rotl (a:uint64) (b:size_t{0 < uint_v b /\ uint_v b < 64}) = rotate_left a b inline_for_extraction noextract val state_theta0: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h -> live h s /\ live h _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc _C) h0 h1 /\ as_seq h1 _C == S.state_theta0 (as_seq h0 s) (as_seq h0 _C)) let state_theta0 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_C (as_seq h0 s) in let h0 = ST.get () in loop1 h0 5ul _C spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 _C) (v x); _C.(x) <- get s x 0ul ^. get s x 1ul ^. get s x 2ul ^. get s x 3ul ^. get s x 4ul ) inline_for_extraction noextract val state_theta_inner_s: _C:lbuffer uint64 5ul -> x:index -> s:state -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta_inner_s (as_seq h0 _C) (v x) (as_seq h0 s)) let state_theta_inner_s _C x s = let _D = _C.((x +. 4ul) %. 5ul) ^. rotl _C.((x +. 1ul) %. 5ul) 1ul in [@ inline_let] let spec h0 = S.state_theta_inner_s_inner (v x) _D in let h0 = ST.get () in loop1 h0 5ul s spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v y); set s x y (get s x y ^. _D) ) inline_for_extraction noextract val state_theta1: s:state -> _C:lbuffer uint64 5ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 _C /\ disjoint _C s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta1 (as_seq h0 s) (as_seq h0 _C)) let state_theta1 s _C = [@ inline_let] let spec h0 = S.state_theta_inner_s (as_seq h0 _C) in let h0 = ST.get () in loop1 h0 5ul s spec (fun x -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 s) (v x); state_theta_inner_s _C x s ) inline_for_extraction noextract val state_theta: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_theta (as_seq h0 s)) let state_theta s = push_frame (); let h0 = ST.get() in let _C = create 5ul (u64 0) in state_theta0 s _C; state_theta1 s _C; pop_frame() #reset-options "--max_fuel 1 --max_ifuel 1 --z3rlimit 50" private val index_map: #a:Type -> #b:Type -> f:(a -> b) -> l:list a -> i:nat{i < List.Tot.length l} -> Lemma (List.Tot.index (List.Tot.map f l) i == f (List.Tot.index l i)) let rec index_map #a #b f l i = if i = 0 then () else match l with | [] -> () | _ :: l' -> index_map f l' (i - 1) #reset-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" inline_for_extraction noextract val state_pi_rho_inner: i:size_t{v i < 24} -> current:lbuffer uint64 1ul -> s:state -> Stack unit (requires fun h -> live h s /\ live h current /\ disjoint current s) (ensures fun h0 _ h1 -> modifies (loc_union (loc s) (loc current)) h0 h1 /\ (let c', s' = S.state_pi_rho_inner (v i) (bget h0 current 0, as_seq h0 s) in bget h1 current 0 == c' /\ as_seq h1 s == s')) let state_pi_rho_inner i current s = assert_norm (List.Tot.length piln_list == 24); let h0 = ST.get () in recall_contents keccak_rotc Spec.SHA3.Constants.keccak_rotc; recall_contents keccak_piln Spec.SHA3.Constants.keccak_piln; index_map v piln_list (v i); let _Y = keccak_piln.(i) in let r = keccak_rotc.(i) in let temp = s.(_Y) in s.(_Y) <- rotl current.(0ul) r; current.(0ul) <- temp inline_for_extraction noextract val state_pi_rho: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_pi_rho (as_seq h0 s)) let state_pi_rho s = push_frame(); let x = get s 1ul 0ul in let h0 = ST.get() in let current = create 1ul x in let h1 = ST.get () in assert (bget h1 current 0 == S.get (as_seq h0 s) 1 0); [@ inline_let] let refl h i : GTot (uint64 & S.state) = bget h current 0, as_seq h s in [@ inline_let] let footprint i = loc_union (loc current) (loc s) in [@ inline_let] let spec h0 = S.state_pi_rho_inner in let h0 = ST.get () in loop h0 24ul S.state_pi_rho_s refl footprint spec (fun i -> Loop.unfold_repeat_gen 24 S.state_pi_rho_s (spec h0) (refl h0 0) (v i); state_pi_rho_inner i current s ); pop_frame() inline_for_extraction noextract val state_chi_inner: st:state -> y:index -> Stack unit (requires fun h0 -> live h0 st) (ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\ as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) let state_chi_inner st y = let h0 = ST.get() in let v0 = get st 0ul y ^. ((lognot (get st 1ul y)) &. get st 2ul y) in let v1 = get st 1ul y ^. ((lognot (get st 2ul y)) &. get st 3ul y) in let v2 = get st 2ul y ^. ((lognot (get st 3ul y)) &. get st 4ul y) in let v3 = get st 3ul y ^. ((lognot (get st 4ul y)) &. get st 0ul y) in let v4 = get st 4ul y ^. ((lognot (get st 0ul y)) &. get st 1ul y) in set st 0ul y v0; set st 1ul y v1; set st 2ul y v2; set st 3ul y v3; set st 4ul y v4; let h1 = ST.get() in assert (modifies (loc st) h0 h1); assert (as_seq h1 st == Equiv.state_chi_inner (v y) (as_seq h0 st)) inline_for_extraction noextract val state_chi: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_chi (as_seq h0 s)) let state_chi st = let h0 = ST.get() in [@ inline_let] let spec h0 = Equiv.state_chi_inner in let h0 = ST.get () in loop1 h0 5ul st spec (fun y -> Loop.unfold_repeati 5 (spec h0) (as_seq h0 st) (v y); state_chi_inner st y ); let h1 = ST.get() in assert(as_seq h1 st == Equiv.state_chi (as_seq h0 st)); Equiv.state_chi_equivalence (as_seq h0 st) inline_for_extraction noextract val state_iota: s:state -> round:size_t{v round < 24} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_iota (as_seq h0 s) (v round)) let state_iota s round = recall_contents keccak_rndc Spec.SHA3.Constants.keccak_rndc; let c = keccak_rndc.(round) in set s 0ul 0ul (get s 0ul 0ul ^. secret c) private val state_permute: s:state -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.state_permute (as_seq h0 s)) let state_permute s = [@ inline_let] let spec h0 = S.state_permute1 in let h0 = ST.get () in loop1 h0 24ul s spec (fun round -> Loop.unfold_repeati 24 (spec h0) (as_seq h0 s) (v round); state_theta s; state_pi_rho s; state_chi s; state_iota s round) private val loadState: rateInBytes:size_t{v rateInBytes <= 200} -> input:lbuffer uint8 rateInBytes -> s:state -> Stack unit (requires fun h -> live h input /\ live h s /\ disjoint input s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.loadState (v rateInBytes) (as_seq h0 input) (as_seq h0 s)) let loadState rateInBytes input s = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in update_sub block 0ul rateInBytes input; [@ inline_let] let spec h0 = S.loadState_inner (as_seq h0 block) in let h0 = ST.get () in loop1 h0 25ul s spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 s) (v j); let h0 = ST.get() in let x = uint_from_bytes_le #U64 (sub block (j *! 8ul) 8ul) in s.(j) <- s.(j) ^. x ); pop_frame() inline_for_extraction noextract val storeState_inner: s:state -> j:size_t{v j < 25} -> block:lbuffer uint8 200ul -> Stack unit (requires fun h0 -> live h0 s /\ live h0 block /\ disjoint s block) (ensures fun h0 _ h1 -> modifies (loc block) h0 h1 /\ as_seq h1 block == S.storeState_inner (as_seq h0 s) (v j) (as_seq h0 block)) let storeState_inner s j block = let sj = s.(j) in let h0 = ST.get () in update_sub_f h0 block (j *! 8ul) 8ul (fun h -> Lib.ByteSequence.uint_to_bytes_le sj) (fun _ -> uint_to_bytes_le #U64 (sub block (j *! 8ul) 8ul) sj) private val storeState: rateInBytes:size_t{v rateInBytes <= 200} -> s:state -> res:lbuffer uint8 rateInBytes -> Stack unit (requires fun h0 -> live h0 s /\ live h0 res) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ as_seq h1 res == S.storeState (v rateInBytes) (as_seq h0 s)) let storeState rateInBytes s res = push_frame(); let h0 = ST.get() in let block = create 200ul (u8 0) in [@ inline_let] let spec h0 = S.storeState_inner (as_seq h0 s) in let h0 = ST.get () in loop1 h0 25ul block spec (fun j -> Loop.unfold_repeati 25 (spec h0) (as_seq h0 block) (v j); storeState_inner s j block ); copy res (sub block 0ul rateInBytes); pop_frame() #reset-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" inline_for_extraction noextract val absorb_next: s:state -> rateInBytes:size_t{v rateInBytes > 0 /\ v rateInBytes <= 200} -> Stack unit (requires fun h -> live h s) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_next (as_seq h0 s) (v rateInBytes)) let absorb_next s rateInBytes = push_frame(); let h0 = ST.get() in let nextBlock_ = create 200ul (u8 0) in let nextBlock = sub nextBlock_ 0ul rateInBytes in let h1 = ST.get () in assert (as_seq h1 nextBlock `Seq.equal` Lib.Sequence.create (v rateInBytes) (u8 0)); nextBlock.(rateInBytes -! 1ul) <- u8 0x80; loadState rateInBytes nextBlock s; state_permute s; pop_frame() inline_for_extraction noextract val absorb_last: delimitedSuffix:byte_t -> rateInBytes:size_t{0 < v rateInBytes /\ v rateInBytes <= 200} -> rem:size_t{v rem < v rateInBytes} -> input:lbuffer uint8 rem -> s:state -> Stack unit (requires fun h -> live h s /\ live h input /\ disjoint s input) (ensures fun h0 _ h1 -> modifies (loc s) h0 h1 /\ as_seq h1 s == S.absorb_last delimitedSuffix (v rateInBytes) (v rem)
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Equivalence.fst.checked", "Spec.SHA3.Constants.fst.checked", "Spec.SHA3.fst.checked", "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SHA3.fst" }
[ { "abbrev": true, "full_module": "Spec.SHA3.Equivalence", "short_module": "Equiv" }, { "abbrev": true, "full_module": "Spec.SHA3", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loop" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Spec.SHA3.Constants", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "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": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
delimitedSuffix: Lib.IntTypes.byte_t -> rateInBytes: Lib.IntTypes.size_t{0 < Lib.IntTypes.v rateInBytes /\ Lib.IntTypes.v rateInBytes <= 200} -> rem: Lib.IntTypes.size_t{Lib.IntTypes.v rem < Lib.IntTypes.v rateInBytes} -> input: Lib.Buffer.lbuffer Lib.IntTypes.uint8 rem -> s: Hacl.Impl.SHA3.state -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.IntTypes.byte_t", "Lib.IntTypes.size_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.Impl.SHA3.state", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.SHA3.absorb_next", "Prims.op_AmpAmp", "Prims.op_Negation", "Lib.IntTypes.op_Equals_Dot", "Lib.IntTypes.U8", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.byte", "Prims.op_Equality", "FStar.UInt32.t", "Prims.l_or", "Prims.int", "Lib.IntTypes.range", "FStar.UInt.size", "FStar.UInt32.n", "Lib.IntTypes.uint_v", "FStar.UInt32.v", "Lib.IntTypes.op_Subtraction_Dot", "FStar.UInt32.__uint_to_t", "Lib.RawIntTypes.size_to_UInt32", "Hacl.Impl.SHA3.state_permute", "Prims.bool", "Hacl.Impl.SHA3.loadState", "Lib.Buffer.op_Array_Assignment", "Lib.IntTypes.byte_to_uint8", "Lib.Buffer.update_sub", "Lib.Buffer.MUT", "Lib.IntTypes.size", "Prims._assert", "FStar.Seq.Base.equal", "Lib.Buffer.as_seq", "Lib.Sequence.create", "Lib.IntTypes.u8", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.Buffer.sub", "FStar.UInt32.uint_to_t", "Lib.Buffer.create", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let absorb_last delimitedSuffix rateInBytes rem input s =
push_frame (); let h0 = ST.get () in let lastBlock_ = create 200ul (u8 0) in let lastBlock = sub lastBlock_ 0ul rateInBytes in let h1 = ST.get () in assert ((as_seq h1 lastBlock) `Seq.equal` (Lib.Sequence.create (v rateInBytes) (u8 0))); let open Lib.RawIntTypes in update_sub lastBlock (size 0) rem input; lastBlock.(rem) <- byte_to_uint8 delimitedSuffix; loadState rateInBytes lastBlock s; if not ((delimitedSuffix &. byte 0x80) =. byte 0) && (size_to_UInt32 rem = size_to_UInt32 (rateInBytes -. 1ul)) then state_permute s; absorb_next s rateInBytes; pop_frame ()
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.bezout_prop'
val bezout_prop' (n l: nat) (d: pos) (q_n q_l: nat) (u_n u_l: int) : Tot prop
val bezout_prop' (n l: nat) (d: pos) (q_n q_l: nat) (u_n u_l: int) : Tot prop
let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 24, "end_line": 91, "start_col": 0, "start_line": 80 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> l: Prims.nat -> d: Prims.pos -> q_n: Prims.nat -> q_l: Prims.nat -> u_n: Prims.int -> u_l: Prims.int -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.pos", "Prims.int", "Prims.l_and", "Prims.eq2", "FStar.Mul.op_Star", "Prims.op_Addition", "Prims.prop" ]
[]
false
false
false
true
true
let bezout_prop' (n l: nat) (d: pos) (q_n q_l: nat) (u_n u_l: int) : Tot prop =
n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.int_semiring
val int_semiring : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed ()
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 22, "end_line": 68, "start_col": 0, "start_line": 65 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V1.Derived.qed", "FStar.Tactics.V1.Derived.trefl", "FStar.Tactics.CanonCommSemiring.int_semiring" ]
[]
false
true
false
false
false
let int_semiring () =
FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed ()
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.bezout_prop
val bezout_prop (n l: nat) (b: bezout_t) : Tot prop
val bezout_prop (n l: nat) (b: bezout_t) : Tot prop
let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 46, "end_line": 98, "start_col": 0, "start_line": 93 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> l: Prims.nat -> b: Steel.ST.GenArraySwap.Proof.bezout_t -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout_t", "Steel.ST.GenArraySwap.Proof.bezout_prop'", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_l", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__u_n", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__u_l", "Prims.prop" ]
[]
false
false
false
true
true
let bezout_prop (n l: nat) (b: bezout_t) : Tot prop =
bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l
false
FStar.Map.fst
FStar.Map.sel
val sel: #key:eqtype -> #value:Type -> t key value -> key -> Tot value
val sel: #key:eqtype -> #value:Type -> t key value -> key -> Tot value
let sel #key #value m k = m.mappings k
{ "file_name": "ulib/FStar.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 38, "start_col": 0, "start_line": 38 }
(* Copyright 2008-2018 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. *) (** * Implementation of partial maps with extensional equality *) module FStar.Map open FStar.Set open FStar.FunctionalExtensionality module S = FStar.Set module F = FStar.FunctionalExtensionality (* The main "trick" in the representation of the type `t` * is to use a domain-restricted function type `key ^-> value` * from the FStar.FunctionalExtensionality library. * These restricted function types enjoy extensional equality, * which is necessary if Map.t is to also enjoy extensional equality. *) noeq type t (key:eqtype) (value:Type) = { mappings: key ^-> value; domain: set key }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "FStar.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Set", "short_module": null }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Map.t key value -> k: key -> value
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.Map.t", "FStar.Map.__proj__Mkt__item__mappings" ]
[]
false
false
false
false
false
let sel #key #value m k =
m.mappings k
false
FStar.Map.fst
FStar.Map.domain
val domain: #key:eqtype -> #value:Type -> t key value -> Tot (S.set key)
val domain: #key:eqtype -> #value:Type -> t key value -> Tot (S.set key)
let domain #key #value m = m.domain
{ "file_name": "ulib/FStar.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 54, "start_col": 0, "start_line": 54 }
(* Copyright 2008-2018 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. *) (** * Implementation of partial maps with extensional equality *) module FStar.Map open FStar.Set open FStar.FunctionalExtensionality module S = FStar.Set module F = FStar.FunctionalExtensionality (* The main "trick" in the representation of the type `t` * is to use a domain-restricted function type `key ^-> value` * from the FStar.FunctionalExtensionality library. * These restricted function types enjoy extensional equality, * which is necessary if Map.t is to also enjoy extensional equality. *) noeq type t (key:eqtype) (value:Type) = { mappings: key ^-> value; domain: set key } let sel #key #value m k = m.mappings k (* Since mappings are restricted functions, assignments to that field must use `F.on` to restrict the domain of the functional maps *) let upd #key #value m k v = { mappings = F.on key (fun x -> if x = k then v else m.mappings x); domain = S.union m.domain (singleton k) } (* idem *) let const #key #value v = { mappings = F.on key (fun _ -> v); domain = complement empty }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "FStar.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Set", "short_module": null }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Map.t key value -> FStar.Set.set key
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.Map.t", "FStar.Map.__proj__Mkt__item__domain", "FStar.Set.set" ]
[]
false
false
false
false
false
let domain #key #value m =
m.domain
false
FStar.Map.fst
FStar.Map.const
val const: #key:eqtype -> #value:Type -> value -> Tot (t key value)
val const: #key:eqtype -> #value:Type -> value -> Tot (t key value)
let const #key #value v = { mappings = F.on key (fun _ -> v); domain = complement empty }
{ "file_name": "ulib/FStar.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 1, "end_line": 52, "start_col": 0, "start_line": 49 }
(* Copyright 2008-2018 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. *) (** * Implementation of partial maps with extensional equality *) module FStar.Map open FStar.Set open FStar.FunctionalExtensionality module S = FStar.Set module F = FStar.FunctionalExtensionality (* The main "trick" in the representation of the type `t` * is to use a domain-restricted function type `key ^-> value` * from the FStar.FunctionalExtensionality library. * These restricted function types enjoy extensional equality, * which is necessary if Map.t is to also enjoy extensional equality. *) noeq type t (key:eqtype) (value:Type) = { mappings: key ^-> value; domain: set key } let sel #key #value m k = m.mappings k (* Since mappings are restricted functions, assignments to that field must use `F.on` to restrict the domain of the functional maps *) let upd #key #value m k v = { mappings = F.on key (fun x -> if x = k then v else m.mappings x); domain = S.union m.domain (singleton k) }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "FStar.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Set", "short_module": null }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: value -> FStar.Map.t key value
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.Map.Mkt", "FStar.FunctionalExtensionality.on", "FStar.Set.complement", "FStar.Set.empty", "FStar.Map.t" ]
[]
false
false
false
false
false
let const #key #value v =
{ mappings = F.on key (fun _ -> v); domain = complement empty }
false
FStar.Map.fst
FStar.Map.contains
val contains: #key:eqtype -> #value:Type -> t key value -> key -> Tot bool
val contains: #key:eqtype -> #value:Type -> t key value -> key -> Tot bool
let contains #key #value m k = mem k m.domain
{ "file_name": "ulib/FStar.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 45, "end_line": 56, "start_col": 0, "start_line": 56 }
(* Copyright 2008-2018 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. *) (** * Implementation of partial maps with extensional equality *) module FStar.Map open FStar.Set open FStar.FunctionalExtensionality module S = FStar.Set module F = FStar.FunctionalExtensionality (* The main "trick" in the representation of the type `t` * is to use a domain-restricted function type `key ^-> value` * from the FStar.FunctionalExtensionality library. * These restricted function types enjoy extensional equality, * which is necessary if Map.t is to also enjoy extensional equality. *) noeq type t (key:eqtype) (value:Type) = { mappings: key ^-> value; domain: set key } let sel #key #value m k = m.mappings k (* Since mappings are restricted functions, assignments to that field must use `F.on` to restrict the domain of the functional maps *) let upd #key #value m k v = { mappings = F.on key (fun x -> if x = k then v else m.mappings x); domain = S.union m.domain (singleton k) } (* idem *) let const #key #value v = { mappings = F.on key (fun _ -> v); domain = complement empty } let domain #key #value m = m.domain
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "FStar.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Set", "short_module": null }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Map.t key value -> k: key -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.Map.t", "FStar.Set.mem", "FStar.Map.__proj__Mkt__item__domain", "Prims.bool" ]
[]
false
false
false
false
false
let contains #key #value m k =
mem k m.domain
false
FStar.Map.fst
FStar.Map.upd
val upd: #key:eqtype -> #value:Type -> t key value -> key -> value -> Tot (t key value)
val upd: #key:eqtype -> #value:Type -> t key value -> key -> value -> Tot (t key value)
let upd #key #value m k v = { mappings = F.on key (fun x -> if x = k then v else m.mappings x); domain = S.union m.domain (singleton k) }
{ "file_name": "ulib/FStar.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 1, "end_line": 46, "start_col": 0, "start_line": 43 }
(* Copyright 2008-2018 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. *) (** * Implementation of partial maps with extensional equality *) module FStar.Map open FStar.Set open FStar.FunctionalExtensionality module S = FStar.Set module F = FStar.FunctionalExtensionality (* The main "trick" in the representation of the type `t` * is to use a domain-restricted function type `key ^-> value` * from the FStar.FunctionalExtensionality library. * These restricted function types enjoy extensional equality, * which is necessary if Map.t is to also enjoy extensional equality. *) noeq type t (key:eqtype) (value:Type) = { mappings: key ^-> value; domain: set key } let sel #key #value m k = m.mappings k (* Since mappings are restricted functions, assignments to that field must use `F.on`
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "FStar.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Set", "short_module": null }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Map.t key value -> k: key -> v: value -> FStar.Map.t key value
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.Map.t", "FStar.Map.Mkt", "FStar.FunctionalExtensionality.on", "Prims.op_Equality", "Prims.bool", "FStar.Map.__proj__Mkt__item__mappings", "FStar.Set.union", "FStar.Map.__proj__Mkt__item__domain", "FStar.Set.singleton" ]
[]
false
false
false
false
false
let upd #key #value m k v =
{ mappings = F.on key (fun x -> if x = k then v else m.mappings x); domain = S.union m.domain (singleton k) }
false
FStar.Map.fst
FStar.Map.concat
val concat: #key:eqtype -> #value:Type -> t key value -> t key value -> Tot (t key value)
val concat: #key:eqtype -> #value:Type -> t key value -> t key value -> Tot (t key value)
let concat #key #value m1 m2 = { mappings = F.on key (fun x -> if mem x m2.domain then m2.mappings x else m1.mappings x); domain = union m1.domain m2.domain }
{ "file_name": "ulib/FStar.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 1, "end_line": 62, "start_col": 0, "start_line": 59 }
(* Copyright 2008-2018 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. *) (** * Implementation of partial maps with extensional equality *) module FStar.Map open FStar.Set open FStar.FunctionalExtensionality module S = FStar.Set module F = FStar.FunctionalExtensionality (* The main "trick" in the representation of the type `t` * is to use a domain-restricted function type `key ^-> value` * from the FStar.FunctionalExtensionality library. * These restricted function types enjoy extensional equality, * which is necessary if Map.t is to also enjoy extensional equality. *) noeq type t (key:eqtype) (value:Type) = { mappings: key ^-> value; domain: set key } let sel #key #value m k = m.mappings k (* Since mappings are restricted functions, assignments to that field must use `F.on` to restrict the domain of the functional maps *) let upd #key #value m k v = { mappings = F.on key (fun x -> if x = k then v else m.mappings x); domain = S.union m.domain (singleton k) } (* idem *) let const #key #value v = { mappings = F.on key (fun _ -> v); domain = complement empty } let domain #key #value m = m.domain let contains #key #value m k = mem k m.domain
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "FStar.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Set", "short_module": null }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m1: FStar.Map.t key value -> m2: FStar.Map.t key value -> FStar.Map.t key value
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.Map.t", "FStar.Map.Mkt", "FStar.FunctionalExtensionality.on", "FStar.Set.mem", "FStar.Map.__proj__Mkt__item__domain", "FStar.Map.__proj__Mkt__item__mappings", "Prims.bool", "FStar.Set.union" ]
[]
false
false
false
false
false
let concat #key #value m1 m2 =
{ mappings = F.on key (fun x -> if mem x m2.domain then m2.mappings x else m1.mappings x); domain = union m1.domain m2.domain }
false
FStar.Map.fst
FStar.Map.map_val
val map_val: #val1:Type -> #val2:Type -> f:(val1 -> val2) -> #key:eqtype -> t key val1 -> Tot (t key val2)
val map_val: #val1:Type -> #val2:Type -> f:(val1 -> val2) -> #key:eqtype -> t key val1 -> Tot (t key val2)
let map_val #_ #_ f #key m = { mappings = F.on key (fun x -> f (m.mappings x)); domain = m.domain }
{ "file_name": "ulib/FStar.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 1, "end_line": 67, "start_col": 0, "start_line": 64 }
(* Copyright 2008-2018 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. *) (** * Implementation of partial maps with extensional equality *) module FStar.Map open FStar.Set open FStar.FunctionalExtensionality module S = FStar.Set module F = FStar.FunctionalExtensionality (* The main "trick" in the representation of the type `t` * is to use a domain-restricted function type `key ^-> value` * from the FStar.FunctionalExtensionality library. * These restricted function types enjoy extensional equality, * which is necessary if Map.t is to also enjoy extensional equality. *) noeq type t (key:eqtype) (value:Type) = { mappings: key ^-> value; domain: set key } let sel #key #value m k = m.mappings k (* Since mappings are restricted functions, assignments to that field must use `F.on` to restrict the domain of the functional maps *) let upd #key #value m k v = { mappings = F.on key (fun x -> if x = k then v else m.mappings x); domain = S.union m.domain (singleton k) } (* idem *) let const #key #value v = { mappings = F.on key (fun _ -> v); domain = complement empty } let domain #key #value m = m.domain let contains #key #value m k = mem k m.domain (* Again, use F.on to build a domain-restricted function *) let concat #key #value m1 m2 = { mappings = F.on key (fun x -> if mem x m2.domain then m2.mappings x else m1.mappings x); domain = union m1.domain m2.domain }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "FStar.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Set", "short_module": null }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: val1 -> val2) -> m: FStar.Map.t key val1 -> FStar.Map.t key val2
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.Map.t", "FStar.Map.Mkt", "FStar.FunctionalExtensionality.on", "FStar.Map.__proj__Mkt__item__mappings", "FStar.Map.__proj__Mkt__item__domain" ]
[]
false
false
false
false
false
let map_val #_ #_ f #key m =
{ mappings = F.on key (fun x -> f (m.mappings x)); domain = m.domain }
false
FStar.Map.fst
FStar.Map.map_literal
val map_literal (#k:eqtype) (#v:Type) (f: k -> Tot v) : t k v
val map_literal (#k:eqtype) (#v:Type) (f: k -> Tot v) : t k v
let map_literal #k #v f = { mappings = F.on k f; domain = complement empty; }
{ "file_name": "ulib/FStar.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 1, "end_line": 77, "start_col": 0, "start_line": 74 }
(* Copyright 2008-2018 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. *) (** * Implementation of partial maps with extensional equality *) module FStar.Map open FStar.Set open FStar.FunctionalExtensionality module S = FStar.Set module F = FStar.FunctionalExtensionality (* The main "trick" in the representation of the type `t` * is to use a domain-restricted function type `key ^-> value` * from the FStar.FunctionalExtensionality library. * These restricted function types enjoy extensional equality, * which is necessary if Map.t is to also enjoy extensional equality. *) noeq type t (key:eqtype) (value:Type) = { mappings: key ^-> value; domain: set key } let sel #key #value m k = m.mappings k (* Since mappings are restricted functions, assignments to that field must use `F.on` to restrict the domain of the functional maps *) let upd #key #value m k v = { mappings = F.on key (fun x -> if x = k then v else m.mappings x); domain = S.union m.domain (singleton k) } (* idem *) let const #key #value v = { mappings = F.on key (fun _ -> v); domain = complement empty } let domain #key #value m = m.domain let contains #key #value m k = mem k m.domain (* Again, use F.on to build a domain-restricted function *) let concat #key #value m1 m2 = { mappings = F.on key (fun x -> if mem x m2.domain then m2.mappings x else m1.mappings x); domain = union m1.domain m2.domain } let map_val #_ #_ f #key m = { mappings = F.on key (fun x -> f (m.mappings x)); domain = m.domain } let restrict #key #value s m = { mappings = m.mappings; domain = intersect s m.domain }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "FStar.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Set", "short_module": null }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: k -> v) -> FStar.Map.t k v
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.Map.Mkt", "FStar.FunctionalExtensionality.on", "FStar.Set.complement", "FStar.Set.empty", "FStar.Map.t" ]
[]
false
false
false
false
false
let map_literal #k #v f =
{ mappings = F.on k f; domain = complement empty }
false
FStar.Map.fst
FStar.Map.restrict
val restrict: #key:eqtype -> #value:Type -> S.set key -> t key value -> Tot (t key value)
val restrict: #key:eqtype -> #value:Type -> S.set key -> t key value -> Tot (t key value)
let restrict #key #value s m = { mappings = m.mappings; domain = intersect s m.domain }
{ "file_name": "ulib/FStar.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 1, "end_line": 72, "start_col": 0, "start_line": 69 }
(* Copyright 2008-2018 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. *) (** * Implementation of partial maps with extensional equality *) module FStar.Map open FStar.Set open FStar.FunctionalExtensionality module S = FStar.Set module F = FStar.FunctionalExtensionality (* The main "trick" in the representation of the type `t` * is to use a domain-restricted function type `key ^-> value` * from the FStar.FunctionalExtensionality library. * These restricted function types enjoy extensional equality, * which is necessary if Map.t is to also enjoy extensional equality. *) noeq type t (key:eqtype) (value:Type) = { mappings: key ^-> value; domain: set key } let sel #key #value m k = m.mappings k (* Since mappings are restricted functions, assignments to that field must use `F.on` to restrict the domain of the functional maps *) let upd #key #value m k v = { mappings = F.on key (fun x -> if x = k then v else m.mappings x); domain = S.union m.domain (singleton k) } (* idem *) let const #key #value v = { mappings = F.on key (fun _ -> v); domain = complement empty } let domain #key #value m = m.domain let contains #key #value m k = mem k m.domain (* Again, use F.on to build a domain-restricted function *) let concat #key #value m1 m2 = { mappings = F.on key (fun x -> if mem x m2.domain then m2.mappings x else m1.mappings x); domain = union m1.domain m2.domain } let map_val #_ #_ f #key m = { mappings = F.on key (fun x -> f (m.mappings x)); domain = m.domain }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "FStar.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Set", "short_module": null }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Set.set key -> m: FStar.Map.t key value -> FStar.Map.t key value
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.Set.set", "FStar.Map.t", "FStar.Map.Mkt", "FStar.Map.__proj__Mkt__item__mappings", "FStar.Set.intersect", "FStar.Map.__proj__Mkt__item__domain" ]
[]
false
false
false
false
false
let restrict #key #value s m =
{ mappings = m.mappings; domain = intersect s m.domain }
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_iter_mod_d
val jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k)
val jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k)
let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 234, "start_col": 0, "start_line": 220 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> b: Steel.ST.GenArraySwap.Proof.bezout n l -> x: Steel.ST.GenArraySwap.Proof.nat_up_to n -> k: Prims.nat -> FStar.Pervasives.Lemma (ensures Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) k x % Mkbezout_t?.d b == x % Mkbezout_t?.d b) (decreases k)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Prims.op_Equality", "Prims.int", "Prims.bool", "Steel.ST.GenArraySwap.Proof.jump_iter_mod_d", "Steel.ST.GenArraySwap.Proof.jump", "Prims.op_Subtraction", "Prims.unit", "Steel.ST.GenArraySwap.Proof.jump_mod_d", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.op_Modulus", "Steel.ST.GenArraySwap.Proof.iter_fun", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) =
if k = 0 then () else (jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1))
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.bezout_pos_le
val bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)]
val bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)]
let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 34, "end_line": 264, "start_col": 0, "start_line": 257 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> b: Steel.ST.GenArraySwap.Proof.bezout n l -> FStar.Pervasives.Lemma (ensures Mkbezout_t?.d b <= n /\ Mkbezout_t?.q_n b > 0) [SMTPat (Steel.ST.GenArraySwap.Proof.bezout_prop n l b)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "Steel.ST.GenArraySwap.Proof.lemma_pos_mul_pos_args", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.prop", "Steel.ST.GenArraySwap.Proof.bezout_prop", "Prims.Nil" ]
[]
true
false
true
false
false
let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] =
lemma_pos_mul_pos_args b.q_n b.d
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.iter_fun
val iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n)
val iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n)
let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x)
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 31, "end_line": 187, "start_col": 0, "start_line": 178 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: t -> Prims.GTot t) -> n: Prims.nat -> x: t -> Prims.GTot t
Prims.GTot
[ "sometrivial", "" ]
[]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.bool", "Steel.ST.GenArraySwap.Proof.iter_fun", "Prims.op_Subtraction" ]
[ "recursion" ]
false
false
false
false
false
let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) =
if n = 0 then x else iter_fun f (n - 1) (f x)
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_coverage_strong
val jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat). k' < k ==> (~(x == iter_fun (jump n l) k' (x % b.d))))))
val jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat). k' < k ==> (~(x == iter_fun (jump n l) k' (x % b.d))))))
let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k'
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 66, "end_line": 349, "start_col": 0, "start_line": 337 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> b: Steel.ST.GenArraySwap.Proof.bezout n l -> x: Steel.ST.GenArraySwap.Proof.nat_up_to n -> Prims.Ghost Prims.nat
Prims.Ghost
[]
[]
[ "Prims.pos", "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Steel.ST.GenArraySwap.Proof.minimal_exists", "Prims.op_Equality", "Steel.ST.GenArraySwap.Proof.iter_fun", "Steel.ST.GenArraySwap.Proof.jump", "Prims.op_Modulus", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Prims.bool", "Steel.ST.GenArraySwap.Proof.jump_coverage", "Prims.l_True", "Prims.l_and", "Prims.eq2", "Prims.l_Forall", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan", "Prims.l_not" ]
[]
false
false
false
false
false
let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat). k' < k ==> (~(x == iter_fun (jump n l) k' (x % b.d)))))) =
let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k'
false
FStar.Map.fst
FStar.Map.equal
val equal (#key:eqtype) (#value:Type) (m1:t key value) (m2:t key value) : prop
val equal (#key:eqtype) (#value:Type) (m1:t key value) (m2:t key value) : prop
let equal (#key:eqtype) (#value:Type) (m1:t key value) (m2:t key value) : Type0 = F.feq m1.mappings m2.mappings /\ S.equal m1.domain m2.domain
{ "file_name": "ulib/FStar.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 98, "start_col": 0, "start_line": 96 }
(* Copyright 2008-2018 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. *) (** * Implementation of partial maps with extensional equality *) module FStar.Map open FStar.Set open FStar.FunctionalExtensionality module S = FStar.Set module F = FStar.FunctionalExtensionality (* The main "trick" in the representation of the type `t` * is to use a domain-restricted function type `key ^-> value` * from the FStar.FunctionalExtensionality library. * These restricted function types enjoy extensional equality, * which is necessary if Map.t is to also enjoy extensional equality. *) noeq type t (key:eqtype) (value:Type) = { mappings: key ^-> value; domain: set key } let sel #key #value m k = m.mappings k (* Since mappings are restricted functions, assignments to that field must use `F.on` to restrict the domain of the functional maps *) let upd #key #value m k v = { mappings = F.on key (fun x -> if x = k then v else m.mappings x); domain = S.union m.domain (singleton k) } (* idem *) let const #key #value v = { mappings = F.on key (fun _ -> v); domain = complement empty } let domain #key #value m = m.domain let contains #key #value m k = mem k m.domain (* Again, use F.on to build a domain-restricted function *) let concat #key #value m1 m2 = { mappings = F.on key (fun x -> if mem x m2.domain then m2.mappings x else m1.mappings x); domain = union m1.domain m2.domain } let map_val #_ #_ f #key m = { mappings = F.on key (fun x -> f (m.mappings x)); domain = m.domain } let restrict #key #value s m = { mappings = m.mappings; domain = intersect s m.domain } let map_literal #k #v f = { mappings = F.on k f; domain = complement empty; } let lemma_SelUpd1 #key #value m k v = () let lemma_SelUpd2 #key #value m k1 k2 v = () let lemma_SelConst #key #value v k = () let lemma_SelRestrict #key #value m ks k = () let lemma_SelConcat1 #key #value m1 m2 k = () let lemma_SelConcat2 #key #value m1 m2 k = () let lemma_SelMapVal #val1 #val2 f #key m k = () let lemma_InDomUpd1 #key #value m k1 k2 v = () let lemma_InDomUpd2 #key #value m k1 k2 v = () let lemma_InDomConstMap #key #value v k = () let lemma_InDomConcat #key #value m1 m2 k = () let lemma_InMapVal #val1 #val2 f #key m k = () let lemma_InDomRestrict #key #value m ks k = () let lemma_ContainsDom #key #value m k = () let lemma_UpdDomain #key #value m k v = () let lemma_map_literal #key #value f = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": true, "source_file": "FStar.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Set", "short_module": null }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "S" }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m1: FStar.Map.t key value -> m2: FStar.Map.t key value -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.Map.t", "Prims.l_and", "FStar.FunctionalExtensionality.feq", "FStar.Map.__proj__Mkt__item__mappings", "FStar.Set.equal", "FStar.Map.__proj__Mkt__item__domain", "Prims.prop" ]
[]
false
false
false
false
true
let equal (#key: eqtype) (#value: Type) (m1 m2: t key value) : Type0 =
F.feq m1.mappings m2.mappings /\ S.equal m1.domain m2.domain
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.bezout_q_eq
val bezout_q_eq (n l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n]
val bezout_q_eq (n l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n]
let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 28, "end_line": 176, "start_col": 0, "start_line": 169 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> l: Prims.nat -> bz: Steel.ST.GenArraySwap.Proof.bezout n l -> FStar.Pervasives.Lemma (ensures Mkbezout_t?.q_n bz == n / Mkbezout_t?.d bz) [SMTPat (Steel.ST.GenArraySwap.Proof.bezout_prop n l bz); SMTPat (Mkbezout_t?.q_n bz)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "FStar.Math.Lemmas.cancel_mul_div", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.op_Division", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.prop", "Steel.ST.GenArraySwap.Proof.bezout_prop", "Prims.Nil" ]
[]
true
false
true
false
false
let bezout_q_eq (n l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] =
cancel_mul_div bz.q_n bz.d
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.minimal_exists'
val minimal_exists' (p: (nat -> GTot bool)) (n i: nat) : Ghost nat (requires (p n == true /\ i <= n /\ (forall (j: nat). j < i ==> p j == false))) (ensures (fun k -> p k == true /\ (forall (j: nat). j < k ==> p j == false))) (decreases (n - i))
val minimal_exists' (p: (nat -> GTot bool)) (n i: nat) : Ghost nat (requires (p n == true /\ i <= n /\ (forall (j: nat). j < i ==> p j == false))) (ensures (fun k -> p k == true /\ (forall (j: nat). j < k ==> p j == false))) (decreases (n - i))
let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1)
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 34, "end_line": 318, "start_col": 0, "start_line": 301 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: (_: Prims.nat -> Prims.GTot Prims.bool) -> n: Prims.nat -> i: Prims.nat -> Prims.Ghost Prims.nat
Prims.Ghost
[ "" ]
[]
[ "Prims.nat", "Prims.bool", "Steel.ST.GenArraySwap.Proof.minimal_exists'", "Prims.op_Addition", "Prims.l_and", "Prims.eq2", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.l_Forall", "Prims.l_imp", "Prims.op_LessThan" ]
[ "recursion" ]
false
false
false
false
false
let rec minimal_exists' (p: (nat -> GTot bool)) (n i: nat) : Ghost nat (requires (p n == true /\ i <= n /\ (forall (j: nat). j < i ==> p j == false))) (ensures (fun k -> p k == true /\ (forall (j: nat). j < k ==> p j == false))) (decreases (n - i)) =
if p i then i else minimal_exists' p n (i + 1)
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.array_swap_outer_invariant
val array_swap_outer_invariant (#t: Type0) (s0: Seq.seq t) (n l: nat) (bz: bezout (n) (l)) (s: Seq.seq t) (i: nat) : Tot prop
val array_swap_outer_invariant (#t: Type0) (s0: Seq.seq t) (n l: nat) (bz: bezout (n) (l)) (s: Seq.seq t) (i: nat) : Tot prop
let array_swap_outer_invariant // hoisting necessary because "Let binding is effectful" (#t: Type0) (s0: Seq.seq t) (n: nat) (l: nat) (bz: bezout (n) (l)) (s: Seq.seq t) (i: nat) : Tot prop = 0 < l /\ l < n /\ i <= bz.d /\ n == Seq.length s0 /\ n == Seq.length s /\ (forall (i': nat_up_to bz.d) . // this is always true, but I need it here for the pattern Seq.index s i' == Seq.index s (iter_fun #(nat_up_to (n)) (jump (n) (l)) 0 i') ) /\ (forall (i': nat_up_to bz.d) . (forall (j: nat_up_to bz.q_n) . let idx = iter_fun #(nat_up_to (n)) (jump (n) (l)) j i' in Seq.index s idx == Seq.index s0 (if i' < i then jump (n) (l) idx else idx) ))
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 4, "end_line": 655, "start_col": 0, "start_line": 639 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq let jump_iter_inj (n: nat) (l: nat) (b: bezout_t) (i1 i2: nat) (k1 k2: nat) : Lemma (requires ( n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2 )) (ensures ( i1 == i2 /\ k1 == k2 )) [SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b)] = jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n #restart-solver let jump_iter_elim (n: pos) (p: nat_up_to n -> prop) (l: nat) (b: bezout n l) : Lemma (requires ( forall (i: nat_up_to b.d) (k: nat_up_to b.q_n) . p (iter_fun (jump n l) k i) )) (ensures ( forall (x: nat_up_to n) . p x )) = let prf (x: nat_up_to n) : Lemma (p x) = let i : nat_up_to b.d = x % b.d in let k' = jump_coverage_strong n l b x in jump_coverage_strong_bound n l b x; assert (p (iter_fun (jump n l) k' i)) in Classical.forall_intro prf let jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l)) = let idx' = (if idx + l >= n then idx - (n - l) else idx + l) in small_mod idx n; small_mod idx' n; lemma_mod_plus (idx + l) (-1) n let jump_iter_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (ensures ( iter_fun (jump n l) b.q_n x == x )) = cancel_mul_mod 1 b.q_n; jump_iter_mod_q n l b x b.q_n let rec iter_fun_add (#t: Type) (f: (t -> GTot t)) (n1 n2: nat) (x: t) : Lemma (ensures (iter_fun f n1 (iter_fun f n2 x) == iter_fun f (n1 + n2) x)) (decreases n2) = if n2 = 0 then () else iter_fun_add f n1 (n2 - 1) (f x) let iter_succ_l (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : Lemma (f (iter_fun f n x) == iter_fun f (n + 1) x) [SMTPat (f (iter_fun f n x))] = iter_fun_add f 1 n x let jump_jump_iter_pred_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (j: nat_up_to b.q_n) : Lemma (requires ( j == b.q_n - 1 )) (ensures ( jump n l (iter_fun (jump n l) j x) == x )) [SMTPat (jump n l (iter_fun (jump n l) j x)); SMTPat (bezout_prop n l b)] = jump_iter_q n l b x let array_swap_post (#t: Type) (s0: Seq.seq t) (n: nat) (l: nat) (s: Seq.seq t) : Tot prop = n == Seq.length s0 /\ 0 <= l /\ l <= n /\ s `Seq.equal` (Seq.slice s0 l n `Seq.append` Seq.slice s0 0 l) let array_as_ring_buffer_swap (#t: Type) (n: nat) (l: nat) (bz: bezout n l) (s0: Seq.seq t) (s: Seq.seq t) : Lemma (requires ( n == Seq.length s0 /\ n == Seq.length s /\ 0 < l /\ l < n /\ (forall (i': nat_up_to bz.d) . (forall (j: nat_up_to bz.q_n) . (i' < bz.d) ==> ( let idx = iter_fun #(nat_up_to n) (jump n l) j i' in Seq.index s idx == Seq.index s0 (jump n l idx) ))) )) (ensures ( array_swap_post s0 n l s )) [SMTPat (array_swap_post s0 n l s); SMTPat (bezout_prop n l bz)] = Classical.forall_intro (jump_if n l ()); let p (idx: nat_up_to n) : Tot prop = Seq.index s idx == Seq.index s0 (jump n l idx) in jump_iter_elim n p l bz
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: FStar.Seq.Base.seq t -> n: Prims.nat -> l: Prims.nat -> bz: Steel.ST.GenArraySwap.Proof.bezout n l -> s: FStar.Seq.Base.seq t -> i: Prims.nat -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Prims.op_LessThanOrEqual", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Prims.eq2", "FStar.Seq.Base.length", "Prims.l_Forall", "Steel.ST.GenArraySwap.Proof.nat_up_to", "FStar.Seq.Base.index", "Steel.ST.GenArraySwap.Proof.iter_fun", "Steel.ST.GenArraySwap.Proof.jump", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Prims.bool", "Prims.prop" ]
[]
false
false
false
false
true
let array_swap_outer_invariant (#t: Type0) (s0: Seq.seq t) (n l: nat) (bz: bezout (n) (l)) (s: Seq.seq t) (i: nat) : Tot prop =
0 < l /\ l < n /\ i <= bz.d /\ n == Seq.length s0 /\ n == Seq.length s /\ (forall (i': nat_up_to bz.d). Seq.index s i' == Seq.index s (iter_fun #(nat_up_to (n)) (jump (n) (l)) 0 i')) /\ (forall (i': nat_up_to bz.d). (forall (j: nat_up_to bz.q_n). let idx = iter_fun #(nat_up_to (n)) (jump (n) (l)) j i' in Seq.index s idx == Seq.index s0 (if i' < i then jump (n) (l) idx else idx)))
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.array_swap_post
val array_swap_post (#t: Type) (s0: Seq.seq t) (n l: nat) (s: Seq.seq t) : Tot prop
val array_swap_post (#t: Type) (s0: Seq.seq t) (n l: nat) (s: Seq.seq t) : Tot prop
let array_swap_post (#t: Type) (s0: Seq.seq t) (n: nat) (l: nat) (s: Seq.seq t) : Tot prop = n == Seq.length s0 /\ 0 <= l /\ l <= n /\ s `Seq.equal` (Seq.slice s0 l n `Seq.append` Seq.slice s0 0 l)
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 66, "end_line": 605, "start_col": 0, "start_line": 594 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq let jump_iter_inj (n: nat) (l: nat) (b: bezout_t) (i1 i2: nat) (k1 k2: nat) : Lemma (requires ( n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2 )) (ensures ( i1 == i2 /\ k1 == k2 )) [SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b)] = jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n #restart-solver let jump_iter_elim (n: pos) (p: nat_up_to n -> prop) (l: nat) (b: bezout n l) : Lemma (requires ( forall (i: nat_up_to b.d) (k: nat_up_to b.q_n) . p (iter_fun (jump n l) k i) )) (ensures ( forall (x: nat_up_to n) . p x )) = let prf (x: nat_up_to n) : Lemma (p x) = let i : nat_up_to b.d = x % b.d in let k' = jump_coverage_strong n l b x in jump_coverage_strong_bound n l b x; assert (p (iter_fun (jump n l) k' i)) in Classical.forall_intro prf let jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l)) = let idx' = (if idx + l >= n then idx - (n - l) else idx + l) in small_mod idx n; small_mod idx' n; lemma_mod_plus (idx + l) (-1) n let jump_iter_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (ensures ( iter_fun (jump n l) b.q_n x == x )) = cancel_mul_mod 1 b.q_n; jump_iter_mod_q n l b x b.q_n let rec iter_fun_add (#t: Type) (f: (t -> GTot t)) (n1 n2: nat) (x: t) : Lemma (ensures (iter_fun f n1 (iter_fun f n2 x) == iter_fun f (n1 + n2) x)) (decreases n2) = if n2 = 0 then () else iter_fun_add f n1 (n2 - 1) (f x) let iter_succ_l (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : Lemma (f (iter_fun f n x) == iter_fun f (n + 1) x) [SMTPat (f (iter_fun f n x))] = iter_fun_add f 1 n x let jump_jump_iter_pred_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (j: nat_up_to b.q_n) : Lemma (requires ( j == b.q_n - 1 )) (ensures ( jump n l (iter_fun (jump n l) j x) == x )) [SMTPat (jump n l (iter_fun (jump n l) j x)); SMTPat (bezout_prop n l b)] = jump_iter_q n l b x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: FStar.Seq.Base.seq t -> n: Prims.nat -> l: Prims.nat -> s: FStar.Seq.Base.seq t -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "Prims.nat", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.length", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.equal", "FStar.Seq.Base.append", "FStar.Seq.Base.slice", "Prims.prop" ]
[]
false
false
false
true
true
let array_swap_post (#t: Type) (s0: Seq.seq t) (n l: nat) (s: Seq.seq t) : Tot prop =
n == Seq.length s0 /\ 0 <= l /\ l <= n /\ s `Seq.equal` ((Seq.slice s0 l n) `Seq.append` (Seq.slice s0 0 l))
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.iter_succ_l
val iter_succ_l (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : Lemma (f (iter_fun f n x) == iter_fun f (n + 1) x) [SMTPat (f (iter_fun f n x))]
val iter_succ_l (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : Lemma (f (iter_fun f n x) == iter_fun f (n + 1) x) [SMTPat (f (iter_fun f n x))]
let iter_succ_l (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : Lemma (f (iter_fun f n x) == iter_fun f (n + 1) x) [SMTPat (f (iter_fun f n x))] = iter_fun_add f 1 n x
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 22, "end_line": 576, "start_col": 0, "start_line": 568 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq let jump_iter_inj (n: nat) (l: nat) (b: bezout_t) (i1 i2: nat) (k1 k2: nat) : Lemma (requires ( n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2 )) (ensures ( i1 == i2 /\ k1 == k2 )) [SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b)] = jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n #restart-solver let jump_iter_elim (n: pos) (p: nat_up_to n -> prop) (l: nat) (b: bezout n l) : Lemma (requires ( forall (i: nat_up_to b.d) (k: nat_up_to b.q_n) . p (iter_fun (jump n l) k i) )) (ensures ( forall (x: nat_up_to n) . p x )) = let prf (x: nat_up_to n) : Lemma (p x) = let i : nat_up_to b.d = x % b.d in let k' = jump_coverage_strong n l b x in jump_coverage_strong_bound n l b x; assert (p (iter_fun (jump n l) k' i)) in Classical.forall_intro prf let jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l)) = let idx' = (if idx + l >= n then idx - (n - l) else idx + l) in small_mod idx n; small_mod idx' n; lemma_mod_plus (idx + l) (-1) n let jump_iter_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (ensures ( iter_fun (jump n l) b.q_n x == x )) = cancel_mul_mod 1 b.q_n; jump_iter_mod_q n l b x b.q_n let rec iter_fun_add (#t: Type) (f: (t -> GTot t)) (n1 n2: nat) (x: t) : Lemma (ensures (iter_fun f n1 (iter_fun f n2 x) == iter_fun f (n1 + n2) x)) (decreases n2) = if n2 = 0 then () else iter_fun_add f n1 (n2 - 1) (f x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: t -> Prims.GTot t) -> n: Prims.nat -> x: t -> FStar.Pervasives.Lemma (ensures f (Steel.ST.GenArraySwap.Proof.iter_fun f n x) == Steel.ST.GenArraySwap.Proof.iter_fun f (n + 1) x) [SMTPat (f (Steel.ST.GenArraySwap.Proof.iter_fun f n x))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Steel.ST.GenArraySwap.Proof.iter_fun_add", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Steel.ST.GenArraySwap.Proof.iter_fun", "Prims.op_Addition", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let iter_succ_l (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : Lemma (f (iter_fun f n x) == iter_fun f (n + 1) x) [SMTPat (f (iter_fun f n x))] =
iter_fun_add f 1 n x
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_iter_mod_q_inj_weak
val jump_iter_mod_q_inj_weak (n l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires (iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x)) (ensures (b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n))
val jump_iter_mod_q_inj_weak (n l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires (iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x)) (ensures (b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n))
let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 29, "end_line": 475, "start_col": 0, "start_line": 456 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.pos -> b: Steel.ST.GenArraySwap.Proof.bezout n l -> x: Steel.ST.GenArraySwap.Proof.nat_up_to n -> k1: Prims.nat -> k2: Prims.nat -> FStar.Pervasives.Lemma (requires Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) k1 x == Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) k2 x) (ensures Mkbezout_t?.q_n b > 0 /\ k1 % Mkbezout_t?.q_n b == k2 % Mkbezout_t?.q_n b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Steel.ST.GenArraySwap.Proof.bezout", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Prims.nat", "Steel.ST.GenArraySwap.Proof.mod_eq_intro", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Prims.int", "Steel.ST.GenArraySwap.Proof.gauss", "Prims.op_Addition", "Prims.op_Minus", "Prims.unit", "FStar.Tactics.Effect.assert_by_tactic", "Prims.eq2", "FStar.Mul.op_Star", "Steel.ST.GenArraySwap.Proof.int_semiring", "Steel.ST.GenArraySwap.Proof.mod_eq_elim", "Steel.ST.GenArraySwap.Proof.jump_iter", "Steel.ST.GenArraySwap.Proof.iter_fun", "Steel.ST.GenArraySwap.Proof.jump", "Prims.squash", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_Modulus", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let jump_iter_mod_q_inj_weak (n l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires (iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x)) (ensures (b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n)) =
jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in FStar.Tactics.Effect.assert_by_tactic ((k1 + - k2) * l == (k1 * l + - (k2 * l))) (fun _ -> (); (int_semiring ())); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.minimal_exists
val minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires (p n == true)) (ensures (fun k -> p k == true /\ (forall (j: nat). j < k ==> p j == false)))
val minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires (p n == true)) (ensures (fun k -> p k == true /\ (forall (j: nat). j < k ==> p j == false)))
let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 23, "end_line": 333, "start_col": 0, "start_line": 322 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: (_: Prims.nat -> Prims.GTot Prims.bool) -> n: Prims.nat -> Prims.Ghost Prims.nat
Prims.Ghost
[]
[]
[ "Prims.nat", "Prims.bool", "Steel.ST.GenArraySwap.Proof.minimal_exists'", "Prims.eq2", "Prims.l_and", "Prims.l_Forall", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThan" ]
[]
false
false
false
false
false
let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires (p n == true)) (ensures (fun k -> p k == true /\ (forall (j: nat). j < k ==> p j == false))) =
minimal_exists' p n 0
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.array_swap_inner_invariant
val array_swap_inner_invariant (#t: Type0) (s0: Seq.seq t) (n l: nat) (bz: bezout (n) (l)) (s: Seq.seq t) (i j idx: nat) : Tot prop
val array_swap_inner_invariant (#t: Type0) (s0: Seq.seq t) (n l: nat) (bz: bezout (n) (l)) (s: Seq.seq t) (i j idx: nat) : Tot prop
let array_swap_inner_invariant (#t: Type0) (s0: Seq.seq t) (n: nat) (l: nat) (bz: bezout (n) (l)) (s: Seq.seq t) (i: nat) (j: nat) (idx: nat) : Tot prop = 0 < l /\ l < n /\ n == Seq.length s0 /\ i < bz.d /\ j < bz.q_n /\ idx == iter_fun #(nat_up_to (n)) (jump (n) (l)) (j) (i) /\ n == Seq.length s /\ (forall (i': nat_up_to bz.d) . (forall (j': nat_up_to bz.q_n) . let idx = iter_fun #(nat_up_to (n)) (jump (n) (l)) j' i' in Seq.index s idx == Seq.index s0 (if i' < i || (i' = i && j' < j) then jump (n) (l) idx else idx) ))
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 4, "end_line": 672, "start_col": 0, "start_line": 657 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq let jump_iter_inj (n: nat) (l: nat) (b: bezout_t) (i1 i2: nat) (k1 k2: nat) : Lemma (requires ( n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2 )) (ensures ( i1 == i2 /\ k1 == k2 )) [SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b)] = jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n #restart-solver let jump_iter_elim (n: pos) (p: nat_up_to n -> prop) (l: nat) (b: bezout n l) : Lemma (requires ( forall (i: nat_up_to b.d) (k: nat_up_to b.q_n) . p (iter_fun (jump n l) k i) )) (ensures ( forall (x: nat_up_to n) . p x )) = let prf (x: nat_up_to n) : Lemma (p x) = let i : nat_up_to b.d = x % b.d in let k' = jump_coverage_strong n l b x in jump_coverage_strong_bound n l b x; assert (p (iter_fun (jump n l) k' i)) in Classical.forall_intro prf let jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l)) = let idx' = (if idx + l >= n then idx - (n - l) else idx + l) in small_mod idx n; small_mod idx' n; lemma_mod_plus (idx + l) (-1) n let jump_iter_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (ensures ( iter_fun (jump n l) b.q_n x == x )) = cancel_mul_mod 1 b.q_n; jump_iter_mod_q n l b x b.q_n let rec iter_fun_add (#t: Type) (f: (t -> GTot t)) (n1 n2: nat) (x: t) : Lemma (ensures (iter_fun f n1 (iter_fun f n2 x) == iter_fun f (n1 + n2) x)) (decreases n2) = if n2 = 0 then () else iter_fun_add f n1 (n2 - 1) (f x) let iter_succ_l (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : Lemma (f (iter_fun f n x) == iter_fun f (n + 1) x) [SMTPat (f (iter_fun f n x))] = iter_fun_add f 1 n x let jump_jump_iter_pred_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (j: nat_up_to b.q_n) : Lemma (requires ( j == b.q_n - 1 )) (ensures ( jump n l (iter_fun (jump n l) j x) == x )) [SMTPat (jump n l (iter_fun (jump n l) j x)); SMTPat (bezout_prop n l b)] = jump_iter_q n l b x let array_swap_post (#t: Type) (s0: Seq.seq t) (n: nat) (l: nat) (s: Seq.seq t) : Tot prop = n == Seq.length s0 /\ 0 <= l /\ l <= n /\ s `Seq.equal` (Seq.slice s0 l n `Seq.append` Seq.slice s0 0 l) let array_as_ring_buffer_swap (#t: Type) (n: nat) (l: nat) (bz: bezout n l) (s0: Seq.seq t) (s: Seq.seq t) : Lemma (requires ( n == Seq.length s0 /\ n == Seq.length s /\ 0 < l /\ l < n /\ (forall (i': nat_up_to bz.d) . (forall (j: nat_up_to bz.q_n) . (i' < bz.d) ==> ( let idx = iter_fun #(nat_up_to n) (jump n l) j i' in Seq.index s idx == Seq.index s0 (jump n l idx) ))) )) (ensures ( array_swap_post s0 n l s )) [SMTPat (array_swap_post s0 n l s); SMTPat (bezout_prop n l bz)] = Classical.forall_intro (jump_if n l ()); let p (idx: nat_up_to n) : Tot prop = Seq.index s idx == Seq.index s0 (jump n l idx) in jump_iter_elim n p l bz let array_swap_outer_invariant // hoisting necessary because "Let binding is effectful" (#t: Type0) (s0: Seq.seq t) (n: nat) (l: nat) (bz: bezout (n) (l)) (s: Seq.seq t) (i: nat) : Tot prop = 0 < l /\ l < n /\ i <= bz.d /\ n == Seq.length s0 /\ n == Seq.length s /\ (forall (i': nat_up_to bz.d) . // this is always true, but I need it here for the pattern Seq.index s i' == Seq.index s (iter_fun #(nat_up_to (n)) (jump (n) (l)) 0 i') ) /\ (forall (i': nat_up_to bz.d) . (forall (j: nat_up_to bz.q_n) . let idx = iter_fun #(nat_up_to (n)) (jump (n) (l)) j i' in Seq.index s idx == Seq.index s0 (if i' < i then jump (n) (l) idx else idx) ))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: FStar.Seq.Base.seq t -> n: Prims.nat -> l: Prims.nat -> bz: Steel.ST.GenArraySwap.Proof.bezout n l -> s: FStar.Seq.Base.seq t -> i: Prims.nat -> j: Prims.nat -> idx: Prims.nat -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Prims.eq2", "FStar.Seq.Base.length", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Steel.ST.GenArraySwap.Proof.iter_fun", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Steel.ST.GenArraySwap.Proof.jump", "Prims.l_Forall", "FStar.Seq.Base.index", "Prims.op_BarBar", "Prims.op_AmpAmp", "Prims.op_Equality", "Prims.bool", "Prims.prop" ]
[]
false
false
false
false
true
let array_swap_inner_invariant (#t: Type0) (s0: Seq.seq t) (n l: nat) (bz: bezout (n) (l)) (s: Seq.seq t) (i j idx: nat) : Tot prop =
0 < l /\ l < n /\ n == Seq.length s0 /\ i < bz.d /\ j < bz.q_n /\ idx == iter_fun #(nat_up_to (n)) (jump (n) (l)) (j) (i) /\ n == Seq.length s /\ (forall (i': nat_up_to bz.d). (forall (j': nat_up_to bz.q_n). let idx = iter_fun #(nat_up_to (n)) (jump (n) (l)) j' i' in Seq.index s idx == Seq.index s0 (if i' < i || (i' = i && j' < j) then jump (n) (l) idx else idx)))
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump
val jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n)
val jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n)
let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 196, "start_col": 0, "start_line": 191 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n })
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> x: Steel.ST.GenArraySwap.Proof.nat_up_to n -> Prims.GTot (Steel.ST.GenArraySwap.Proof.nat_up_to n)
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.pos", "Prims.nat", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Prims.op_Modulus", "Prims.op_Addition" ]
[]
false
false
false
false
false
let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) =
(x + l) % n
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_coverage_strong_bound
val jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n) [SMTPat (jump_coverage_strong n l b x)]
val jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n) [SMTPat (jump_coverage_strong n l b x)]
let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 35, "end_line": 384, "start_col": 0, "start_line": 373 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> b: Steel.ST.GenArraySwap.Proof.bezout n l -> x: Steel.ST.GenArraySwap.Proof.nat_up_to n -> FStar.Pervasives.Lemma (ensures Mkbezout_t?.q_n b > 0 /\ Steel.ST.GenArraySwap.Proof.jump_coverage_strong n l b x < Mkbezout_t?.q_n b) [SMTPat (Steel.ST.GenArraySwap.Proof.jump_coverage_strong n l b x)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Steel.ST.GenArraySwap.Proof.jump_iter_mod_q", "Prims.op_Modulus", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__d", "Steel.ST.GenArraySwap.Proof.jump_coverage_strong", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Prims.op_LessThan", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n) [SMTPat (jump_coverage_strong n l b x)] =
let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k
false
Functor.fst
Functor.functor_list
[@@ FStar.Tactics.Typeclasses.tcinstance] val functor_list:functor list
[@@ FStar.Tactics.Typeclasses.tcinstance] val functor_list:functor list
instance functor_list : functor list = { fmap = List.Tot.map }
{ "file_name": "examples/typeclasses/Functor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 62, "end_line": 25, "start_col": 0, "start_line": 25 }
(* Copyright 2008-2018 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 Functor open FStar.Tactics.Typeclasses class functor f = { fmap : (#a:Type) -> (#b:Type) -> (a -> b) -> f a -> f b ; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Functor.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Functor.functor Prims.list
Prims.Tot
[ "total" ]
[]
[ "Functor.Mkfunctor", "Prims.list", "FStar.List.Tot.Base.map" ]
[]
false
false
false
true
false
[@@ FStar.Tactics.Typeclasses.tcinstance] let functor_list:functor list =
{ fmap = List.Tot.map }
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_iter
val jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k)
val jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k)
let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 255, "start_col": 0, "start_line": 238 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> x: Steel.ST.GenArraySwap.Proof.nat_up_to n -> k: Prims.nat -> FStar.Pervasives.Lemma (ensures Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) k x == (x + k * l) % n) (decreases k)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.nat", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Prims.op_Equality", "Prims.int", "FStar.Math.Lemmas.small_mod", "Prims.unit", "FStar.Tactics.Effect.assert_by_tactic", "Prims.eq2", "Prims.op_Addition", "FStar.Mul.op_Star", "Steel.ST.GenArraySwap.Proof.int_semiring", "Prims.bool", "FStar.Math.Lemmas.lemma_mod_add_distr", "Steel.ST.GenArraySwap.Proof.jump_iter", "Prims.op_Modulus", "Prims.op_Subtraction", "Prims.l_True", "Prims.squash", "Steel.ST.GenArraySwap.Proof.iter_fun", "Steel.ST.GenArraySwap.Proof.jump", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) =
if k = 0 then (FStar.Tactics.Effect.assert_by_tactic (eq2 #int (x + 0 * l) x) (fun _ -> (); (int_semiring ())); small_mod x n) else let k' = k - 1 in FStar.Tactics.Effect.assert_by_tactic (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) (fun _ -> (); (int_semiring ())); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_if
val jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l))
val jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l))
let jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l)) = let idx' = (if idx + l >= n then idx - (n - l) else idx + l) in small_mod idx n; small_mod idx' n; lemma_mod_plus (idx + l) (-1) n
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 33, "end_line": 542, "start_col": 0, "start_line": 532 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq let jump_iter_inj (n: nat) (l: nat) (b: bezout_t) (i1 i2: nat) (k1 k2: nat) : Lemma (requires ( n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2 )) (ensures ( i1 == i2 /\ k1 == k2 )) [SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b)] = jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n #restart-solver let jump_iter_elim (n: pos) (p: nat_up_to n -> prop) (l: nat) (b: bezout n l) : Lemma (requires ( forall (i: nat_up_to b.d) (k: nat_up_to b.q_n) . p (iter_fun (jump n l) k i) )) (ensures ( forall (x: nat_up_to n) . p x )) = let prf (x: nat_up_to n) : Lemma (p x) = let i : nat_up_to b.d = x % b.d in let k' = jump_coverage_strong n l b x in jump_coverage_strong_bound n l b x; assert (p (iter_fun (jump n l) k' i)) in Classical.forall_intro prf
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> sq: Prims.squash (l < n) -> idx: Steel.ST.GenArraySwap.Proof.nat_up_to n -> FStar.Pervasives.Lemma (ensures Steel.ST.GenArraySwap.Proof.jump n l idx == (match idx + l >= n with | true -> idx - (n - l) | _ -> idx + l))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.squash", "Prims.b2t", "Prims.op_LessThan", "Steel.ST.GenArraySwap.Proof.nat_up_to", "FStar.Math.Lemmas.lemma_mod_plus", "Prims.op_Addition", "Prims.op_Minus", "Prims.unit", "FStar.Math.Lemmas.small_mod", "Prims.op_GreaterThanOrEqual", "Prims.op_Subtraction", "Prims.bool", "Prims.l_True", "Prims.eq2", "Prims.int", "Steel.ST.GenArraySwap.Proof.jump", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l)) =
let idx' = (if idx + l >= n then idx - (n - l) else idx + l) in small_mod idx n; small_mod idx' n; lemma_mod_plus (idx + l) (- 1) n
false
Functor.fst
Functor.functor_id
[@@ FStar.Tactics.Typeclasses.tcinstance] val functor_id:functor id
[@@ FStar.Tactics.Typeclasses.tcinstance] val functor_id:functor id
instance functor_id : functor id = { fmap = fun #_ #_ f a -> f a }
{ "file_name": "examples/typeclasses/Functor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 66, "end_line": 26, "start_col": 0, "start_line": 26 }
(* Copyright 2008-2018 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 Functor open FStar.Tactics.Typeclasses class functor f = { fmap : (#a:Type) -> (#b:Type) -> (a -> b) -> f a -> f b ; } (* Two concrete instances *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Functor.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Functor.functor (fun x -> x <: Type)
Prims.Tot
[ "total" ]
[]
[ "Functor.Mkfunctor" ]
[]
false
false
false
false
false
[@@ FStar.Tactics.Typeclasses.tcinstance] let functor_id:functor id =
{ fmap = fun #_ #_ f a -> f a }
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.jump_iter_q
val jump_iter_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (ensures (iter_fun (jump n l) b.q_n x == x))
val jump_iter_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (ensures (iter_fun (jump n l) b.q_n x == x))
let jump_iter_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (ensures ( iter_fun (jump n l) b.q_n x == x )) = cancel_mul_mod 1 b.q_n; jump_iter_mod_q n l b x b.q_n
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 31, "end_line": 554, "start_col": 0, "start_line": 544 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq let jump_iter_inj (n: nat) (l: nat) (b: bezout_t) (i1 i2: nat) (k1 k2: nat) : Lemma (requires ( n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2 )) (ensures ( i1 == i2 /\ k1 == k2 )) [SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b)] = jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n #restart-solver let jump_iter_elim (n: pos) (p: nat_up_to n -> prop) (l: nat) (b: bezout n l) : Lemma (requires ( forall (i: nat_up_to b.d) (k: nat_up_to b.q_n) . p (iter_fun (jump n l) k i) )) (ensures ( forall (x: nat_up_to n) . p x )) = let prf (x: nat_up_to n) : Lemma (p x) = let i : nat_up_to b.d = x % b.d in let k' = jump_coverage_strong n l b x in jump_coverage_strong_bound n l b x; assert (p (iter_fun (jump n l) k' i)) in Classical.forall_intro prf let jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l)) = let idx' = (if idx + l >= n then idx - (n - l) else idx + l) in small_mod idx n; small_mod idx' n; lemma_mod_plus (idx + l) (-1) n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> l: Prims.nat -> b: Steel.ST.GenArraySwap.Proof.bezout n l -> x: Steel.ST.GenArraySwap.Proof.nat_up_to n -> FStar.Pervasives.Lemma (ensures Steel.ST.GenArraySwap.Proof.iter_fun (Steel.ST.GenArraySwap.Proof.jump n l) (Mkbezout_t?.q_n b) x == x)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.nat", "Steel.ST.GenArraySwap.Proof.bezout", "Steel.ST.GenArraySwap.Proof.nat_up_to", "Steel.ST.GenArraySwap.Proof.jump_iter_mod_q", "Steel.ST.GenArraySwap.Proof.__proj__Mkbezout_t__item__q_n", "Prims.unit", "FStar.Math.Lemmas.cancel_mul_mod", "Prims.l_True", "Prims.squash", "Prims.eq2", "Steel.ST.GenArraySwap.Proof.iter_fun", "Steel.ST.GenArraySwap.Proof.jump", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let jump_iter_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (ensures (iter_fun (jump n l) b.q_n x == x)) =
cancel_mul_mod 1 b.q_n; jump_iter_mod_q n l b x b.q_n
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.mod_eq_intro
val mod_eq_intro (n: pos) (x1 x2 k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n))
val mod_eq_intro (n: pos) (x1 x2 k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n))
let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 23, "end_line": 412, "start_col": 0, "start_line": 405 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> x1: Prims.int -> x2: Prims.int -> k: Prims.int -> FStar.Pervasives.Lemma (requires x1 - x2 == k * n) (ensures x1 % n == x2 % n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.int", "FStar.Math.Lemmas.lemma_mod_plus", "Prims.unit", "Prims.eq2", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Prims.squash", "Prims.op_Modulus", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let mod_eq_intro (n: pos) (x1 x2 k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) =
lemma_mod_plus x2 k n
false
Functor.fst
Functor.comp
[@@ FStar.Tactics.Typeclasses.tcinstance] val comp: #ff: _ -> #gg: _ -> functor ff -> functor gg -> functor (compose ff gg)
[@@ FStar.Tactics.Typeclasses.tcinstance] val comp: #ff: _ -> #gg: _ -> functor ff -> functor gg -> functor (compose ff gg)
instance comp #ff #gg (_ : functor ff) (_ : functor gg) : functor (compose ff gg) = { fmap = (fun #a #b f x -> fmap #ff (fmap #gg f) x) }
{ "file_name": "examples/typeclasses/Functor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 31, "start_col": 0, "start_line": 30 }
(* Copyright 2008-2018 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 Functor open FStar.Tactics.Typeclasses class functor f = { fmap : (#a:Type) -> (#b:Type) -> (a -> b) -> f a -> f b ; } (* Two concrete instances *) instance functor_list : functor list = { fmap = List.Tot.map } instance functor_id : functor id = { fmap = fun #_ #_ f a -> f a } let compose t1 t2 = fun x -> t1 (t2 x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Functor.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
_: Functor.functor ff -> _: Functor.functor gg -> Functor.functor (Functor.compose ff gg)
Prims.Tot
[ "total" ]
[]
[ "Functor.functor", "Functor.Mkfunctor", "Functor.fmap", "Functor.compose" ]
[]
false
false
false
false
false
[@@ FStar.Tactics.Typeclasses.tcinstance] let comp #ff #gg (_: functor ff) (_: functor gg) : functor (compose ff gg) =
{ fmap = (fun #a #b f x -> fmap #ff (fmap #gg f) x) }
false
Functor.fst
Functor.compose
val compose : t1: (_: _ -> _) -> t2: (_: _ -> _) -> x: _ -> _
let compose t1 t2 = fun x -> t1 (t2 x)
{ "file_name": "examples/typeclasses/Functor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 28, "start_col": 0, "start_line": 28 }
(* Copyright 2008-2018 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 Functor open FStar.Tactics.Typeclasses class functor f = { fmap : (#a:Type) -> (#b:Type) -> (a -> b) -> f a -> f b ; } (* Two concrete instances *) instance functor_list : functor list = { fmap = List.Tot.map } instance functor_id : functor id = { fmap = fun #_ #_ f a -> f a }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Functor.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
t1: (_: _ -> _) -> t2: (_: _ -> _) -> x: _ -> _
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let compose t1 t2 =
fun x -> t1 (t2 x)
false
Functor.fst
Functor.t2
val t2 : Functor.compose Prims.list Prims.list Prims.int
let t2 = fmap #(compose list list) (fun x -> x + 1) [[1] ; [2 ; 3]]
{ "file_name": "examples/typeclasses/Functor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 67, "end_line": 35, "start_col": 0, "start_line": 35 }
(* Copyright 2008-2018 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 Functor open FStar.Tactics.Typeclasses class functor f = { fmap : (#a:Type) -> (#b:Type) -> (a -> b) -> f a -> f b ; } (* Two concrete instances *) instance functor_list : functor list = { fmap = List.Tot.map } instance functor_id : functor id = { fmap = fun #_ #_ f a -> f a } let compose t1 t2 = fun x -> t1 (t2 x) instance comp #ff #gg (_ : functor ff) (_ : functor gg) : functor (compose ff gg) = { fmap = (fun #a #b f x -> fmap #ff (fmap #gg f) x) } let t1 = fmap #list (fun x -> x + 1) [1 ; 2 ; 3]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Functor.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Functor.compose Prims.list Prims.list Prims.int
Prims.Tot
[ "total" ]
[]
[ "Functor.fmap", "Functor.compose", "Prims.list", "Functor.comp", "Functor.functor_list", "Prims.int", "Prims.op_Addition", "Prims.Cons", "Prims.Nil" ]
[]
false
false
false
true
false
let t2 =
fmap #(compose list list) (fun x -> x + 1) [[1]; [2; 3]]
false
Steel.ST.GenArraySwap.Proof.fst
Steel.ST.GenArraySwap.Proof.iter_fun_add
val iter_fun_add (#t: Type) (f: (t -> GTot t)) (n1 n2: nat) (x: t) : Lemma (ensures (iter_fun f n1 (iter_fun f n2 x) == iter_fun f (n1 + n2) x)) (decreases n2)
val iter_fun_add (#t: Type) (f: (t -> GTot t)) (n1 n2: nat) (x: t) : Lemma (ensures (iter_fun f n1 (iter_fun f n2 x) == iter_fun f (n1 + n2) x)) (decreases n2)
let rec iter_fun_add (#t: Type) (f: (t -> GTot t)) (n1 n2: nat) (x: t) : Lemma (ensures (iter_fun f n1 (iter_fun f n2 x) == iter_fun f (n1 + n2) x)) (decreases n2) = if n2 = 0 then () else iter_fun_add f n1 (n2 - 1) (f x)
{ "file_name": "lib/steel/Steel.ST.GenArraySwap.Proof.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 39, "end_line": 566, "start_col": 0, "start_line": 556 }
module Steel.ST.GenArraySwap.Proof open FStar.Math.Lemmas open FStar.Mul let lemma_mod_lt (a:int) (b:pos) : Lemma (let r = a % b in 0 <= r /\ r < b) [SMTPat (a % b)] = () let lemma_mul_nat_nat_is_nat (a b: nat) : Lemma (a * b >= 0) [SMTPat (a * b)] = () let lemma_pos_mul_pos_args (a: nat) (b: nat) : Lemma (requires (a * b > 0)) (ensures (a > 0 /\ b > 0 /\ a <= a * b /\ b <= a * b /\ a * b == b * a)) = () let lemma_div_nat (a: nat) (b: pos) : Lemma (a / b >= 0) [SMTPat (a / b)] = () let lemma_mult_reg_l (k: int) (x1 x2: int) : Lemma (requires ( k * x1 == k * x2 /\ k <> 0 )) (ensures ( x1 == x2 )) = () let lemma_bezout_one_zero (x1: int) (x2: nat) (y1 y2: int) : Lemma (requires ( x1 * x2 + y1 * y2 == 1 /\ y1 == 0 )) (ensures ( x1 == 1 /\ x2 == 1 )) = () #set-options "--z3cliopt smt.arith.nl=false" let int_semiring () = FStar.Tactics.CanonCommSemiring.int_semiring (); FStar.Tactics.trefl (); FStar.Tactics.qed () [@@erasable] noeq type bezout_t = { d: pos; q_n: nat; q_l: nat; u_n: int; u_l: int; } let bezout_prop' (n: nat) (l: nat) (d: pos) (q_n: nat) (q_l: nat) (u_n: int) (u_l: int) : Tot prop = n == d * q_n /\ l == d * q_l /\ d == n * u_n + l * u_l let bezout_prop (n: nat) (l: nat) (b: bezout_t) : Tot prop = bezout_prop' n l b.d b.q_n b.q_l b.u_n b.u_l let bezout (n: nat) (l: nat) : Tot Type = (b: bezout_t { bezout_prop n l b }) #restart-solver let rec mk_bezout (n: pos) (l: nat) : Pure (bezout n l) (requires (l < n)) (ensures (fun _ -> True)) (decreases l) = if l = 0 then begin let d : pos = n in let q_n : nat = 1 in let q_l : nat = 0 in let u_n : int = 1 in let u_l : int = 0 in let res = { d = d; q_n = q_n; q_l = q_l; u_n = u_n; u_l = u_l; } in assert (eq2 #int n (d * q_n)) by (int_semiring ()); assert (eq2 #int 0 (d * q_l)) by (int_semiring ()); assert (eq2 #int d (n * 1 + 0 * res.u_l)) by (int_semiring ()); res end else begin let lpre = n % l in let ql = n / l in euclidean_division_definition n l; let bpre = mk_bezout l lpre in let d = bpre.d in let q_l = bpre.q_n in let qpre_lpre = bpre.q_l in let upre_l = bpre.u_n in let upre_lpre = bpre.u_l in let n_alt0 = l * ql + lpre in assert (n == n_alt0); let l_alt = d * q_l in let lpre_alt1 = d * qpre_lpre in let n_alt1 = l_alt * ql + lpre_alt1 in assert (n_alt1 == n); let q_n = q_l * ql + qpre_lpre in assert (eq2 #int n_alt1 (d * q_n)) by (int_semiring ()); let lpre_alt2 = n + - l * ql in assert (lpre_alt2 == lpre); let d_alt = l * upre_l + lpre_alt2 * upre_lpre in assert (d_alt == d); let u_l = upre_l + - ql * upre_lpre in assert (eq2 #int (n * upre_lpre + l * u_l) d_alt) by (int_semiring ()); let res = { d = d; q_n = q_n; q_l = q_l; u_n = upre_lpre; u_l = u_l; } in res end let bezout_q_eq (n: nat) (l: nat) (bz: bezout n l) : Lemma (bz.q_n == n / bz.d) [SMTPat (bezout_prop n l bz); SMTPat bz.q_n] = cancel_mul_div bz.q_n bz.d let rec iter_fun (#t: Type) (f: (t -> GTot t)) (n: nat) (x: t) : GTot t (decreases n) = if n = 0 then x else iter_fun f (n - 1) (f x) let nat_up_to (n: nat) : Tot Type = (i: nat { i < n }) let jump (n: pos) (l: nat) (x: nat_up_to n) : GTot (nat_up_to n) = (x + l) % n #restart-solver let jump_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (jump n l x % b.d == x % b.d) = let x' = jump n l x in let x'q = (x + l) / n in euclidean_division_definition (x + l) n; let l_alt = b.d * b.q_l in assert (l_alt == l); let n_alt = b.d * b.q_n in assert (n_alt == n); let x'_alt = x + l_alt + - x'q * n_alt in assert (x'_alt == x'); let qx = b.q_l + - x'q * b.q_n in assert (eq2 #int x'_alt (x + qx * b.d)) by (int_semiring ()); lemma_mod_plus x qx b.d let rec jump_iter_mod_d (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x % b.d == x % b.d)) (decreases k) = if k = 0 then () else begin jump_mod_d n l b x; jump_iter_mod_d n l b (jump n l x) (k - 1) end (* Coverage *) let rec jump_iter (n: pos) (l: nat) (x: nat_up_to n) (k: nat) : Lemma (ensures (iter_fun #(nat_up_to n) (jump n l) k x == (x + k * l) % n)) (decreases k) = if k = 0 then begin assert (eq2 #int (x + 0 * l) x) by (int_semiring ()); small_mod x n end else begin let k' = k - 1 in assert (eq2 #int (x + (k' + 1) * l) ((x + l) + k' * l)) by (int_semiring ()); jump_iter n l ((x + l) % n) k'; lemma_mod_add_distr (k' * l) (x + l) n end let bezout_pos_le (n: pos) (l: nat) (b: bezout n l) : Lemma (b.d <= n /\ b.q_n > 0) [SMTPat (bezout_prop n l b)] = lemma_pos_mul_pos_args b.q_n b.d #restart-solver [@@"opaque_to_smt"] irreducible let jump_coverage (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) )) = let i = x % b.d in let qx = x / b.d in euclidean_division_definition x b.d; let k1 = qx * b.u_l in let m = qx * b.u_n in assert (eq2 #int (qx * (n * b.u_n + l * b.u_l) + i) (i + k1 * l + m * n)) by (int_semiring ()); assert (x == i + k1 * l + m * n); small_mod x n; lemma_mod_plus (i + k1 * l) m n; assert (x == (i + k1 * l) % n); let k = k1 % n in let qk = k1 / n in euclidean_division_definition k1 n; assert (i + (qk * n + k) * l == i + k * l + (qk * l) * n) by (int_semiring ()); lemma_mod_plus (i + k * l) (qk * l) n; assert (eq2 #int x ((i + k * l) % n)); jump_iter n l i k; k [@@"opaque_to_smt"] irreducible let rec minimal_exists' (p: (nat -> GTot bool)) (n: nat) (i: nat) : Ghost nat (requires ( p n == true /\ i <= n /\ (forall (j: nat) . j < i ==> p j == false) )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) (decreases (n - i)) = if p i then i else minimal_exists' p n (i + 1) [@@"opaque_to_smt"] irreducible let minimal_exists (p: (nat -> GTot bool)) (n: nat) : Ghost nat (requires ( p n == true )) (ensures (fun k -> p k == true /\ (forall (j: nat) . j < k ==> p j == false) )) = minimal_exists' p n 0 [@@"opaque_to_smt"] irreducible let jump_coverage_strong (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Ghost nat (requires True) (ensures (fun k -> x == iter_fun (jump n l) k (x % b.d) /\ (forall (k': nat) . k' < k ==> (~ (x == iter_fun (jump n l) k' (x % b.d)))) )) = let k' = jump_coverage n l b x in minimal_exists (fun k -> x = iter_fun (jump n l) k (x % b.d)) k' #restart-solver let jump_iter_mod_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) (k: nat) : Lemma (ensures ( b.q_n > 0 /\ iter_fun (jump n l) (k % b.q_n) x == iter_fun (jump n l) k x )) = assert (b.q_n > 0); let k' = k % b.q_n in let qk = k / b.q_n in euclidean_division_definition k b.q_n; jump_iter n l x k'; jump_iter n l x k; assert (eq2 #int (x + (qk * b.q_n + k') * (b.d * b.q_l)) (x + k' * (b.d * b.q_l) + (qk * b.q_l) * (b.d * b.q_n))) by (int_semiring ()); assert (x + k * l == x + k' * l + (qk * b.q_l) * n); lemma_mod_plus (x + k' * l) (qk * b.q_l) n let jump_coverage_strong_bound (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (b.q_n > 0 /\ jump_coverage_strong n l b x < b.q_n ) [SMTPat (jump_coverage_strong n l b x)] = let k = jump_coverage_strong n l b x in jump_iter_mod_q n l b (x % b.d) k #restart-solver [@@"opaque_to_smt"] irreducible let mod_eq_elim (n: pos) (x1 x2: int) : Ghost int (requires (x1 % n == x2 % n)) (ensures (fun k -> x1 - x2 == k * n)) = euclidean_division_definition x1 n; euclidean_division_definition x2 n; let q1 = x1 / n in let q2 = x2 / n in let k = q1 + - q2 in let r = x1 % n in assert (q1 * n + r + - (q2 * n + r) == k * n) by (int_semiring ()); k let mod_eq_intro (n: pos) (x1 x2: int) (k: int) : Lemma (requires (x1 - x2 == k * n)) (ensures (x1 % n == x2 % n)) = lemma_mod_plus x2 k n #restart-solver [@@"opaque_to_smt"] irreducible let gauss (n: pos) (l: pos) // necessary here (b: bezout n l) (kl kn: int) : Ghost int (requires ( kl * l == kn * n )) (ensures (fun k -> kl == k * b.q_n )) = assert ((b.d * b.q_n) * b.u_n + (b.d * b.q_l) * b.u_l == b.d * (b.u_n * b.q_n + b.u_l * b.q_l)) by (int_semiring ()); assert (b.d == b.d * 1) by (int_semiring ()); assert (b.d * (b.u_n * b.q_n + b.u_l * b.q_l) == b.d * 1); lemma_mult_reg_l b.d (b.u_n * b.q_n + b.u_l * b.q_l) 1; assert (b.u_n * b.q_n + b.u_l * b.q_l == 1); if b.u_l = 0 then begin lemma_bezout_one_zero b.u_n b.q_n b.u_l b.q_l; assert (b.q_n == 1); assert (kl * 1 == kl) by (int_semiring ()); kl end else begin assert (kl * (b.d * b.q_l) == kn * (b.d * b.q_n)); assert (kl * (b.d * b.q_l) == b.d * (kl * b.q_l)) by (int_semiring ()); assert (kn * (b.d * b.q_n) == b.d * (kn * b.q_n)) by (int_semiring ()); assert (b.d * (kl * b.q_l) == b.d * (kn * b.q_n)); lemma_mult_reg_l b.d (kl * b.q_l) (kn * b.q_n); assert (kl * b.q_l == kn * b.q_n); assert (b.u_l * (kl * b.q_l) == b.u_l * (kn * b.q_n)); assert (b.u_l * (kl * b.q_l) == kl * (b.u_l * b.q_l)) by (int_semiring ()); assert (b.u_l * (kn * b.q_n) == (kn * b.u_l) * b.q_n) by (int_semiring ()); assert (kl * (b.u_l * b.q_l) == (kn * b.u_l) * b.q_n); assert (kl * (1 + - (b.u_n * b.q_n)) == kl + - kl * b.u_n * b.q_n) by (int_semiring ()); assert (kl * b.u_n * b.q_n + (kn * b.u_l) * b.q_n == (kn * b.u_l + kl * b.u_n) * b.q_n) by (int_semiring ()); kn * b.u_l + kl * b.u_n end let jump_iter_mod_q_inj_weak (n: pos) (l: pos) (b: bezout n l) (x: nat_up_to n) (k1 k2: nat) : Lemma (requires ( iter_fun (jump n l) k1 x == iter_fun (jump n l) k2 x )) (ensures ( b.q_n > 0 /\ k1 % b.q_n == k2 % b.q_n )) = jump_iter n l x k1; jump_iter n l x k2; let kn = mod_eq_elim n (x + k1 * l) (x + k2 * l) in assert ((k1 + - k2) * l == (k1 * l + - (k2 * l))) by (int_semiring ()); let kq = gauss n l b (k1 + - k2) kn in mod_eq_intro b.q_n k1 k2 kq let jump_iter_inj (n: nat) (l: nat) (b: bezout_t) (i1 i2: nat) (k1 k2: nat) : Lemma (requires ( n > 0 /\ l > 0 /\ bezout_prop n l b /\ i1 < b.d /\ i2 < b.d /\ k1 < b.q_n /\ k2 < b.q_n /\ iter_fun (jump n l) k1 i1 == iter_fun (jump n l) k2 i2 )) (ensures ( i1 == i2 /\ k1 == k2 )) [SMTPat (iter_fun (jump n l) k1 i1); SMTPat (iter_fun (jump n l) k2 i2); SMTPat (bezout_prop n l b)] = jump_iter_mod_d n l b i1 k1; jump_iter_mod_d n l b i2 k2; small_mod i1 b.d; small_mod i2 b.d; jump_iter_mod_q_inj_weak n l b i1 k1 k2; small_mod k1 b.q_n; small_mod k2 b.q_n #restart-solver let jump_iter_elim (n: pos) (p: nat_up_to n -> prop) (l: nat) (b: bezout n l) : Lemma (requires ( forall (i: nat_up_to b.d) (k: nat_up_to b.q_n) . p (iter_fun (jump n l) k i) )) (ensures ( forall (x: nat_up_to n) . p x )) = let prf (x: nat_up_to n) : Lemma (p x) = let i : nat_up_to b.d = x % b.d in let k' = jump_coverage_strong n l b x in jump_coverage_strong_bound n l b x; assert (p (iter_fun (jump n l) k' i)) in Classical.forall_intro prf let jump_if (n: pos) (l: nat) (sq: squash (l < n)) (idx: nat_up_to n) : Lemma (jump n l idx == (if idx + l >= n then idx - (n - l) else idx + l)) = let idx' = (if idx + l >= n then idx - (n - l) else idx + l) in small_mod idx n; small_mod idx' n; lemma_mod_plus (idx + l) (-1) n let jump_iter_q (n: pos) (l: nat) (b: bezout n l) (x: nat_up_to n) : Lemma (ensures ( iter_fun (jump n l) b.q_n x == x )) = cancel_mul_mod 1 b.q_n; jump_iter_mod_q n l b x b.q_n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.CanonCommSemiring.fst.checked", "FStar.Tactics.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Steel.ST.GenArraySwap.Proof.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.GenArraySwap", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: t -> Prims.GTot t) -> n1: Prims.nat -> n2: Prims.nat -> x: t -> FStar.Pervasives.Lemma (ensures Steel.ST.GenArraySwap.Proof.iter_fun f n1 (Steel.ST.GenArraySwap.Proof.iter_fun f n2 x) == Steel.ST.GenArraySwap.Proof.iter_fun f (n1 + n2) x) (decreases n2)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.bool", "Steel.ST.GenArraySwap.Proof.iter_fun_add", "Prims.op_Subtraction", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Steel.ST.GenArraySwap.Proof.iter_fun", "Prims.op_Addition", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec iter_fun_add (#t: Type) (f: (t -> GTot t)) (n1 n2: nat) (x: t) : Lemma (ensures (iter_fun f n1 (iter_fun f n2 x) == iter_fun f (n1 + n2) x)) (decreases n2) =
if n2 = 0 then () else iter_fun_add f n1 (n2 - 1) (f x)
false