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
BinaryTrees.fst
BinaryTrees.find_some
val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t)))
val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t)))
let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 50, "end_line": 53, "start_col": 0, "start_line": 50 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: (_: Prims.int -> Prims.bool) -> t: BinaryTrees.tree -> FStar.Pervasives.Lemma (ensures None? (BinaryTrees.find p t) \/ p (Some?.v (BinaryTrees.find p t)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.bool", "BinaryTrees.tree", "BinaryTrees.find_some", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec find_some p t =
match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2
false
BinaryTrees.fst
BinaryTrees.map_option
val map_option : f: (_: _ -> _) -> o: FStar.Pervasives.Native.option _ -> FStar.Pervasives.Native.option _
let map_option f o = match o with | Some n -> Some (f n) | None -> None
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 57, "start_col": 0, "start_line": 55 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: (_: _ -> _) -> o: FStar.Pervasives.Native.option _ -> FStar.Pervasives.Native.option _
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.None" ]
[]
false
false
false
true
false
let map_option f o =
match o with | Some n -> Some (f n) | None -> None
false
BinaryTrees.fst
BinaryTrees.map_find
val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t))
val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t))
let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 66, "start_col": 0, "start_line": 63 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: (_: Prims.int -> Prims.bool) -> f: (_: Prims.int -> Prims.int) -> t: BinaryTrees.tree -> FStar.Pervasives.Lemma (ensures BinaryTrees.find p (BinaryTrees.map f t) = BinaryTrees.map_option f (BinaryTrees.find (BinaryTrees.compose p f) t))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.bool", "BinaryTrees.tree", "BinaryTrees.map_find", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec map_find p f t =
match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2
false
BinaryTrees.fst
BinaryTrees.fold_map
val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t)
val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t)
let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 60, "end_line": 85, "start_col": 0, "start_line": 82 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
fm: (_: Prims.int -> Prims.int) -> ff: (_: Prims.int -> _: Prims.int -> _: Prims.int -> Prims.int) -> a: Prims.int -> t: BinaryTrees.tree -> FStar.Pervasives.Lemma (ensures BinaryTrees.fold ff a (BinaryTrees.map fm t) = BinaryTrees.fold (BinaryTrees.compose ff fm) a t)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "BinaryTrees.tree", "BinaryTrees.fold_map", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec fold_map fm ff a t =
match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2
false
BinaryTrees.fst
BinaryTrees.in_tree
val in_tree : int -> tree -> Tot bool
val in_tree : int -> tree -> Tot bool
let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 57, "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. *) module BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> t: BinaryTrees.tree -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "BinaryTrees.tree", "Prims.op_BarBar", "Prims.op_Equality", "BinaryTrees.in_tree", "Prims.bool" ]
[ "recursion" ]
false
false
false
true
false
let rec in_tree x t =
match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2
false
BinaryTrees.fst
BinaryTrees.fold
val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a
val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a
let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2)
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 78, "start_col": 0, "start_line": 75 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: Prims.int -> _: 'a -> _: 'a -> 'a) -> a: 'a -> t: BinaryTrees.tree -> 'a
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "BinaryTrees.tree", "BinaryTrees.fold" ]
[ "recursion" ]
false
false
false
true
false
let rec fold f a t =
match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2)
false
BinaryTrees.fst
BinaryTrees.find
val find : p:(int -> Tot bool) -> tree -> Tot (option int)
val find : p:(int -> Tot bool) -> tree -> Tot (option int)
let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 46, "start_col": 0, "start_line": 41 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: (_: Prims.int -> Prims.bool) -> t: BinaryTrees.tree -> FStar.Pervasives.Native.option Prims.int
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Prims.bool", "BinaryTrees.tree", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.uu___is_Some", "BinaryTrees.find", "FStar.Pervasives.Native.option" ]
[ "recursion" ]
false
false
false
true
false
let rec find p t =
match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2
false
BinaryTrees.fst
BinaryTrees.in_tree_fold
val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t)
val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t)
let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 56, "end_line": 99, "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. *) module BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> t: BinaryTrees.tree -> FStar.Pervasives.Lemma (ensures BinaryTrees.in_tree x t = BinaryTrees.fold (fun n b1 b2 -> x = n || b1 || b2) false t)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "BinaryTrees.tree", "BinaryTrees.in_tree_fold", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec in_tree_fold x t =
match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2
false
BinaryTrees.fst
BinaryTrees.size_fold
val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t)
val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t)
let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 92, "start_col": 0, "start_line": 89 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: BinaryTrees.tree -> FStar.Pervasives.Lemma (ensures BinaryTrees.size t = BinaryTrees.fold (fun _ s1 s2 -> 1 + s1 + s2) 0 t)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "BinaryTrees.tree", "Prims.int", "BinaryTrees.size_fold", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec size_fold t =
match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2
false
BinaryTrees.fst
BinaryTrees.find_fold
val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x}))
val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x}))
let find_fold f = fold #(option (x:int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 73, "end_line": 104, "start_col": 0, "start_line": 102 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t) let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: Prims.int -> Prims.bool) -> _: BinaryTrees.tree -> FStar.Pervasives.Native.option (x: Prims.int{f x})
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Prims.bool", "BinaryTrees.fold", "FStar.Pervasives.Native.option", "Prims.b2t", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.uu___is_Some", "FStar.Pervasives.Native.None", "BinaryTrees.tree" ]
[]
false
false
false
false
false
let find_fold f =
fold #(option (x: int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None
false
GMST.fst
GMST.gmst_post
val gmst_post : s: Type -> a: Type -> s0: s -> Type
let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 93, "end_line": 29, "start_col": 0, "start_line": 29 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Type -> a: Type -> s0: s -> Type
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.relation" ]
[]
false
false
false
true
true
let gmst_post (s a: Type) (s0: s) =
rel: relation s -> a -> s1: s{rel s0 s1} -> GTot Type0
false
BinaryTrees.fst
BinaryTrees.revert_fold
val revert_fold : t:tree -> Lemma (revert t = fold (fun n t1 t2 -> Node n t2 t1) Leaf t)
val revert_fold : t:tree -> Lemma (revert t = fold (fun n t1 t2 -> Node n t2 t1) Leaf t)
let rec revert_fold t = match t with | Leaf -> () | Node n t1 t2 -> revert_fold t1; revert_fold t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 50, "end_line": 133, "start_col": 0, "start_line": 130 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t) let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2 val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x})) let find_fold f = fold #(option (x:int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None val revert : tree -> Tot tree let rec revert t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node n (revert t2) (revert t1) (* simpler than for lists because revert is symmetric, while List.rev is not *) val revert_involutive : t:tree -> Lemma (revert (revert t) = t) let rec revert_involutive t = match t with | Leaf -> () | Node n t1 t2 -> revert_involutive t1; revert_involutive t2 (* again, much simpler than for lists *) val revert_injective : t1:tree -> t2:tree -> Lemma (requires (revert t1 = revert t2)) (ensures (t1 = t2)) let rec revert_injective t1 t2 = match t1, t2 with | Leaf, Leaf -> () | Node n1 t11 t12, Node n2 t21 t22 -> revert_injective t11 t21; revert_injective t12 t22 val revert_fold : t:tree ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: BinaryTrees.tree -> FStar.Pervasives.Lemma (ensures BinaryTrees.revert t = BinaryTrees.fold (fun n t1 t2 -> BinaryTrees.Node n t2 t1) BinaryTrees.Leaf t)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "BinaryTrees.tree", "Prims.int", "BinaryTrees.revert_fold", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec revert_fold t =
match t with | Leaf -> () | Node n t1 t2 -> revert_fold t1; revert_fold t2
false
GMST.fst
GMST.gmst_wp
val gmst_wp : s: Type -> a: Type -> Type
let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 79, "end_line": 30, "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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Type -> a: Type -> Type
Prims.Tot
[ "total" ]
[]
[ "GMST.gmst_post" ]
[]
false
false
false
true
true
let gmst_wp (s a: Type) =
s0: s -> gmst_post s a s0 -> GTot Type0
false
GMST.fst
GMST.gmst_return
val gmst_return : s: Type -> a: Type -> x: a -> s0: s -> p: GMST.gmst_post s a s0 -> Prims.logical
let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 37, "start_col": 0, "start_line": 36 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Type -> a: Type -> x: a -> s0: s -> p: GMST.gmst_post s a s0 -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "GMST.gmst_post", "Prims.l_Forall", "Prims.l_imp", "Prims.eq2", "Prims.logical" ]
[]
false
false
false
false
true
let gmst_return (s a: Type) (x: a) (s0: s) (p: gmst_post s a s0) =
forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0
false
GMST.fst
GMST.gmst_if_then_else
val gmst_if_then_else : s: Type -> a: Type -> p: Type0 -> wp_then: GMST.gmst_wp s a -> wp_else: GMST.gmst_wp s a -> s0: s -> post: GMST.gmst_post s a s0 -> Prims.logical
let gmst_if_then_else (s:Type) (a:Type) (p:Type) (wp_then:gmst_wp s a) (wp_else:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = l_ITE p (wp_then s0 post) (wp_else s0 post)
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 48, "start_col": 0, "start_line": 46 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0 unfold let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Type -> a: Type -> p: Type0 -> wp_then: GMST.gmst_wp s a -> wp_else: GMST.gmst_wp s a -> s0: s -> post: GMST.gmst_post s a s0 -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "GMST.gmst_wp", "GMST.gmst_post", "Prims.l_ITE", "Prims.logical" ]
[]
false
false
false
false
true
let gmst_if_then_else (s a p: Type) (wp_then wp_else: gmst_wp s a) (s0: s) (post: gmst_post s a s0) =
l_ITE p (wp_then s0 post) (wp_else s0 post)
false
GMST.fst
GMST.gmst_ite
val gmst_ite : s: Type -> a: Type -> wp: GMST.gmst_wp s a -> s0: s -> post: GMST.gmst_post s a s0 -> Type0
let gmst_ite (s:Type) (a:Type) (wp:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = wp s0 post
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 52, "start_col": 0, "start_line": 51 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0 unfold let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1))) unfold let gmst_if_then_else (s:Type) (a:Type) (p:Type) (wp_then:gmst_wp s a) (wp_else:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = l_ITE p (wp_then s0 post) (wp_else s0 post)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Type -> a: Type -> wp: GMST.gmst_wp s a -> s0: s -> post: GMST.gmst_post s a s0 -> Type0
Prims.Tot
[ "total" ]
[]
[ "GMST.gmst_wp", "GMST.gmst_post" ]
[]
false
false
false
false
true
let gmst_ite (s a: Type) (wp: gmst_wp s a) (s0: s) (post: gmst_post s a s0) =
wp s0 post
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.fadd_zero
val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1}
val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1}
let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 44, "start_col": 0, "start_line": 37 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f1: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f1 (1, 2, 1, 1, 1)} -> out: Hacl.Spec.Curve25519.Field51.Definition.felem5 { Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 out (9, 10, 9, 9, 9) /\ Hacl.Spec.Curve25519.Field51.Definition.feval out == Hacl.Spec.Curve25519.Field51.Definition.feval f1 }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Lib.IntTypes.uint64", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_add_zero", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.u64", "Prims.l_and", "Prims.eq2", "Spec.Curve25519.elem", "Hacl.Spec.Curve25519.Field51.Definition.feval" ]
[]
false
false
false
false
false
let fadd_zero (f10, f11, f12, f13, f14) =
let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4)
false
GMST.fst
GMST.gmst_stronger
val gmst_stronger : s: Type -> a: Type -> wp1: GMST.gmst_wp s a -> wp2: GMST.gmst_wp s a -> Prims.logical
let gmst_stronger (s:Type) (a:Type) (wp1:gmst_wp s a) (wp2:gmst_wp s a) = forall s0 p. wp1 s0 p ==> wp2 s0 p
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 56, "start_col": 0, "start_line": 55 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0 unfold let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1))) unfold let gmst_if_then_else (s:Type) (a:Type) (p:Type) (wp_then:gmst_wp s a) (wp_else:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = l_ITE p (wp_then s0 post) (wp_else s0 post) unfold let gmst_ite (s:Type) (a:Type) (wp:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = wp s0 post
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Type -> a: Type -> wp1: GMST.gmst_wp s a -> wp2: GMST.gmst_wp s a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "GMST.gmst_wp", "Prims.l_Forall", "GMST.gmst_post", "Prims.l_imp", "Prims.logical" ]
[]
false
false
false
true
true
let gmst_stronger (s a: Type) (wp1 wp2: gmst_wp s a) =
forall s0 p. wp1 s0 p ==> wp2 s0 p
false
BinaryTrees.fst
BinaryTrees.revert_involutive
val revert_involutive : t:tree -> Lemma (revert (revert t) = t)
val revert_involutive : t:tree -> Lemma (revert (revert t) = t)
let rec revert_involutive t = match t with | Leaf -> () | Node n t1 t2 -> revert_involutive t1; revert_involutive t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 62, "end_line": 117, "start_col": 0, "start_line": 114 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t) let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2 val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x})) let find_fold f = fold #(option (x:int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None val revert : tree -> Tot tree let rec revert t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node n (revert t2) (revert t1) (* simpler than for lists because revert is symmetric, while List.rev is not *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: BinaryTrees.tree -> FStar.Pervasives.Lemma (ensures BinaryTrees.revert (BinaryTrees.revert t) = t)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "BinaryTrees.tree", "Prims.int", "BinaryTrees.revert_involutive", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec revert_involutive t =
match t with | Leaf -> () | Node n t1 t2 -> revert_involutive t1; revert_involutive t2
false
BinaryTrees.fst
BinaryTrees.remove_root
val remove_root : t:tree{Node? t} -> Tot tree
val remove_root : t:tree{Node? t} -> Tot tree
let rec remove_root t = match t with | Node n t1 t2 -> if Leaf? t1 then t2 else Node (Node?.root t1) (remove_root t1) t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 65, "end_line": 144, "start_col": 0, "start_line": 141 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t) let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2 val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x})) let find_fold f = fold #(option (x:int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None val revert : tree -> Tot tree let rec revert t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node n (revert t2) (revert t1) (* simpler than for lists because revert is symmetric, while List.rev is not *) val revert_involutive : t:tree -> Lemma (revert (revert t) = t) let rec revert_involutive t = match t with | Leaf -> () | Node n t1 t2 -> revert_involutive t1; revert_involutive t2 (* again, much simpler than for lists *) val revert_injective : t1:tree -> t2:tree -> Lemma (requires (revert t1 = revert t2)) (ensures (t1 = t2)) let rec revert_injective t1 t2 = match t1, t2 with | Leaf, Leaf -> () | Node n1 t11 t12, Node n2 t21 t22 -> revert_injective t11 t21; revert_injective t12 t22 val revert_fold : t:tree -> Lemma (revert t = fold (fun n t1 t2 -> Node n t2 t1) Leaf t) let rec revert_fold t = match t with | Leaf -> () | Node n t1 t2 -> revert_fold t1; revert_fold t2 (* open FStar.List *) (* val list_of : tree -> Tot (list int) *) (* let list_of = fold (fun n t1 t2 -> t1 @ [n] @ t2) [] *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: BinaryTrees.tree{Node? t} -> BinaryTrees.tree
Prims.Tot
[ "total" ]
[]
[ "BinaryTrees.tree", "Prims.b2t", "BinaryTrees.uu___is_Node", "Prims.int", "BinaryTrees.uu___is_Leaf", "Prims.bool", "BinaryTrees.Node", "BinaryTrees.__proj__Node__item__root", "BinaryTrees.remove_root" ]
[ "recursion" ]
false
false
false
false
false
let rec remove_root t =
match t with | Node n t1 t2 -> if Leaf? t1 then t2 else Node (Node?.root t1) (remove_root t1) t2
false
BinaryTrees.fst
BinaryTrees.remove_add_root
val remove_add_root : x:int -> t:tree -> Lemma (requires True) (ensures (remove_root (add_root x t) = t)) (decreases t)
val remove_add_root : x:int -> t:tree -> Lemma (requires True) (ensures (remove_root (add_root x t) = t)) (decreases t)
let rec remove_add_root x t = match t with | Leaf -> () | Node n t1 t2 -> remove_add_root x t1
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 160, "start_col": 0, "start_line": 157 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t) let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2 val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x})) let find_fold f = fold #(option (x:int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None val revert : tree -> Tot tree let rec revert t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node n (revert t2) (revert t1) (* simpler than for lists because revert is symmetric, while List.rev is not *) val revert_involutive : t:tree -> Lemma (revert (revert t) = t) let rec revert_involutive t = match t with | Leaf -> () | Node n t1 t2 -> revert_involutive t1; revert_involutive t2 (* again, much simpler than for lists *) val revert_injective : t1:tree -> t2:tree -> Lemma (requires (revert t1 = revert t2)) (ensures (t1 = t2)) let rec revert_injective t1 t2 = match t1, t2 with | Leaf, Leaf -> () | Node n1 t11 t12, Node n2 t21 t22 -> revert_injective t11 t21; revert_injective t12 t22 val revert_fold : t:tree -> Lemma (revert t = fold (fun n t1 t2 -> Node n t2 t1) Leaf t) let rec revert_fold t = match t with | Leaf -> () | Node n t1 t2 -> revert_fold t1; revert_fold t2 (* open FStar.List *) (* val list_of : tree -> Tot (list int) *) (* let list_of = fold (fun n t1 t2 -> t1 @ [n] @ t2) [] *) val remove_root : t:tree{Node? t} -> Tot tree let rec remove_root t = match t with | Node n t1 t2 -> if Leaf? t1 then t2 else Node (Node?.root t1) (remove_root t1) t2 val add_root : x:int -> t:tree -> Tot (t':tree{Node? t'}) (decreases t) let rec add_root x t = match t with | Leaf -> Node x Leaf Leaf | Node n t1 t2 -> Node x (add_root n t1) t2 (* remove and add implemented this way round-trip; TODO: does the converse hold? *) val remove_add_root : x:int -> t:tree -> Lemma (requires True) (ensures (remove_root (add_root x t) = t))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> t: BinaryTrees.tree -> FStar.Pervasives.Lemma (ensures BinaryTrees.remove_root (BinaryTrees.add_root x t) = t) (decreases t)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.int", "BinaryTrees.tree", "BinaryTrees.remove_add_root", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec remove_add_root x t =
match t with | Leaf -> () | Node n t1 t2 -> remove_add_root x t1
false
BinaryTrees.fst
BinaryTrees.revert_injective
val revert_injective : t1:tree -> t2:tree -> Lemma (requires (revert t1 = revert t2)) (ensures (t1 = t2))
val revert_injective : t1:tree -> t2:tree -> Lemma (requires (revert t1 = revert t2)) (ensures (t1 = t2))
let rec revert_injective t1 t2 = match t1, t2 with | Leaf, Leaf -> () | Node n1 t11 t12, Node n2 t21 t22 -> revert_injective t11 t21; revert_injective t12 t22
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 62, "end_line": 126, "start_col": 0, "start_line": 122 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t) let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2 val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x})) let find_fold f = fold #(option (x:int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None val revert : tree -> Tot tree let rec revert t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node n (revert t2) (revert t1) (* simpler than for lists because revert is symmetric, while List.rev is not *) val revert_involutive : t:tree -> Lemma (revert (revert t) = t) let rec revert_involutive t = match t with | Leaf -> () | Node n t1 t2 -> revert_involutive t1; revert_involutive t2 (* again, much simpler than for lists *) val revert_injective : t1:tree -> t2:tree ->
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: BinaryTrees.tree -> t2: BinaryTrees.tree -> FStar.Pervasives.Lemma (requires BinaryTrees.revert t1 = BinaryTrees.revert t2) (ensures t1 = t2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "BinaryTrees.tree", "FStar.Pervasives.Native.Mktuple2", "Prims.int", "BinaryTrees.revert_injective", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec revert_injective t1 t2 =
match t1, t2 with | Leaf, Leaf -> () | Node n1 t11 t12, Node n2 t21 t22 -> revert_injective t11 t21; revert_injective t12 t22
false
BinaryTrees.fst
BinaryTrees.revert
val revert : tree -> Tot tree
val revert : tree -> Tot tree
let rec revert t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node n (revert t2) (revert t1)
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 50, "end_line": 110, "start_col": 0, "start_line": 107 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t) let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2 val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x})) let find_fold f = fold #(option (x:int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: BinaryTrees.tree -> BinaryTrees.tree
Prims.Tot
[ "total" ]
[]
[ "BinaryTrees.tree", "BinaryTrees.Leaf", "Prims.int", "BinaryTrees.Node", "BinaryTrees.revert" ]
[ "recursion" ]
false
false
false
true
false
let rec revert t =
match t with | Leaf -> Leaf | Node n t1 t2 -> Node n (revert t2) (revert t1)
false
GMST.fst
GMST.gmst_close
val gmst_close : s: Type -> a: Type -> b: Type -> wp: (_: b -> Prims.GTot (GMST.gmst_wp s a)) -> s0: s -> p: GMST.gmst_post s a s0 -> Prims.logical
let gmst_close (s:Type) (a:Type) (b:Type) (wp:(b -> GTot (gmst_wp s a))) (s0:s) (p:gmst_post s a s0) = forall x. wp x s0 p
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 61, "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. *) module GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0 unfold let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1))) unfold let gmst_if_then_else (s:Type) (a:Type) (p:Type) (wp_then:gmst_wp s a) (wp_else:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = l_ITE p (wp_then s0 post) (wp_else s0 post) unfold let gmst_ite (s:Type) (a:Type) (wp:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = wp s0 post unfold let gmst_stronger (s:Type) (a:Type) (wp1:gmst_wp s a) (wp2:gmst_wp s a) = forall s0 p. wp1 s0 p ==> wp2 s0 p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Type -> a: Type -> b: Type -> wp: (_: b -> Prims.GTot (GMST.gmst_wp s a)) -> s0: s -> p: GMST.gmst_post s a s0 -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "GMST.gmst_wp", "GMST.gmst_post", "Prims.l_Forall", "Prims.logical" ]
[]
false
false
false
false
true
let gmst_close (s a b: Type) (wp: (b -> GTot (gmst_wp s a))) (s0: s) (p: gmst_post s a s0) =
forall x. wp x s0 p
false
BinaryTrees.fst
BinaryTrees.remove
val remove (x: int) (t: tree{count x t > 0}) : Tot tree (decreases t)
val remove (x: int) (t: tree{count x t > 0}) : Tot tree (decreases t)
let rec remove (x:int) (t:tree{count x t > 0}) : Tot tree (decreases t) = match t with | Node n t1 t2 -> if x = n then remove_root t else if count x t1 > 0 then Node n (remove x t1) t2 else Node n t1 (remove x t2)
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 66, "end_line": 171, "start_col": 0, "start_line": 167 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t) let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2 val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x})) let find_fold f = fold #(option (x:int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None val revert : tree -> Tot tree let rec revert t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node n (revert t2) (revert t1) (* simpler than for lists because revert is symmetric, while List.rev is not *) val revert_involutive : t:tree -> Lemma (revert (revert t) = t) let rec revert_involutive t = match t with | Leaf -> () | Node n t1 t2 -> revert_involutive t1; revert_involutive t2 (* again, much simpler than for lists *) val revert_injective : t1:tree -> t2:tree -> Lemma (requires (revert t1 = revert t2)) (ensures (t1 = t2)) let rec revert_injective t1 t2 = match t1, t2 with | Leaf, Leaf -> () | Node n1 t11 t12, Node n2 t21 t22 -> revert_injective t11 t21; revert_injective t12 t22 val revert_fold : t:tree -> Lemma (revert t = fold (fun n t1 t2 -> Node n t2 t1) Leaf t) let rec revert_fold t = match t with | Leaf -> () | Node n t1 t2 -> revert_fold t1; revert_fold t2 (* open FStar.List *) (* val list_of : tree -> Tot (list int) *) (* let list_of = fold (fun n t1 t2 -> t1 @ [n] @ t2) [] *) val remove_root : t:tree{Node? t} -> Tot tree let rec remove_root t = match t with | Node n t1 t2 -> if Leaf? t1 then t2 else Node (Node?.root t1) (remove_root t1) t2 val add_root : x:int -> t:tree -> Tot (t':tree{Node? t'}) (decreases t) let rec add_root x t = match t with | Leaf -> Node x Leaf Leaf | Node n t1 t2 -> Node x (add_root n t1) t2 (* remove and add implemented this way round-trip; TODO: does the converse hold? *) val remove_add_root : x:int -> t:tree -> Lemma (requires True) (ensures (remove_root (add_root x t) = t)) (decreases t) let rec remove_add_root x t = match t with | Leaf -> () | Node n t1 t2 -> remove_add_root x t1 let rec count (x:int) (t:tree) : Tot nat = match t with | Leaf -> 0 | Node n t1 t2 -> (if n = x then 1 else 0) + count x t1 + count x t2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> t: BinaryTrees.tree{BinaryTrees.count x t > 0} -> Prims.Tot BinaryTrees.tree
Prims.Tot
[ "total", "" ]
[]
[ "Prims.int", "BinaryTrees.tree", "Prims.b2t", "Prims.op_GreaterThan", "BinaryTrees.count", "Prims.op_Equality", "BinaryTrees.remove_root", "Prims.bool", "BinaryTrees.Node", "BinaryTrees.remove" ]
[ "recursion" ]
false
false
false
false
false
let rec remove (x: int) (t: tree{count x t > 0}) : Tot tree (decreases t) =
match t with | Node n t1 t2 -> if x = n then remove_root t else if count x t1 > 0 then Node n (remove x t1) t2 else Node n t1 (remove x t2)
false
BinaryTrees.fst
BinaryTrees.add_root
val add_root : x:int -> t:tree -> Tot (t':tree{Node? t'}) (decreases t)
val add_root : x:int -> t:tree -> Tot (t':tree{Node? t'}) (decreases t)
let rec add_root x t = match t with | Leaf -> Node x Leaf Leaf | Node n t1 t2 -> Node x (add_root n t1) t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 45, "end_line": 151, "start_col": 0, "start_line": 148 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t) let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2 val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x})) let find_fold f = fold #(option (x:int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None val revert : tree -> Tot tree let rec revert t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node n (revert t2) (revert t1) (* simpler than for lists because revert is symmetric, while List.rev is not *) val revert_involutive : t:tree -> Lemma (revert (revert t) = t) let rec revert_involutive t = match t with | Leaf -> () | Node n t1 t2 -> revert_involutive t1; revert_involutive t2 (* again, much simpler than for lists *) val revert_injective : t1:tree -> t2:tree -> Lemma (requires (revert t1 = revert t2)) (ensures (t1 = t2)) let rec revert_injective t1 t2 = match t1, t2 with | Leaf, Leaf -> () | Node n1 t11 t12, Node n2 t21 t22 -> revert_injective t11 t21; revert_injective t12 t22 val revert_fold : t:tree -> Lemma (revert t = fold (fun n t1 t2 -> Node n t2 t1) Leaf t) let rec revert_fold t = match t with | Leaf -> () | Node n t1 t2 -> revert_fold t1; revert_fold t2 (* open FStar.List *) (* val list_of : tree -> Tot (list int) *) (* let list_of = fold (fun n t1 t2 -> t1 @ [n] @ t2) [] *) val remove_root : t:tree{Node? t} -> Tot tree let rec remove_root t = match t with | Node n t1 t2 -> if Leaf? t1 then t2 else Node (Node?.root t1) (remove_root t1) t2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> t: BinaryTrees.tree -> Prims.Tot (t': BinaryTrees.tree{Node? t'})
Prims.Tot
[ "total", "" ]
[]
[ "Prims.int", "BinaryTrees.tree", "BinaryTrees.Node", "BinaryTrees.Leaf", "BinaryTrees.add_root", "Prims.b2t", "BinaryTrees.uu___is_Node" ]
[ "recursion" ]
false
false
false
false
false
let rec add_root x t =
match t with | Leaf -> Node x Leaf Leaf | Node n t1 t2 -> Node x (add_root n t1) t2
false
GMST.fst
GMST.gmst_trivial
val gmst_trivial : s: Type -> a: Type -> wp: GMST.gmst_wp s a -> Prims.logical
let gmst_trivial (s:Type) (a:Type) (wp:gmst_wp s a) = forall s0. wp s0 (fun _ _ _ -> True)
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 65, "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. *) module GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0 unfold let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1))) unfold let gmst_if_then_else (s:Type) (a:Type) (p:Type) (wp_then:gmst_wp s a) (wp_else:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = l_ITE p (wp_then s0 post) (wp_else s0 post) unfold let gmst_ite (s:Type) (a:Type) (wp:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = wp s0 post unfold let gmst_stronger (s:Type) (a:Type) (wp1:gmst_wp s a) (wp2:gmst_wp s a) = forall s0 p. wp1 s0 p ==> wp2 s0 p unfold let gmst_close (s:Type) (a:Type) (b:Type) (wp:(b -> GTot (gmst_wp s a))) (s0:s) (p:gmst_post s a s0) = forall x. wp x s0 p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Type -> a: Type -> wp: GMST.gmst_wp s a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "GMST.gmst_wp", "Prims.l_Forall", "FStar.Preorder.relation", "Prims.l_True", "Prims.logical" ]
[]
false
false
false
true
true
let gmst_trivial (s a: Type) (wp: gmst_wp s a) =
forall s0. wp s0 (fun _ _ _ -> True)
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.fsqr5
val fsqr5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f) (feval f)}
val fsqr5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f) (feval f)}
let fsqr5 (f0, f1, f2, f3, f4) = let (o0, o1, o2, o3, o4) = fsqr_felem5 (f0, f1, f2, f3, f4) in carry_wide5 (o0, o1, o2, o3, o4)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 416, "start_col": 0, "start_line": 414 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul)) let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1) #push-options "--ifuel 1" val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1)) let lemma_mul_inv f cin = assert_norm (pow51 = pow2 51) #pop-options #push-options "--z3rlimit 100" inline_for_extraction noextract val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == feval_wide inp) let carry_wide5 (i0, i1, i2, i3, i4) = assert_norm (6579 < pow2 13); assert_norm (pow2 13 < max51); let tmp0, c0 = carry51_wide #6579 i0 (u64 0) in let tmp1, c1 = carry51_wide #4797 i1 c0 in let tmp2, c2 = carry51_wide #3340 i2 c1 in let tmp3, c3 = carry51_wide #1881 i3 c2 in let tmp4, c4 = carry51_wide #423 i4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; (tmp0', tmp1', tmp2, tmp3, tmp4) #pop-options inline_for_extraction noextract val fmul5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f1) (feval f2)} let fmul5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (tmp0, tmp1, tmp2, tmp3, tmp4) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp0, tmp1, tmp2, tmp3, tmp4) in carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) inline_for_extraction noextract val fmul25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> f3:felem5{felem_fits5 f3 (9, 10, 9, 9, 9)} -> f4:felem5{felem_fits5 f4 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f2) /\ feval out2 == fmul (feval f3) (feval f4)) let fmul25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) = let (tmp10, tmp11, tmp12, tmp13, tmp14) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp20, tmp21, tmp22, tmp23, tmp24) = precomp_r19 (f40, f41, f42, f43, f44) in let (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp10, tmp11, tmp12, tmp13, tmp14) in let (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) = mul_felem5 (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) (tmp20, tmp21, tmp22, tmp23, tmp24) in let (o10,o11,o12,o13,o14) = carry_wide5 (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) in let (o20,o21,o22,o23,o24) = carry_wide5 (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) in ((o10,o11,o12,o13,o14), (o20,o21,o22,o23,o24)) inline_for_extraction noextract val fmul15: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:uint64{felem_fits1 f2 1} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == (feval f1 * v f2) % prime) let fmul15 (f10, f11, f12, f13, f14) f2 = let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = smul_felem5 #1 #(9, 10, 9, 9, 9) f2 (f10, f11, f12, f13, f14) in let out = (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in [@inline_let] let res = carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (uint_v f2) prime; assert (feval res == feval_wide (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)); assert (feval res == (wide_as_nat5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)) % prime); assert (feval res == (v f2 * as_nat5 (f10, f11, f12, f13, f14)) % prime); FStar.Math.Lemmas.swap_mul (v f2) (as_nat5 (f10, f11, f12, f13, f14)); assert (feval res == (as_nat5 (f10, f11, f12, f13, f14) * v f2) % prime); res // inline_for_extraction noextract // val fsqr_felem5: // f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} // -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423)} // let fsqr_felem5 (f0, f1, f2, f3, f4) = // let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 20, 18, 18, 18) f0 (f0, u64 2 *! f1, u64 2 *! f2, u64 2 *! f3, u64 2 *! f4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(342, 0, 10, 18, 18) #(81, 180, 162, 162, 162) // f1 (u64 38 *! f4, u64 0, f1, u64 2 *! f2, u64 2 *! f3) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(342, 342, 0, 0, 9) #(3501, 180, 262, 342, 342) // f2 (u64 38 *! f3, u64 38 *! f4, u64 0, u64 0, f2) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 171, 342, 0, 0) #(6579, 3258, 262, 342, 423) // f3 (u64 0, u64 19 *. f3, u64 38 *. f4, u64 0, u64 0) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 0, 0, 171, 0) #(6579, 4797, 3340, 342, 423) // f4 (u64 0, u64 0, u64 0, u64 19 *. f4, u64 0) (o0, o1, o2, o3, o4) in // (o0, o1, o2, o3, o4) inline_for_extraction noextract val mul64_wide_add3: #m0:scale64 -> #m1:scale64 -> #m2:scale64 -> #m3:scale64 -> #m4:scale64 -> #m5:scale64 -> a0:uint64{felem_fits1 a0 m0} -> a1:uint64{felem_fits1 a1 m1} -> b0:uint64{felem_fits1 b0 m2} -> b1:uint64{felem_fits1 b1 m3} -> c0:uint64{felem_fits1 c0 m4} -> c1:uint64{felem_fits1 c1 m5} -> Pure uint128 (requires m0 * m1 + m2 * m3 + m4 * m5 < 8192) (ensures fun res -> felem_wide_fits1 res (m0 * m1 + m2 * m3 + m4 * m5) /\ v res == v a0 * v a1 + v b0 * v b1 + v c0 * v c1) let mul64_wide_add3 #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1 = assert_norm (pow2 13 = 8192); mul64_wide_add3_lemma #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1; mul64_wide a0 a1 +! mul64_wide b0 b1 +! mul64_wide c0 c1 inline_for_extraction noextract val fsqr_felem5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> Pure felem_wide5 (requires True) (ensures fun out -> felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f) (feval f)) let fsqr_felem5 (f0, f1, f2, f3, f4) = assert_norm (pow2 13 = 8192); let d0 = u64 2 *! f0 in let d1 = u64 2 *! f1 in let d2 = u64 38 *! f2 in let d3 = u64 19 *! f3 in let d419 = u64 19 *! f4 in let d4 = u64 2 *! d419 in let s0 = mul64_wide_add3 #9 #9 #342 #10 #342 #9 f0 f0 d4 f1 d2 f3 in let s1 = mul64_wide_add3 #18 #10 #342 #9 #171 #9 d0 f1 d4 f2 d3 f3 in let s2 = mul64_wide_add3 #18 #9 #10 #10 #342 #9 d0 f2 f1 f1 d4 f3 in let s3 = mul64_wide_add3 #18 #9 #20 #9 #9 #171 d0 f3 d1 f2 f4 d419 in let s4 = mul64_wide_add3 #18 #9 #20 #9 #9 #9 d0 f4 d1 f3 f2 f2 in lemma_fmul_fsqr5 (f0, f1, f2, f3, f4); (s0, s1, s2, s3, s4) inline_for_extraction noextract val fsqr5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)}
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f (9, 10, 9, 9, 9)} -> out: Hacl.Spec.Curve25519.Field51.Definition.felem5 { Hacl.Spec.Curve25519.Field51.mul_inv_t out /\ Hacl.Spec.Curve25519.Field51.Definition.feval out == Spec.Curve25519.fmul (Hacl.Spec.Curve25519.Field51.Definition.feval f) (Hacl.Spec.Curve25519.Field51.Definition.feval f) }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Lib.IntTypes.uint64", "Lib.IntTypes.uint128", "Hacl.Spec.Curve25519.Field51.carry_wide5", "Prims.l_and", "Hacl.Spec.Curve25519.Field51.mul_inv_t", "Prims.eq2", "Spec.Curve25519.elem", "Hacl.Spec.Curve25519.Field51.Definition.feval", "Spec.Curve25519.fmul", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide5", "Hacl.Spec.Curve25519.Field51.fsqr_felem5" ]
[]
false
false
false
false
false
let fsqr5 (f0, f1, f2, f3, f4) =
let o0, o1, o2, o3, o4 = fsqr_felem5 (f0, f1, f2, f3, f4) in carry_wide5 (o0, o1, o2, o3, o4)
false
BinaryTrees.fst
BinaryTrees.count_remove_root
val count_remove_root (t: tree{Node? t}) : Lemma (ensures (let r = Node?.root t in (count r (remove_root t) = count r t - 1) /\ (forall y. {:pattern (count y (remove_root t))} y <> r ==> count y (remove_root t) = count y t)))
val count_remove_root (t: tree{Node? t}) : Lemma (ensures (let r = Node?.root t in (count r (remove_root t) = count r t - 1) /\ (forall y. {:pattern (count y (remove_root t))} y <> r ==> count y (remove_root t) = count y t)))
let rec count_remove_root (t:tree{Node? t}) : Lemma (ensures (let r = Node?.root t in (count r (remove_root t) = count r t - 1) /\ (forall y.{:pattern (count y (remove_root t))} y <> r ==> count y (remove_root t) = count y t))) = let Node n t1 t2 = t in if Leaf? t1 then () else count_remove_root t1
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 184, "start_col": 0, "start_line": 178 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t) let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2 val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x})) let find_fold f = fold #(option (x:int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None val revert : tree -> Tot tree let rec revert t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node n (revert t2) (revert t1) (* simpler than for lists because revert is symmetric, while List.rev is not *) val revert_involutive : t:tree -> Lemma (revert (revert t) = t) let rec revert_involutive t = match t with | Leaf -> () | Node n t1 t2 -> revert_involutive t1; revert_involutive t2 (* again, much simpler than for lists *) val revert_injective : t1:tree -> t2:tree -> Lemma (requires (revert t1 = revert t2)) (ensures (t1 = t2)) let rec revert_injective t1 t2 = match t1, t2 with | Leaf, Leaf -> () | Node n1 t11 t12, Node n2 t21 t22 -> revert_injective t11 t21; revert_injective t12 t22 val revert_fold : t:tree -> Lemma (revert t = fold (fun n t1 t2 -> Node n t2 t1) Leaf t) let rec revert_fold t = match t with | Leaf -> () | Node n t1 t2 -> revert_fold t1; revert_fold t2 (* open FStar.List *) (* val list_of : tree -> Tot (list int) *) (* let list_of = fold (fun n t1 t2 -> t1 @ [n] @ t2) [] *) val remove_root : t:tree{Node? t} -> Tot tree let rec remove_root t = match t with | Node n t1 t2 -> if Leaf? t1 then t2 else Node (Node?.root t1) (remove_root t1) t2 val add_root : x:int -> t:tree -> Tot (t':tree{Node? t'}) (decreases t) let rec add_root x t = match t with | Leaf -> Node x Leaf Leaf | Node n t1 t2 -> Node x (add_root n t1) t2 (* remove and add implemented this way round-trip; TODO: does the converse hold? *) val remove_add_root : x:int -> t:tree -> Lemma (requires True) (ensures (remove_root (add_root x t) = t)) (decreases t) let rec remove_add_root x t = match t with | Leaf -> () | Node n t1 t2 -> remove_add_root x t1 let rec count (x:int) (t:tree) : Tot nat = match t with | Leaf -> 0 | Node n t1 t2 -> (if n = x then 1 else 0) + count x t1 + count x t2 let rec remove (x:int) (t:tree{count x t > 0}) : Tot tree (decreases t) = match t with | Node n t1 t2 -> if x = n then remove_root t else if count x t1 > 0 then Node n (remove x t1) t2 else Node n t1 (remove x t2) //This proof is flaky with Z3-4.5.0, //It seems to require too much fuel to go through, although it should only need 2 //Z3-4.5.1 nightly successfully solves it with initial_fuel 2 //NS: 05/08 added a pattern on y to stabilize the proof
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 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": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: BinaryTrees.tree{Node? t} -> FStar.Pervasives.Lemma (ensures (let r = Node?.root t in BinaryTrees.count r (BinaryTrees.remove_root t) = BinaryTrees.count r t - 1 /\ (forall (y: Prims.int). {:pattern BinaryTrees.count y (BinaryTrees.remove_root t)} y <> r ==> BinaryTrees.count y (BinaryTrees.remove_root t) = BinaryTrees.count y t)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "BinaryTrees.tree", "Prims.b2t", "BinaryTrees.uu___is_Node", "Prims.int", "BinaryTrees.uu___is_Leaf", "Prims.bool", "BinaryTrees.count_remove_root", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_and", "Prims.op_Equality", "BinaryTrees.count", "BinaryTrees.remove_root", "Prims.op_Subtraction", "Prims.l_Forall", "Prims.l_imp", "Prims.op_disEquality", "Prims.nat", "BinaryTrees.__proj__Node__item__root", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec count_remove_root (t: tree{Node? t}) : Lemma (ensures (let r = Node?.root t in (count r (remove_root t) = count r t - 1) /\ (forall y. {:pattern (count y (remove_root t))} y <> r ==> count y (remove_root t) = count y t))) =
let Node n t1 t2 = t in if Leaf? t1 then () else count_remove_root t1
false
Hacl.Curve25519_51.fst
Hacl.Curve25519_51.montgomery_ladder
val montgomery_ladder : Hacl.Meta.Curve25519.generic_montgomery_ladder_higher_t Prims.l_True
let montgomery_ladder = generic_montgomery_ladder_higher #M51 True point_double C.cswap2 point_add_and_double
{ "file_name": "code/curve25519/Hacl.Curve25519_51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 87, "end_line": 18, "start_col": 0, "start_line": 17 }
module Hacl.Curve25519_51 friend Hacl.Meta.Curve25519 open Hacl.Meta.Curve25519 // The Hacl core. module C = Hacl.Impl.Curve25519.Field51 let g25519: g25519_t = Lib.Buffer.createL_global Spec.Curve25519.basepoint_list #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" let point_add_and_double = addanddouble_point_add_and_double_higher #M51 True C.fmul C.fsqr2 C.fmul1 C.fmul2 C.fsub C.fadd let point_double =
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Curve25519.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Curve25519_51.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "C" }, { "abbrev": false, "full_module": "Hacl.Meta.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Meta.Curve25519.generic_montgomery_ladder_higher_t Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Curve25519.generic_montgomery_ladder_higher", "Hacl.Impl.Curve25519.Fields.Core.M51", "Prims.l_True", "Hacl.Curve25519_51.point_double", "Hacl.Impl.Curve25519.Field51.cswap2", "Hacl.Curve25519_51.point_add_and_double" ]
[]
false
false
false
true
false
let montgomery_ladder =
generic_montgomery_ladder_higher #M51 True point_double C.cswap2 point_add_and_double
false
Pulse.Soundness.Bind.fst
Pulse.Soundness.Bind.bind_fn_typing
val bind_fn_typing (#g:stt_env) (#t:st_term) (#c:comp) (d:st_typing g t c{T_BindFn? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
val bind_fn_typing (#g:stt_env) (#t:st_term) (#c:comp) (d:st_typing g t c{T_BindFn? d}) (soundness:soundness_t d) : GTot (RT.tot_typing (elab_env g) (elab_st_typing d) (elab_comp c))
let bind_fn_typing #g #t #c d soundness = let T_BindFn _ e1 e2 c1 c2 b x e1_typing u t1_typing e2_typing c2_typing = d in let t1 = comp_res c1 in let g_x = push_binding g x ppname_default t1 in let re1 = elab_st_typing e1_typing in let rt1 = elab_term t1 in let re2 = elab_st_typing e2_typing in let re1_typing : RT.tot_typing (elab_env g) re1 rt1 = soundness g e1 c1 e1_typing in let re2_typing : RT.tot_typing (elab_env g_x) re2 (elab_comp c2) = soundness g_x (open_st_term_nv e2 (v_as_nv x)) c2 e2_typing in RT.well_typed_terms_are_ln _ _ _ re2_typing; calc (==) { RT.open_term (RT.close_term re2 x) x; (==) { RT.open_term_spec (RT.close_term re2 x) x } RT.subst_term (RT.close_term re2 x) (RT.open_with_var x 0); (==) { RT.close_term_spec re2 x } RT.subst_term (RT.subst_term re2 [ RT.ND x 0 ]) (RT.open_with_var x 0); (==) { RT.open_close_inverse' 0 re2 x } re2; }; let elab_t = RT.mk_let RT.pp_name_default re1 rt1 (RT.close_term re2 x) in let res : RT.tot_typing (elab_env g) elab_t (RT.open_with (RT.close_term (elab_comp c2) x) re1) = RT.T_Let (elab_env g) x re1 rt1 (RT.close_term re2 x) (elab_comp c2) T.E_Total RT.pp_name_default re1_typing re2_typing in Pulse.Typing.LN.comp_typing_ln c2_typing; Pulse.Elaborate.elab_ln_comp c (-1); assert (RT.ln (elab_comp c2)); open_close_inverse_t (elab_comp c2) x re1; assert (RT.open_with (RT.close_term (elab_comp c2) x) re1 == elab_comp c2); res
{ "file_name": "lib/steel/pulse/Pulse.Soundness.Bind.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 231, "start_col": 0, "start_line": 197 }
(* 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.Bind module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module L = FStar.List.Tot module T = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot open Pulse.Syntax open Pulse.Typing open Pulse.Elaborate open Pulse.Soundness.Common #push-options "--z3rlimit_factor 5" (*** Soundness of bind elaboration *) (* x:t1 -> stt t2 pre post ~ x:t1 -> stt t2 ((fun x -> pre) x) post *) let mequiv_arrow (g:R.env) (t1:R.term) (u2:R.universe) (t2:R.term) (pre:R.term) (post:R.term) //need some ln preconditions : GTot (RT.equiv g (mk_arrow (t1, R.Q_Explicit) (mk_stt_comp u2 t2 pre post)) (mk_arrow (t1, R.Q_Explicit) (mk_stt_comp u2 t2 (R.mk_app (mk_abs t1 R.Q_Explicit pre) [bound_var 0, R.Q_Explicit]) post))) = admit() #push-options "--fuel 2 --ifuel 1 --query_stats" let inst_bind_t1 #u1 #u2 #g #head (head_typing: RT.tot_typing g head (bind_type u1 u2)) (#t1:_) (t1_typing: RT.tot_typing g t1 (RT.tm_type u1)) : GTot (RT.tot_typing g (R.mk_app head [(t1, R.Q_Implicit)]) (bind_type_t1 u1 u2 t1)) = let open_with_spec (t v:R.term) : Lemma (RT.open_with t v == RT.subst_term t [ RT.DT 0 v ]) [SMTPat (RT.open_with t v)] = RT.open_with_spec t v in let d : RT.tot_typing g (R.mk_app head [(t1, R.Q_Implicit)]) _ = RT.T_App _ _ _ _ (RT.subst_term (bind_type_t1 u1 u2 (mk_name 4)) [ RT.ND 4 0 ]) _ head_typing t1_typing in assume (bind_type_t1 u1 u2 t1 == RT.open_with (RT.subst_term (bind_type_t1 u1 u2 (mk_name 4)) [ RT.ND 4 0 ]) t1); d #pop-options let inst_bind_t2 #u1 #u2 #g #head #t1 (head_typing: RT.tot_typing g head (bind_type_t1 u1 u2 t1)) (#t2:_) (t2_typing: RT.tot_typing g t2 (RT.tm_type u2)) : RT.tot_typing g (R.mk_app head [(t2, R.Q_Implicit)]) (bind_type_t1_t2 u1 u2 t1 t2) = admit() let inst_bind_pre #u1 #u2 #g #head #t1 #t2 (head_typing: RT.tot_typing g head (bind_type_t1_t2 u1 u2 t1 t2)) (#pre:_) (pre_typing: RT.tot_typing g pre vprop_tm) : RT.tot_typing g (R.mk_app head [(pre, R.Q_Implicit)]) (bind_type_t1_t2_pre u1 u2 t1 t2 pre) = admit() let inst_bind_post1 #u1 #u2 #g #head #t1 #t2 #pre (head_typing: RT.tot_typing g head (bind_type_t1_t2_pre u1 u2 t1 t2 pre)) (#post1:_) (post1_typing: RT.tot_typing g post1 (post1_type_bind t1)) : RT.tot_typing g (R.mk_app head [(post1, R.Q_Implicit)]) (bind_type_t1_t2_pre_post1 u1 u2 t1 t2 pre post1) = admit() let inst_bind_post2 #u1 #u2 #g #head #t1 #t2 #pre #post1 (head_typing: RT.tot_typing g head (bind_type_t1_t2_pre_post1 u1 u2 t1 t2 pre post1)) (#post2:_) (post2_typing: RT.tot_typing g post2 (post2_type_bind t2)) : RT.tot_typing g (R.mk_app head [(post2, R.Q_Implicit)]) (bind_type_t1_t2_pre_post1_post2 u1 u2 t1 t2 pre post1 post2) = admit() let inst_bind_f #u1 #u2 #g #head #t1 #t2 #pre #post1 #post2 (head_typing: RT.tot_typing g head (bind_type_t1_t2_pre_post1_post2 u1 u2 t1 t2 pre post1 post2)) (#f:_) (f_typing: RT.tot_typing g f (mk_stt_comp u1 t1 pre post1)) : RT.tot_typing g (R.mk_app head [(f, R.Q_Explicit)]) (bind_type_t1_t2_pre_post1_post2_f u1 u2 t1 t2 pre post1 post2) = admit() let inst_bind_g #u1 #u2 #g #head #t1 #t2 #pre #post1 #post2 (head_typing: RT.tot_typing g head (bind_type_t1_t2_pre_post1_post2_f u1 u2 t1 t2 pre post1 post2)) (#gg:_) (g_typing: RT.tot_typing g gg (g_type_bind u2 t1 t2 post1 post2)) : RT.tot_typing g (R.mk_app head [(gg, R.Q_Explicit)]) (bind_res u2 t2 pre post2) = let open_with_spec (t v:R.term) : Lemma (RT.open_with t v == RT.subst_term t [ RT.DT 0 v ]) [SMTPat (RT.open_with t v)] = RT.open_with_spec t v in let d : RT.tot_typing g (R.mk_app head [(gg, R.Q_Explicit)]) _ = RT.T_App _ _ _ _ (bind_res u2 t2 pre post2) _ head_typing g_typing in admit(); d #pop-options #push-options "--z3rlimit_factor 8" let elab_bind_typing (g:stt_env) (c1 c2 c:ln_comp) (x:var { ~ (x `Set.mem` freevars_comp c1) }) (r1:R.term) (r1_typing: RT.tot_typing (elab_env g) r1 (elab_comp c1)) (r2:R.term) (r2_typing: RT.tot_typing (elab_env g) r2 (elab_term (tm_arrow (null_binder (comp_res c1)) None (close_comp c2 x)))) (bc:bind_comp g x c1 c2 c) (t2_typing : RT.tot_typing (elab_env g) (elab_term (comp_res c2)) (RT.tm_type (comp_u c2))) (post2_typing: RT.tot_typing (elab_env g) (elab_comp_post c2) (post2_type_bind (elab_term (comp_res c2)))) = assume (C_ST? c1 /\ C_ST? c2); let rg = elab_env g in let u1 = comp_u c1 in let u2 = comp_u c2 in let bind_lid = mk_pulse_lib_core_lid "bind_stt" in let bind_fv = R.pack_fv bind_lid in let head = R.pack_ln (R.Tv_UInst bind_fv [u1;u2]) in assume (RT.lookup_fvar_uinst rg bind_fv [u1; u2] == Some (bind_type u1 u2)); let head_typing : RT.tot_typing _ _ (bind_type u1 u2) = RT.T_UInst rg bind_fv [u1;u2] in let (| _, c1_typing |) = RT.type_correctness _ _ _ r1_typing in let t1_typing, pre_typing, post_typing = inversion_of_stt_typing _ _ c1_typing in let t1 = (elab_term (comp_res c1)) in let t2 = (elab_term (comp_res c2)) in let t1_typing : RT.tot_typing rg t1 (RT.tm_type u1) = t1_typing in let post1 = elab_comp_post c1 in let c2_x = close_comp c2 x in assume (comp_res c2_x == comp_res c2); assume (comp_post c2_x == comp_post c2); assert (open_term (comp_post c1) x == comp_pre c2); assert (~ (x `Set.mem` freevars (comp_post c1))); close_open_inverse (comp_post c1) x; assert (comp_post c1 == close_term (comp_pre c2) x); assert (post1 == mk_abs t1 R.Q_Explicit (elab_term (comp_post c1))); assert (elab_term (comp_post c1) == elab_term (comp_pre (close_comp c2 x))); //ln (comp_post c1) 0 let g_typing : RT.tot_typing _ _ (mk_arrow (t1, R.Q_Explicit) (mk_stt_comp u2 t2 (elab_term (comp_post c1)) (elab_comp_post c2))) = r2_typing in let g_typing : RT.tot_typing _ _ (mk_arrow (t1, R.Q_Explicit) (mk_stt_comp u2 t2 (R.mk_app (mk_abs t1 R.Q_Explicit (elab_term (comp_post c1))) [bound_var 0, R.Q_Explicit]) (elab_comp_post c2))) = RT.T_Sub _ _ _ _ r2_typing (RT.Relc_typ _ _ _ _ _ (RT.Rel_equiv _ _ _ _ (mequiv_arrow _ _ _ _ _ _))) in let d : RT.tot_typing _ (elab_bind bc r1 r2) _ = inst_bind_g (inst_bind_f (inst_bind_post2 (inst_bind_post1 (inst_bind_pre (inst_bind_t2 (inst_bind_t1 head_typing t1_typing) t2_typing) pre_typing) post_typing) post2_typing) r1_typing) g_typing in d #pop-options #push-options "--query_stats --z3rlimit_factor 4 --split_queries no" assume val open_close_inverse_t (e:R.term { RT.ln e }) (x:var) (t:R.term) : Lemma (RT.open_with (RT.close_term e x) t == e)
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.LN.fsti.checked", "Pulse.Typing.fst.checked", "Pulse.Syntax.fst.checked", "Pulse.Soundness.Common.fst.checked", "Pulse.RuntimeUtils.fsti.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", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Pulse.Soundness.Bind.fst" }
[ { "abbrev": false, "full_module": "Pulse.Soundness.Common", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Elaborate", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Typing", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "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.Common", "short_module": null }, { "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
d: Pulse.Typing.st_typing g t c {T_BindFn? d} -> soundness: Pulse.Soundness.Common.soundness_t d -> Prims.GTot (FStar.Reflection.Typing.tot_typing (Pulse.Typing.elab_env g) (Pulse.Elaborate.Core.elab_st_typing d) (Pulse.Elaborate.Pure.elab_comp c))
Prims.GTot
[ "sometrivial" ]
[]
[ "Pulse.Soundness.Common.stt_env", "Pulse.Syntax.Base.st_term", "Pulse.Syntax.Base.comp", "Pulse.Typing.st_typing", "Prims.b2t", "Pulse.Typing.uu___is_T_BindFn", "Pulse.Soundness.Common.soundness_t", "Pulse.Typing.Env.env", "Pulse.Syntax.Base.uu___is_C_Tot", "Pulse.Syntax.Base.comp_st", "Pulse.Syntax.Base.binder", "Prims.eq2", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty", "Pulse.Syntax.Base.comp_res", "Pulse.Syntax.Base.var", "Prims.l_and", "FStar.Pervasives.Native.uu___is_None", "Pulse.Syntax.Base.typ", "Pulse.Typing.Env.lookup", "Prims.l_not", "FStar.Set.mem", "Pulse.Syntax.Naming.freevars_st", "FStar.Ghost.erased", "Pulse.Syntax.Base.universe", "Pulse.Typing.tot_typing", "Pulse.Syntax.Pure.tm_type", "FStar.Ghost.reveal", "Pulse.Typing.Env.push_binding", "Pulse.Syntax.Base.ppname_default", "Pulse.Syntax.Naming.open_st_term_nv", "FStar.Pervasives.Native.Mktuple2", "Pulse.Syntax.Base.ppname", "Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ppname", "Pulse.Typing.comp_typing_u", "Prims.unit", "Prims._assert", "FStar.Stubs.Reflection.Types.term", "FStar.Reflection.Typing.open_with", "FStar.Reflection.Typing.close_term", "Pulse.Elaborate.Pure.elab_comp", "Pulse.Soundness.Bind.open_close_inverse_t", "FStar.Reflection.Typing.ln", "Pulse.Elaborate.elab_ln_comp", "Prims.op_Minus", "Pulse.Typing.LN.comp_typing_ln", "Pulse.Syntax.Base.universe_of_comp", "FStar.Reflection.Typing.tot_typing", "Pulse.Typing.elab_env", "FStar.Reflection.Typing.T_Let", "FStar.Stubs.TypeChecker.Core.E_Total", "FStar.Reflection.Typing.pp_name_default", "FStar.Reflection.Typing.mk_let", "FStar.Calc.calc_finish", "FStar.Reflection.Typing.open_term", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Reflection.Typing.subst_term", "FStar.Reflection.Typing.subst_elt", "FStar.Reflection.Typing.ND", "FStar.Reflection.Typing.open_with_var", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Reflection.Typing.open_term_spec", "Prims.squash", "FStar.Reflection.Typing.close_term_spec", "FStar.Reflection.Typing.open_close_inverse'", "FStar.Reflection.Typing.well_typed_terms_are_ln", "FStar.Stubs.TypeChecker.Core.tot_or_ghost", "FStar.Stubs.Reflection.Types.typ", "Pulse.Syntax.Base.v_as_nv", "Pulse.Elaborate.Core.elab_st_typing", "Pulse.Elaborate.Pure.elab_term", "FStar.Reflection.Typing.fstar_top_env", "Pulse.Typing.Env.fstar_env" ]
[]
false
false
false
false
false
let bind_fn_typing #g #t #c d soundness =
let T_BindFn _ e1 e2 c1 c2 b x e1_typing u t1_typing e2_typing c2_typing = d in let t1 = comp_res c1 in let g_x = push_binding g x ppname_default t1 in let re1 = elab_st_typing e1_typing in let rt1 = elab_term t1 in let re2 = elab_st_typing e2_typing in let re1_typing:RT.tot_typing (elab_env g) re1 rt1 = soundness g e1 c1 e1_typing in let re2_typing:RT.tot_typing (elab_env g_x) re2 (elab_comp c2) = soundness g_x (open_st_term_nv e2 (v_as_nv x)) c2 e2_typing in RT.well_typed_terms_are_ln _ _ _ re2_typing; calc ( == ) { RT.open_term (RT.close_term re2 x) x; ( == ) { RT.open_term_spec (RT.close_term re2 x) x } RT.subst_term (RT.close_term re2 x) (RT.open_with_var x 0); ( == ) { RT.close_term_spec re2 x } RT.subst_term (RT.subst_term re2 [RT.ND x 0]) (RT.open_with_var x 0); ( == ) { RT.open_close_inverse' 0 re2 x } re2; }; let elab_t = RT.mk_let RT.pp_name_default re1 rt1 (RT.close_term re2 x) in let res:RT.tot_typing (elab_env g) elab_t (RT.open_with (RT.close_term (elab_comp c2) x) re1) = RT.T_Let (elab_env g) x re1 rt1 (RT.close_term re2 x) (elab_comp c2) T.E_Total RT.pp_name_default re1_typing re2_typing in Pulse.Typing.LN.comp_typing_ln c2_typing; Pulse.Elaborate.elab_ln_comp c (- 1); assert (RT.ln (elab_comp c2)); open_close_inverse_t (elab_comp c2) x re1; assert (RT.open_with (RT.close_term (elab_comp c2) x) re1 == elab_comp c2); res
false
GMST.fst
GMST.lift_div_gmst
val lift_div_gmst : a: Type -> wp: Prims.pure_wp a -> s0: GMST.state -> p: GMST.gmst_post GMST.state a s0 -> Prims.pure_pre
let lift_div_gmst (a:Type) (wp:pure_wp a) (s0:state) (p:gmst_post state a s0) = wp (fun x -> p (fun s0 s1 -> s0 == s1) x s0)
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 124, "end_line": 95, "start_col": 0, "start_line": 95 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0 unfold let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1))) unfold let gmst_if_then_else (s:Type) (a:Type) (p:Type) (wp_then:gmst_wp s a) (wp_else:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = l_ITE p (wp_then s0 post) (wp_else s0 post) unfold let gmst_ite (s:Type) (a:Type) (wp:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = wp s0 post unfold let gmst_stronger (s:Type) (a:Type) (wp1:gmst_wp s a) (wp2:gmst_wp s a) = forall s0 p. wp1 s0 p ==> wp2 s0 p unfold let gmst_close (s:Type) (a:Type) (b:Type) (wp:(b -> GTot (gmst_wp s a))) (s0:s) (p:gmst_post s a s0) = forall x. wp x s0 p unfold let gmst_trivial (s:Type) (a:Type) (wp:gmst_wp s a) = forall s0. wp s0 (fun _ _ _ -> True) new_effect { GMST_h (s:Type) : result:Type -> wp:gmst_wp s result -> Effect with //repr = s0:s -> M (rel:relation a & a * s1:s{rel s0 s1}) return_wp = gmst_return s ; bind_wp = gmst_bind s ; if_then_else = gmst_if_then_else s ; ite_wp = gmst_ite s ; stronger = gmst_stronger s ; close_wp = gmst_close s ; trivial = gmst_trivial s } (* DA: For some reason, DM4F didn't accept the representation s -> M ((s -> s -> Type0) * a * s) thus the explicit effect definition for time being *) (* Instatiating the graded MST with int as a proof-of-concept *) let state = int new_effect GMST = GMST_h state
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> wp: Prims.pure_wp a -> s0: GMST.state -> p: GMST.gmst_post GMST.state a s0 -> Prims.pure_pre
Prims.Tot
[ "total" ]
[]
[ "Prims.pure_wp", "GMST.state", "GMST.gmst_post", "Prims.l_True", "Prims.eq2", "Prims.pure_pre" ]
[]
false
false
false
false
false
let lift_div_gmst (a: Type) (wp: pure_wp a) (s0: state) (p: gmst_post state a s0) =
wp (fun x -> p (fun s0 s1 -> s0 == s1) x s0)
false
GMST.fst
GMST.state
val state : Prims.eqtype
let state = int
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 91, "start_col": 0, "start_line": 91 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0 unfold let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1))) unfold let gmst_if_then_else (s:Type) (a:Type) (p:Type) (wp_then:gmst_wp s a) (wp_else:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = l_ITE p (wp_then s0 post) (wp_else s0 post) unfold let gmst_ite (s:Type) (a:Type) (wp:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = wp s0 post unfold let gmst_stronger (s:Type) (a:Type) (wp1:gmst_wp s a) (wp2:gmst_wp s a) = forall s0 p. wp1 s0 p ==> wp2 s0 p unfold let gmst_close (s:Type) (a:Type) (b:Type) (wp:(b -> GTot (gmst_wp s a))) (s0:s) (p:gmst_post s a s0) = forall x. wp x s0 p unfold let gmst_trivial (s:Type) (a:Type) (wp:gmst_wp s a) = forall s0. wp s0 (fun _ _ _ -> True) new_effect { GMST_h (s:Type) : result:Type -> wp:gmst_wp s result -> Effect with //repr = s0:s -> M (rel:relation a & a * s1:s{rel s0 s1}) return_wp = gmst_return s ; bind_wp = gmst_bind s ; if_then_else = gmst_if_then_else s ; ite_wp = gmst_ite s ; stronger = gmst_stronger s ; close_wp = gmst_close s ; trivial = gmst_trivial s } (* DA: For some reason, DM4F didn't accept the representation s -> M ((s -> s -> Type0) * a * s) thus the explicit effect definition for time being *) (* Instatiating the graded MST with int as a proof-of-concept *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.eqtype
Prims.Tot
[ "total" ]
[]
[ "Prims.int" ]
[]
false
false
false
true
false
let state =
int
false
GMST.fst
GMST.gmst_bind
val gmst_bind : s: Type -> a: Type -> b: Type -> wp1: GMST.gmst_wp s a -> wp2: (_: a -> Prims.GTot (GMST.gmst_wp s b)) -> s0: s -> p: GMST.gmst_post s b s0 -> Type0
let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1)))
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 68, "end_line": 43, "start_col": 0, "start_line": 40 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Type -> a: Type -> b: Type -> wp1: GMST.gmst_wp s a -> wp2: (_: a -> Prims.GTot (GMST.gmst_wp s b)) -> s0: s -> p: GMST.gmst_post s b s0 -> Type0
Prims.Tot
[ "total" ]
[]
[ "GMST.gmst_wp", "GMST.gmst_post", "FStar.Preorder.relation", "GMST.op_At" ]
[]
false
false
false
false
true
let gmst_bind (s a b: Type) (wp1: gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0: s) (p: gmst_post s b s0) =
wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1)))
false
Hacl.Curve25519_51.fst
Hacl.Curve25519_51.secret_to_public
val secret_to_public: secret_to_public_st M51 True
val secret_to_public: secret_to_public_st M51 True
let secret_to_public = generic_secret_to_public_higher #M51 True scalarmult g25519
{ "file_name": "code/curve25519/Hacl.Curve25519_51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 82, "end_line": 23, "start_col": 0, "start_line": 23 }
module Hacl.Curve25519_51 friend Hacl.Meta.Curve25519 open Hacl.Meta.Curve25519 // The Hacl core. module C = Hacl.Impl.Curve25519.Field51 let g25519: g25519_t = Lib.Buffer.createL_global Spec.Curve25519.basepoint_list #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" let point_add_and_double = addanddouble_point_add_and_double_higher #M51 True C.fmul C.fsqr2 C.fmul1 C.fmul2 C.fsub C.fadd let point_double = addanddouble_point_double_higher #M51 True C.fmul2 C.fmul1 C.fsqr2 C.fsub C.fadd let montgomery_ladder = generic_montgomery_ladder_higher #M51 True point_double C.cswap2 point_add_and_double let fsquare_times = finv_fsquare_times_higher #M51 True C.fsqr let finv = finv_finv_higher #M51 True C.fmul fsquare_times let encode_point = generic_encode_point_higher #M51 True C.store_felem C.fmul finv
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Curve25519.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Curve25519_51.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "C" }, { "abbrev": false, "full_module": "Hacl.Meta.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Curve25519.Generic.secret_to_public_st Hacl.Impl.Curve25519.Fields.Core.M51 Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Curve25519.generic_secret_to_public_higher", "Hacl.Impl.Curve25519.Fields.Core.M51", "Prims.l_True", "Hacl.Curve25519_51.scalarmult", "Hacl.Curve25519_51.g25519" ]
[]
false
false
false
true
false
let secret_to_public =
generic_secret_to_public_higher #M51 True scalarmult g25519
false
Hacl.Curve25519_51.fst
Hacl.Curve25519_51.point_double
val point_double : Hacl.Meta.Curve25519.addanddouble_point_double_higher_t Prims.l_True
let point_double = addanddouble_point_double_higher #M51 True C.fmul2 C.fmul1 C.fsqr2 C.fsub C.fadd
{ "file_name": "code/curve25519/Hacl.Curve25519_51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 82, "end_line": 16, "start_col": 0, "start_line": 15 }
module Hacl.Curve25519_51 friend Hacl.Meta.Curve25519 open Hacl.Meta.Curve25519 // The Hacl core. module C = Hacl.Impl.Curve25519.Field51 let g25519: g25519_t = Lib.Buffer.createL_global Spec.Curve25519.basepoint_list #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" let point_add_and_double =
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Curve25519.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Curve25519_51.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "C" }, { "abbrev": false, "full_module": "Hacl.Meta.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Meta.Curve25519.addanddouble_point_double_higher_t Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Curve25519.addanddouble_point_double_higher", "Hacl.Impl.Curve25519.Fields.Core.M51", "Prims.l_True", "Hacl.Impl.Curve25519.Field51.fmul2", "Hacl.Impl.Curve25519.Field51.fmul1", "Hacl.Impl.Curve25519.Field51.fsqr2", "Hacl.Impl.Curve25519.Field51.fsub", "Hacl.Impl.Curve25519.Field51.fadd" ]
[]
false
false
false
true
false
let point_double =
addanddouble_point_double_higher #M51 True C.fmul2 C.fmul1 C.fsqr2 C.fsub C.fadd
false
BinaryTrees.fst
BinaryTrees.count_remove
val count_remove (x: int) (t: tree{count x t > 0}) : Lemma (requires True) (ensures (count x (remove x t) = count x t - 1)) (decreases t)
val count_remove (x: int) (t: tree{count x t > 0}) : Lemma (requires True) (ensures (count x (remove x t) = count x t - 1)) (decreases t)
let rec count_remove (x:int) (t:tree{count x t > 0}) : Lemma (requires True) (ensures (count x (remove x t) = count x t - 1)) (decreases t) = match t with | Node n t1 t2 -> if x = n then count_remove_root t else if count x t1 > 0 then count_remove x t1 else count_remove x t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 60, "end_line": 193, "start_col": 0, "start_line": 187 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t) let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2 val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x})) let find_fold f = fold #(option (x:int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None val revert : tree -> Tot tree let rec revert t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node n (revert t2) (revert t1) (* simpler than for lists because revert is symmetric, while List.rev is not *) val revert_involutive : t:tree -> Lemma (revert (revert t) = t) let rec revert_involutive t = match t with | Leaf -> () | Node n t1 t2 -> revert_involutive t1; revert_involutive t2 (* again, much simpler than for lists *) val revert_injective : t1:tree -> t2:tree -> Lemma (requires (revert t1 = revert t2)) (ensures (t1 = t2)) let rec revert_injective t1 t2 = match t1, t2 with | Leaf, Leaf -> () | Node n1 t11 t12, Node n2 t21 t22 -> revert_injective t11 t21; revert_injective t12 t22 val revert_fold : t:tree -> Lemma (revert t = fold (fun n t1 t2 -> Node n t2 t1) Leaf t) let rec revert_fold t = match t with | Leaf -> () | Node n t1 t2 -> revert_fold t1; revert_fold t2 (* open FStar.List *) (* val list_of : tree -> Tot (list int) *) (* let list_of = fold (fun n t1 t2 -> t1 @ [n] @ t2) [] *) val remove_root : t:tree{Node? t} -> Tot tree let rec remove_root t = match t with | Node n t1 t2 -> if Leaf? t1 then t2 else Node (Node?.root t1) (remove_root t1) t2 val add_root : x:int -> t:tree -> Tot (t':tree{Node? t'}) (decreases t) let rec add_root x t = match t with | Leaf -> Node x Leaf Leaf | Node n t1 t2 -> Node x (add_root n t1) t2 (* remove and add implemented this way round-trip; TODO: does the converse hold? *) val remove_add_root : x:int -> t:tree -> Lemma (requires True) (ensures (remove_root (add_root x t) = t)) (decreases t) let rec remove_add_root x t = match t with | Leaf -> () | Node n t1 t2 -> remove_add_root x t1 let rec count (x:int) (t:tree) : Tot nat = match t with | Leaf -> 0 | Node n t1 t2 -> (if n = x then 1 else 0) + count x t1 + count x t2 let rec remove (x:int) (t:tree{count x t > 0}) : Tot tree (decreases t) = match t with | Node n t1 t2 -> if x = n then remove_root t else if count x t1 > 0 then Node n (remove x t1) t2 else Node n t1 (remove x t2) //This proof is flaky with Z3-4.5.0, //It seems to require too much fuel to go through, although it should only need 2 //Z3-4.5.1 nightly successfully solves it with initial_fuel 2 //NS: 05/08 added a pattern on y to stabilize the proof #reset-options "--z3rlimit 20 --initial_fuel 2 --initial_ifuel 2" let rec count_remove_root (t:tree{Node? t}) : Lemma (ensures (let r = Node?.root t in (count r (remove_root t) = count r t - 1) /\ (forall y.{:pattern (count y (remove_root t))} y <> r ==> count y (remove_root t) = count y t))) = let Node n t1 t2 = t in if Leaf? t1 then () else count_remove_root t1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> t: BinaryTrees.tree{BinaryTrees.count x t > 0} -> FStar.Pervasives.Lemma (ensures BinaryTrees.count x (BinaryTrees.remove x t) = BinaryTrees.count x t - 1) (decreases t)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.int", "BinaryTrees.tree", "Prims.b2t", "Prims.op_GreaterThan", "BinaryTrees.count", "Prims.op_Equality", "BinaryTrees.count_remove_root", "Prims.bool", "BinaryTrees.count_remove", "Prims.unit", "Prims.l_True", "Prims.squash", "BinaryTrees.remove", "Prims.op_Subtraction", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec count_remove (x: int) (t: tree{count x t > 0}) : Lemma (requires True) (ensures (count x (remove x t) = count x t - 1)) (decreases t) =
match t with | Node n t1 t2 -> if x = n then count_remove_root t else if count x t1 > 0 then count_remove x t1 else count_remove x t2
false
GMST.fst
GMST.mst_wp
val mst_wp : s: Type -> a: Type -> rel: FStar.Preorder.relation s -> Type
let mst_wp (s:Type) (a:Type) (rel:relation s) = s0:s -> (a -> s1:s{rel s0 s1} -> Type0) -> Type0
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 99, "end_line": 101, "start_col": 0, "start_line": 101 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0 unfold let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1))) unfold let gmst_if_then_else (s:Type) (a:Type) (p:Type) (wp_then:gmst_wp s a) (wp_else:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = l_ITE p (wp_then s0 post) (wp_else s0 post) unfold let gmst_ite (s:Type) (a:Type) (wp:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = wp s0 post unfold let gmst_stronger (s:Type) (a:Type) (wp1:gmst_wp s a) (wp2:gmst_wp s a) = forall s0 p. wp1 s0 p ==> wp2 s0 p unfold let gmst_close (s:Type) (a:Type) (b:Type) (wp:(b -> GTot (gmst_wp s a))) (s0:s) (p:gmst_post s a s0) = forall x. wp x s0 p unfold let gmst_trivial (s:Type) (a:Type) (wp:gmst_wp s a) = forall s0. wp s0 (fun _ _ _ -> True) new_effect { GMST_h (s:Type) : result:Type -> wp:gmst_wp s result -> Effect with //repr = s0:s -> M (rel:relation a & a * s1:s{rel s0 s1}) return_wp = gmst_return s ; bind_wp = gmst_bind s ; if_then_else = gmst_if_then_else s ; ite_wp = gmst_ite s ; stronger = gmst_stronger s ; close_wp = gmst_close s ; trivial = gmst_trivial s } (* DA: For some reason, DM4F didn't accept the representation s -> M ((s -> s -> Type0) * a * s) thus the explicit effect definition for time being *) (* Instatiating the graded MST with int as a proof-of-concept *) let state = int new_effect GMST = GMST_h state let lift_div_gmst (a:Type) (wp:pure_wp a) (s0:state) (p:gmst_post state a s0) = wp (fun x -> p (fun s0 s1 -> s0 == s1) x s0) sub_effect DIV ~> GMST = lift_div_gmst (* Syntactic sugar packaging a relation index and MST WP *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Type -> a: Type -> rel: FStar.Preorder.relation s -> Type
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.relation" ]
[]
false
false
false
true
true
let mst_wp (s a: Type) (rel: relation s) =
s0: s -> (a -> s1: s{rel s0 s1} -> Type0) -> Type0
false
GMST.fst
GMST.stable
val stable : p: FStar.Preorder.predicate a -> rel: FStar.Preorder.preorder a -> Prims.logical
let stable (#a:Type) (p:predicate a) (rel:preorder a) = forall x y . p x /\ rel x y ==> p y
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 39, "end_line": 116, "start_col": 0, "start_line": 115 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0 unfold let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1))) unfold let gmst_if_then_else (s:Type) (a:Type) (p:Type) (wp_then:gmst_wp s a) (wp_else:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = l_ITE p (wp_then s0 post) (wp_else s0 post) unfold let gmst_ite (s:Type) (a:Type) (wp:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = wp s0 post unfold let gmst_stronger (s:Type) (a:Type) (wp1:gmst_wp s a) (wp2:gmst_wp s a) = forall s0 p. wp1 s0 p ==> wp2 s0 p unfold let gmst_close (s:Type) (a:Type) (b:Type) (wp:(b -> GTot (gmst_wp s a))) (s0:s) (p:gmst_post s a s0) = forall x. wp x s0 p unfold let gmst_trivial (s:Type) (a:Type) (wp:gmst_wp s a) = forall s0. wp s0 (fun _ _ _ -> True) new_effect { GMST_h (s:Type) : result:Type -> wp:gmst_wp s result -> Effect with //repr = s0:s -> M (rel:relation a & a * s1:s{rel s0 s1}) return_wp = gmst_return s ; bind_wp = gmst_bind s ; if_then_else = gmst_if_then_else s ; ite_wp = gmst_ite s ; stronger = gmst_stronger s ; close_wp = gmst_close s ; trivial = gmst_trivial s } (* DA: For some reason, DM4F didn't accept the representation s -> M ((s -> s -> Type0) * a * s) thus the explicit effect definition for time being *) (* Instatiating the graded MST with int as a proof-of-concept *) let state = int new_effect GMST = GMST_h state let lift_div_gmst (a:Type) (wp:pure_wp a) (s0:state) (p:gmst_post state a s0) = wp (fun x -> p (fun s0 s1 -> s0 == s1) x s0) sub_effect DIV ~> GMST = lift_div_gmst (* Syntactic sugar packaging a relation index and MST WP *) let mst_wp (s:Type) (a:Type) (rel:relation s) = s0:s -> (a -> s1:s{rel s0 s1} -> Type0) -> Type0 unfold let (><) (#a:Type) (rel:relation state) (wp:mst_wp state a rel) : gmst_wp state a = fun s0 post -> wp s0 (post rel) (* Actions with specs defined in terms of (><) *) assume val gst_get: unit -> GMST state ((fun s0 s1 -> s0 == s1) >< (fun s0 post -> post s0 s0)) assume val gst_put: #rel:relation state -> s1:state -> GMST unit (rel >< (fun s0 post -> rel s0 s1 /\ post () s1)) assume val witnessed: predicate state -> Type0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: FStar.Preorder.predicate a -> rel: FStar.Preorder.preorder a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Preorder.predicate", "FStar.Preorder.preorder", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "Prims.logical" ]
[]
false
false
false
true
true
let stable (#a: Type) (p: predicate a) (rel: preorder a) =
forall x y. p x /\ rel x y ==> p y
false
Hacl.Curve25519_51.fst
Hacl.Curve25519_51.fsquare_times
val fsquare_times : Hacl.Meta.Curve25519.finv_fsquare_times_higher_t Prims.l_True
let fsquare_times = finv_fsquare_times_higher #M51 True C.fsqr
{ "file_name": "code/curve25519/Hacl.Curve25519_51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 19, "start_col": 0, "start_line": 19 }
module Hacl.Curve25519_51 friend Hacl.Meta.Curve25519 open Hacl.Meta.Curve25519 // The Hacl core. module C = Hacl.Impl.Curve25519.Field51 let g25519: g25519_t = Lib.Buffer.createL_global Spec.Curve25519.basepoint_list #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" let point_add_and_double = addanddouble_point_add_and_double_higher #M51 True C.fmul C.fsqr2 C.fmul1 C.fmul2 C.fsub C.fadd let point_double = addanddouble_point_double_higher #M51 True C.fmul2 C.fmul1 C.fsqr2 C.fsub C.fadd let montgomery_ladder =
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Curve25519.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Curve25519_51.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "C" }, { "abbrev": false, "full_module": "Hacl.Meta.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Meta.Curve25519.finv_fsquare_times_higher_t Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Curve25519.finv_fsquare_times_higher", "Hacl.Impl.Curve25519.Fields.Core.M51", "Prims.l_True", "Hacl.Impl.Curve25519.Field51.fsqr" ]
[]
false
false
false
true
false
let fsquare_times =
finv_fsquare_times_higher #M51 True C.fsqr
false
BinaryTrees.fst
BinaryTrees.count
val count (x: int) (t: tree) : Tot nat
val count (x: int) (t: tree) : Tot nat
let rec count (x:int) (t:tree) : Tot nat = match t with | Leaf -> 0 | Node n t1 t2 -> (if n = x then 1 else 0) + count x t1 + count x t2
{ "file_name": "examples/data_structures/BinaryTrees.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 70, "end_line": 165, "start_col": 0, "start_line": 162 }
(* 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 BinaryTrees type tree = | Leaf : tree | Node : root:int -> left:tree -> right:tree -> tree val size : tree -> Tot nat let rec size t = match t with | Leaf -> 0 | Node n t1 t2 -> 1 + size t1 + size t2 val map : f:(int -> Tot int) -> tree -> Tot tree let rec map f t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node (f n) (map f t1) (map f t2) val map_size : f:(int -> Tot int) -> t:tree -> Lemma (size (map f t) = size t) let rec map_size f t = match t with | Leaf -> () | Node n t1 t2 -> map_size f t1; map_size f t2 val find : p:(int -> Tot bool) -> tree -> Tot (option int) let rec find p t = match t with | Leaf -> None | Node n t1 t2 -> if p n then Some n else if Some? (find p t1) then find p t1 else find p t2 val find_some : p:(int -> Tot bool) -> t:tree -> Lemma (None? (find p t) \/ p (Some?.v (find p t))) let rec find_some p t = match t with | Leaf -> () | Node n t1 t2 -> find_some p t1; find_some p t2 let map_option f o = match o with | Some n -> Some (f n) | None -> None let compose f1 f2 x = f1 (f2 x) val map_find : p:(int -> Tot bool) -> f:(int -> Tot int) -> t:tree -> Lemma (find p (map f t) = map_option f (find (compose p f) t)) let rec map_find p f t = match t with | Leaf -> () | Node n t1 t2 -> map_find p f t1; map_find p f t2 val in_tree : int -> tree -> Tot bool let rec in_tree x t = match t with | Leaf -> false | Node n t1 t2 -> x = n || in_tree x t1 || in_tree x t2 val fold : (int -> 'a -> 'a -> 'a) -> 'a -> tree -> 'a let rec fold f a t = match t with | Leaf -> a | Node n t1 t2 -> f n (fold f a t1) (fold f a t2) val fold_map : fm:(int -> int) -> ff:(int -> int -> int -> int) -> a:int -> t:tree -> Lemma (fold ff a (map fm t) = fold (compose ff fm) a t) let rec fold_map fm ff a t = match t with | Leaf -> () | Node n t1 t2 -> fold_map fm ff a t1; fold_map fm ff a t2 val size_fold : t:tree -> Lemma (size t = fold #nat (fun _ s1 s2 -> 1 + s1 + s2) 0 t) let rec size_fold t = match t with | Leaf -> () | Node n t1 t2 -> size_fold t1; size_fold t2 val in_tree_fold : x:int -> t:tree -> Lemma (in_tree x t = fold (fun n b1 b2 -> x = n || b1 || b2) false t) let rec in_tree_fold x t = match t with | Leaf -> () | Node n t1 t2 -> in_tree_fold x t1; in_tree_fold x t2 val find_fold : f:(int -> Tot bool) -> tree -> Tot (option (x:int{f x})) let find_fold f = fold #(option (x:int{f x})) (fun n o1 o2 -> if f n then Some n else if Some? o1 then o1 else o2) None val revert : tree -> Tot tree let rec revert t = match t with | Leaf -> Leaf | Node n t1 t2 -> Node n (revert t2) (revert t1) (* simpler than for lists because revert is symmetric, while List.rev is not *) val revert_involutive : t:tree -> Lemma (revert (revert t) = t) let rec revert_involutive t = match t with | Leaf -> () | Node n t1 t2 -> revert_involutive t1; revert_involutive t2 (* again, much simpler than for lists *) val revert_injective : t1:tree -> t2:tree -> Lemma (requires (revert t1 = revert t2)) (ensures (t1 = t2)) let rec revert_injective t1 t2 = match t1, t2 with | Leaf, Leaf -> () | Node n1 t11 t12, Node n2 t21 t22 -> revert_injective t11 t21; revert_injective t12 t22 val revert_fold : t:tree -> Lemma (revert t = fold (fun n t1 t2 -> Node n t2 t1) Leaf t) let rec revert_fold t = match t with | Leaf -> () | Node n t1 t2 -> revert_fold t1; revert_fold t2 (* open FStar.List *) (* val list_of : tree -> Tot (list int) *) (* let list_of = fold (fun n t1 t2 -> t1 @ [n] @ t2) [] *) val remove_root : t:tree{Node? t} -> Tot tree let rec remove_root t = match t with | Node n t1 t2 -> if Leaf? t1 then t2 else Node (Node?.root t1) (remove_root t1) t2 val add_root : x:int -> t:tree -> Tot (t':tree{Node? t'}) (decreases t) let rec add_root x t = match t with | Leaf -> Node x Leaf Leaf | Node n t1 t2 -> Node x (add_root n t1) t2 (* remove and add implemented this way round-trip; TODO: does the converse hold? *) val remove_add_root : x:int -> t:tree -> Lemma (requires True) (ensures (remove_root (add_root x t) = t)) (decreases t) let rec remove_add_root x t = match t with | Leaf -> () | Node n t1 t2 -> remove_add_root x t1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "BinaryTrees.fst" }
[ { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> t: BinaryTrees.tree -> Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "BinaryTrees.tree", "Prims.op_Addition", "Prims.op_Equality", "Prims.bool", "BinaryTrees.count", "Prims.nat" ]
[ "recursion" ]
false
false
false
true
false
let rec count (x: int) (t: tree) : Tot nat =
match t with | Leaf -> 0 | Node n t1 t2 -> (if n = x then 1 else 0) + count x t1 + count x t2
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.fsub5
val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)}
val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)}
let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 65, "start_col": 0, "start_line": 52 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f1: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f2 (1, 2, 1, 1, 1)} -> out: Hacl.Spec.Curve25519.Field51.Definition.felem5 { Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 out (9, 10, 9, 9, 9) /\ Hacl.Spec.Curve25519.Field51.Definition.feval out == Spec.Curve25519.fsub (Hacl.Spec.Curve25519.Field51.Definition.feval f1) (Hacl.Spec.Curve25519.Field51.Definition.feval f2) }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.uint64", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_mod_sub_distr", "Prims.op_Modulus", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "Spec.Curve25519.prime", "FStar.Math.Lemmas.lemma_mod_plus_distr_l", "Prims.op_Minus", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Subtraction_Bang", "Prims.l_and", "Prims.eq2", "Spec.Curve25519.elem", "Hacl.Spec.Curve25519.Field51.Definition.feval", "Spec.Curve25519.fsub", "Hacl.Spec.Curve25519.Field51.fadd_zero" ]
[]
false
false
false
false
false
let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) =
let t0, t1, t2, t3, t4 = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.fadd5
val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)}
val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)}
let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 30, "start_col": 0, "start_line": 19 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f1: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f2 (1, 2, 1, 1, 1)} -> out: Hacl.Spec.Curve25519.Field51.Definition.felem5 { Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 out (2, 4, 2, 2, 2) /\ Hacl.Spec.Curve25519.Field51.Definition.feval out == Spec.Curve25519.fadd (Hacl.Spec.Curve25519.Field51.Definition.feval f1) (Hacl.Spec.Curve25519.Field51.Definition.feval f2) }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.uint64", "Prims.unit", "FStar.Math.Lemmas.lemma_mod_plus_distr_r", "Prims.op_Modulus", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "Spec.Curve25519.prime", "FStar.Math.Lemmas.lemma_mod_plus_distr_l", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Plus_Bang", "Prims.l_and", "Prims.eq2", "Spec.Curve25519.elem", "Hacl.Spec.Curve25519.Field51.Definition.feval", "Spec.Curve25519.fadd" ]
[]
false
false
false
false
false
let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) =
let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.fmul5
val fmul5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f1) (feval f2)}
val fmul5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f1) (feval f2)}
let fmul5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (tmp0, tmp1, tmp2, tmp3, tmp4) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp0, tmp1, tmp2, tmp3, tmp4) in carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 295, "start_col": 0, "start_line": 291 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul)) let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1) #push-options "--ifuel 1" val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1)) let lemma_mul_inv f cin = assert_norm (pow51 = pow2 51) #pop-options #push-options "--z3rlimit 100" inline_for_extraction noextract val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == feval_wide inp) let carry_wide5 (i0, i1, i2, i3, i4) = assert_norm (6579 < pow2 13); assert_norm (pow2 13 < max51); let tmp0, c0 = carry51_wide #6579 i0 (u64 0) in let tmp1, c1 = carry51_wide #4797 i1 c0 in let tmp2, c2 = carry51_wide #3340 i2 c1 in let tmp3, c3 = carry51_wide #1881 i3 c2 in let tmp4, c4 = carry51_wide #423 i4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; (tmp0', tmp1', tmp2, tmp3, tmp4) #pop-options inline_for_extraction noextract val fmul5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f1: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f2 (9, 10, 9, 9, 9)} -> out: Hacl.Spec.Curve25519.Field51.Definition.felem5 { Hacl.Spec.Curve25519.Field51.mul_inv_t out /\ Hacl.Spec.Curve25519.Field51.Definition.feval out == Spec.Curve25519.fmul (Hacl.Spec.Curve25519.Field51.Definition.feval f1) (Hacl.Spec.Curve25519.Field51.Definition.feval f2) }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.uint64", "Lib.IntTypes.uint128", "Hacl.Spec.Curve25519.Field51.carry_wide5", "Prims.l_and", "Hacl.Spec.Curve25519.Field51.mul_inv_t", "Prims.eq2", "Spec.Curve25519.elem", "Hacl.Spec.Curve25519.Field51.Definition.feval", "Spec.Curve25519.fmul", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide5", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits5", "Hacl.Spec.Curve25519.Field51.Definition.feval_wide", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.Curve25519.Field51.mul_felem5", "Hacl.Spec.Curve25519.Field51.precomp_r19" ]
[]
false
false
false
false
false
let fmul5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) =
let tmp0, tmp1, tmp2, tmp3, tmp4 = precomp_r19 (f20, f21, f22, f23, f24) in let tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4 = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp0, tmp1, tmp2, tmp3, tmp4) in carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)
false
Hacl.Curve25519_51.fst
Hacl.Curve25519_51.point_add_and_double
val point_add_and_double : Hacl.Meta.Curve25519.addanddouble_point_add_and_double_higher_t Prims.l_True
let point_add_and_double = addanddouble_point_add_and_double_higher #M51 True C.fmul C.fsqr2 C.fmul1 C.fmul2 C.fsub C.fadd
{ "file_name": "code/curve25519/Hacl.Curve25519_51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 97, "end_line": 14, "start_col": 0, "start_line": 13 }
module Hacl.Curve25519_51 friend Hacl.Meta.Curve25519 open Hacl.Meta.Curve25519 // The Hacl core. module C = Hacl.Impl.Curve25519.Field51 let g25519: g25519_t = Lib.Buffer.createL_global Spec.Curve25519.basepoint_list
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Curve25519.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Curve25519_51.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "C" }, { "abbrev": false, "full_module": "Hacl.Meta.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Meta.Curve25519.addanddouble_point_add_and_double_higher_t Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Curve25519.addanddouble_point_add_and_double_higher", "Hacl.Impl.Curve25519.Fields.Core.M51", "Prims.l_True", "Hacl.Impl.Curve25519.Field51.fmul", "Hacl.Impl.Curve25519.Field51.fsqr2", "Hacl.Impl.Curve25519.Field51.fmul1", "Hacl.Impl.Curve25519.Field51.fmul2", "Hacl.Impl.Curve25519.Field51.fsub", "Hacl.Impl.Curve25519.Field51.fadd" ]
[]
false
false
false
true
false
let point_add_and_double =
addanddouble_point_add_and_double_higher #M51 True C.fmul C.fsqr2 C.fmul1 C.fmul2 C.fsub C.fadd
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.smul_felem5
val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2}
val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2}
let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 126, "start_col": 0, "start_line": 111 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
u1: Lib.IntTypes.uint64{Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 u1 m1} -> f2: Hacl.Spec.Curve25519.Field51.Definition.felem5 { Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f2 m2 /\ m1 *^ m2 <=* Hacl.Spec.Curve25519.Field51.Definition.s128x5 67108864 } -> out: Hacl.Spec.Curve25519.Field51.Definition.felem_wide5 { Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits5 out (m1 *^ m2) /\ Hacl.Spec.Curve25519.Field51.Definition.wide_as_nat5 out == Lib.IntTypes.uint_v u1 * Hacl.Spec.Curve25519.Field51.Definition.as_nat5 f2 }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.scale64", "Hacl.Spec.Curve25519.Field51.Definition.scale64_5", "Lib.IntTypes.uint64", "Prims.b2t", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits1", "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Prims.l_and", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "Hacl.Spec.Curve25519.Field51.Definition.op_Less_Equals_Star", "Hacl.Spec.Curve25519.Field51.Definition.op_Star_Hat", "Hacl.Spec.Curve25519.Field51.Definition.s128x5", "Prims.nat", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_smul_felem5", "FStar.Pervasives.Native.Mktuple5", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.int_t", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "Lib.IntTypes.uint128", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Prims.op_Multiply", "Lib.IntTypes.U64", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits1", "Hacl.Spec.Curve25519.Field51.mul_wide64", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide5", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits5", "Hacl.Spec.Curve25519.Field51.Definition.wide_as_nat5", "FStar.Mul.op_Star", "Lib.IntTypes.uint_v", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5" ]
[]
false
false
false
false
false
let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) =
let m20, m21, m22, m23, m24 = m2 in [@@ inline_let ]let o0 = mul_wide64 #m1 #m20 u1 f20 in [@@ inline_let ]let o1 = mul_wide64 #m1 #m21 u1 f21 in [@@ inline_let ]let o2 = mul_wide64 #m1 #m22 u1 f22 in [@@ inline_let ]let o3 = mul_wide64 #m1 #m23 u1 f23 in [@@ inline_let ]let o4 = mul_wide64 #m1 #m24 u1 f24 in [@@ inline_let ]let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out
false
Hacl.Curve25519_51.fst
Hacl.Curve25519_51.scalarmult
val scalarmult: scalarmult_st M51 True
val scalarmult: scalarmult_st M51 True
let scalarmult = generic_scalarmult_higher #M51 True encode_point montgomery_ladder decode_point
{ "file_name": "code/curve25519/Hacl.Curve25519_51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 96, "end_line": 22, "start_col": 0, "start_line": 22 }
module Hacl.Curve25519_51 friend Hacl.Meta.Curve25519 open Hacl.Meta.Curve25519 // The Hacl core. module C = Hacl.Impl.Curve25519.Field51 let g25519: g25519_t = Lib.Buffer.createL_global Spec.Curve25519.basepoint_list #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" let point_add_and_double = addanddouble_point_add_and_double_higher #M51 True C.fmul C.fsqr2 C.fmul1 C.fmul2 C.fsub C.fadd let point_double = addanddouble_point_double_higher #M51 True C.fmul2 C.fmul1 C.fsqr2 C.fsub C.fadd let montgomery_ladder = generic_montgomery_ladder_higher #M51 True point_double C.cswap2 point_add_and_double let fsquare_times = finv_fsquare_times_higher #M51 True C.fsqr let finv = finv_finv_higher #M51 True C.fmul fsquare_times
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Curve25519.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Curve25519_51.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "C" }, { "abbrev": false, "full_module": "Hacl.Meta.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Curve25519.Generic.scalarmult_st Hacl.Impl.Curve25519.Fields.Core.M51 Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Curve25519.generic_scalarmult_higher", "Hacl.Impl.Curve25519.Fields.Core.M51", "Prims.l_True", "Hacl.Curve25519_51.encode_point", "Hacl.Curve25519_51.montgomery_ladder", "Hacl.Impl.Curve25519.Generic.decode_point" ]
[]
false
false
false
true
false
let scalarmult =
generic_scalarmult_higher #M51 True encode_point montgomery_ladder decode_point
false
GMST.fst
GMST.preorder_app'
val preorder_app' (#a #b: Type) (#rel: preorder state) (#wp1: mst_wp state a rel) (#wp2: (a -> mst_wp state b rel)) (f: (unit -> GMST a (rel >< wp1))) (g: (x: a -> GMST b (rel >< wp2 x))) : GMST b (rel @ rel >< (fun s0 p -> wp1 s0 (fun x s1 -> wp2 x s1 p)))
val preorder_app' (#a #b: Type) (#rel: preorder state) (#wp1: mst_wp state a rel) (#wp2: (a -> mst_wp state b rel)) (f: (unit -> GMST a (rel >< wp1))) (g: (x: a -> GMST b (rel >< wp2 x))) : GMST b (rel @ rel >< (fun s0 p -> wp1 s0 (fun x s1 -> wp2 x s1 p)))
let preorder_app' (#a:Type) (#b:Type) (#rel:preorder state) (#wp1:mst_wp state a rel) (#wp2:a -> mst_wp state b rel) (f:unit -> GMST a (rel >< wp1)) (g:(x:a -> GMST b (rel >< wp2 x))) : GMST b (rel @ rel >< (fun s0 p -> wp1 s0 (fun x s1 -> wp2 x s1 p))) = g (f ())
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 170, "start_col": 0, "start_line": 163 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0 unfold let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1))) unfold let gmst_if_then_else (s:Type) (a:Type) (p:Type) (wp_then:gmst_wp s a) (wp_else:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = l_ITE p (wp_then s0 post) (wp_else s0 post) unfold let gmst_ite (s:Type) (a:Type) (wp:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = wp s0 post unfold let gmst_stronger (s:Type) (a:Type) (wp1:gmst_wp s a) (wp2:gmst_wp s a) = forall s0 p. wp1 s0 p ==> wp2 s0 p unfold let gmst_close (s:Type) (a:Type) (b:Type) (wp:(b -> GTot (gmst_wp s a))) (s0:s) (p:gmst_post s a s0) = forall x. wp x s0 p unfold let gmst_trivial (s:Type) (a:Type) (wp:gmst_wp s a) = forall s0. wp s0 (fun _ _ _ -> True) new_effect { GMST_h (s:Type) : result:Type -> wp:gmst_wp s result -> Effect with //repr = s0:s -> M (rel:relation a & a * s1:s{rel s0 s1}) return_wp = gmst_return s ; bind_wp = gmst_bind s ; if_then_else = gmst_if_then_else s ; ite_wp = gmst_ite s ; stronger = gmst_stronger s ; close_wp = gmst_close s ; trivial = gmst_trivial s } (* DA: For some reason, DM4F didn't accept the representation s -> M ((s -> s -> Type0) * a * s) thus the explicit effect definition for time being *) (* Instatiating the graded MST with int as a proof-of-concept *) let state = int new_effect GMST = GMST_h state let lift_div_gmst (a:Type) (wp:pure_wp a) (s0:state) (p:gmst_post state a s0) = wp (fun x -> p (fun s0 s1 -> s0 == s1) x s0) sub_effect DIV ~> GMST = lift_div_gmst (* Syntactic sugar packaging a relation index and MST WP *) let mst_wp (s:Type) (a:Type) (rel:relation s) = s0:s -> (a -> s1:s{rel s0 s1} -> Type0) -> Type0 unfold let (><) (#a:Type) (rel:relation state) (wp:mst_wp state a rel) : gmst_wp state a = fun s0 post -> wp s0 (post rel) (* Actions with specs defined in terms of (><) *) assume val gst_get: unit -> GMST state ((fun s0 s1 -> s0 == s1) >< (fun s0 post -> post s0 s0)) assume val gst_put: #rel:relation state -> s1:state -> GMST unit (rel >< (fun s0 post -> rel s0 s1 /\ post () s1)) assume val witnessed: predicate state -> Type0 let stable (#a:Type) (p:predicate a) (rel:preorder a) = forall x y . p x /\ rel x y ==> p y assume val gst_witness: #rel:preorder state -> p:predicate state -> GMST unit (rel >< (fun s0 post -> stable p rel /\ p s0 /\ (witnessed p ==> post () s0))) assume val gst_recall: #rel:preorder state -> p:predicate state -> GMST unit (rel >< (fun s0 post -> stable p rel /\ witnessed p /\ (p s0 ==> post () s0))) (* Sequential composition results in composition of relations *) let app (#a:Type) (#b:Type) (#rel1:relation state) (#rel2:relation state) (#wp1:mst_wp state a rel1) (#wp2:a -> mst_wp state b rel2) (f:unit -> GMST a (rel1 >< wp1)) (g:(x:a -> GMST b (rel2 >< wp2 x))) : GMST b ((rel2 @ rel1) >< (fun s0 p -> wp1 s0 (fun x s1 -> wp2 x s1 p))) = g (f ()) (* In case the relations are the same, and moreover preorders, we ought to get the usual MST typing for app However, currently we don't get this result because of the lack of proper prop (one that would also soundly support propositional extensionality). *) (* Temporarily assuming propositional extensionality for rel's. As preorder is defined using Type0 not the (upcoming) prop, then this can actually lead to an inconsistency, e.g., see examples/paradoxes/PropositionalExtensionalityInconsistent.fst *) let lemma_preorder_comp_equiv (a:Type) (rel:preorder a) : Lemma (forall x y . (rel @ rel) x y <==> rel x y) = () let lemma_preorder_comp_equal (a:Type) (rel:preorder a) : Lemma (rel @ rel == rel) [SMTPat (rel @ rel)] = admit () (* The inferred type of app *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: Prims.unit -> GMST.GMST a) -> g: (x: a -> GMST.GMST b) -> GMST.GMST b
GMST.GMST
[]
[]
[ "FStar.Preorder.preorder", "GMST.state", "GMST.mst_wp", "Prims.unit", "GMST.op_Greater_Less", "GMST.op_At" ]
[]
false
true
false
false
false
let preorder_app' (#a #b: Type) (#rel: preorder state) (#wp1: mst_wp state a rel) (#wp2: (a -> mst_wp state b rel)) (f: (unit -> GMST a (rel >< wp1))) (g: (x: a -> GMST b (rel >< wp2 x))) : GMST b (rel @ rel >< (fun s0 p -> wp1 s0 (fun x s1 -> wp2 x s1 p))) =
g (f ())
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.mul_wide64
val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)}
val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)}
let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 100, "start_col": 0, "start_line": 89 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)}
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.uint64{Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 x m1} -> y: Lib.IntTypes.uint64 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z: Lib.IntTypes.uint128 { Lib.IntTypes.uint_v z == Lib.IntTypes.uint_v x * Lib.IntTypes.uint_v y /\ Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits1 z (m1 * m2) }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.scale64", "Lib.IntTypes.uint64", "Prims.b2t", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits1", "Prims.l_and", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.mul64_wide", "Prims.unit", "Prims._assert", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.Curve25519.Field51.Definition.max51", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.swap_mul", "FStar.Math.Lemmas.lemma_mult_le_right", "FStar.Math.Lemmas.lemma_mult_le_left", "Lib.IntTypes.uint128", "Prims.eq2", "Prims.int", "Lib.IntTypes.uint_v", "Lib.IntTypes.U128", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits1" ]
[]
false
false
false
false
false
let mul_wide64 #m1 #m2 x y =
let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); paren_mul_right (m1 * max51) m2 max51; paren_mul_right m1 max51 m2; swap_mul max51 m2; paren_mul_right m1 m2 max51; paren_mul_right (m1 * m2) max51 max51; assert (v x * v y <= ((m1 * max51) * m2) * max51); assert (v x * v y <= ((m1 * m2) * max51) * max51); mul64_wide x y
false
GMST.fst
GMST.transport_gmst_rel
val transport_gmst_rel (#a: Type) (#rel1: relation state) (#rel2: relation state {rel1 == rel2}) (#wp: mst_wp state a rel1) (f: (unit -> GMST a (rel1 >< wp))) : GMST a (rel2 >< wp)
val transport_gmst_rel (#a: Type) (#rel1: relation state) (#rel2: relation state {rel1 == rel2}) (#wp: mst_wp state a rel1) (f: (unit -> GMST a (rel1 >< wp))) : GMST a (rel2 >< wp)
let transport_gmst_rel (#a:Type) (#rel1:relation state) (#rel2:relation state{rel1 == rel2}) (#wp:mst_wp state a rel1) (f:unit -> GMST a (rel1 >< wp)) : GMST a (rel2 >< wp) = f ()
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 8, "end_line": 178, "start_col": 0, "start_line": 175 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0 unfold let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1))) unfold let gmst_if_then_else (s:Type) (a:Type) (p:Type) (wp_then:gmst_wp s a) (wp_else:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = l_ITE p (wp_then s0 post) (wp_else s0 post) unfold let gmst_ite (s:Type) (a:Type) (wp:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = wp s0 post unfold let gmst_stronger (s:Type) (a:Type) (wp1:gmst_wp s a) (wp2:gmst_wp s a) = forall s0 p. wp1 s0 p ==> wp2 s0 p unfold let gmst_close (s:Type) (a:Type) (b:Type) (wp:(b -> GTot (gmst_wp s a))) (s0:s) (p:gmst_post s a s0) = forall x. wp x s0 p unfold let gmst_trivial (s:Type) (a:Type) (wp:gmst_wp s a) = forall s0. wp s0 (fun _ _ _ -> True) new_effect { GMST_h (s:Type) : result:Type -> wp:gmst_wp s result -> Effect with //repr = s0:s -> M (rel:relation a & a * s1:s{rel s0 s1}) return_wp = gmst_return s ; bind_wp = gmst_bind s ; if_then_else = gmst_if_then_else s ; ite_wp = gmst_ite s ; stronger = gmst_stronger s ; close_wp = gmst_close s ; trivial = gmst_trivial s } (* DA: For some reason, DM4F didn't accept the representation s -> M ((s -> s -> Type0) * a * s) thus the explicit effect definition for time being *) (* Instatiating the graded MST with int as a proof-of-concept *) let state = int new_effect GMST = GMST_h state let lift_div_gmst (a:Type) (wp:pure_wp a) (s0:state) (p:gmst_post state a s0) = wp (fun x -> p (fun s0 s1 -> s0 == s1) x s0) sub_effect DIV ~> GMST = lift_div_gmst (* Syntactic sugar packaging a relation index and MST WP *) let mst_wp (s:Type) (a:Type) (rel:relation s) = s0:s -> (a -> s1:s{rel s0 s1} -> Type0) -> Type0 unfold let (><) (#a:Type) (rel:relation state) (wp:mst_wp state a rel) : gmst_wp state a = fun s0 post -> wp s0 (post rel) (* Actions with specs defined in terms of (><) *) assume val gst_get: unit -> GMST state ((fun s0 s1 -> s0 == s1) >< (fun s0 post -> post s0 s0)) assume val gst_put: #rel:relation state -> s1:state -> GMST unit (rel >< (fun s0 post -> rel s0 s1 /\ post () s1)) assume val witnessed: predicate state -> Type0 let stable (#a:Type) (p:predicate a) (rel:preorder a) = forall x y . p x /\ rel x y ==> p y assume val gst_witness: #rel:preorder state -> p:predicate state -> GMST unit (rel >< (fun s0 post -> stable p rel /\ p s0 /\ (witnessed p ==> post () s0))) assume val gst_recall: #rel:preorder state -> p:predicate state -> GMST unit (rel >< (fun s0 post -> stable p rel /\ witnessed p /\ (p s0 ==> post () s0))) (* Sequential composition results in composition of relations *) let app (#a:Type) (#b:Type) (#rel1:relation state) (#rel2:relation state) (#wp1:mst_wp state a rel1) (#wp2:a -> mst_wp state b rel2) (f:unit -> GMST a (rel1 >< wp1)) (g:(x:a -> GMST b (rel2 >< wp2 x))) : GMST b ((rel2 @ rel1) >< (fun s0 p -> wp1 s0 (fun x s1 -> wp2 x s1 p))) = g (f ()) (* In case the relations are the same, and moreover preorders, we ought to get the usual MST typing for app However, currently we don't get this result because of the lack of proper prop (one that would also soundly support propositional extensionality). *) (* Temporarily assuming propositional extensionality for rel's. As preorder is defined using Type0 not the (upcoming) prop, then this can actually lead to an inconsistency, e.g., see examples/paradoxes/PropositionalExtensionalityInconsistent.fst *) let lemma_preorder_comp_equiv (a:Type) (rel:preorder a) : Lemma (forall x y . (rel @ rel) x y <==> rel x y) = () let lemma_preorder_comp_equal (a:Type) (rel:preorder a) : Lemma (rel @ rel == rel) [SMTPat (rel @ rel)] = admit () (* The inferred type of app *) let preorder_app' (#a:Type) (#b:Type) (#rel:preorder state) (#wp1:mst_wp state a rel) (#wp2:a -> mst_wp state b rel) (f:unit -> GMST a (rel >< wp1)) (g:(x:a -> GMST b (rel >< wp2 x))) : GMST b (rel @ rel >< (fun s0 p -> wp1 s0 (fun x s1 -> wp2 x s1 p))) = g (f ()) (* Deriving the usual typing of MST for preorders *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: Prims.unit -> GMST.GMST a) -> GMST.GMST a
GMST.GMST
[]
[]
[ "FStar.Preorder.relation", "GMST.state", "Prims.eq2", "GMST.mst_wp", "Prims.unit", "GMST.op_Greater_Less" ]
[]
false
true
false
false
false
let transport_gmst_rel (#a: Type) (#rel1: relation state) (#rel2: relation state {rel1 == rel2}) (#wp: mst_wp state a rel1) (f: (unit -> GMST a (rel1 >< wp))) : GMST a (rel2 >< wp) =
f ()
false
GMST.fst
GMST.app
val app (#a #b: Type) (#rel1 #rel2: relation state) (#wp1: mst_wp state a rel1) (#wp2: (a -> mst_wp state b rel2)) (f: (unit -> GMST a (rel1 >< wp1))) (g: (x: a -> GMST b (rel2 >< wp2 x))) : GMST b ((rel2 @ rel1) >< (fun s0 p -> wp1 s0 (fun x s1 -> wp2 x s1 p)))
val app (#a #b: Type) (#rel1 #rel2: relation state) (#wp1: mst_wp state a rel1) (#wp2: (a -> mst_wp state b rel2)) (f: (unit -> GMST a (rel1 >< wp1))) (g: (x: a -> GMST b (rel2 >< wp2 x))) : GMST b ((rel2 @ rel1) >< (fun s0 p -> wp1 s0 (fun x s1 -> wp2 x s1 p)))
let app (#a:Type) (#b:Type) (#rel1:relation state) (#rel2:relation state) (#wp1:mst_wp state a rel1) (#wp2:a -> mst_wp state b rel2) (f:unit -> GMST a (rel1 >< wp1)) (g:(x:a -> GMST b (rel2 >< wp2 x))) : GMST b ((rel2 @ rel1) >< (fun s0 p -> wp1 s0 (fun x s1 -> wp2 x s1 p))) = g (f ())
{ "file_name": "examples/indexed_effects/GMST.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 132, "start_col": 0, "start_line": 124 }
(* 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 GMST (* A proof-of-concept example of a Graded Dijkstra Monad---the MST monad graded by the relation/preorder on states In other words, this is a demonstration how using writer monad like structure in the underlying representation of effects allows one to use the resulting WPs to encode indexed effects in F* (as long as the indexes form a magma) *) open FStar.Preorder (* The graded MST effect *) let gmst_post (s:Type) (a:Type) (s0:s) = rel:relation s -> a -> s1:s{rel s0 s1} -> GTot Type0 let gmst_wp (s:Type) (a:Type) = s0:s -> gmst_post s a s0 -> GTot Type0 let (@) (#a:Type) (rel1:relation a) (rel0:relation a) : relation a = fun x z -> exists y . rel0 x y /\ rel1 y z unfold let gmst_return (s:Type) (a:Type) (x:a) (s0:s) (p:gmst_post s a s0) = forall v. v == x ==> p (fun s0 s1 -> s0 == s1) v s0 unfold let gmst_bind (s:Type) (a:Type) (b:Type) (wp1:gmst_wp s a) (wp2: (a -> GTot (gmst_wp s b))) (s0:s) (p:gmst_post s b s0) = wp1 s0 (fun rel1 x s1 -> wp2 x s1 (fun rel2 -> p (rel2 @ rel1))) unfold let gmst_if_then_else (s:Type) (a:Type) (p:Type) (wp_then:gmst_wp s a) (wp_else:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = l_ITE p (wp_then s0 post) (wp_else s0 post) unfold let gmst_ite (s:Type) (a:Type) (wp:gmst_wp s a) (s0:s) (post:gmst_post s a s0) = wp s0 post unfold let gmst_stronger (s:Type) (a:Type) (wp1:gmst_wp s a) (wp2:gmst_wp s a) = forall s0 p. wp1 s0 p ==> wp2 s0 p unfold let gmst_close (s:Type) (a:Type) (b:Type) (wp:(b -> GTot (gmst_wp s a))) (s0:s) (p:gmst_post s a s0) = forall x. wp x s0 p unfold let gmst_trivial (s:Type) (a:Type) (wp:gmst_wp s a) = forall s0. wp s0 (fun _ _ _ -> True) new_effect { GMST_h (s:Type) : result:Type -> wp:gmst_wp s result -> Effect with //repr = s0:s -> M (rel:relation a & a * s1:s{rel s0 s1}) return_wp = gmst_return s ; bind_wp = gmst_bind s ; if_then_else = gmst_if_then_else s ; ite_wp = gmst_ite s ; stronger = gmst_stronger s ; close_wp = gmst_close s ; trivial = gmst_trivial s } (* DA: For some reason, DM4F didn't accept the representation s -> M ((s -> s -> Type0) * a * s) thus the explicit effect definition for time being *) (* Instatiating the graded MST with int as a proof-of-concept *) let state = int new_effect GMST = GMST_h state let lift_div_gmst (a:Type) (wp:pure_wp a) (s0:state) (p:gmst_post state a s0) = wp (fun x -> p (fun s0 s1 -> s0 == s1) x s0) sub_effect DIV ~> GMST = lift_div_gmst (* Syntactic sugar packaging a relation index and MST WP *) let mst_wp (s:Type) (a:Type) (rel:relation s) = s0:s -> (a -> s1:s{rel s0 s1} -> Type0) -> Type0 unfold let (><) (#a:Type) (rel:relation state) (wp:mst_wp state a rel) : gmst_wp state a = fun s0 post -> wp s0 (post rel) (* Actions with specs defined in terms of (><) *) assume val gst_get: unit -> GMST state ((fun s0 s1 -> s0 == s1) >< (fun s0 post -> post s0 s0)) assume val gst_put: #rel:relation state -> s1:state -> GMST unit (rel >< (fun s0 post -> rel s0 s1 /\ post () s1)) assume val witnessed: predicate state -> Type0 let stable (#a:Type) (p:predicate a) (rel:preorder a) = forall x y . p x /\ rel x y ==> p y assume val gst_witness: #rel:preorder state -> p:predicate state -> GMST unit (rel >< (fun s0 post -> stable p rel /\ p s0 /\ (witnessed p ==> post () s0))) assume val gst_recall: #rel:preorder state -> p:predicate state -> GMST unit (rel >< (fun s0 post -> stable p rel /\ witnessed p /\ (p s0 ==> post () s0))) (* Sequential composition results in composition of relations *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "GMST.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: Prims.unit -> GMST.GMST a) -> g: (x: a -> GMST.GMST b) -> GMST.GMST b
GMST.GMST
[]
[]
[ "FStar.Preorder.relation", "GMST.state", "GMST.mst_wp", "Prims.unit", "GMST.op_Greater_Less", "GMST.op_At" ]
[]
false
true
false
false
false
let app (#a #b: Type) (#rel1 #rel2: relation state) (#wp1: mst_wp state a rel1) (#wp2: (a -> mst_wp state b rel2)) (f: (unit -> GMST a (rel1 >< wp1))) (g: (x: a -> GMST b (rel2 >< wp2 x))) : GMST b ((rel2 @ rel1) >< (fun s0 p -> wp1 s0 (fun x s1 -> wp2 x s1 p))) =
g (f ())
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.carry51
val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13)
val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13)
let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 220, "start_col": 0, "start_line": 217 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Lib.IntTypes.uint64 -> cin: Lib.IntTypes.uint64 -> Prims.Pure (Lib.IntTypes.uint64 * Lib.IntTypes.uint64)
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple2", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.Curve25519.Field51.Definition.mask51", "Lib.IntTypes.op_Greater_Greater_Dot", "FStar.UInt32.__uint_to_t", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_carry51", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Plus_Bang", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let carry51 l cin =
let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul)
false
FStar.BigOps.fsti
FStar.BigOps.normal
val normal (#a: Type) (x: a) : a
val normal (#a: Type) (x: a) : a
let normal (#a: Type) (x: a) : a = FStar.Pervasives.norm [ iota; zeta; delta_only [`%L.fold_right_gtot; `%L.map_gtot]; delta_attr [`%__reduce__]; primops; simplify ] x
{ "file_name": "ulib/FStar.BigOps.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 57, "start_col": 0, "start_line": 48 }
(* 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 FStar.BigOps /// This library provides propositional connectives over finite sets /// expressed as lists, aka "big operators", in analogy with LaTeX /// usage for \bigand, \bigor, etc. /// /// The library is designed with a dual usage in mind: /// /// 1. Normalization: When applied to a list literal, we want /// {[big_and f [a;b;c]]} to implicilty reduce to [f a /\ f b /\ f c] /// /// 2. Symbolic manipulation: We provide lemmas of the form /// /// [big_and f l <==> forall x. L.memP x l ==> f x] /// /// In this latter form, partially computing [big_and] as a fold over /// a list is cumbersome for proof. So, we provide variants [big_and'] /// etc., that do not reduce implicitly. module L = FStar.List.Tot (** We control reduction using the [delta_attr] feature of the normalizer. See FStar.Pervasives for how that works. Every term that is to be reduced is with the [__reduce__] attribute *) let __reduce__ = () (** We wrap [norm] with a module-specific custom usage, triggering specific reduction steps *) [@@ __reduce__]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.BigOps.fsti" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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
x: a -> a
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "FStar.Pervasives.delta_only", "Prims.string", "Prims.Nil", "FStar.Pervasives.delta_attr", "FStar.Pervasives.primops", "FStar.Pervasives.simplify" ]
[]
false
false
false
true
false
let normal (#a: Type) (x: a) : a =
FStar.Pervasives.norm [ iota; zeta; delta_only [`%L.fold_right_gtot; `%L.map_gtot]; delta_attr [`%__reduce__]; primops; simplify ] x
false
Hacl.Curve25519_51.fst
Hacl.Curve25519_51.ecdh
val ecdh: ecdh_st M51 True
val ecdh: ecdh_st M51 True
let ecdh = generic_ecdh_higher #M51 True scalarmult
{ "file_name": "code/curve25519/Hacl.Curve25519_51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 51, "end_line": 24, "start_col": 0, "start_line": 24 }
module Hacl.Curve25519_51 friend Hacl.Meta.Curve25519 open Hacl.Meta.Curve25519 // The Hacl core. module C = Hacl.Impl.Curve25519.Field51 let g25519: g25519_t = Lib.Buffer.createL_global Spec.Curve25519.basepoint_list #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" let point_add_and_double = addanddouble_point_add_and_double_higher #M51 True C.fmul C.fsqr2 C.fmul1 C.fmul2 C.fsub C.fadd let point_double = addanddouble_point_double_higher #M51 True C.fmul2 C.fmul1 C.fsqr2 C.fsub C.fadd let montgomery_ladder = generic_montgomery_ladder_higher #M51 True point_double C.cswap2 point_add_and_double let fsquare_times = finv_fsquare_times_higher #M51 True C.fsqr let finv = finv_finv_higher #M51 True C.fmul fsquare_times let encode_point = generic_encode_point_higher #M51 True C.store_felem C.fmul finv let scalarmult = generic_scalarmult_higher #M51 True encode_point montgomery_ladder decode_point
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Curve25519.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Curve25519_51.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "C" }, { "abbrev": false, "full_module": "Hacl.Meta.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Curve25519.Generic.ecdh_st Hacl.Impl.Curve25519.Fields.Core.M51 Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Curve25519.generic_ecdh_higher", "Hacl.Impl.Curve25519.Fields.Core.M51", "Prims.l_True", "Hacl.Curve25519_51.scalarmult" ]
[]
false
false
false
true
false
let ecdh =
generic_ecdh_higher #M51 True scalarmult
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.mul_add_wide128
val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)}
val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)}
let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 138, "start_col": 0, "start_line": 137 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864}
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.IntTypes.uint64{Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 x m1} -> y: Lib.IntTypes.uint64{Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 y m2} -> z: Lib.IntTypes.uint128 {Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r: Lib.IntTypes.uint128 { Lib.IntTypes.uint_v r == Lib.IntTypes.uint_v z + Lib.IntTypes.uint_v x * Lib.IntTypes.uint_v y /\ Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits1 r (m3 + m1 * m2) }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.scale64", "Hacl.Spec.Curve25519.Field51.Definition.scale128", "Lib.IntTypes.uint64", "Prims.b2t", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits1", "Lib.IntTypes.uint128", "Prims.l_and", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits1", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.Mul.op_Star", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "Hacl.Spec.Curve25519.Field51.mul_wide64", "Prims.eq2", "Prims.int", "Lib.IntTypes.uint_v", "Lib.IntTypes.U64" ]
[]
false
false
false
false
false
let mul_add_wide128 #m1 #m2 #m3 x y z =
z +! mul_wide64 #m1 #m2 x y
false
FStar.BigOps.fsti
FStar.BigOps.map_op'
val map_op' (#a #b #c: _) (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (l: list a) (z: c) : GTot c
val map_op' (#a #b #c: _) (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (l: list a) (z: c) : GTot c
let map_op' #a #b #c (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (l: list a) (z: c) : GTot c = L.fold_right_gtot #a #c l (fun x acc -> (f x) `op` acc) z
{ "file_name": "ulib/FStar.BigOps.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 59, "end_line": 68, "start_col": 0, "start_line": 67 }
(* 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 FStar.BigOps /// This library provides propositional connectives over finite sets /// expressed as lists, aka "big operators", in analogy with LaTeX /// usage for \bigand, \bigor, etc. /// /// The library is designed with a dual usage in mind: /// /// 1. Normalization: When applied to a list literal, we want /// {[big_and f [a;b;c]]} to implicilty reduce to [f a /\ f b /\ f c] /// /// 2. Symbolic manipulation: We provide lemmas of the form /// /// [big_and f l <==> forall x. L.memP x l ==> f x] /// /// In this latter form, partially computing [big_and] as a fold over /// a list is cumbersome for proof. So, we provide variants [big_and'] /// etc., that do not reduce implicitly. module L = FStar.List.Tot (** We control reduction using the [delta_attr] feature of the normalizer. See FStar.Pervasives for how that works. Every term that is to be reduced is with the [__reduce__] attribute *) let __reduce__ = () (** We wrap [norm] with a module-specific custom usage, triggering specific reduction steps *) [@@ __reduce__] unfold let normal (#a: Type) (x: a) : a = FStar.Pervasives.norm [ iota; zeta; delta_only [`%L.fold_right_gtot; `%L.map_gtot]; delta_attr [`%__reduce__]; primops; simplify ] x (** A useful lemma to relate terms to their implicilty reducing variants *) val normal_eq (#a: Type) (f: a) : Lemma (f == normal f) (**** Map and fold *) (** A utility that combines map and fold: [map_op' op f l z] maps each element of [l] by [f] and then combines them using [op] *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.BigOps.fsti" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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
op: (_: b -> _: c -> Prims.GTot c) -> f: (_: a -> Prims.GTot b) -> l: Prims.list a -> z: c -> Prims.GTot c
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "FStar.List.Tot.Base.fold_right_gtot" ]
[]
false
false
false
false
false
let map_op' #a #b #c (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (l: list a) (z: c) : GTot c =
L.fold_right_gtot #a #c l (fun x acc -> (f x) `op` acc) z
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.fsqr25
val fsqr25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f1) /\ feval out2 == fmul (feval f2) (feval f2))
val fsqr25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f1) /\ feval out2 == fmul (feval f2) (feval f2))
let fsqr25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (o10, o11, o12, o13, o14) = fsqr_felem5 (f10, f11, f12, f13, f14) in let (o20, o21, o22, o23, o24) = fsqr_felem5 (f20, f21, f22, f23, f24) in let (o10, o11, o12, o13, o14) = carry_wide5 (o10, o11, o12, o13, o14) in let (o20, o21, o22, o23, o24) = carry_wide5 (o20, o21, o22, o23, o24) in ((o10, o11, o12, o13, o14), (o20, o21, o22, o23, o24))
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 434, "start_col": 0, "start_line": 429 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul)) let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1) #push-options "--ifuel 1" val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1)) let lemma_mul_inv f cin = assert_norm (pow51 = pow2 51) #pop-options #push-options "--z3rlimit 100" inline_for_extraction noextract val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == feval_wide inp) let carry_wide5 (i0, i1, i2, i3, i4) = assert_norm (6579 < pow2 13); assert_norm (pow2 13 < max51); let tmp0, c0 = carry51_wide #6579 i0 (u64 0) in let tmp1, c1 = carry51_wide #4797 i1 c0 in let tmp2, c2 = carry51_wide #3340 i2 c1 in let tmp3, c3 = carry51_wide #1881 i3 c2 in let tmp4, c4 = carry51_wide #423 i4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; (tmp0', tmp1', tmp2, tmp3, tmp4) #pop-options inline_for_extraction noextract val fmul5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f1) (feval f2)} let fmul5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (tmp0, tmp1, tmp2, tmp3, tmp4) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp0, tmp1, tmp2, tmp3, tmp4) in carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) inline_for_extraction noextract val fmul25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> f3:felem5{felem_fits5 f3 (9, 10, 9, 9, 9)} -> f4:felem5{felem_fits5 f4 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f2) /\ feval out2 == fmul (feval f3) (feval f4)) let fmul25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) = let (tmp10, tmp11, tmp12, tmp13, tmp14) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp20, tmp21, tmp22, tmp23, tmp24) = precomp_r19 (f40, f41, f42, f43, f44) in let (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp10, tmp11, tmp12, tmp13, tmp14) in let (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) = mul_felem5 (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) (tmp20, tmp21, tmp22, tmp23, tmp24) in let (o10,o11,o12,o13,o14) = carry_wide5 (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) in let (o20,o21,o22,o23,o24) = carry_wide5 (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) in ((o10,o11,o12,o13,o14), (o20,o21,o22,o23,o24)) inline_for_extraction noextract val fmul15: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:uint64{felem_fits1 f2 1} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == (feval f1 * v f2) % prime) let fmul15 (f10, f11, f12, f13, f14) f2 = let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = smul_felem5 #1 #(9, 10, 9, 9, 9) f2 (f10, f11, f12, f13, f14) in let out = (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in [@inline_let] let res = carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (uint_v f2) prime; assert (feval res == feval_wide (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)); assert (feval res == (wide_as_nat5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)) % prime); assert (feval res == (v f2 * as_nat5 (f10, f11, f12, f13, f14)) % prime); FStar.Math.Lemmas.swap_mul (v f2) (as_nat5 (f10, f11, f12, f13, f14)); assert (feval res == (as_nat5 (f10, f11, f12, f13, f14) * v f2) % prime); res // inline_for_extraction noextract // val fsqr_felem5: // f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} // -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423)} // let fsqr_felem5 (f0, f1, f2, f3, f4) = // let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 20, 18, 18, 18) f0 (f0, u64 2 *! f1, u64 2 *! f2, u64 2 *! f3, u64 2 *! f4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(342, 0, 10, 18, 18) #(81, 180, 162, 162, 162) // f1 (u64 38 *! f4, u64 0, f1, u64 2 *! f2, u64 2 *! f3) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(342, 342, 0, 0, 9) #(3501, 180, 262, 342, 342) // f2 (u64 38 *! f3, u64 38 *! f4, u64 0, u64 0, f2) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 171, 342, 0, 0) #(6579, 3258, 262, 342, 423) // f3 (u64 0, u64 19 *. f3, u64 38 *. f4, u64 0, u64 0) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 0, 0, 171, 0) #(6579, 4797, 3340, 342, 423) // f4 (u64 0, u64 0, u64 0, u64 19 *. f4, u64 0) (o0, o1, o2, o3, o4) in // (o0, o1, o2, o3, o4) inline_for_extraction noextract val mul64_wide_add3: #m0:scale64 -> #m1:scale64 -> #m2:scale64 -> #m3:scale64 -> #m4:scale64 -> #m5:scale64 -> a0:uint64{felem_fits1 a0 m0} -> a1:uint64{felem_fits1 a1 m1} -> b0:uint64{felem_fits1 b0 m2} -> b1:uint64{felem_fits1 b1 m3} -> c0:uint64{felem_fits1 c0 m4} -> c1:uint64{felem_fits1 c1 m5} -> Pure uint128 (requires m0 * m1 + m2 * m3 + m4 * m5 < 8192) (ensures fun res -> felem_wide_fits1 res (m0 * m1 + m2 * m3 + m4 * m5) /\ v res == v a0 * v a1 + v b0 * v b1 + v c0 * v c1) let mul64_wide_add3 #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1 = assert_norm (pow2 13 = 8192); mul64_wide_add3_lemma #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1; mul64_wide a0 a1 +! mul64_wide b0 b1 +! mul64_wide c0 c1 inline_for_extraction noextract val fsqr_felem5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> Pure felem_wide5 (requires True) (ensures fun out -> felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f) (feval f)) let fsqr_felem5 (f0, f1, f2, f3, f4) = assert_norm (pow2 13 = 8192); let d0 = u64 2 *! f0 in let d1 = u64 2 *! f1 in let d2 = u64 38 *! f2 in let d3 = u64 19 *! f3 in let d419 = u64 19 *! f4 in let d4 = u64 2 *! d419 in let s0 = mul64_wide_add3 #9 #9 #342 #10 #342 #9 f0 f0 d4 f1 d2 f3 in let s1 = mul64_wide_add3 #18 #10 #342 #9 #171 #9 d0 f1 d4 f2 d3 f3 in let s2 = mul64_wide_add3 #18 #9 #10 #10 #342 #9 d0 f2 f1 f1 d4 f3 in let s3 = mul64_wide_add3 #18 #9 #20 #9 #9 #171 d0 f3 d1 f2 f4 d419 in let s4 = mul64_wide_add3 #18 #9 #20 #9 #9 #9 d0 f4 d1 f3 f2 f2 in lemma_fmul_fsqr5 (f0, f1, f2, f3, f4); (s0, s1, s2, s3, s4) inline_for_extraction noextract val fsqr5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f) (feval f)} let fsqr5 (f0, f1, f2, f3, f4) = let (o0, o1, o2, o3, o4) = fsqr_felem5 (f0, f1, f2, f3, f4) in carry_wide5 (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsqr25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f1) /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f1: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f2 (9, 10, 9, 9, 9)} -> Prims.Pure (Hacl.Spec.Curve25519.Field51.Definition.felem5 * Hacl.Spec.Curve25519.Field51.Definition.felem5 )
Prims.Pure
[]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.uint64", "Lib.IntTypes.uint128", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Curve25519.Field51.carry_wide5", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide5", "Hacl.Spec.Curve25519.Field51.fsqr_felem5" ]
[]
false
false
false
false
false
let fsqr25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) =
let o10, o11, o12, o13, o14 = fsqr_felem5 (f10, f11, f12, f13, f14) in let o20, o21, o22, o23, o24 = fsqr_felem5 (f20, f21, f22, f23, f24) in let o10, o11, o12, o13, o14 = carry_wide5 (o10, o11, o12, o13, o14) in let o20, o21, o22, o23, o24 = carry_wide5 (o20, o21, o22, o23, o24) in ((o10, o11, o12, o13, o14), (o20, o21, o22, o23, o24))
false
FStar.BigOps.fsti
FStar.BigOps.symmetric
val symmetric : f: (_: a -> _: a -> Type0) -> Prims.logical
let symmetric (#a: Type) (f: (a -> a -> Type)) = forall x y. f x y <==> f y x
{ "file_name": "ulib/FStar.BigOps.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 77, "end_line": 183, "start_col": 0, "start_line": 183 }
(* 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 FStar.BigOps /// This library provides propositional connectives over finite sets /// expressed as lists, aka "big operators", in analogy with LaTeX /// usage for \bigand, \bigor, etc. /// /// The library is designed with a dual usage in mind: /// /// 1. Normalization: When applied to a list literal, we want /// {[big_and f [a;b;c]]} to implicilty reduce to [f a /\ f b /\ f c] /// /// 2. Symbolic manipulation: We provide lemmas of the form /// /// [big_and f l <==> forall x. L.memP x l ==> f x] /// /// In this latter form, partially computing [big_and] as a fold over /// a list is cumbersome for proof. So, we provide variants [big_and'] /// etc., that do not reduce implicitly. module L = FStar.List.Tot (** We control reduction using the [delta_attr] feature of the normalizer. See FStar.Pervasives for how that works. Every term that is to be reduced is with the [__reduce__] attribute *) let __reduce__ = () (** We wrap [norm] with a module-specific custom usage, triggering specific reduction steps *) [@@ __reduce__] unfold let normal (#a: Type) (x: a) : a = FStar.Pervasives.norm [ iota; zeta; delta_only [`%L.fold_right_gtot; `%L.map_gtot]; delta_attr [`%__reduce__]; primops; simplify ] x (** A useful lemma to relate terms to their implicilty reducing variants *) val normal_eq (#a: Type) (f: a) : Lemma (f == normal f) (**** Map and fold *) (** A utility that combines map and fold: [map_op' op f l z] maps each element of [l] by [f] and then combines them using [op] *) [@@ __reduce__] let map_op' #a #b #c (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (l: list a) (z: c) : GTot c = L.fold_right_gtot #a #c l (fun x acc -> (f x) `op` acc) z (** Equations for [map_op'] showing how it folds over the empty list *) val map_op'_nil (#a #b #c: Type) (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (z: c) : Lemma (map_op' op f [] z == z) (** Equations for [map_op'] showing how it folds over a cons cell *) val map_op'_cons (#a #b #c: Type) (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (hd: a) (tl: list a) (z: c) : Lemma (map_op' op f (hd :: tl) z == (f hd) `op` (map_op' op f tl z)) (**** Conjunction *) (** [big_and' f l] = [/\_{x in l} f x] *) [@@ __reduce__] let big_and' #a (f: (a -> Type)) (l: list a) : Type = map_op' l_and f l True (** Equations for [big_and'] showing it to be trivial over the empty list *) val big_and'_nil (#a: Type) (f: (a -> Type)) : Lemma (big_and' f [] == True) (** Equations for [big_and'] showing it to be a fold over a list with [/\] *) val big_and'_cons (#a: Type) (f: (a -> Type)) (hd: a) (tl: list a) : Lemma (big_and' f (hd :: tl) == (f hd /\ big_and' f tl)) (** [big_and' f l] is a [prop], i.e., it is proof irrelevant. Note: defining `big_and'` to intrinsically be in `prop` is also possible, but it's much more tedious in proofs. This is in part because the [/\] is not defined in prop, though one can prove that [a /\ b] is a prop. The discrepancy means that I preferred to prove these operators in [prop] extrinsically. *) val big_and'_prop (#a: Type) (f: (a -> Type)) (l: list a) : Lemma ((big_and' f l) `subtype_of` unit) (** Interpreting the finite conjunction [big_and f l] as an infinite conjunction [forall] *) val big_and'_forall (#a: Type) (f: (a -> Type)) (l: list a) : Lemma (big_and' f l <==> (forall x. L.memP x l ==> f x)) (** [big_and f l] is an implicitly reducing variant of [big_and'] It is defined in [prop] *) [@@ __reduce__] unfold let big_and #a (f: (a -> Type)) (l: list a) : prop = big_and'_prop f l; normal (big_and' f l) (**** Disjunction *) (** [big_or f l] = [\/_{x in l} f x] *) [@@ __reduce__] let big_or' #a (f: (a -> Type)) (l: list a) : Type = map_op' l_or f l False (** Equations for [big_or] showing it to be [False] on the empty list *) val big_or'_nil (#a: Type) (f: (a -> Type)) : Lemma (big_or' f [] == False) (** Equations for [big_or] showing it to fold over a list *) val big_or'_cons (#a: Type) (f: (a -> Type)) (hd: a) (tl: list a) : Lemma (big_or' f (hd :: tl) == (f hd \/ big_or' f tl)) (** [big_or f l] is a `prop` See the remark above on the style of proof for prop *) val big_or'_prop (#a: Type) (f: (a -> Type)) (l: list a) : Lemma ((big_or' f l) `subtype_of` unit) (** Interpreting the finite disjunction [big_or f l] as an infinite disjunction [exists] *) val big_or'_exists (#a: Type) (f: (a -> Type)) (l: list a) : Lemma (big_or' f l <==> (exists x. L.memP x l /\ f x)) (** [big_or f l] is an implicitly reducing variant of [big_or'] It is defined in [prop] *) [@@ __reduce__] unfold let big_or #a (f: (a -> Type)) (l: list a) : prop = big_or'_prop f l; normal (big_or' f l) (**** Pairwise operators *) /// We provide functions to apply a reflexive, symmetric binary /// operator to elements in a list [l] pairwise, in a triangle of /// elements in the square matrix of [l X l]. To illustrate, for a /// list of [n] elements, we fold the operator over the pairwise /// elements of the list in top-down, left-to-right order of the /// diagram below /// /// /// {[ /// 0 1 2 3 ... n /// 0 /// 1 x /// 2 x x /// 3 x x x /// . x x x x /// n x x x x ]} (** Mapping pairs of elements of [l] using [f] and combining them with [op]. *) [@@ __reduce__] let rec pairwise_op' #a #b (op: (b -> b -> GTot b)) (f: (a -> a -> b)) (l: list a) (z: b) : GTot b = match l with | [] -> z | hd :: tl -> (map_op' op (f hd) tl z) `op` (pairwise_op' op f tl z)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.BigOps.fsti" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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: (_: a -> _: a -> Type0) -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.l_Forall", "Prims.l_iff", "Prims.logical" ]
[]
false
false
false
true
true
let symmetric (#a: Type) (f: (a -> a -> Type)) =
forall x y. f x y <==> f y x
false
Hacl.Curve25519_51.fst
Hacl.Curve25519_51.finv
val finv : Hacl.Meta.Curve25519.finv_finv_higher_t Prims.l_True
let finv = finv_finv_higher #M51 True C.fmul fsquare_times
{ "file_name": "code/curve25519/Hacl.Curve25519_51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 20, "start_col": 0, "start_line": 20 }
module Hacl.Curve25519_51 friend Hacl.Meta.Curve25519 open Hacl.Meta.Curve25519 // The Hacl core. module C = Hacl.Impl.Curve25519.Field51 let g25519: g25519_t = Lib.Buffer.createL_global Spec.Curve25519.basepoint_list #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" let point_add_and_double = addanddouble_point_add_and_double_higher #M51 True C.fmul C.fsqr2 C.fmul1 C.fmul2 C.fsub C.fadd let point_double = addanddouble_point_double_higher #M51 True C.fmul2 C.fmul1 C.fsqr2 C.fsub C.fadd let montgomery_ladder = generic_montgomery_ladder_higher #M51 True point_double C.cswap2 point_add_and_double
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Curve25519.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Curve25519_51.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "C" }, { "abbrev": false, "full_module": "Hacl.Meta.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Meta.Curve25519.finv_finv_higher_t Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Curve25519.finv_finv_higher", "Hacl.Impl.Curve25519.Fields.Core.M51", "Prims.l_True", "Hacl.Impl.Curve25519.Field51.fmul", "Hacl.Curve25519_51.fsquare_times" ]
[]
false
false
false
true
false
let finv =
finv_finv_higher #M51 True C.fmul fsquare_times
false
FStar.BigOps.fsti
FStar.BigOps.anti_reflexive
val anti_reflexive : f: (_: a -> _: a -> Type0) -> Prims.logical
let anti_reflexive (#a: Type) (f: (a -> a -> Type)) = forall x. ~(f x x)
{ "file_name": "ulib/FStar.BigOps.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 72, "end_line": 189, "start_col": 0, "start_line": 189 }
(* 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 FStar.BigOps /// This library provides propositional connectives over finite sets /// expressed as lists, aka "big operators", in analogy with LaTeX /// usage for \bigand, \bigor, etc. /// /// The library is designed with a dual usage in mind: /// /// 1. Normalization: When applied to a list literal, we want /// {[big_and f [a;b;c]]} to implicilty reduce to [f a /\ f b /\ f c] /// /// 2. Symbolic manipulation: We provide lemmas of the form /// /// [big_and f l <==> forall x. L.memP x l ==> f x] /// /// In this latter form, partially computing [big_and] as a fold over /// a list is cumbersome for proof. So, we provide variants [big_and'] /// etc., that do not reduce implicitly. module L = FStar.List.Tot (** We control reduction using the [delta_attr] feature of the normalizer. See FStar.Pervasives for how that works. Every term that is to be reduced is with the [__reduce__] attribute *) let __reduce__ = () (** We wrap [norm] with a module-specific custom usage, triggering specific reduction steps *) [@@ __reduce__] unfold let normal (#a: Type) (x: a) : a = FStar.Pervasives.norm [ iota; zeta; delta_only [`%L.fold_right_gtot; `%L.map_gtot]; delta_attr [`%__reduce__]; primops; simplify ] x (** A useful lemma to relate terms to their implicilty reducing variants *) val normal_eq (#a: Type) (f: a) : Lemma (f == normal f) (**** Map and fold *) (** A utility that combines map and fold: [map_op' op f l z] maps each element of [l] by [f] and then combines them using [op] *) [@@ __reduce__] let map_op' #a #b #c (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (l: list a) (z: c) : GTot c = L.fold_right_gtot #a #c l (fun x acc -> (f x) `op` acc) z (** Equations for [map_op'] showing how it folds over the empty list *) val map_op'_nil (#a #b #c: Type) (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (z: c) : Lemma (map_op' op f [] z == z) (** Equations for [map_op'] showing how it folds over a cons cell *) val map_op'_cons (#a #b #c: Type) (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (hd: a) (tl: list a) (z: c) : Lemma (map_op' op f (hd :: tl) z == (f hd) `op` (map_op' op f tl z)) (**** Conjunction *) (** [big_and' f l] = [/\_{x in l} f x] *) [@@ __reduce__] let big_and' #a (f: (a -> Type)) (l: list a) : Type = map_op' l_and f l True (** Equations for [big_and'] showing it to be trivial over the empty list *) val big_and'_nil (#a: Type) (f: (a -> Type)) : Lemma (big_and' f [] == True) (** Equations for [big_and'] showing it to be a fold over a list with [/\] *) val big_and'_cons (#a: Type) (f: (a -> Type)) (hd: a) (tl: list a) : Lemma (big_and' f (hd :: tl) == (f hd /\ big_and' f tl)) (** [big_and' f l] is a [prop], i.e., it is proof irrelevant. Note: defining `big_and'` to intrinsically be in `prop` is also possible, but it's much more tedious in proofs. This is in part because the [/\] is not defined in prop, though one can prove that [a /\ b] is a prop. The discrepancy means that I preferred to prove these operators in [prop] extrinsically. *) val big_and'_prop (#a: Type) (f: (a -> Type)) (l: list a) : Lemma ((big_and' f l) `subtype_of` unit) (** Interpreting the finite conjunction [big_and f l] as an infinite conjunction [forall] *) val big_and'_forall (#a: Type) (f: (a -> Type)) (l: list a) : Lemma (big_and' f l <==> (forall x. L.memP x l ==> f x)) (** [big_and f l] is an implicitly reducing variant of [big_and'] It is defined in [prop] *) [@@ __reduce__] unfold let big_and #a (f: (a -> Type)) (l: list a) : prop = big_and'_prop f l; normal (big_and' f l) (**** Disjunction *) (** [big_or f l] = [\/_{x in l} f x] *) [@@ __reduce__] let big_or' #a (f: (a -> Type)) (l: list a) : Type = map_op' l_or f l False (** Equations for [big_or] showing it to be [False] on the empty list *) val big_or'_nil (#a: Type) (f: (a -> Type)) : Lemma (big_or' f [] == False) (** Equations for [big_or] showing it to fold over a list *) val big_or'_cons (#a: Type) (f: (a -> Type)) (hd: a) (tl: list a) : Lemma (big_or' f (hd :: tl) == (f hd \/ big_or' f tl)) (** [big_or f l] is a `prop` See the remark above on the style of proof for prop *) val big_or'_prop (#a: Type) (f: (a -> Type)) (l: list a) : Lemma ((big_or' f l) `subtype_of` unit) (** Interpreting the finite disjunction [big_or f l] as an infinite disjunction [exists] *) val big_or'_exists (#a: Type) (f: (a -> Type)) (l: list a) : Lemma (big_or' f l <==> (exists x. L.memP x l /\ f x)) (** [big_or f l] is an implicitly reducing variant of [big_or'] It is defined in [prop] *) [@@ __reduce__] unfold let big_or #a (f: (a -> Type)) (l: list a) : prop = big_or'_prop f l; normal (big_or' f l) (**** Pairwise operators *) /// We provide functions to apply a reflexive, symmetric binary /// operator to elements in a list [l] pairwise, in a triangle of /// elements in the square matrix of [l X l]. To illustrate, for a /// list of [n] elements, we fold the operator over the pairwise /// elements of the list in top-down, left-to-right order of the /// diagram below /// /// /// {[ /// 0 1 2 3 ... n /// 0 /// 1 x /// 2 x x /// 3 x x x /// . x x x x /// n x x x x ]} (** Mapping pairs of elements of [l] using [f] and combining them with [op]. *) [@@ __reduce__] let rec pairwise_op' #a #b (op: (b -> b -> GTot b)) (f: (a -> a -> b)) (l: list a) (z: b) : GTot b = match l with | [] -> z | hd :: tl -> (map_op' op (f hd) tl z) `op` (pairwise_op' op f tl z) (** [f] is a symmetric relation *) let symmetric (#a: Type) (f: (a -> a -> Type)) = forall x y. f x y <==> f y x (** [f] is a reflexive relation *) let reflexive (#a: Type) (f: (a -> a -> Type)) = forall x. f x x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.BigOps.fsti" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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: (_: a -> _: a -> Type0) -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.l_Forall", "Prims.l_not", "Prims.logical" ]
[]
false
false
false
true
true
let anti_reflexive (#a: Type) (f: (a -> a -> Type)) =
forall x. ~(f x x)
false
FStar.BigOps.fsti
FStar.BigOps.reflexive
val reflexive : f: (_: a -> _: a -> Type0) -> Prims.logical
let reflexive (#a: Type) (f: (a -> a -> Type)) = forall x. f x x
{ "file_name": "ulib/FStar.BigOps.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 64, "end_line": 186, "start_col": 0, "start_line": 186 }
(* 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 FStar.BigOps /// This library provides propositional connectives over finite sets /// expressed as lists, aka "big operators", in analogy with LaTeX /// usage for \bigand, \bigor, etc. /// /// The library is designed with a dual usage in mind: /// /// 1. Normalization: When applied to a list literal, we want /// {[big_and f [a;b;c]]} to implicilty reduce to [f a /\ f b /\ f c] /// /// 2. Symbolic manipulation: We provide lemmas of the form /// /// [big_and f l <==> forall x. L.memP x l ==> f x] /// /// In this latter form, partially computing [big_and] as a fold over /// a list is cumbersome for proof. So, we provide variants [big_and'] /// etc., that do not reduce implicitly. module L = FStar.List.Tot (** We control reduction using the [delta_attr] feature of the normalizer. See FStar.Pervasives for how that works. Every term that is to be reduced is with the [__reduce__] attribute *) let __reduce__ = () (** We wrap [norm] with a module-specific custom usage, triggering specific reduction steps *) [@@ __reduce__] unfold let normal (#a: Type) (x: a) : a = FStar.Pervasives.norm [ iota; zeta; delta_only [`%L.fold_right_gtot; `%L.map_gtot]; delta_attr [`%__reduce__]; primops; simplify ] x (** A useful lemma to relate terms to their implicilty reducing variants *) val normal_eq (#a: Type) (f: a) : Lemma (f == normal f) (**** Map and fold *) (** A utility that combines map and fold: [map_op' op f l z] maps each element of [l] by [f] and then combines them using [op] *) [@@ __reduce__] let map_op' #a #b #c (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (l: list a) (z: c) : GTot c = L.fold_right_gtot #a #c l (fun x acc -> (f x) `op` acc) z (** Equations for [map_op'] showing how it folds over the empty list *) val map_op'_nil (#a #b #c: Type) (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (z: c) : Lemma (map_op' op f [] z == z) (** Equations for [map_op'] showing how it folds over a cons cell *) val map_op'_cons (#a #b #c: Type) (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (hd: a) (tl: list a) (z: c) : Lemma (map_op' op f (hd :: tl) z == (f hd) `op` (map_op' op f tl z)) (**** Conjunction *) (** [big_and' f l] = [/\_{x in l} f x] *) [@@ __reduce__] let big_and' #a (f: (a -> Type)) (l: list a) : Type = map_op' l_and f l True (** Equations for [big_and'] showing it to be trivial over the empty list *) val big_and'_nil (#a: Type) (f: (a -> Type)) : Lemma (big_and' f [] == True) (** Equations for [big_and'] showing it to be a fold over a list with [/\] *) val big_and'_cons (#a: Type) (f: (a -> Type)) (hd: a) (tl: list a) : Lemma (big_and' f (hd :: tl) == (f hd /\ big_and' f tl)) (** [big_and' f l] is a [prop], i.e., it is proof irrelevant. Note: defining `big_and'` to intrinsically be in `prop` is also possible, but it's much more tedious in proofs. This is in part because the [/\] is not defined in prop, though one can prove that [a /\ b] is a prop. The discrepancy means that I preferred to prove these operators in [prop] extrinsically. *) val big_and'_prop (#a: Type) (f: (a -> Type)) (l: list a) : Lemma ((big_and' f l) `subtype_of` unit) (** Interpreting the finite conjunction [big_and f l] as an infinite conjunction [forall] *) val big_and'_forall (#a: Type) (f: (a -> Type)) (l: list a) : Lemma (big_and' f l <==> (forall x. L.memP x l ==> f x)) (** [big_and f l] is an implicitly reducing variant of [big_and'] It is defined in [prop] *) [@@ __reduce__] unfold let big_and #a (f: (a -> Type)) (l: list a) : prop = big_and'_prop f l; normal (big_and' f l) (**** Disjunction *) (** [big_or f l] = [\/_{x in l} f x] *) [@@ __reduce__] let big_or' #a (f: (a -> Type)) (l: list a) : Type = map_op' l_or f l False (** Equations for [big_or] showing it to be [False] on the empty list *) val big_or'_nil (#a: Type) (f: (a -> Type)) : Lemma (big_or' f [] == False) (** Equations for [big_or] showing it to fold over a list *) val big_or'_cons (#a: Type) (f: (a -> Type)) (hd: a) (tl: list a) : Lemma (big_or' f (hd :: tl) == (f hd \/ big_or' f tl)) (** [big_or f l] is a `prop` See the remark above on the style of proof for prop *) val big_or'_prop (#a: Type) (f: (a -> Type)) (l: list a) : Lemma ((big_or' f l) `subtype_of` unit) (** Interpreting the finite disjunction [big_or f l] as an infinite disjunction [exists] *) val big_or'_exists (#a: Type) (f: (a -> Type)) (l: list a) : Lemma (big_or' f l <==> (exists x. L.memP x l /\ f x)) (** [big_or f l] is an implicitly reducing variant of [big_or'] It is defined in [prop] *) [@@ __reduce__] unfold let big_or #a (f: (a -> Type)) (l: list a) : prop = big_or'_prop f l; normal (big_or' f l) (**** Pairwise operators *) /// We provide functions to apply a reflexive, symmetric binary /// operator to elements in a list [l] pairwise, in a triangle of /// elements in the square matrix of [l X l]. To illustrate, for a /// list of [n] elements, we fold the operator over the pairwise /// elements of the list in top-down, left-to-right order of the /// diagram below /// /// /// {[ /// 0 1 2 3 ... n /// 0 /// 1 x /// 2 x x /// 3 x x x /// . x x x x /// n x x x x ]} (** Mapping pairs of elements of [l] using [f] and combining them with [op]. *) [@@ __reduce__] let rec pairwise_op' #a #b (op: (b -> b -> GTot b)) (f: (a -> a -> b)) (l: list a) (z: b) : GTot b = match l with | [] -> z | hd :: tl -> (map_op' op (f hd) tl z) `op` (pairwise_op' op f tl z) (** [f] is a symmetric relation *) let symmetric (#a: Type) (f: (a -> a -> Type)) = forall x y. f x y <==> f y x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.BigOps.fsti" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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: (_: a -> _: a -> Type0) -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.l_Forall", "Prims.logical" ]
[]
false
false
false
true
true
let reflexive (#a: Type) (f: (a -> a -> Type)) =
forall x. f x x
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.fmul15
val fmul15: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:uint64{felem_fits1 f2 1} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == (feval f1 * v f2) % prime)
val fmul15: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:uint64{felem_fits1 f2 1} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == (feval f1 * v f2) % prime)
let fmul15 (f10, f11, f12, f13, f14) f2 = let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = smul_felem5 #1 #(9, 10, 9, 9, 9) f2 (f10, f11, f12, f13, f14) in let out = (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in [@inline_let] let res = carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (uint_v f2) prime; assert (feval res == feval_wide (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)); assert (feval res == (wide_as_nat5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)) % prime); assert (feval res == (v f2 * as_nat5 (f10, f11, f12, f13, f14)) % prime); FStar.Math.Lemmas.swap_mul (v f2) (as_nat5 (f10, f11, f12, f13, f14)); assert (feval res == (as_nat5 (f10, f11, f12, f13, f14) * v f2) % prime); res
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 342, "start_col": 0, "start_line": 328 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul)) let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1) #push-options "--ifuel 1" val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1)) let lemma_mul_inv f cin = assert_norm (pow51 = pow2 51) #pop-options #push-options "--z3rlimit 100" inline_for_extraction noextract val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == feval_wide inp) let carry_wide5 (i0, i1, i2, i3, i4) = assert_norm (6579 < pow2 13); assert_norm (pow2 13 < max51); let tmp0, c0 = carry51_wide #6579 i0 (u64 0) in let tmp1, c1 = carry51_wide #4797 i1 c0 in let tmp2, c2 = carry51_wide #3340 i2 c1 in let tmp3, c3 = carry51_wide #1881 i3 c2 in let tmp4, c4 = carry51_wide #423 i4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; (tmp0', tmp1', tmp2, tmp3, tmp4) #pop-options inline_for_extraction noextract val fmul5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f1) (feval f2)} let fmul5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (tmp0, tmp1, tmp2, tmp3, tmp4) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp0, tmp1, tmp2, tmp3, tmp4) in carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) inline_for_extraction noextract val fmul25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> f3:felem5{felem_fits5 f3 (9, 10, 9, 9, 9)} -> f4:felem5{felem_fits5 f4 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f2) /\ feval out2 == fmul (feval f3) (feval f4)) let fmul25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) = let (tmp10, tmp11, tmp12, tmp13, tmp14) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp20, tmp21, tmp22, tmp23, tmp24) = precomp_r19 (f40, f41, f42, f43, f44) in let (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp10, tmp11, tmp12, tmp13, tmp14) in let (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) = mul_felem5 (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) (tmp20, tmp21, tmp22, tmp23, tmp24) in let (o10,o11,o12,o13,o14) = carry_wide5 (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) in let (o20,o21,o22,o23,o24) = carry_wide5 (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) in ((o10,o11,o12,o13,o14), (o20,o21,o22,o23,o24)) inline_for_extraction noextract val fmul15: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:uint64{felem_fits1 f2 1} -> Pure felem5 (requires True) (ensures fun out ->
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f1: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2: Lib.IntTypes.uint64{Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 f2 1} -> Prims.Pure Hacl.Spec.Curve25519.Field51.Definition.felem5
Prims.Pure
[]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Lib.IntTypes.uint64", "Prims.b2t", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits1", "Lib.IntTypes.uint128", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.Curve25519.Field51.Definition.feval", "Prims.op_Modulus", "FStar.Mul.op_Star", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Spec.Curve25519.prime", "FStar.Math.Lemmas.swap_mul", "Hacl.Spec.Curve25519.Field51.Definition.wide_as_nat5", "Spec.Curve25519.elem", "Hacl.Spec.Curve25519.Field51.Definition.feval_wide", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Lib.IntTypes.uint_v", "Hacl.Spec.Curve25519.Field51.carry_wide5", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.int_t", "Lib.IntTypes.U128", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide5", "Prims.l_and", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits5", "Hacl.Spec.Curve25519.Field51.Definition.op_Star_Hat", "Prims.op_Multiply", "Hacl.Spec.Curve25519.Field51.smul_felem5" ]
[]
false
false
false
false
false
let fmul15 (f10, f11, f12, f13, f14) f2 =
let tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4 = smul_felem5 #1 #(9, 10, 9, 9, 9) f2 (f10, f11, f12, f13, f14) in let out = (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in [@@ inline_let ]let res = carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (uint_v f2) prime; assert (feval res == feval_wide (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)); assert (feval res == (wide_as_nat5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)) % prime); assert (feval res == (v f2 * as_nat5 (f10, f11, f12, f13, f14)) % prime); FStar.Math.Lemmas.swap_mul (v f2) (as_nat5 (f10, f11, f12, f13, f14)); assert (feval res == (as_nat5 (f10, f11, f12, f13, f14) * v f2) % prime); res
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.mul_inv_t
val mul_inv_t : f: Hacl.Spec.Curve25519.Field51.Definition.felem5 -> Prims.logical
let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 241, "start_col": 0, "start_line": 237 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul))
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Spec.Curve25519.Field51.Definition.felem5 -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Lib.IntTypes.uint64", "Prims.op_GreaterThanOrEqual", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.pow2", "Prims.l_and", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Modulus", "Prims.bool", "Prims.logical" ]
[]
false
false
false
true
true
let mul_inv_t (f: felem5) =
let o0, o1, o2, o3, o4 = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1)
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.precomp_r19
val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)}
val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)}
let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 186, "start_col": 0, "start_line": 175 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)}
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f2: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 r19 (171, 190, 171, 171, 171)}
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Lib.IntTypes.uint64", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.u64" ]
[]
false
false
false
false
false
let precomp_r19 (f20, f21, f22, f23, f24) =
[@@ inline_let ]let r190 = f20 *! u64 19 in [@@ inline_let ]let r191 = f21 *! u64 19 in [@@ inline_let ]let r192 = f22 *! u64 19 in [@@ inline_let ]let r193 = f23 *! u64 19 in [@@ inline_let ]let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194)
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.fmul25
val fmul25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> f3:felem5{felem_fits5 f3 (9, 10, 9, 9, 9)} -> f4:felem5{felem_fits5 f4 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f2) /\ feval out2 == fmul (feval f3) (feval f4))
val fmul25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> f3:felem5{felem_fits5 f3 (9, 10, 9, 9, 9)} -> f4:felem5{felem_fits5 f4 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f2) /\ feval out2 == fmul (feval f3) (feval f4))
let fmul25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) = let (tmp10, tmp11, tmp12, tmp13, tmp14) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp20, tmp21, tmp22, tmp23, tmp24) = precomp_r19 (f40, f41, f42, f43, f44) in let (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp10, tmp11, tmp12, tmp13, tmp14) in let (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) = mul_felem5 (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) (tmp20, tmp21, tmp22, tmp23, tmp24) in let (o10,o11,o12,o13,o14) = carry_wide5 (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) in let (o20,o21,o22,o23,o24) = carry_wide5 (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) in ((o10,o11,o12,o13,o14), (o20,o21,o22,o23,o24))
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 318, "start_col": 0, "start_line": 309 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul)) let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1) #push-options "--ifuel 1" val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1)) let lemma_mul_inv f cin = assert_norm (pow51 = pow2 51) #pop-options #push-options "--z3rlimit 100" inline_for_extraction noextract val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == feval_wide inp) let carry_wide5 (i0, i1, i2, i3, i4) = assert_norm (6579 < pow2 13); assert_norm (pow2 13 < max51); let tmp0, c0 = carry51_wide #6579 i0 (u64 0) in let tmp1, c1 = carry51_wide #4797 i1 c0 in let tmp2, c2 = carry51_wide #3340 i2 c1 in let tmp3, c3 = carry51_wide #1881 i3 c2 in let tmp4, c4 = carry51_wide #423 i4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; (tmp0', tmp1', tmp2, tmp3, tmp4) #pop-options inline_for_extraction noextract val fmul5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f1) (feval f2)} let fmul5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (tmp0, tmp1, tmp2, tmp3, tmp4) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp0, tmp1, tmp2, tmp3, tmp4) in carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) inline_for_extraction noextract val fmul25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> f3:felem5{felem_fits5 f3 (9, 10, 9, 9, 9)} -> f4:felem5{felem_fits5 f4 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f2) /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f1: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f2 (9, 10, 9, 9, 9)} -> f3: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f3 (9, 10, 9, 9, 9)} -> f4: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f4 (9, 10, 9, 9, 9)} -> Prims.Pure (Hacl.Spec.Curve25519.Field51.Definition.felem5 * Hacl.Spec.Curve25519.Field51.Definition.felem5 )
Prims.Pure
[]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "FStar.Pervasives.Native.Mktuple4", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.uint64", "Lib.IntTypes.uint128", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Curve25519.Field51.carry_wide5", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide5", "Prims.l_and", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits5", "Prims.eq2", "Spec.Curve25519.elem", "Hacl.Spec.Curve25519.Field51.Definition.feval_wide", "Spec.Curve25519.fmul", "Hacl.Spec.Curve25519.Field51.Definition.feval", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.Spec.Curve25519.Field51.mul_felem5", "Hacl.Spec.Curve25519.Field51.precomp_r19" ]
[]
false
false
false
false
false
let fmul25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) =
let tmp10, tmp11, tmp12, tmp13, tmp14 = precomp_r19 (f20, f21, f22, f23, f24) in let tmp20, tmp21, tmp22, tmp23, tmp24 = precomp_r19 (f40, f41, f42, f43, f44) in let tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14 = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp10, tmp11, tmp12, tmp13, tmp14) in let tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24 = mul_felem5 (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) (tmp20, tmp21, tmp22, tmp23, tmp24) in let o10, o11, o12, o13, o14 = carry_wide5 (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) in let o20, o21, o22, o23, o24 = carry_wide5 (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) in ((o10, o11, o12, o13, o14), (o20, o21, o22, o23, o24))
false
Vale.AES.GF128.fsti
Vale.AES.GF128.gf128_mul_rev
val gf128_mul_rev (a b: poly) : poly
val gf128_mul_rev (a b: poly) : poly
let gf128_mul_rev (a b:poly) : poly = reverse (gf128_mul (reverse a 127) (reverse b 127)) 127
{ "file_name": "vale/code/crypto/aes/Vale.AES.GF128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 164, "start_col": 0, "start_line": 163 }
module Vale.AES.GF128 open FStar.Seq open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GF128_s open Vale.Math.Poly2_s open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2 open Vale.Math.Poly2.Lemmas let quad32_shift_left_1 (q:quad32) : quad32 = let l = four_map (fun (i:nat32) -> ishl i 1) q in let r = four_map (fun (i:nat32) -> ishr i 31) q in let Mkfour r0 r1 r2 r3 = r in quad32_xor l (Mkfour 0 r0 r1 r2) let quad32_shift_2_left_1 (qa qb:quad32) : quad32 & quad32 = let la = four_map (fun (i:nat32) -> ishl i 1) qa in let lb = four_map (fun (i:nat32) -> ishl i 1) qb in let ra = four_map (fun (i:nat32) -> ishr i 31) qa in let rb = four_map (fun (i:nat32) -> ishr i 31) qb in let Mkfour ra0 ra1 ra2 ra3 = ra in let Mkfour rb0 rb1 rb2 rb3 = rb in let qa' = quad32_xor la (Mkfour 0 ra0 ra1 ra2) in let qb' = quad32_xor lb (quad32_xor (Mkfour ra3 0 0 0) (Mkfour 0 rb0 rb1 rb2)) in (qa', qb') val lemma_shift_left_1 (a:poly) : Lemma (requires degree a < 128) (ensures to_quad32 (shift a 1) == quad32_shift_left_1 (to_quad32 a)) val lemma_shift_2_left_1 (lo hi:poly) : Lemma (requires degree hi < 127 /\ degree lo < 128) (ensures ( let n = monomial 128 in let a = hi *. n +. lo in let a' = shift a 1 in let (lo', hi') = quad32_shift_2_left_1 (to_quad32 lo) (to_quad32 hi) in lo' == to_quad32 (a' %. n) /\ hi' == to_quad32 (a' /. n) )) // TODO: move this to Poly library val lemma_reverse_reverse (a:poly) (n:nat) : Lemma (requires degree a <= n) (ensures reverse (reverse a n) n == a) [SMTPat (reverse (reverse a n) n)] val lemma_gf128_degree (_:unit) : Lemma (ensures degree gf128_modulus_low_terms == 7 /\ degree (monomial 128) == 128 /\ degree gf128_modulus == 128 ) val lemma_gf128_constant_rev (q:quad32) : Lemma (ensures to_quad32 (reverse gf128_modulus_low_terms 127) == Mkfour 0 0 0 0xe1000000 /\ quad32_xor q q == Mkfour 0 0 0 0 ) val lemma_quad32_double_hi_rev (a:poly) : Lemma (requires degree a <= 127 /\ degree (reverse a 127) <= 63) (ensures of_double32 (quad32_double_hi (to_quad32 a)) == reverse (reverse a 127) 63) // Compute 128-bit multiply in terms of 64-bit multiplies val lemma_gf128_mul (a b c d:poly) (n:nat) : Lemma (ensures ( let m = monomial n in let ab = a *. m +. b in let cd = c *. m +. d in let ac = a *. c in let ad = a *. d in let bc = b *. c in let bd = b *. d in ab *. cd == shift (ac +. bc /. m +. ad /. m) (n + n) +. ((bc %. m) *. m +. (ad %. m) *. m +. bd) )) // Compute (a * b) % g, where g = n + h and %. n is easy to compute (e.g. n = x^128) val lemma_gf128_reduce (a b g n h:poly) : Lemma (requires degree h >= 0 /\ degree n > 2 * degree h /\ degree g == degree n /\ degree a <= degree n /\ degree b <= degree n /\ g == n +. h ) (ensures ( let d = (a *. b) /. n in let dh = d *. h in degree ((dh /. n) *. h) <= 2 * degree h /\ (a *. b) %. g == (dh /. n) *. h +. dh %. n +. (a *. b) %. n )) val lemma_gf128_reduce_rev (a b h:poly) (n:pos) : Lemma (requires degree h >= 0 /\ n > 2 * degree h /\ degree (monomial n +. h) == n /\ degree a < n /\ degree b < n ) (ensures ( let m = monomial n in let g = m +. h in let r x = reverse x (n - 1) in let rr x = reverse x (2 * n - 1) in let rab = rr (a *. b) in let rd = rab %. m in let rdh = rr (r rd *. h) in let rdhL = rdh %. m in let rdhLh = r (r rdhL *. h) in degree (r rdhL) <= 2 * degree h /\ degree (r rdhLh) <= 2 * degree h /\ r ((a *. b) %. g) == rdhLh +. rdh /. m +. rab /. m )) val lemma_reduce_rev (a0 a1 a2 h:poly) (n:pos) : Lemma (requires n == 64 /\ // verification times out unless n is known degree a0 < n + n /\ degree a1 < n + n /\ degree a2 < n + n /\ degree (monomial (n + n) +. h) == n + n /\ degree h < n /\ h.[0] ) (ensures ( let nn = n + n in let mm = monomial nn in let m = monomial n in let g = mm +. h in let c = reverse (shift h (-1)) (n - 1) in let y_10 = a0 +. shift (mask a1 64) 64 in let y_0 = mask y_10 64 in let y_10c = swap y_10 64 +. y_0 *. c in let a = a0 +. shift a1 64 +. shift a2 128 in let x = reverse a (nn + nn - 1) in reverse (x %. g) (nn - 1) == swap y_10c 64 +. (a2 +. shift a1 (-64)) +. mask y_10c 64 *. c )) // of_fun 8 (fun (i:nat) -> i = 0 || i = 1 || i = 6) let gf128_low_shift : poly = shift gf128_modulus_low_terms (-1) // of_fun 8 (fun (i:nat) -> i = 127 || i = 126 || i = 121) let gf128_rev_shift : poly = reverse gf128_low_shift 127 val lemma_gf128_low_shift (_:unit) : Lemma (shift (of_quad32 (Mkfour 0 0 0 0xc2000000)) (-64) == reverse gf128_low_shift 63) val lemma_gf128_high_bit (_:unit) : Lemma (of_quad32 (Mkfour 0 0 0 0x80000000) == monomial 127) val lemma_gf128_low_shift_1 (_:unit) : Lemma (of_quad32 (Mkfour 1 0 0 0xc2000000) == reverse (shift (monomial 128 +. gf128_modulus_low_terms) (-1)) 127)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GF128.fsti" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> Vale.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2_s.reverse", "Vale.AES.GF128_s.gf128_mul" ]
[]
false
false
false
true
false
let gf128_mul_rev (a b: poly) : poly =
reverse (gf128_mul (reverse a 127) (reverse b 127)) 127
false
FStar.BigOps.fsti
FStar.BigOps.pairwise_op'
val pairwise_op' (#a #b: _) (op: (b -> b -> GTot b)) (f: (a -> a -> b)) (l: list a) (z: b) : GTot b
val pairwise_op' (#a #b: _) (op: (b -> b -> GTot b)) (f: (a -> a -> b)) (l: list a) (z: b) : GTot b
let rec pairwise_op' #a #b (op: (b -> b -> GTot b)) (f: (a -> a -> b)) (l: list a) (z: b) : GTot b = match l with | [] -> z | hd :: tl -> (map_op' op (f hd) tl z) `op` (pairwise_op' op f tl z)
{ "file_name": "ulib/FStar.BigOps.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 70, "end_line": 180, "start_col": 0, "start_line": 177 }
(* 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 FStar.BigOps /// This library provides propositional connectives over finite sets /// expressed as lists, aka "big operators", in analogy with LaTeX /// usage for \bigand, \bigor, etc. /// /// The library is designed with a dual usage in mind: /// /// 1. Normalization: When applied to a list literal, we want /// {[big_and f [a;b;c]]} to implicilty reduce to [f a /\ f b /\ f c] /// /// 2. Symbolic manipulation: We provide lemmas of the form /// /// [big_and f l <==> forall x. L.memP x l ==> f x] /// /// In this latter form, partially computing [big_and] as a fold over /// a list is cumbersome for proof. So, we provide variants [big_and'] /// etc., that do not reduce implicitly. module L = FStar.List.Tot (** We control reduction using the [delta_attr] feature of the normalizer. See FStar.Pervasives for how that works. Every term that is to be reduced is with the [__reduce__] attribute *) let __reduce__ = () (** We wrap [norm] with a module-specific custom usage, triggering specific reduction steps *) [@@ __reduce__] unfold let normal (#a: Type) (x: a) : a = FStar.Pervasives.norm [ iota; zeta; delta_only [`%L.fold_right_gtot; `%L.map_gtot]; delta_attr [`%__reduce__]; primops; simplify ] x (** A useful lemma to relate terms to their implicilty reducing variants *) val normal_eq (#a: Type) (f: a) : Lemma (f == normal f) (**** Map and fold *) (** A utility that combines map and fold: [map_op' op f l z] maps each element of [l] by [f] and then combines them using [op] *) [@@ __reduce__] let map_op' #a #b #c (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (l: list a) (z: c) : GTot c = L.fold_right_gtot #a #c l (fun x acc -> (f x) `op` acc) z (** Equations for [map_op'] showing how it folds over the empty list *) val map_op'_nil (#a #b #c: Type) (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (z: c) : Lemma (map_op' op f [] z == z) (** Equations for [map_op'] showing how it folds over a cons cell *) val map_op'_cons (#a #b #c: Type) (op: (b -> c -> GTot c)) (f: (a -> GTot b)) (hd: a) (tl: list a) (z: c) : Lemma (map_op' op f (hd :: tl) z == (f hd) `op` (map_op' op f tl z)) (**** Conjunction *) (** [big_and' f l] = [/\_{x in l} f x] *) [@@ __reduce__] let big_and' #a (f: (a -> Type)) (l: list a) : Type = map_op' l_and f l True (** Equations for [big_and'] showing it to be trivial over the empty list *) val big_and'_nil (#a: Type) (f: (a -> Type)) : Lemma (big_and' f [] == True) (** Equations for [big_and'] showing it to be a fold over a list with [/\] *) val big_and'_cons (#a: Type) (f: (a -> Type)) (hd: a) (tl: list a) : Lemma (big_and' f (hd :: tl) == (f hd /\ big_and' f tl)) (** [big_and' f l] is a [prop], i.e., it is proof irrelevant. Note: defining `big_and'` to intrinsically be in `prop` is also possible, but it's much more tedious in proofs. This is in part because the [/\] is not defined in prop, though one can prove that [a /\ b] is a prop. The discrepancy means that I preferred to prove these operators in [prop] extrinsically. *) val big_and'_prop (#a: Type) (f: (a -> Type)) (l: list a) : Lemma ((big_and' f l) `subtype_of` unit) (** Interpreting the finite conjunction [big_and f l] as an infinite conjunction [forall] *) val big_and'_forall (#a: Type) (f: (a -> Type)) (l: list a) : Lemma (big_and' f l <==> (forall x. L.memP x l ==> f x)) (** [big_and f l] is an implicitly reducing variant of [big_and'] It is defined in [prop] *) [@@ __reduce__] unfold let big_and #a (f: (a -> Type)) (l: list a) : prop = big_and'_prop f l; normal (big_and' f l) (**** Disjunction *) (** [big_or f l] = [\/_{x in l} f x] *) [@@ __reduce__] let big_or' #a (f: (a -> Type)) (l: list a) : Type = map_op' l_or f l False (** Equations for [big_or] showing it to be [False] on the empty list *) val big_or'_nil (#a: Type) (f: (a -> Type)) : Lemma (big_or' f [] == False) (** Equations for [big_or] showing it to fold over a list *) val big_or'_cons (#a: Type) (f: (a -> Type)) (hd: a) (tl: list a) : Lemma (big_or' f (hd :: tl) == (f hd \/ big_or' f tl)) (** [big_or f l] is a `prop` See the remark above on the style of proof for prop *) val big_or'_prop (#a: Type) (f: (a -> Type)) (l: list a) : Lemma ((big_or' f l) `subtype_of` unit) (** Interpreting the finite disjunction [big_or f l] as an infinite disjunction [exists] *) val big_or'_exists (#a: Type) (f: (a -> Type)) (l: list a) : Lemma (big_or' f l <==> (exists x. L.memP x l /\ f x)) (** [big_or f l] is an implicitly reducing variant of [big_or'] It is defined in [prop] *) [@@ __reduce__] unfold let big_or #a (f: (a -> Type)) (l: list a) : prop = big_or'_prop f l; normal (big_or' f l) (**** Pairwise operators *) /// We provide functions to apply a reflexive, symmetric binary /// operator to elements in a list [l] pairwise, in a triangle of /// elements in the square matrix of [l X l]. To illustrate, for a /// list of [n] elements, we fold the operator over the pairwise /// elements of the list in top-down, left-to-right order of the /// diagram below /// /// /// {[ /// 0 1 2 3 ... n /// 0 /// 1 x /// 2 x x /// 3 x x x /// . x x x x /// n x x x x ]} (** Mapping pairs of elements of [l] using [f] and combining them with [op]. *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.BigOps.fsti" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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
op: (_: b -> _: b -> Prims.GTot b) -> f: (_: a -> _: a -> b) -> l: Prims.list a -> z: b -> Prims.GTot b
Prims.GTot
[ "sometrivial" ]
[]
[ "Prims.list", "FStar.BigOps.map_op'", "FStar.BigOps.pairwise_op'" ]
[ "recursion" ]
false
false
false
false
false
let rec pairwise_op' #a #b (op: (b -> b -> GTot b)) (f: (a -> a -> b)) (l: list a) (z: b) : GTot b =
match l with | [] -> z | hd :: tl -> (map_op' op (f hd) tl z) `op` (pairwise_op' op f tl z)
false
Vale.AES.GF128.fsti
Vale.AES.GF128.quad32_shift_2_left_1
val quad32_shift_2_left_1 (qa qb: quad32) : quad32 & quad32
val quad32_shift_2_left_1 (qa qb: quad32) : quad32 & quad32
let quad32_shift_2_left_1 (qa qb:quad32) : quad32 & quad32 = let la = four_map (fun (i:nat32) -> ishl i 1) qa in let lb = four_map (fun (i:nat32) -> ishl i 1) qb in let ra = four_map (fun (i:nat32) -> ishr i 31) qa in let rb = four_map (fun (i:nat32) -> ishr i 31) qb in let Mkfour ra0 ra1 ra2 ra3 = ra in let Mkfour rb0 rb1 rb2 rb3 = rb in let qa' = quad32_xor la (Mkfour 0 ra0 ra1 ra2) in let qb' = quad32_xor lb (quad32_xor (Mkfour ra3 0 0 0) (Mkfour 0 rb0 rb1 rb2)) in (qa', qb')
{ "file_name": "vale/code/crypto/aes/Vale.AES.GF128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 12, "end_line": 29, "start_col": 0, "start_line": 20 }
module Vale.AES.GF128 open FStar.Seq open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GF128_s open Vale.Math.Poly2_s open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2 open Vale.Math.Poly2.Lemmas let quad32_shift_left_1 (q:quad32) : quad32 = let l = four_map (fun (i:nat32) -> ishl i 1) q in let r = four_map (fun (i:nat32) -> ishr i 31) q in let Mkfour r0 r1 r2 r3 = r in quad32_xor l (Mkfour 0 r0 r1 r2)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GF128.fsti" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
qa: Vale.Def.Types_s.quad32 -> qb: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32 * Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.natN", "Vale.Def.Words_s.pow2_32", "FStar.Pervasives.Native.Mktuple2", "Vale.Def.Types_s.quad32_xor", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "FStar.Pervasives.Native.tuple2", "Vale.Def.Words_s.four", "Vale.Def.Words.Four_s.four_map", "Vale.Def.Types_s.ishr", "Vale.Def.Types_s.ishl" ]
[]
false
false
false
true
false
let quad32_shift_2_left_1 (qa qb: quad32) : quad32 & quad32 =
let la = four_map (fun (i: nat32) -> ishl i 1) qa in let lb = four_map (fun (i: nat32) -> ishl i 1) qb in let ra = four_map (fun (i: nat32) -> ishr i 31) qa in let rb = four_map (fun (i: nat32) -> ishr i 31) qb in let Mkfour ra0 ra1 ra2 ra3 = ra in let Mkfour rb0 rb1 rb2 rb3 = rb in let qa' = quad32_xor la (Mkfour 0 ra0 ra1 ra2) in let qb' = quad32_xor lb (quad32_xor (Mkfour ra3 0 0 0) (Mkfour 0 rb0 rb1 rb2)) in (qa', qb')
false
Vale.AES.GF128.fsti
Vale.AES.GF128.quad32_shift_left_1
val quad32_shift_left_1 (q: quad32) : quad32
val quad32_shift_left_1 (q: quad32) : quad32
let quad32_shift_left_1 (q:quad32) : quad32 = let l = four_map (fun (i:nat32) -> ishl i 1) q in let r = four_map (fun (i:nat32) -> ishr i 31) q in let Mkfour r0 r1 r2 r3 = r in quad32_xor l (Mkfour 0 r0 r1 r2)
{ "file_name": "vale/code/crypto/aes/Vale.AES.GF128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 18, "start_col": 0, "start_line": 14 }
module Vale.AES.GF128 open FStar.Seq open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GF128_s open Vale.Math.Poly2_s open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2 open Vale.Math.Poly2.Lemmas
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GF128.fsti" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
q: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32
Prims.Tot
[ "total" ]
[]
[ "Vale.Def.Types_s.quad32", "Vale.Def.Words_s.natN", "Vale.Def.Words_s.pow2_32", "Vale.Def.Types_s.quad32_xor", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.nat32", "Vale.Def.Words_s.four", "Vale.Def.Words.Four_s.four_map", "Vale.Def.Types_s.ishr", "Vale.Def.Types_s.ishl" ]
[]
false
false
false
true
false
let quad32_shift_left_1 (q: quad32) : quad32 =
let l = four_map (fun (i: nat32) -> ishl i 1) q in let r = four_map (fun (i: nat32) -> ishr i 31) q in let Mkfour r0 r1 r2 r3 = r in quad32_xor l (Mkfour 0 r0 r1 r2)
false
Vale.AES.GF128.fsti
Vale.AES.GF128.gf128_low_shift
val gf128_low_shift:poly
val gf128_low_shift:poly
let gf128_low_shift : poly = shift gf128_modulus_low_terms (-1)
{ "file_name": "vale/code/crypto/aes/Vale.AES.GF128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 63, "end_line": 149, "start_col": 0, "start_line": 149 }
module Vale.AES.GF128 open FStar.Seq open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GF128_s open Vale.Math.Poly2_s open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2 open Vale.Math.Poly2.Lemmas let quad32_shift_left_1 (q:quad32) : quad32 = let l = four_map (fun (i:nat32) -> ishl i 1) q in let r = four_map (fun (i:nat32) -> ishr i 31) q in let Mkfour r0 r1 r2 r3 = r in quad32_xor l (Mkfour 0 r0 r1 r2) let quad32_shift_2_left_1 (qa qb:quad32) : quad32 & quad32 = let la = four_map (fun (i:nat32) -> ishl i 1) qa in let lb = four_map (fun (i:nat32) -> ishl i 1) qb in let ra = four_map (fun (i:nat32) -> ishr i 31) qa in let rb = four_map (fun (i:nat32) -> ishr i 31) qb in let Mkfour ra0 ra1 ra2 ra3 = ra in let Mkfour rb0 rb1 rb2 rb3 = rb in let qa' = quad32_xor la (Mkfour 0 ra0 ra1 ra2) in let qb' = quad32_xor lb (quad32_xor (Mkfour ra3 0 0 0) (Mkfour 0 rb0 rb1 rb2)) in (qa', qb') val lemma_shift_left_1 (a:poly) : Lemma (requires degree a < 128) (ensures to_quad32 (shift a 1) == quad32_shift_left_1 (to_quad32 a)) val lemma_shift_2_left_1 (lo hi:poly) : Lemma (requires degree hi < 127 /\ degree lo < 128) (ensures ( let n = monomial 128 in let a = hi *. n +. lo in let a' = shift a 1 in let (lo', hi') = quad32_shift_2_left_1 (to_quad32 lo) (to_quad32 hi) in lo' == to_quad32 (a' %. n) /\ hi' == to_quad32 (a' /. n) )) // TODO: move this to Poly library val lemma_reverse_reverse (a:poly) (n:nat) : Lemma (requires degree a <= n) (ensures reverse (reverse a n) n == a) [SMTPat (reverse (reverse a n) n)] val lemma_gf128_degree (_:unit) : Lemma (ensures degree gf128_modulus_low_terms == 7 /\ degree (monomial 128) == 128 /\ degree gf128_modulus == 128 ) val lemma_gf128_constant_rev (q:quad32) : Lemma (ensures to_quad32 (reverse gf128_modulus_low_terms 127) == Mkfour 0 0 0 0xe1000000 /\ quad32_xor q q == Mkfour 0 0 0 0 ) val lemma_quad32_double_hi_rev (a:poly) : Lemma (requires degree a <= 127 /\ degree (reverse a 127) <= 63) (ensures of_double32 (quad32_double_hi (to_quad32 a)) == reverse (reverse a 127) 63) // Compute 128-bit multiply in terms of 64-bit multiplies val lemma_gf128_mul (a b c d:poly) (n:nat) : Lemma (ensures ( let m = monomial n in let ab = a *. m +. b in let cd = c *. m +. d in let ac = a *. c in let ad = a *. d in let bc = b *. c in let bd = b *. d in ab *. cd == shift (ac +. bc /. m +. ad /. m) (n + n) +. ((bc %. m) *. m +. (ad %. m) *. m +. bd) )) // Compute (a * b) % g, where g = n + h and %. n is easy to compute (e.g. n = x^128) val lemma_gf128_reduce (a b g n h:poly) : Lemma (requires degree h >= 0 /\ degree n > 2 * degree h /\ degree g == degree n /\ degree a <= degree n /\ degree b <= degree n /\ g == n +. h ) (ensures ( let d = (a *. b) /. n in let dh = d *. h in degree ((dh /. n) *. h) <= 2 * degree h /\ (a *. b) %. g == (dh /. n) *. h +. dh %. n +. (a *. b) %. n )) val lemma_gf128_reduce_rev (a b h:poly) (n:pos) : Lemma (requires degree h >= 0 /\ n > 2 * degree h /\ degree (monomial n +. h) == n /\ degree a < n /\ degree b < n ) (ensures ( let m = monomial n in let g = m +. h in let r x = reverse x (n - 1) in let rr x = reverse x (2 * n - 1) in let rab = rr (a *. b) in let rd = rab %. m in let rdh = rr (r rd *. h) in let rdhL = rdh %. m in let rdhLh = r (r rdhL *. h) in degree (r rdhL) <= 2 * degree h /\ degree (r rdhLh) <= 2 * degree h /\ r ((a *. b) %. g) == rdhLh +. rdh /. m +. rab /. m )) val lemma_reduce_rev (a0 a1 a2 h:poly) (n:pos) : Lemma (requires n == 64 /\ // verification times out unless n is known degree a0 < n + n /\ degree a1 < n + n /\ degree a2 < n + n /\ degree (monomial (n + n) +. h) == n + n /\ degree h < n /\ h.[0] ) (ensures ( let nn = n + n in let mm = monomial nn in let m = monomial n in let g = mm +. h in let c = reverse (shift h (-1)) (n - 1) in let y_10 = a0 +. shift (mask a1 64) 64 in let y_0 = mask y_10 64 in let y_10c = swap y_10 64 +. y_0 *. c in let a = a0 +. shift a1 64 +. shift a2 128 in let x = reverse a (nn + nn - 1) in reverse (x %. g) (nn - 1) == swap y_10c 64 +. (a2 +. shift a1 (-64)) +. mask y_10c 64 *. c ))
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GF128.fsti" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.shift", "Vale.AES.GF128_s.gf128_modulus_low_terms", "Prims.op_Minus" ]
[]
false
false
false
true
false
let gf128_low_shift:poly =
shift gf128_modulus_low_terms (- 1)
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.mul64_wide_add3
val mul64_wide_add3: #m0:scale64 -> #m1:scale64 -> #m2:scale64 -> #m3:scale64 -> #m4:scale64 -> #m5:scale64 -> a0:uint64{felem_fits1 a0 m0} -> a1:uint64{felem_fits1 a1 m1} -> b0:uint64{felem_fits1 b0 m2} -> b1:uint64{felem_fits1 b1 m3} -> c0:uint64{felem_fits1 c0 m4} -> c1:uint64{felem_fits1 c1 m5} -> Pure uint128 (requires m0 * m1 + m2 * m3 + m4 * m5 < 8192) (ensures fun res -> felem_wide_fits1 res (m0 * m1 + m2 * m3 + m4 * m5) /\ v res == v a0 * v a1 + v b0 * v b1 + v c0 * v c1)
val mul64_wide_add3: #m0:scale64 -> #m1:scale64 -> #m2:scale64 -> #m3:scale64 -> #m4:scale64 -> #m5:scale64 -> a0:uint64{felem_fits1 a0 m0} -> a1:uint64{felem_fits1 a1 m1} -> b0:uint64{felem_fits1 b0 m2} -> b1:uint64{felem_fits1 b1 m3} -> c0:uint64{felem_fits1 c0 m4} -> c1:uint64{felem_fits1 c1 m5} -> Pure uint128 (requires m0 * m1 + m2 * m3 + m4 * m5 < 8192) (ensures fun res -> felem_wide_fits1 res (m0 * m1 + m2 * m3 + m4 * m5) /\ v res == v a0 * v a1 + v b0 * v b1 + v c0 * v c1)
let mul64_wide_add3 #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1 = assert_norm (pow2 13 = 8192); mul64_wide_add3_lemma #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1; mul64_wide a0 a1 +! mul64_wide b0 b1 +! mul64_wide c0 c1
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 380, "start_col": 0, "start_line": 377 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul)) let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1) #push-options "--ifuel 1" val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1)) let lemma_mul_inv f cin = assert_norm (pow51 = pow2 51) #pop-options #push-options "--z3rlimit 100" inline_for_extraction noextract val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == feval_wide inp) let carry_wide5 (i0, i1, i2, i3, i4) = assert_norm (6579 < pow2 13); assert_norm (pow2 13 < max51); let tmp0, c0 = carry51_wide #6579 i0 (u64 0) in let tmp1, c1 = carry51_wide #4797 i1 c0 in let tmp2, c2 = carry51_wide #3340 i2 c1 in let tmp3, c3 = carry51_wide #1881 i3 c2 in let tmp4, c4 = carry51_wide #423 i4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; (tmp0', tmp1', tmp2, tmp3, tmp4) #pop-options inline_for_extraction noextract val fmul5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f1) (feval f2)} let fmul5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (tmp0, tmp1, tmp2, tmp3, tmp4) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp0, tmp1, tmp2, tmp3, tmp4) in carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) inline_for_extraction noextract val fmul25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> f3:felem5{felem_fits5 f3 (9, 10, 9, 9, 9)} -> f4:felem5{felem_fits5 f4 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f2) /\ feval out2 == fmul (feval f3) (feval f4)) let fmul25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) = let (tmp10, tmp11, tmp12, tmp13, tmp14) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp20, tmp21, tmp22, tmp23, tmp24) = precomp_r19 (f40, f41, f42, f43, f44) in let (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp10, tmp11, tmp12, tmp13, tmp14) in let (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) = mul_felem5 (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) (tmp20, tmp21, tmp22, tmp23, tmp24) in let (o10,o11,o12,o13,o14) = carry_wide5 (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) in let (o20,o21,o22,o23,o24) = carry_wide5 (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) in ((o10,o11,o12,o13,o14), (o20,o21,o22,o23,o24)) inline_for_extraction noextract val fmul15: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:uint64{felem_fits1 f2 1} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == (feval f1 * v f2) % prime) let fmul15 (f10, f11, f12, f13, f14) f2 = let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = smul_felem5 #1 #(9, 10, 9, 9, 9) f2 (f10, f11, f12, f13, f14) in let out = (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in [@inline_let] let res = carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (uint_v f2) prime; assert (feval res == feval_wide (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)); assert (feval res == (wide_as_nat5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)) % prime); assert (feval res == (v f2 * as_nat5 (f10, f11, f12, f13, f14)) % prime); FStar.Math.Lemmas.swap_mul (v f2) (as_nat5 (f10, f11, f12, f13, f14)); assert (feval res == (as_nat5 (f10, f11, f12, f13, f14) * v f2) % prime); res // inline_for_extraction noextract // val fsqr_felem5: // f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} // -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423)} // let fsqr_felem5 (f0, f1, f2, f3, f4) = // let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 20, 18, 18, 18) f0 (f0, u64 2 *! f1, u64 2 *! f2, u64 2 *! f3, u64 2 *! f4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(342, 0, 10, 18, 18) #(81, 180, 162, 162, 162) // f1 (u64 38 *! f4, u64 0, f1, u64 2 *! f2, u64 2 *! f3) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(342, 342, 0, 0, 9) #(3501, 180, 262, 342, 342) // f2 (u64 38 *! f3, u64 38 *! f4, u64 0, u64 0, f2) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 171, 342, 0, 0) #(6579, 3258, 262, 342, 423) // f3 (u64 0, u64 19 *. f3, u64 38 *. f4, u64 0, u64 0) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 0, 0, 171, 0) #(6579, 4797, 3340, 342, 423) // f4 (u64 0, u64 0, u64 0, u64 19 *. f4, u64 0) (o0, o1, o2, o3, o4) in // (o0, o1, o2, o3, o4) inline_for_extraction noextract val mul64_wide_add3: #m0:scale64 -> #m1:scale64 -> #m2:scale64 -> #m3:scale64 -> #m4:scale64 -> #m5:scale64 -> a0:uint64{felem_fits1 a0 m0} -> a1:uint64{felem_fits1 a1 m1} -> b0:uint64{felem_fits1 b0 m2} -> b1:uint64{felem_fits1 b1 m3} -> c0:uint64{felem_fits1 c0 m4} -> c1:uint64{felem_fits1 c1 m5} -> Pure uint128 (requires m0 * m1 + m2 * m3 + m4 * m5 < 8192) (ensures fun res -> felem_wide_fits1 res (m0 * m1 + m2 * m3 + m4 * m5) /\ v res == v a0 * v a1 + v b0 * v b1 + v c0 * v c1)
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a0: Lib.IntTypes.uint64{Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 a0 m0} -> a1: Lib.IntTypes.uint64{Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 a1 m1} -> b0: Lib.IntTypes.uint64{Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 b0 m2} -> b1: Lib.IntTypes.uint64{Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 b1 m3} -> c0: Lib.IntTypes.uint64{Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 c0 m4} -> c1: Lib.IntTypes.uint64{Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 c1 m5} -> Prims.Pure Lib.IntTypes.uint128
Prims.Pure
[]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.scale64", "Lib.IntTypes.uint64", "Prims.b2t", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits1", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "Lib.IntTypes.mul64_wide", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.mul64_wide_add3_lemma", "FStar.Pervasives.assert_norm", "Prims.op_Equality", "Prims.int", "Prims.pow2", "Lib.IntTypes.uint128" ]
[]
false
false
false
false
false
let mul64_wide_add3 #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1 =
assert_norm (pow2 13 = 8192); mul64_wide_add3_lemma #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1; mul64_wide a0 a1 +! mul64_wide b0 b1 +! mul64_wide c0 c1
false
Vale.AES.GF128.fsti
Vale.AES.GF128.gf128_rev_shift
val gf128_rev_shift:poly
val gf128_rev_shift:poly
let gf128_rev_shift : poly = reverse gf128_low_shift 127
{ "file_name": "vale/code/crypto/aes/Vale.AES.GF128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 152, "start_col": 0, "start_line": 152 }
module Vale.AES.GF128 open FStar.Seq open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GF128_s open Vale.Math.Poly2_s open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2 open Vale.Math.Poly2.Lemmas let quad32_shift_left_1 (q:quad32) : quad32 = let l = four_map (fun (i:nat32) -> ishl i 1) q in let r = four_map (fun (i:nat32) -> ishr i 31) q in let Mkfour r0 r1 r2 r3 = r in quad32_xor l (Mkfour 0 r0 r1 r2) let quad32_shift_2_left_1 (qa qb:quad32) : quad32 & quad32 = let la = four_map (fun (i:nat32) -> ishl i 1) qa in let lb = four_map (fun (i:nat32) -> ishl i 1) qb in let ra = four_map (fun (i:nat32) -> ishr i 31) qa in let rb = four_map (fun (i:nat32) -> ishr i 31) qb in let Mkfour ra0 ra1 ra2 ra3 = ra in let Mkfour rb0 rb1 rb2 rb3 = rb in let qa' = quad32_xor la (Mkfour 0 ra0 ra1 ra2) in let qb' = quad32_xor lb (quad32_xor (Mkfour ra3 0 0 0) (Mkfour 0 rb0 rb1 rb2)) in (qa', qb') val lemma_shift_left_1 (a:poly) : Lemma (requires degree a < 128) (ensures to_quad32 (shift a 1) == quad32_shift_left_1 (to_quad32 a)) val lemma_shift_2_left_1 (lo hi:poly) : Lemma (requires degree hi < 127 /\ degree lo < 128) (ensures ( let n = monomial 128 in let a = hi *. n +. lo in let a' = shift a 1 in let (lo', hi') = quad32_shift_2_left_1 (to_quad32 lo) (to_quad32 hi) in lo' == to_quad32 (a' %. n) /\ hi' == to_quad32 (a' /. n) )) // TODO: move this to Poly library val lemma_reverse_reverse (a:poly) (n:nat) : Lemma (requires degree a <= n) (ensures reverse (reverse a n) n == a) [SMTPat (reverse (reverse a n) n)] val lemma_gf128_degree (_:unit) : Lemma (ensures degree gf128_modulus_low_terms == 7 /\ degree (monomial 128) == 128 /\ degree gf128_modulus == 128 ) val lemma_gf128_constant_rev (q:quad32) : Lemma (ensures to_quad32 (reverse gf128_modulus_low_terms 127) == Mkfour 0 0 0 0xe1000000 /\ quad32_xor q q == Mkfour 0 0 0 0 ) val lemma_quad32_double_hi_rev (a:poly) : Lemma (requires degree a <= 127 /\ degree (reverse a 127) <= 63) (ensures of_double32 (quad32_double_hi (to_quad32 a)) == reverse (reverse a 127) 63) // Compute 128-bit multiply in terms of 64-bit multiplies val lemma_gf128_mul (a b c d:poly) (n:nat) : Lemma (ensures ( let m = monomial n in let ab = a *. m +. b in let cd = c *. m +. d in let ac = a *. c in let ad = a *. d in let bc = b *. c in let bd = b *. d in ab *. cd == shift (ac +. bc /. m +. ad /. m) (n + n) +. ((bc %. m) *. m +. (ad %. m) *. m +. bd) )) // Compute (a * b) % g, where g = n + h and %. n is easy to compute (e.g. n = x^128) val lemma_gf128_reduce (a b g n h:poly) : Lemma (requires degree h >= 0 /\ degree n > 2 * degree h /\ degree g == degree n /\ degree a <= degree n /\ degree b <= degree n /\ g == n +. h ) (ensures ( let d = (a *. b) /. n in let dh = d *. h in degree ((dh /. n) *. h) <= 2 * degree h /\ (a *. b) %. g == (dh /. n) *. h +. dh %. n +. (a *. b) %. n )) val lemma_gf128_reduce_rev (a b h:poly) (n:pos) : Lemma (requires degree h >= 0 /\ n > 2 * degree h /\ degree (monomial n +. h) == n /\ degree a < n /\ degree b < n ) (ensures ( let m = monomial n in let g = m +. h in let r x = reverse x (n - 1) in let rr x = reverse x (2 * n - 1) in let rab = rr (a *. b) in let rd = rab %. m in let rdh = rr (r rd *. h) in let rdhL = rdh %. m in let rdhLh = r (r rdhL *. h) in degree (r rdhL) <= 2 * degree h /\ degree (r rdhLh) <= 2 * degree h /\ r ((a *. b) %. g) == rdhLh +. rdh /. m +. rab /. m )) val lemma_reduce_rev (a0 a1 a2 h:poly) (n:pos) : Lemma (requires n == 64 /\ // verification times out unless n is known degree a0 < n + n /\ degree a1 < n + n /\ degree a2 < n + n /\ degree (monomial (n + n) +. h) == n + n /\ degree h < n /\ h.[0] ) (ensures ( let nn = n + n in let mm = monomial nn in let m = monomial n in let g = mm +. h in let c = reverse (shift h (-1)) (n - 1) in let y_10 = a0 +. shift (mask a1 64) 64 in let y_0 = mask y_10 64 in let y_10c = swap y_10 64 +. y_0 *. c in let a = a0 +. shift a1 64 +. shift a2 128 in let x = reverse a (nn + nn - 1) in reverse (x %. g) (nn - 1) == swap y_10c 64 +. (a2 +. shift a1 (-64)) +. mask y_10c 64 *. c )) // of_fun 8 (fun (i:nat) -> i = 0 || i = 1 || i = 6) let gf128_low_shift : poly = shift gf128_modulus_low_terms (-1)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GF128.fsti" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Vale.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2_s.reverse", "Vale.AES.GF128.gf128_low_shift" ]
[]
false
false
false
true
false
let gf128_rev_shift:poly =
reverse gf128_low_shift 127
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.mul_felem5
val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)}
val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)}
let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 206, "start_col": 0, "start_line": 195 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f1: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f1 (9, 10, 9, 9, 9)} -> r: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 r (9, 10, 9, 9, 9)} -> r19: Hacl.Spec.Curve25519.Field51.Definition.felem5 { Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == Hacl.Spec.Curve25519.Field51.precomp_r19 r } -> out: Hacl.Spec.Curve25519.Field51.Definition.felem_wide5 { Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ Hacl.Spec.Curve25519.Field51.Definition.feval_wide out == Spec.Curve25519.fmul (Hacl.Spec.Curve25519.Field51.Definition.feval f1) (Hacl.Spec.Curve25519.Field51.Definition.feval r) }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Prims.l_and", "Prims.eq2", "Hacl.Spec.Curve25519.Field51.precomp_r19", "FStar.Pervasives.Native.Mktuple3", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.uint64", "Lib.IntTypes.uint128", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_fmul5", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide5", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits5", "Spec.Curve25519.elem", "Hacl.Spec.Curve25519.Field51.Definition.feval_wide", "Spec.Curve25519.fmul", "Hacl.Spec.Curve25519.Field51.Definition.feval", "Prims.int", "Hacl.Spec.Curve25519.Field51.Definition.wide_as_nat5", "Prims.op_Addition", "Lib.IntTypes.int_t", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "Prims.op_Multiply", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "Hacl.Spec.Curve25519.Field51.Definition.op_Plus_Star", "Hacl.Spec.Curve25519.Field51.Definition.op_Star_Hat", "Hacl.Spec.Curve25519.Field51.smul_add_felem5", "Hacl.Spec.Curve25519.Field51.smul_felem5" ]
[]
false
false
false
false
false
let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) =
let o0, o1, o2, o3, o4 = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let o0, o1, o2, o3, o4 = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let o0, o1, o2, o3, o4 = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let o0, o1, o2, o3, o4 = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let o0, o1, o2, o3, o4 = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4)
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.subtract_p5
val subtract_p5: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> Pure felem5 (requires True) (ensures fun out -> as_nat5 out == feval f /\ felem_fits5 out (1, 1, 1, 1, 1) /\ as_nat5 out < prime)
val subtract_p5: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> Pure felem5 (requires True) (ensures fun out -> as_nat5 out == feval f /\ felem_fits5 out (1, 1, 1, 1, 1) /\ as_nat5 out < prime)
let subtract_p5 (f0, f1, f2, f3, f4) = let m0 = gte_mask f0 (u64 0x7ffffffffffed) in let m1 = eq_mask f1 (u64 0x7ffffffffffff) in let m2 = eq_mask f2 (u64 0x7ffffffffffff) in let m3 = eq_mask f3 (u64 0x7ffffffffffff) in let m4 = eq_mask f4 (u64 0x7ffffffffffff) in let mask = m0 &. m1 &. m2 &. m3 &. m4 in let f0' = f0 -. (mask &. u64 0x7ffffffffffed) in let f1' = f1 -. (mask &. u64 0x7ffffffffffff) in let f2' = f2 -. (mask &. u64 0x7ffffffffffff) in let f3' = f3 -. (mask &. u64 0x7ffffffffffff) in let f4' = f4 -. (mask &. u64 0x7ffffffffffff) in logand_lemma mask (u64 0x7ffffffffffed); logand_lemma mask (u64 0x7ffffffffffff); lemma_subtract_p (f0, f1, f2, f3, f4) (f0', f1', f2', f3', f4'); (f0', f1', f2', f3', f4')
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 481, "start_col": 0, "start_line": 466 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul)) let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1) #push-options "--ifuel 1" val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1)) let lemma_mul_inv f cin = assert_norm (pow51 = pow2 51) #pop-options #push-options "--z3rlimit 100" inline_for_extraction noextract val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == feval_wide inp) let carry_wide5 (i0, i1, i2, i3, i4) = assert_norm (6579 < pow2 13); assert_norm (pow2 13 < max51); let tmp0, c0 = carry51_wide #6579 i0 (u64 0) in let tmp1, c1 = carry51_wide #4797 i1 c0 in let tmp2, c2 = carry51_wide #3340 i2 c1 in let tmp3, c3 = carry51_wide #1881 i3 c2 in let tmp4, c4 = carry51_wide #423 i4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; (tmp0', tmp1', tmp2, tmp3, tmp4) #pop-options inline_for_extraction noextract val fmul5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f1) (feval f2)} let fmul5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (tmp0, tmp1, tmp2, tmp3, tmp4) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp0, tmp1, tmp2, tmp3, tmp4) in carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) inline_for_extraction noextract val fmul25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> f3:felem5{felem_fits5 f3 (9, 10, 9, 9, 9)} -> f4:felem5{felem_fits5 f4 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f2) /\ feval out2 == fmul (feval f3) (feval f4)) let fmul25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) = let (tmp10, tmp11, tmp12, tmp13, tmp14) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp20, tmp21, tmp22, tmp23, tmp24) = precomp_r19 (f40, f41, f42, f43, f44) in let (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp10, tmp11, tmp12, tmp13, tmp14) in let (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) = mul_felem5 (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) (tmp20, tmp21, tmp22, tmp23, tmp24) in let (o10,o11,o12,o13,o14) = carry_wide5 (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) in let (o20,o21,o22,o23,o24) = carry_wide5 (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) in ((o10,o11,o12,o13,o14), (o20,o21,o22,o23,o24)) inline_for_extraction noextract val fmul15: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:uint64{felem_fits1 f2 1} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == (feval f1 * v f2) % prime) let fmul15 (f10, f11, f12, f13, f14) f2 = let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = smul_felem5 #1 #(9, 10, 9, 9, 9) f2 (f10, f11, f12, f13, f14) in let out = (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in [@inline_let] let res = carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (uint_v f2) prime; assert (feval res == feval_wide (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)); assert (feval res == (wide_as_nat5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)) % prime); assert (feval res == (v f2 * as_nat5 (f10, f11, f12, f13, f14)) % prime); FStar.Math.Lemmas.swap_mul (v f2) (as_nat5 (f10, f11, f12, f13, f14)); assert (feval res == (as_nat5 (f10, f11, f12, f13, f14) * v f2) % prime); res // inline_for_extraction noextract // val fsqr_felem5: // f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} // -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423)} // let fsqr_felem5 (f0, f1, f2, f3, f4) = // let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 20, 18, 18, 18) f0 (f0, u64 2 *! f1, u64 2 *! f2, u64 2 *! f3, u64 2 *! f4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(342, 0, 10, 18, 18) #(81, 180, 162, 162, 162) // f1 (u64 38 *! f4, u64 0, f1, u64 2 *! f2, u64 2 *! f3) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(342, 342, 0, 0, 9) #(3501, 180, 262, 342, 342) // f2 (u64 38 *! f3, u64 38 *! f4, u64 0, u64 0, f2) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 171, 342, 0, 0) #(6579, 3258, 262, 342, 423) // f3 (u64 0, u64 19 *. f3, u64 38 *. f4, u64 0, u64 0) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 0, 0, 171, 0) #(6579, 4797, 3340, 342, 423) // f4 (u64 0, u64 0, u64 0, u64 19 *. f4, u64 0) (o0, o1, o2, o3, o4) in // (o0, o1, o2, o3, o4) inline_for_extraction noextract val mul64_wide_add3: #m0:scale64 -> #m1:scale64 -> #m2:scale64 -> #m3:scale64 -> #m4:scale64 -> #m5:scale64 -> a0:uint64{felem_fits1 a0 m0} -> a1:uint64{felem_fits1 a1 m1} -> b0:uint64{felem_fits1 b0 m2} -> b1:uint64{felem_fits1 b1 m3} -> c0:uint64{felem_fits1 c0 m4} -> c1:uint64{felem_fits1 c1 m5} -> Pure uint128 (requires m0 * m1 + m2 * m3 + m4 * m5 < 8192) (ensures fun res -> felem_wide_fits1 res (m0 * m1 + m2 * m3 + m4 * m5) /\ v res == v a0 * v a1 + v b0 * v b1 + v c0 * v c1) let mul64_wide_add3 #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1 = assert_norm (pow2 13 = 8192); mul64_wide_add3_lemma #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1; mul64_wide a0 a1 +! mul64_wide b0 b1 +! mul64_wide c0 c1 inline_for_extraction noextract val fsqr_felem5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> Pure felem_wide5 (requires True) (ensures fun out -> felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f) (feval f)) let fsqr_felem5 (f0, f1, f2, f3, f4) = assert_norm (pow2 13 = 8192); let d0 = u64 2 *! f0 in let d1 = u64 2 *! f1 in let d2 = u64 38 *! f2 in let d3 = u64 19 *! f3 in let d419 = u64 19 *! f4 in let d4 = u64 2 *! d419 in let s0 = mul64_wide_add3 #9 #9 #342 #10 #342 #9 f0 f0 d4 f1 d2 f3 in let s1 = mul64_wide_add3 #18 #10 #342 #9 #171 #9 d0 f1 d4 f2 d3 f3 in let s2 = mul64_wide_add3 #18 #9 #10 #10 #342 #9 d0 f2 f1 f1 d4 f3 in let s3 = mul64_wide_add3 #18 #9 #20 #9 #9 #171 d0 f3 d1 f2 f4 d419 in let s4 = mul64_wide_add3 #18 #9 #20 #9 #9 #9 d0 f4 d1 f3 f2 f2 in lemma_fmul_fsqr5 (f0, f1, f2, f3, f4); (s0, s1, s2, s3, s4) inline_for_extraction noextract val fsqr5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f) (feval f)} let fsqr5 (f0, f1, f2, f3, f4) = let (o0, o1, o2, o3, o4) = fsqr_felem5 (f0, f1, f2, f3, f4) in carry_wide5 (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsqr25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f1) /\ feval out2 == fmul (feval f2) (feval f2)) let fsqr25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (o10, o11, o12, o13, o14) = fsqr_felem5 (f10, f11, f12, f13, f14) in let (o20, o21, o22, o23, o24) = fsqr_felem5 (f20, f21, f22, f23, f24) in let (o10, o11, o12, o13, o14) = carry_wide5 (o10, o11, o12, o13, o14) in let (o20, o21, o22, o23, o24) = carry_wide5 (o20, o21, o22, o23, o24) in ((o10, o11, o12, o13, o14), (o20, o21, o22, o23, o24)) #set-options "--z3rlimit 100 --max_fuel 2" inline_for_extraction noextract val carry_felem5_full: inp:felem5{mul_inv_t inp} -> out:felem5{feval out == feval inp /\ felem_fits5 out (1, 1, 1, 1, 1)} let carry_felem5_full (f0, f1, f2, f3, f4) = assert_norm (pow51 = pow2 51); let tmp0, c0 = carry51 f0 (u64 0) in let tmp1, c1 = carry51 f1 c0 in assert (if v f1 < pow2 51 then v tmp1 < pow2 51 else v tmp1 < 8192); let tmp2, c2 = carry51 f2 c1 in let tmp3, c3 = carry51 f3 c2 in let tmp4, c4 = carry51 f4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; [@inline_let] let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in (tmp0', tmp1', tmp2, tmp3, tmp4) inline_for_extraction noextract val subtract_p5: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> Pure felem5 (requires True) (ensures fun out -> as_nat5 out == feval f /\ felem_fits5 out (1, 1, 1, 1, 1) /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 2, "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
f: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f (1, 1, 1, 1, 1)} -> Prims.Pure Hacl.Spec.Curve25519.Field51.Definition.felem5
Prims.Pure
[]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Lib.IntTypes.uint64", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_subtract_p", "Lib.IntTypes.logand_lemma", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.u64", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.eq_mask", "Lib.IntTypes.gte_mask" ]
[]
false
false
false
false
false
let subtract_p5 (f0, f1, f2, f3, f4) =
let m0 = gte_mask f0 (u64 0x7ffffffffffed) in let m1 = eq_mask f1 (u64 0x7ffffffffffff) in let m2 = eq_mask f2 (u64 0x7ffffffffffff) in let m3 = eq_mask f3 (u64 0x7ffffffffffff) in let m4 = eq_mask f4 (u64 0x7ffffffffffff) in let mask = m0 &. m1 &. m2 &. m3 &. m4 in let f0' = f0 -. (mask &. u64 0x7ffffffffffed) in let f1' = f1 -. (mask &. u64 0x7ffffffffffff) in let f2' = f2 -. (mask &. u64 0x7ffffffffffff) in let f3' = f3 -. (mask &. u64 0x7ffffffffffff) in let f4' = f4 -. (mask &. u64 0x7ffffffffffff) in logand_lemma mask (u64 0x7ffffffffffed); logand_lemma mask (u64 0x7ffffffffffff); lemma_subtract_p (f0, f1, f2, f3, f4) (f0', f1', f2', f3', f4'); (f0', f1', f2', f3', f4')
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.smul_add_felem5
val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)}
val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)}
let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 168, "start_col": 0, "start_line": 152 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
u1: Lib.IntTypes.uint64{Hacl.Spec.Curve25519.Field51.Definition.felem_fits1 u1 m1} -> f2: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f2 m2} -> acc1: Hacl.Spec.Curve25519.Field51.Definition.felem_wide5 { Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* Hacl.Spec.Curve25519.Field51.Definition.s128x5 67108864 } -> acc2: Hacl.Spec.Curve25519.Field51.Definition.felem_wide5 { Hacl.Spec.Curve25519.Field51.Definition.wide_as_nat5 acc2 == Hacl.Spec.Curve25519.Field51.Definition.wide_as_nat5 acc1 + Lib.IntTypes.uint_v u1 * Hacl.Spec.Curve25519.Field51.Definition.as_nat5 f2 /\ Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits5 acc2 (m3 +* m1 *^ m2) }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.scale64", "Hacl.Spec.Curve25519.Field51.Definition.scale64_5", "Hacl.Spec.Curve25519.Field51.Definition.scale128_5", "Lib.IntTypes.uint64", "Prims.b2t", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits1", "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide5", "Prims.l_and", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits5", "Hacl.Spec.Curve25519.Field51.Definition.op_Less_Equals_Star", "Hacl.Spec.Curve25519.Field51.Definition.op_Plus_Star", "Hacl.Spec.Curve25519.Field51.Definition.op_Star_Hat", "Hacl.Spec.Curve25519.Field51.Definition.s128x5", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.uint128", "Prims.nat", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_smul_add_felem5", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.int_t", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Prims.op_Addition", "Prims.op_Multiply", "Lib.IntTypes.U64", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits1", "Hacl.Spec.Curve25519.Field51.mul_add_wide128", "Hacl.Spec.Curve25519.Field51.Definition.wide_as_nat5", "FStar.Mul.op_Star", "Lib.IntTypes.uint_v", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5" ]
[]
false
false
false
false
false
let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) =
let m20, m21, m22, m23, m24 = m2 in let m30, m31, m32, m33, m34 = m3 in [@@ inline_let ]let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@@ inline_let ]let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@@ inline_let ]let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@@ inline_let ]let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@@ inline_let ]let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@@ inline_let ]let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.carry_wide5
val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == feval_wide inp)
val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == feval_wide inp)
let carry_wide5 (i0, i1, i2, i3, i4) = assert_norm (6579 < pow2 13); assert_norm (pow2 13 < max51); let tmp0, c0 = carry51_wide #6579 i0 (u64 0) in let tmp1, c1 = carry51_wide #4797 i1 c0 in let tmp2, c2 = carry51_wide #3340 i2 c1 in let tmp3, c3 = carry51_wide #1881 i3 c2 in let tmp4, c4 = carry51_wide #423 i4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; (tmp0', tmp1', tmp2, tmp3, tmp4)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 282, "start_col": 0, "start_line": 268 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul)) let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1) #push-options "--ifuel 1" val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1)) let lemma_mul_inv f cin = assert_norm (pow51 = pow2 51) #pop-options #push-options "--z3rlimit 100" inline_for_extraction noextract val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out ->
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
inp: Hacl.Spec.Curve25519.Field51.Definition.felem_wide5 {Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Prims.Pure Hacl.Spec.Curve25519.Field51.Definition.felem5
Prims.Pure
[]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem_wide5", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Lib.IntTypes.uint128", "Lib.IntTypes.uint64", "Prims.unit", "Hacl.Spec.Curve25519.Field51.lemma_mul_inv", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Plus_Bang", "Hacl.Spec.Curve25519.Field51.Definition.felem5", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Curve25519.Field51.carry51", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.u64", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_carry5_simplify", "Hacl.Spec.Curve25519.Field51.carry51_wide", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Hacl.Spec.Curve25519.Field51.Definition.max51" ]
[]
false
false
false
false
false
let carry_wide5 (i0, i1, i2, i3, i4) =
assert_norm (6579 < pow2 13); assert_norm (pow2 13 < max51); let tmp0, c0 = carry51_wide #6579 i0 (u64 0) in let tmp1, c1 = carry51_wide #4797 i1 c0 in let tmp2, c2 = carry51_wide #3340 i2 c1 in let tmp3, c3 = carry51_wide #1881 i3 c2 in let tmp4, c4 = carry51_wide #423 i4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@@ inline_let ]let tmp1' = tmp1 +! c5 in lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; (tmp0', tmp1', tmp2, tmp3, tmp4)
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.lemma_mul_inv
val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1))
val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1))
let lemma_mul_inv f cin = assert_norm (pow51 = pow2 51)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 257, "start_col": 0, "start_line": 256 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul)) let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1) #push-options "--ifuel 1" val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 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.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f (1, 1, 1, 1, 1)} -> cin: Lib.IntTypes.uint64{Lib.IntTypes.v cin < Prims.pow2 51} -> FStar.Pervasives.Lemma (ensures (let _ = f in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ i0 i1 i2 i3 i4 = _ in FStar.Pervasives.assert_norm (Hacl.Spec.Curve25519.Field51.Definition.pow51 = Prims.pow2 51); let i1' = i1 +! cin in let out = i0, i1', i2, i3, i4 in (match (Lib.IntTypes.v i1 + Lib.IntTypes.v cin) / Prims.pow2 51 > 0 with | true -> Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 out (1, 2, 1, 1, 1) /\ (Lib.IntTypes.v i1 + Lib.IntTypes.v cin) % Prims.pow2 51 < Lib.IntTypes.v cin | _ -> Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 out (1, 1, 1, 1, 1)) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Lib.IntTypes.uint64", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.pow2", "FStar.Pervasives.assert_norm", "Prims.op_Equality", "Prims.pos", "Hacl.Spec.Curve25519.Field51.Definition.pow51", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_mul_inv f cin =
assert_norm (pow51 = pow2 51)
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.carry51_wide
val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1))
val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1))
let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul))
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 235, "start_col": 0, "start_line": 232 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Lib.IntTypes.uint128{Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits1 l m} -> cin: Lib.IntTypes.uint64 -> Prims.Pure (Lib.IntTypes.uint64 * Lib.IntTypes.uint64)
Prims.Pure
[]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.scale64", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.uint128", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide_fits1", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple2", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.to_u64", "Lib.IntTypes.U128", "Hacl.Spec.Curve25519.Field51.Definition.mask51", "Lib.IntTypes.op_Greater_Greater_Dot", "FStar.UInt32.__uint_to_t", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_carry51_wide", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.to_u128", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let carry51_wide #m l cin =
let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul))
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.carry_felem5_full
val carry_felem5_full: inp:felem5{mul_inv_t inp} -> out:felem5{feval out == feval inp /\ felem_fits5 out (1, 1, 1, 1, 1)}
val carry_felem5_full: inp:felem5{mul_inv_t inp} -> out:felem5{feval out == feval inp /\ felem_fits5 out (1, 1, 1, 1, 1)}
let carry_felem5_full (f0, f1, f2, f3, f4) = assert_norm (pow51 = pow2 51); let tmp0, c0 = carry51 f0 (u64 0) in let tmp1, c1 = carry51 f1 c0 in assert (if v f1 < pow2 51 then v tmp1 < pow2 51 else v tmp1 < 8192); let tmp2, c2 = carry51 f2 c1 in let tmp3, c3 = carry51 f3 c2 in let tmp4, c4 = carry51 f4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; [@inline_let] let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in (tmp0', tmp1', tmp2, tmp3, tmp4)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 455, "start_col": 0, "start_line": 442 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul)) let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1) #push-options "--ifuel 1" val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1)) let lemma_mul_inv f cin = assert_norm (pow51 = pow2 51) #pop-options #push-options "--z3rlimit 100" inline_for_extraction noextract val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == feval_wide inp) let carry_wide5 (i0, i1, i2, i3, i4) = assert_norm (6579 < pow2 13); assert_norm (pow2 13 < max51); let tmp0, c0 = carry51_wide #6579 i0 (u64 0) in let tmp1, c1 = carry51_wide #4797 i1 c0 in let tmp2, c2 = carry51_wide #3340 i2 c1 in let tmp3, c3 = carry51_wide #1881 i3 c2 in let tmp4, c4 = carry51_wide #423 i4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; (tmp0', tmp1', tmp2, tmp3, tmp4) #pop-options inline_for_extraction noextract val fmul5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f1) (feval f2)} let fmul5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (tmp0, tmp1, tmp2, tmp3, tmp4) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp0, tmp1, tmp2, tmp3, tmp4) in carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) inline_for_extraction noextract val fmul25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> f3:felem5{felem_fits5 f3 (9, 10, 9, 9, 9)} -> f4:felem5{felem_fits5 f4 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f2) /\ feval out2 == fmul (feval f3) (feval f4)) let fmul25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) = let (tmp10, tmp11, tmp12, tmp13, tmp14) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp20, tmp21, tmp22, tmp23, tmp24) = precomp_r19 (f40, f41, f42, f43, f44) in let (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp10, tmp11, tmp12, tmp13, tmp14) in let (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) = mul_felem5 (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) (tmp20, tmp21, tmp22, tmp23, tmp24) in let (o10,o11,o12,o13,o14) = carry_wide5 (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) in let (o20,o21,o22,o23,o24) = carry_wide5 (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) in ((o10,o11,o12,o13,o14), (o20,o21,o22,o23,o24)) inline_for_extraction noextract val fmul15: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:uint64{felem_fits1 f2 1} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == (feval f1 * v f2) % prime) let fmul15 (f10, f11, f12, f13, f14) f2 = let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = smul_felem5 #1 #(9, 10, 9, 9, 9) f2 (f10, f11, f12, f13, f14) in let out = (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in [@inline_let] let res = carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (uint_v f2) prime; assert (feval res == feval_wide (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)); assert (feval res == (wide_as_nat5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)) % prime); assert (feval res == (v f2 * as_nat5 (f10, f11, f12, f13, f14)) % prime); FStar.Math.Lemmas.swap_mul (v f2) (as_nat5 (f10, f11, f12, f13, f14)); assert (feval res == (as_nat5 (f10, f11, f12, f13, f14) * v f2) % prime); res // inline_for_extraction noextract // val fsqr_felem5: // f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} // -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423)} // let fsqr_felem5 (f0, f1, f2, f3, f4) = // let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 20, 18, 18, 18) f0 (f0, u64 2 *! f1, u64 2 *! f2, u64 2 *! f3, u64 2 *! f4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(342, 0, 10, 18, 18) #(81, 180, 162, 162, 162) // f1 (u64 38 *! f4, u64 0, f1, u64 2 *! f2, u64 2 *! f3) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(342, 342, 0, 0, 9) #(3501, 180, 262, 342, 342) // f2 (u64 38 *! f3, u64 38 *! f4, u64 0, u64 0, f2) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 171, 342, 0, 0) #(6579, 3258, 262, 342, 423) // f3 (u64 0, u64 19 *. f3, u64 38 *. f4, u64 0, u64 0) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 0, 0, 171, 0) #(6579, 4797, 3340, 342, 423) // f4 (u64 0, u64 0, u64 0, u64 19 *. f4, u64 0) (o0, o1, o2, o3, o4) in // (o0, o1, o2, o3, o4) inline_for_extraction noextract val mul64_wide_add3: #m0:scale64 -> #m1:scale64 -> #m2:scale64 -> #m3:scale64 -> #m4:scale64 -> #m5:scale64 -> a0:uint64{felem_fits1 a0 m0} -> a1:uint64{felem_fits1 a1 m1} -> b0:uint64{felem_fits1 b0 m2} -> b1:uint64{felem_fits1 b1 m3} -> c0:uint64{felem_fits1 c0 m4} -> c1:uint64{felem_fits1 c1 m5} -> Pure uint128 (requires m0 * m1 + m2 * m3 + m4 * m5 < 8192) (ensures fun res -> felem_wide_fits1 res (m0 * m1 + m2 * m3 + m4 * m5) /\ v res == v a0 * v a1 + v b0 * v b1 + v c0 * v c1) let mul64_wide_add3 #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1 = assert_norm (pow2 13 = 8192); mul64_wide_add3_lemma #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1; mul64_wide a0 a1 +! mul64_wide b0 b1 +! mul64_wide c0 c1 inline_for_extraction noextract val fsqr_felem5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> Pure felem_wide5 (requires True) (ensures fun out -> felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f) (feval f)) let fsqr_felem5 (f0, f1, f2, f3, f4) = assert_norm (pow2 13 = 8192); let d0 = u64 2 *! f0 in let d1 = u64 2 *! f1 in let d2 = u64 38 *! f2 in let d3 = u64 19 *! f3 in let d419 = u64 19 *! f4 in let d4 = u64 2 *! d419 in let s0 = mul64_wide_add3 #9 #9 #342 #10 #342 #9 f0 f0 d4 f1 d2 f3 in let s1 = mul64_wide_add3 #18 #10 #342 #9 #171 #9 d0 f1 d4 f2 d3 f3 in let s2 = mul64_wide_add3 #18 #9 #10 #10 #342 #9 d0 f2 f1 f1 d4 f3 in let s3 = mul64_wide_add3 #18 #9 #20 #9 #9 #171 d0 f3 d1 f2 f4 d419 in let s4 = mul64_wide_add3 #18 #9 #20 #9 #9 #9 d0 f4 d1 f3 f2 f2 in lemma_fmul_fsqr5 (f0, f1, f2, f3, f4); (s0, s1, s2, s3, s4) inline_for_extraction noextract val fsqr5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f) (feval f)} let fsqr5 (f0, f1, f2, f3, f4) = let (o0, o1, o2, o3, o4) = fsqr_felem5 (f0, f1, f2, f3, f4) in carry_wide5 (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsqr25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f1) /\ feval out2 == fmul (feval f2) (feval f2)) let fsqr25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (o10, o11, o12, o13, o14) = fsqr_felem5 (f10, f11, f12, f13, f14) in let (o20, o21, o22, o23, o24) = fsqr_felem5 (f20, f21, f22, f23, f24) in let (o10, o11, o12, o13, o14) = carry_wide5 (o10, o11, o12, o13, o14) in let (o20, o21, o22, o23, o24) = carry_wide5 (o20, o21, o22, o23, o24) in ((o10, o11, o12, o13, o14), (o20, o21, o22, o23, o24)) #set-options "--z3rlimit 100 --max_fuel 2" inline_for_extraction noextract val carry_felem5_full: inp:felem5{mul_inv_t inp}
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 2, "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
inp: Hacl.Spec.Curve25519.Field51.Definition.felem5{Hacl.Spec.Curve25519.Field51.mul_inv_t inp} -> out: Hacl.Spec.Curve25519.Field51.Definition.felem5 { Hacl.Spec.Curve25519.Field51.Definition.feval out == Hacl.Spec.Curve25519.Field51.Definition.feval inp /\ Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 out (1, 1, 1, 1, 1) }
Prims.Tot
[ "total" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.mul_inv_t", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Plus_Bang", "Prims.l_and", "Prims.eq2", "Spec.Curve25519.elem", "Hacl.Spec.Curve25519.Field51.Definition.feval", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "Prims.nat", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Curve25519.Field51.carry51", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.u64", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_carry5_simplify", "Prims._assert", "Prims.op_LessThan", "Lib.IntTypes.v", "Prims.pow2", "Prims.b2t", "Prims.bool", "FStar.Pervasives.assert_norm", "Prims.op_Equality", "Prims.pos", "Hacl.Spec.Curve25519.Field51.Definition.pow51" ]
[]
false
false
false
false
false
let carry_felem5_full (f0, f1, f2, f3, f4) =
assert_norm (pow51 = pow2 51); let tmp0, c0 = carry51 f0 (u64 0) in let tmp1, c1 = carry51 f1 c0 in assert (if v f1 < pow2 51 then v tmp1 < pow2 51 else v tmp1 < 8192); let tmp2, c2 = carry51 f2 c1 in let tmp3, c3 = carry51 f3 c2 in let tmp4, c4 = carry51 f4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; [@@ inline_let ]let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@@ inline_let ]let tmp1' = tmp1 +! c5 in (tmp0', tmp1', tmp2, tmp3, tmp4)
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.fsqr_felem5
val fsqr_felem5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> Pure felem_wide5 (requires True) (ensures fun out -> felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f) (feval f))
val fsqr_felem5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> Pure felem_wide5 (requires True) (ensures fun out -> felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f) (feval f))
let fsqr_felem5 (f0, f1, f2, f3, f4) = assert_norm (pow2 13 = 8192); let d0 = u64 2 *! f0 in let d1 = u64 2 *! f1 in let d2 = u64 38 *! f2 in let d3 = u64 19 *! f3 in let d419 = u64 19 *! f4 in let d4 = u64 2 *! d419 in let s0 = mul64_wide_add3 #9 #9 #342 #10 #342 #9 f0 f0 d4 f1 d2 f3 in let s1 = mul64_wide_add3 #18 #10 #342 #9 #171 #9 d0 f1 d4 f2 d3 f3 in let s2 = mul64_wide_add3 #18 #9 #10 #10 #342 #9 d0 f2 f1 f1 d4 f3 in let s3 = mul64_wide_add3 #18 #9 #20 #9 #9 #171 d0 f3 d1 f2 f4 d419 in let s4 = mul64_wide_add3 #18 #9 #20 #9 #9 #9 d0 f4 d1 f3 f2 f2 in lemma_fmul_fsqr5 (f0, f1, f2, f3, f4); (s0, s1, s2, s3, s4)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 407, "start_col": 0, "start_line": 391 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul)) let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1) #push-options "--ifuel 1" val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1)) let lemma_mul_inv f cin = assert_norm (pow51 = pow2 51) #pop-options #push-options "--z3rlimit 100" inline_for_extraction noextract val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == feval_wide inp) let carry_wide5 (i0, i1, i2, i3, i4) = assert_norm (6579 < pow2 13); assert_norm (pow2 13 < max51); let tmp0, c0 = carry51_wide #6579 i0 (u64 0) in let tmp1, c1 = carry51_wide #4797 i1 c0 in let tmp2, c2 = carry51_wide #3340 i2 c1 in let tmp3, c3 = carry51_wide #1881 i3 c2 in let tmp4, c4 = carry51_wide #423 i4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; (tmp0', tmp1', tmp2, tmp3, tmp4) #pop-options inline_for_extraction noextract val fmul5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f1) (feval f2)} let fmul5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (tmp0, tmp1, tmp2, tmp3, tmp4) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp0, tmp1, tmp2, tmp3, tmp4) in carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) inline_for_extraction noextract val fmul25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> f3:felem5{felem_fits5 f3 (9, 10, 9, 9, 9)} -> f4:felem5{felem_fits5 f4 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f2) /\ feval out2 == fmul (feval f3) (feval f4)) let fmul25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) = let (tmp10, tmp11, tmp12, tmp13, tmp14) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp20, tmp21, tmp22, tmp23, tmp24) = precomp_r19 (f40, f41, f42, f43, f44) in let (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp10, tmp11, tmp12, tmp13, tmp14) in let (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) = mul_felem5 (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) (tmp20, tmp21, tmp22, tmp23, tmp24) in let (o10,o11,o12,o13,o14) = carry_wide5 (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) in let (o20,o21,o22,o23,o24) = carry_wide5 (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) in ((o10,o11,o12,o13,o14), (o20,o21,o22,o23,o24)) inline_for_extraction noextract val fmul15: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:uint64{felem_fits1 f2 1} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == (feval f1 * v f2) % prime) let fmul15 (f10, f11, f12, f13, f14) f2 = let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = smul_felem5 #1 #(9, 10, 9, 9, 9) f2 (f10, f11, f12, f13, f14) in let out = (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in [@inline_let] let res = carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (uint_v f2) prime; assert (feval res == feval_wide (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)); assert (feval res == (wide_as_nat5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)) % prime); assert (feval res == (v f2 * as_nat5 (f10, f11, f12, f13, f14)) % prime); FStar.Math.Lemmas.swap_mul (v f2) (as_nat5 (f10, f11, f12, f13, f14)); assert (feval res == (as_nat5 (f10, f11, f12, f13, f14) * v f2) % prime); res // inline_for_extraction noextract // val fsqr_felem5: // f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} // -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423)} // let fsqr_felem5 (f0, f1, f2, f3, f4) = // let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 20, 18, 18, 18) f0 (f0, u64 2 *! f1, u64 2 *! f2, u64 2 *! f3, u64 2 *! f4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(342, 0, 10, 18, 18) #(81, 180, 162, 162, 162) // f1 (u64 38 *! f4, u64 0, f1, u64 2 *! f2, u64 2 *! f3) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(342, 342, 0, 0, 9) #(3501, 180, 262, 342, 342) // f2 (u64 38 *! f3, u64 38 *! f4, u64 0, u64 0, f2) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 171, 342, 0, 0) #(6579, 3258, 262, 342, 423) // f3 (u64 0, u64 19 *. f3, u64 38 *. f4, u64 0, u64 0) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 0, 0, 171, 0) #(6579, 4797, 3340, 342, 423) // f4 (u64 0, u64 0, u64 0, u64 19 *. f4, u64 0) (o0, o1, o2, o3, o4) in // (o0, o1, o2, o3, o4) inline_for_extraction noextract val mul64_wide_add3: #m0:scale64 -> #m1:scale64 -> #m2:scale64 -> #m3:scale64 -> #m4:scale64 -> #m5:scale64 -> a0:uint64{felem_fits1 a0 m0} -> a1:uint64{felem_fits1 a1 m1} -> b0:uint64{felem_fits1 b0 m2} -> b1:uint64{felem_fits1 b1 m3} -> c0:uint64{felem_fits1 c0 m4} -> c1:uint64{felem_fits1 c1 m5} -> Pure uint128 (requires m0 * m1 + m2 * m3 + m4 * m5 < 8192) (ensures fun res -> felem_wide_fits1 res (m0 * m1 + m2 * m3 + m4 * m5) /\ v res == v a0 * v a1 + v b0 * v b1 + v c0 * v c1) let mul64_wide_add3 #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1 = assert_norm (pow2 13 = 8192); mul64_wide_add3_lemma #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1; mul64_wide a0 a1 +! mul64_wide b0 b1 +! mul64_wide c0 c1 inline_for_extraction noextract val fsqr_felem5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> Pure felem_wide5 (requires True) (ensures fun out -> felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f (9, 10, 9, 9, 9)} -> Prims.Pure Hacl.Spec.Curve25519.Field51.Definition.felem_wide5
Prims.Pure
[]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "FStar.Pervasives.Native.Mktuple5", "Prims.nat", "Lib.IntTypes.uint64", "Lib.IntTypes.uint128", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_fmul_fsqr5", "Lib.IntTypes.int_t", "Lib.IntTypes.U128", "Lib.IntTypes.SEC", "Hacl.Spec.Curve25519.Field51.mul64_wide_add3", "Lib.IntTypes.U64", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.u64", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.pow2", "Hacl.Spec.Curve25519.Field51.Definition.felem_wide5" ]
[]
false
false
false
false
false
let fsqr_felem5 (f0, f1, f2, f3, f4) =
assert_norm (pow2 13 = 8192); let d0 = u64 2 *! f0 in let d1 = u64 2 *! f1 in let d2 = u64 38 *! f2 in let d3 = u64 19 *! f3 in let d419 = u64 19 *! f4 in let d4 = u64 2 *! d419 in let s0 = mul64_wide_add3 #9 #9 #342 #10 #342 #9 f0 f0 d4 f1 d2 f3 in let s1 = mul64_wide_add3 #18 #10 #342 #9 #171 #9 d0 f1 d4 f2 d3 f3 in let s2 = mul64_wide_add3 #18 #9 #10 #10 #342 #9 d0 f2 f1 f1 d4 f3 in let s3 = mul64_wide_add3 #18 #9 #20 #9 #9 #171 d0 f3 d1 f2 f4 d419 in let s4 = mul64_wide_add3 #18 #9 #20 #9 #9 #9 d0 f4 d1 f3 f2 f2 in lemma_fmul_fsqr5 (f0, f1, f2, f3, f4); (s0, s1, s2, s3, s4)
false
Vale.AES.GF128.fsti
Vale.AES.GF128.mod_rev
val mod_rev (n: pos) (a b: poly) : poly
val mod_rev (n: pos) (a b: poly) : poly
let mod_rev (n:pos) (a b:poly) : poly = reverse (reverse a (n + n - 1) %. b) (n - 1)
{ "file_name": "vale/code/crypto/aes/Vale.AES.GF128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 181, "start_col": 0, "start_line": 180 }
module Vale.AES.GF128 open FStar.Seq open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GF128_s open Vale.Math.Poly2_s open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2 open Vale.Math.Poly2.Lemmas let quad32_shift_left_1 (q:quad32) : quad32 = let l = four_map (fun (i:nat32) -> ishl i 1) q in let r = four_map (fun (i:nat32) -> ishr i 31) q in let Mkfour r0 r1 r2 r3 = r in quad32_xor l (Mkfour 0 r0 r1 r2) let quad32_shift_2_left_1 (qa qb:quad32) : quad32 & quad32 = let la = four_map (fun (i:nat32) -> ishl i 1) qa in let lb = four_map (fun (i:nat32) -> ishl i 1) qb in let ra = four_map (fun (i:nat32) -> ishr i 31) qa in let rb = four_map (fun (i:nat32) -> ishr i 31) qb in let Mkfour ra0 ra1 ra2 ra3 = ra in let Mkfour rb0 rb1 rb2 rb3 = rb in let qa' = quad32_xor la (Mkfour 0 ra0 ra1 ra2) in let qb' = quad32_xor lb (quad32_xor (Mkfour ra3 0 0 0) (Mkfour 0 rb0 rb1 rb2)) in (qa', qb') val lemma_shift_left_1 (a:poly) : Lemma (requires degree a < 128) (ensures to_quad32 (shift a 1) == quad32_shift_left_1 (to_quad32 a)) val lemma_shift_2_left_1 (lo hi:poly) : Lemma (requires degree hi < 127 /\ degree lo < 128) (ensures ( let n = monomial 128 in let a = hi *. n +. lo in let a' = shift a 1 in let (lo', hi') = quad32_shift_2_left_1 (to_quad32 lo) (to_quad32 hi) in lo' == to_quad32 (a' %. n) /\ hi' == to_quad32 (a' /. n) )) // TODO: move this to Poly library val lemma_reverse_reverse (a:poly) (n:nat) : Lemma (requires degree a <= n) (ensures reverse (reverse a n) n == a) [SMTPat (reverse (reverse a n) n)] val lemma_gf128_degree (_:unit) : Lemma (ensures degree gf128_modulus_low_terms == 7 /\ degree (monomial 128) == 128 /\ degree gf128_modulus == 128 ) val lemma_gf128_constant_rev (q:quad32) : Lemma (ensures to_quad32 (reverse gf128_modulus_low_terms 127) == Mkfour 0 0 0 0xe1000000 /\ quad32_xor q q == Mkfour 0 0 0 0 ) val lemma_quad32_double_hi_rev (a:poly) : Lemma (requires degree a <= 127 /\ degree (reverse a 127) <= 63) (ensures of_double32 (quad32_double_hi (to_quad32 a)) == reverse (reverse a 127) 63) // Compute 128-bit multiply in terms of 64-bit multiplies val lemma_gf128_mul (a b c d:poly) (n:nat) : Lemma (ensures ( let m = monomial n in let ab = a *. m +. b in let cd = c *. m +. d in let ac = a *. c in let ad = a *. d in let bc = b *. c in let bd = b *. d in ab *. cd == shift (ac +. bc /. m +. ad /. m) (n + n) +. ((bc %. m) *. m +. (ad %. m) *. m +. bd) )) // Compute (a * b) % g, where g = n + h and %. n is easy to compute (e.g. n = x^128) val lemma_gf128_reduce (a b g n h:poly) : Lemma (requires degree h >= 0 /\ degree n > 2 * degree h /\ degree g == degree n /\ degree a <= degree n /\ degree b <= degree n /\ g == n +. h ) (ensures ( let d = (a *. b) /. n in let dh = d *. h in degree ((dh /. n) *. h) <= 2 * degree h /\ (a *. b) %. g == (dh /. n) *. h +. dh %. n +. (a *. b) %. n )) val lemma_gf128_reduce_rev (a b h:poly) (n:pos) : Lemma (requires degree h >= 0 /\ n > 2 * degree h /\ degree (monomial n +. h) == n /\ degree a < n /\ degree b < n ) (ensures ( let m = monomial n in let g = m +. h in let r x = reverse x (n - 1) in let rr x = reverse x (2 * n - 1) in let rab = rr (a *. b) in let rd = rab %. m in let rdh = rr (r rd *. h) in let rdhL = rdh %. m in let rdhLh = r (r rdhL *. h) in degree (r rdhL) <= 2 * degree h /\ degree (r rdhLh) <= 2 * degree h /\ r ((a *. b) %. g) == rdhLh +. rdh /. m +. rab /. m )) val lemma_reduce_rev (a0 a1 a2 h:poly) (n:pos) : Lemma (requires n == 64 /\ // verification times out unless n is known degree a0 < n + n /\ degree a1 < n + n /\ degree a2 < n + n /\ degree (monomial (n + n) +. h) == n + n /\ degree h < n /\ h.[0] ) (ensures ( let nn = n + n in let mm = monomial nn in let m = monomial n in let g = mm +. h in let c = reverse (shift h (-1)) (n - 1) in let y_10 = a0 +. shift (mask a1 64) 64 in let y_0 = mask y_10 64 in let y_10c = swap y_10 64 +. y_0 *. c in let a = a0 +. shift a1 64 +. shift a2 128 in let x = reverse a (nn + nn - 1) in reverse (x %. g) (nn - 1) == swap y_10c 64 +. (a2 +. shift a1 (-64)) +. mask y_10c 64 *. c )) // of_fun 8 (fun (i:nat) -> i = 0 || i = 1 || i = 6) let gf128_low_shift : poly = shift gf128_modulus_low_terms (-1) // of_fun 8 (fun (i:nat) -> i = 127 || i = 126 || i = 121) let gf128_rev_shift : poly = reverse gf128_low_shift 127 val lemma_gf128_low_shift (_:unit) : Lemma (shift (of_quad32 (Mkfour 0 0 0 0xc2000000)) (-64) == reverse gf128_low_shift 63) val lemma_gf128_high_bit (_:unit) : Lemma (of_quad32 (Mkfour 0 0 0 0x80000000) == monomial 127) val lemma_gf128_low_shift_1 (_:unit) : Lemma (of_quad32 (Mkfour 1 0 0 0xc2000000) == reverse (shift (monomial 128 +. gf128_modulus_low_terms) (-1)) 127) let gf128_mul_rev (a b:poly) : poly = reverse (gf128_mul (reverse a 127) (reverse b 127)) 127 let ( *~ ) = gf128_mul_rev val lemma_gf128_mul_rev_commute (a b:poly) : Lemma (a *~ b == b *~ a) val lemma_gf128_mul_rev_associate (a b c:poly) : Lemma (a *~ (b *~ c) == (a *~ b) *~ c) val lemma_gf128_mul_rev_distribute_left (a b c:poly) : Lemma ((a +. b) *~ c == a *~ c +. b *~ c) val lemma_gf128_mul_rev_distribute_right (a b c:poly) : Lemma (a *~ (b +. c) == a *~ b +. a *~ c)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GF128.fsti" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> a: Vale.Math.Poly2_s.poly -> b: Vale.Math.Poly2_s.poly -> Vale.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2_s.reverse", "Vale.Math.Poly2.op_Percent_Dot", "Prims.op_Subtraction", "Prims.op_Addition" ]
[]
false
false
false
true
false
let mod_rev (n: pos) (a b: poly) : poly =
reverse (reverse a (n + n - 1) %. b) (n - 1)
false
Hacl.Spec.Curve25519.Field51.fst
Hacl.Spec.Curve25519.Field51.store_felem5
val store_felem5: f:felem5{mul_inv_t f} -> Pure (uint64 & uint64 & uint64 & uint64) (requires True) (ensures fun (o0, o1, o2, o3) -> feval f == v o0 + v o1 * pow2 64 + v o2 * pow2 64 * pow2 64 + v o3 * pow2 64 * pow2 64 * pow2 64)
val store_felem5: f:felem5{mul_inv_t f} -> Pure (uint64 & uint64 & uint64 & uint64) (requires True) (ensures fun (o0, o1, o2, o3) -> feval f == v o0 + v o1 * pow2 64 + v o2 * pow2 64 * pow2 64 + v o3 * pow2 64 * pow2 64 * pow2 64)
let store_felem5 (f0, f1, f2, f3, f4) = let (f0, f1, f2, f3, f4) = carry_felem5_full (f0, f1, f2, f3, f4) in let (f0, f1, f2, f3, f4) = subtract_p5 (f0, f1, f2, f3, f4) in let o0 = f0 |. (f1 <<. 51ul) in let o1 = (f1 >>. 13ul) |. (f2 <<. 38ul) in let o2 = (f2 >>. 26ul) |. (f3 <<. 25ul) in let o3 = (f3 >>. 39ul) |. (f4 <<. 12ul) in lemma_store_felem (f0, f1, f2, f3, f4); (o0, o1, o2, o3)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 500, "start_col": 0, "start_line": 491 }
module Hacl.Spec.Curve25519.Field51 open Lib.Sequence open Lib.IntTypes open FStar.Mul open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition open Hacl.Spec.Curve25519.Field51.Lemmas #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --using_facts_from '* -FStar.Seq'" inline_for_extraction noextract val fadd5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (2, 4, 2, 2, 2) /\ feval out == fadd (feval f1) (feval f2)} let fadd5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let o0 = f10 +! f20 in let o1 = f11 +! f21 in let o2 = f12 +! f22 in let o3 = f13 +! f23 in let o4 = f14 +! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (as_nat5 (f20, f21, f22, f23, f24)) prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r ((as_nat5 (f10, f11, f12, f13, f14)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out inline_for_extraction noextract val fadd_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == feval f1} let fadd_zero (f10, f11, f12, f13, f14) = let o0 = f10 +! u64 0x3fffffffffff68 in let o1 = f11 +! u64 0x3ffffffffffff8 in let o2 = f12 +! u64 0x3ffffffffffff8 in let o3 = f13 +! u64 0x3ffffffffffff8 in let o4 = f14 +! u64 0x3ffffffffffff8 in lemma_add_zero (f10, f11, f12, f13, f14); (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsub5: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> out:felem5{felem_fits5 out (9, 10, 9, 9, 9) /\ feval out == fsub (feval f1) (feval f2)} let fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = //assert_norm (0x3fffffffffff68 == pow2 54 - 152); //assert_norm (0x3ffffffffffff8 == pow2 54 - 8); let (t0, t1, t2, t3, t4) = fadd_zero (f10, f11, f12, f13, f14) in let o0 = t0 -! f20 in let o1 = t1 -! f21 in let o2 = t2 -! f22 in let o3 = t3 -! f23 in let o4 = t4 -! f24 in let out = (o0, o1, o2, o3, o4) in FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat5 (t0, t1, t2, t3, t4)) (- as_nat5 (f20, f21, f22, f23, f24)) prime; lemma_mod_sub_distr ((as_nat5 (t0, t1, t2, t3, t4)) % prime) (as_nat5 (f20, f21, f22, f23, f24)) prime; out val lemma_fsub: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> f2:felem5{felem_fits5 f2 (1, 2, 1, 1, 1)} -> Lemma (let (f10, f11, f12, f13, f14) = f1 in let (f20, f21, f22, f23, f24) = f2 in let o0 = f10 +! u64 0x3fffffffffff68 -! f20 in let o1 = f11 +! u64 0x3ffffffffffff8 -! f21 in let o2 = f12 +! u64 0x3ffffffffffff8 -! f22 in let o3 = f13 +! u64 0x3ffffffffffff8 -! f23 in let o4 = f14 +! u64 0x3ffffffffffff8 -! f24 in let out = (o0, o1, o2, o3, o4) in out == fsub5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24)) let lemma_fsub f1 f2 = () inline_for_extraction noextract val mul_wide64: #m1:scale64 -> #m2:scale64 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2 /\ m1 * m2 <= 67108864} -> z:uint128{uint_v z == uint_v x * uint_v y /\ felem_wide_fits1 z (m1 * m2)} #push-options "--z3rlimit 5" let mul_wide64 #m1 #m2 x y = let open FStar.Math.Lemmas in lemma_mult_le_left (v x) (v y) (m2 * max51); //v x * v y <= v x * (m2 * max51) lemma_mult_le_right (m2 * max51) (v x) (m1 * max51); // v x * (m2 * max51) <= (m1 * max51) * (m2 * max51) paren_mul_right (m1 * max51) m2 max51; //(m1 * max51) * (m2 * max51) = ((m1 * max51) * m2) * max51 paren_mul_right m1 max51 m2; //(m1 * max51) * m2 = m1 * (max51 * m2) swap_mul max51 m2; //max51 * m2 = m2 * max51 paren_mul_right m1 m2 max51; //m1 * (m2 * max51) = (m1 * m2) * max51 paren_mul_right (m1 * m2) max51 max51; //((m1 * m2) * max51) * max51 = (m1 * m2) * (max51 * max51) assert (v x * v y <= m1 * max51 * m2 * max51); assert (v x * v y <= m1 * m2 * max51 * max51); mul64_wide x y #pop-options inline_for_extraction noextract val smul_felem5: #m1:scale64 -> #m2:scale64_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2 /\ m1 *^ m2 <=* s128x5 67108864} -> out:felem_wide5{felem_wide_fits5 out (m1 *^ m2) /\ wide_as_nat5 out == uint_v u1 * as_nat5 f2} let smul_felem5 #m1 #m2 u1 (f20, f21, f22, f23, f24) = let (m20, m21, m22, m23, m24) = m2 in [@inline_let] let o0 = mul_wide64 #m1 #m20 u1 f20 in [@inline_let] let o1 = mul_wide64 #m1 #m21 u1 f21 in [@inline_let] let o2 = mul_wide64 #m1 #m22 u1 f22 in [@inline_let] let o3 = mul_wide64 #m1 #m23 u1 f23 in [@inline_let] let o4 = mul_wide64 #m1 #m24 u1 f24 in [@inline_let] let out = (o0, o1, o2, o3, o4) in lemma_smul_felem5 u1 (f20, f21, f22, f23, f24); out inline_for_extraction noextract val mul_add_wide128: #m1:scale64 -> #m2:scale64 -> #m3:scale128 -> x:uint64{felem_fits1 x m1} -> y:uint64{felem_fits1 y m2} -> z:uint128{felem_wide_fits1 z m3 /\ m3 + m1 * m2 <= 67108864} -> r:uint128{uint_v r == uint_v z + uint_v x * uint_v y /\ felem_wide_fits1 r (m3 + m1 * m2)} let mul_add_wide128 #m1 #m2 #m3 x y z = z +! mul_wide64 #m1 #m2 x y #push-options "--z3rlimit 100" inline_for_extraction noextract val smul_add_felem5: #m1:scale64 -> #m2:scale64_5 -> #m3:scale128_5 -> u1:uint64{felem_fits1 u1 m1} -> f2:felem5{felem_fits5 f2 m2} -> acc1:felem_wide5{felem_wide_fits5 acc1 m3 /\ m3 +* m1 *^ m2 <=* s128x5 67108864} -> acc2:felem_wide5{ wide_as_nat5 acc2 == wide_as_nat5 acc1 + uint_v u1 * as_nat5 f2 /\ felem_wide_fits5 acc2 (m3 +* m1 *^ m2)} let smul_add_felem5 #m1 #m2 #m3 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4) = let (m20, m21, m22, m23, m24) = m2 in let (m30, m31, m32, m33, m34) = m3 in [@inline_let] let o0' = mul_add_wide128 #m1 #m20 #m30 u1 f20 o0 in [@inline_let] let o1' = mul_add_wide128 #m1 #m21 #m31 u1 f21 o1 in [@inline_let] let o2' = mul_add_wide128 #m1 #m22 #m32 u1 f22 o2 in [@inline_let] let o3' = mul_add_wide128 #m1 #m23 #m33 u1 f23 o3 in [@inline_let] let o4' = mul_add_wide128 #m1 #m24 #m34 u1 f24 o4 in [@inline_let] let out = (o0', o1', o2', o3', o4') in lemma_smul_add_felem5 u1 (f20, f21, f22, f23, f24) (o0, o1, o2, o3, o4); out #pop-options inline_for_extraction noextract val precomp_r19: f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171)} let precomp_r19 (f20, f21, f22, f23, f24) = [@inline_let] let r190 = f20 *! u64 19 in [@inline_let] let r191 = f21 *! u64 19 in [@inline_let] let r192 = f22 *! u64 19 in [@inline_let] let r193 = f23 *! u64 19 in [@inline_let] let r194 = f24 *! u64 19 in (r190, r191, r192, r193, r194) inline_for_extraction noextract val mul_felem5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> r:felem5{felem_fits5 r (9, 10, 9, 9, 9)} -> r19:felem5{felem_fits5 r19 (171, 190, 171, 171, 171) /\ r19 == precomp_r19 r} -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f1) (feval r)} let mul_felem5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4) (r190, r191, r192, r193, r194) = let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 10, 9, 9, 9) f10 (r0, r1, r2, r3, r4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(171, 9, 10, 9, 9) #(81, 90, 81, 81, 81) f11 (r194, r0, r1, r2, r3) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 9, 10, 9) #(1791, 180, 181, 171, 171) f12 (r193, r194, r0, r1, r2) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(171, 171, 171, 9, 10) #(3330, 1719, 262, 261, 252) f13 (r192, r193, r194, r0, r1) (o0, o1, o2, o3, o4) in let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(190, 171, 171, 171, 9) #(4869, 3258, 1801, 342, 342) f14 (r191, r192, r193, r194, r0) (o0, o1, o2, o3, o4) in lemma_fmul5 (f10, f11, f12, f13, f14) (r0, r1, r2, r3, r4); (o0, o1, o2, o3, o4) inline_for_extraction noextract val carry51: l:uint64 -> cin:uint64 -> Pure (uint64 & uint64) (requires felem_fits1 l 2 /\ felem_fits1 cin 8190) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ uint_v l1 < pow2 13) let carry51 l cin = let l' = l +! cin in lemma_carry51 l cin; (l' &. mask51, l' >>. 51ul) inline_for_extraction noextract val carry51_wide: #m:scale64{m < 8192} -> l:uint128{felem_wide_fits1 l m} -> cin:uint64 -> Pure (uint64 & uint64) (requires True) (ensures fun (l0, l1) -> v l + v cin == v l1 * pow2 51 + v l0 /\ felem_fits1 l0 1 /\ felem_fits1 l1 (m + 1)) let carry51_wide #m l cin = let l' = l +! to_u128 cin in lemma_carry51_wide #m l cin; ((to_u64 l') &. mask51, to_u64 (l' >>. 51ul)) let mul_inv_t (f:felem5) = let (o0, o1, o2, o3, o4) = f in if v o1 >= pow2 51 then felem_fits5 f (1, 2, 1, 1, 1) /\ v o1 % pow2 51 < 8192 else felem_fits5 f (1, 1, 1, 1, 1) #push-options "--ifuel 1" val lemma_mul_inv: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> cin:uint64{v cin < pow2 51} -> Lemma (let (i0, i1, i2, i3, i4) = f in assert_norm (pow51 = pow2 51); let i1' = i1 +! cin in let out = (i0, i1', i2, i3, i4) in if (v i1 + v cin) / pow2 51 > 0 then felem_fits5 out (1, 2, 1, 1, 1) /\ (v i1 + v cin) % pow2 51 < v cin else felem_fits5 out (1, 1, 1, 1, 1)) let lemma_mul_inv f cin = assert_norm (pow51 = pow2 51) #pop-options #push-options "--z3rlimit 100" inline_for_extraction noextract val carry_wide5: inp:felem_wide5{felem_wide_fits5 inp (6579, 4797, 3340, 1881, 423)} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == feval_wide inp) let carry_wide5 (i0, i1, i2, i3, i4) = assert_norm (6579 < pow2 13); assert_norm (pow2 13 < max51); let tmp0, c0 = carry51_wide #6579 i0 (u64 0) in let tmp1, c1 = carry51_wide #4797 i1 c0 in let tmp2, c2 = carry51_wide #3340 i2 c1 in let tmp3, c3 = carry51_wide #1881 i3 c2 in let tmp4, c4 = carry51_wide #423 i4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in lemma_mul_inv (tmp0', tmp1, tmp2, tmp3, tmp4) c5; (tmp0', tmp1', tmp2, tmp3, tmp4) #pop-options inline_for_extraction noextract val fmul5: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f1) (feval f2)} let fmul5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (tmp0, tmp1, tmp2, tmp3, tmp4) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp0, tmp1, tmp2, tmp3, tmp4) in carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) inline_for_extraction noextract val fmul25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> f3:felem5{felem_fits5 f3 (9, 10, 9, 9, 9)} -> f4:felem5{felem_fits5 f4 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f2) /\ feval out2 == fmul (feval f3) (feval f4)) let fmul25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) = let (tmp10, tmp11, tmp12, tmp13, tmp14) = precomp_r19 (f20, f21, f22, f23, f24) in let (tmp20, tmp21, tmp22, tmp23, tmp24) = precomp_r19 (f40, f41, f42, f43, f44) in let (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) = mul_felem5 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (tmp10, tmp11, tmp12, tmp13, tmp14) in let (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) = mul_felem5 (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) (tmp20, tmp21, tmp22, tmp23, tmp24) in let (o10,o11,o12,o13,o14) = carry_wide5 (tmp_w10, tmp_w11, tmp_w12, tmp_w13, tmp_w14) in let (o20,o21,o22,o23,o24) = carry_wide5 (tmp_w20, tmp_w21, tmp_w22, tmp_w23, tmp_w24) in ((o10,o11,o12,o13,o14), (o20,o21,o22,o23,o24)) inline_for_extraction noextract val fmul15: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:uint64{felem_fits1 f2 1} -> Pure felem5 (requires True) (ensures fun out -> mul_inv_t out /\ feval out == (feval f1 * v f2) % prime) let fmul15 (f10, f11, f12, f13, f14) f2 = let (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) = smul_felem5 #1 #(9, 10, 9, 9, 9) f2 (f10, f11, f12, f13, f14) in let out = (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in [@inline_let] let res = carry_wide5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4) in FStar.Math.Lemmas.lemma_mod_mul_distr_l (as_nat5 (f10, f11, f12, f13, f14)) (uint_v f2) prime; assert (feval res == feval_wide (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)); assert (feval res == (wide_as_nat5 (tmp_w0, tmp_w1, tmp_w2, tmp_w3, tmp_w4)) % prime); assert (feval res == (v f2 * as_nat5 (f10, f11, f12, f13, f14)) % prime); FStar.Math.Lemmas.swap_mul (v f2) (as_nat5 (f10, f11, f12, f13, f14)); assert (feval res == (as_nat5 (f10, f11, f12, f13, f14) * v f2) % prime); res // inline_for_extraction noextract // val fsqr_felem5: // f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} // -> out:felem_wide5{felem_wide_fits5 out (6579, 4797, 3340, 1881, 423)} // let fsqr_felem5 (f0, f1, f2, f3, f4) = // let (o0, o1, o2, o3, o4) = smul_felem5 #9 #(9, 20, 18, 18, 18) f0 (f0, u64 2 *! f1, u64 2 *! f2, u64 2 *! f3, u64 2 *! f4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #10 #(342, 0, 10, 18, 18) #(81, 180, 162, 162, 162) // f1 (u64 38 *! f4, u64 0, f1, u64 2 *! f2, u64 2 *! f3) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(342, 342, 0, 0, 9) #(3501, 180, 262, 342, 342) // f2 (u64 38 *! f3, u64 38 *! f4, u64 0, u64 0, f2) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 171, 342, 0, 0) #(6579, 3258, 262, 342, 423) // f3 (u64 0, u64 19 *. f3, u64 38 *. f4, u64 0, u64 0) (o0, o1, o2, o3, o4) in // let (o0, o1, o2, o3, o4) = smul_add_felem5 #9 #(0, 0, 0, 171, 0) #(6579, 4797, 3340, 342, 423) // f4 (u64 0, u64 0, u64 0, u64 19 *. f4, u64 0) (o0, o1, o2, o3, o4) in // (o0, o1, o2, o3, o4) inline_for_extraction noextract val mul64_wide_add3: #m0:scale64 -> #m1:scale64 -> #m2:scale64 -> #m3:scale64 -> #m4:scale64 -> #m5:scale64 -> a0:uint64{felem_fits1 a0 m0} -> a1:uint64{felem_fits1 a1 m1} -> b0:uint64{felem_fits1 b0 m2} -> b1:uint64{felem_fits1 b1 m3} -> c0:uint64{felem_fits1 c0 m4} -> c1:uint64{felem_fits1 c1 m5} -> Pure uint128 (requires m0 * m1 + m2 * m3 + m4 * m5 < 8192) (ensures fun res -> felem_wide_fits1 res (m0 * m1 + m2 * m3 + m4 * m5) /\ v res == v a0 * v a1 + v b0 * v b1 + v c0 * v c1) let mul64_wide_add3 #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1 = assert_norm (pow2 13 = 8192); mul64_wide_add3_lemma #m0 #m1 #m2 #m3 #m4 #m5 a0 a1 b0 b1 c0 c1; mul64_wide a0 a1 +! mul64_wide b0 b1 +! mul64_wide c0 c1 inline_for_extraction noextract val fsqr_felem5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> Pure felem_wide5 (requires True) (ensures fun out -> felem_wide_fits5 out (6579, 4797, 3340, 1881, 423) /\ feval_wide out == fmul (feval f) (feval f)) let fsqr_felem5 (f0, f1, f2, f3, f4) = assert_norm (pow2 13 = 8192); let d0 = u64 2 *! f0 in let d1 = u64 2 *! f1 in let d2 = u64 38 *! f2 in let d3 = u64 19 *! f3 in let d419 = u64 19 *! f4 in let d4 = u64 2 *! d419 in let s0 = mul64_wide_add3 #9 #9 #342 #10 #342 #9 f0 f0 d4 f1 d2 f3 in let s1 = mul64_wide_add3 #18 #10 #342 #9 #171 #9 d0 f1 d4 f2 d3 f3 in let s2 = mul64_wide_add3 #18 #9 #10 #10 #342 #9 d0 f2 f1 f1 d4 f3 in let s3 = mul64_wide_add3 #18 #9 #20 #9 #9 #171 d0 f3 d1 f2 f4 d419 in let s4 = mul64_wide_add3 #18 #9 #20 #9 #9 #9 d0 f4 d1 f3 f2 f2 in lemma_fmul_fsqr5 (f0, f1, f2, f3, f4); (s0, s1, s2, s3, s4) inline_for_extraction noextract val fsqr5: f:felem5{felem_fits5 f (9, 10, 9, 9, 9)} -> out:felem5{mul_inv_t out /\ feval out == fmul (feval f) (feval f)} let fsqr5 (f0, f1, f2, f3, f4) = let (o0, o1, o2, o3, o4) = fsqr_felem5 (f0, f1, f2, f3, f4) in carry_wide5 (o0, o1, o2, o3, o4) inline_for_extraction noextract val fsqr25: f1:felem5{felem_fits5 f1 (9, 10, 9, 9, 9)} -> f2:felem5{felem_fits5 f2 (9, 10, 9, 9, 9)} -> Pure (felem5 & felem5) (requires True) (ensures fun (out1, out2) -> mul_inv_t out1 /\ mul_inv_t out2 /\ feval out1 == fmul (feval f1) (feval f1) /\ feval out2 == fmul (feval f2) (feval f2)) let fsqr25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) = let (o10, o11, o12, o13, o14) = fsqr_felem5 (f10, f11, f12, f13, f14) in let (o20, o21, o22, o23, o24) = fsqr_felem5 (f20, f21, f22, f23, f24) in let (o10, o11, o12, o13, o14) = carry_wide5 (o10, o11, o12, o13, o14) in let (o20, o21, o22, o23, o24) = carry_wide5 (o20, o21, o22, o23, o24) in ((o10, o11, o12, o13, o14), (o20, o21, o22, o23, o24)) #set-options "--z3rlimit 100 --max_fuel 2" inline_for_extraction noextract val carry_felem5_full: inp:felem5{mul_inv_t inp} -> out:felem5{feval out == feval inp /\ felem_fits5 out (1, 1, 1, 1, 1)} let carry_felem5_full (f0, f1, f2, f3, f4) = assert_norm (pow51 = pow2 51); let tmp0, c0 = carry51 f0 (u64 0) in let tmp1, c1 = carry51 f1 c0 in assert (if v f1 < pow2 51 then v tmp1 < pow2 51 else v tmp1 < 8192); let tmp2, c2 = carry51 f2 c1 in let tmp3, c3 = carry51 f3 c2 in let tmp4, c4 = carry51 f4 c3 in lemma_carry5_simplify c0 c1 c2 c3 c4 tmp0 tmp1 tmp2 tmp3 tmp4; [@inline_let] let tmp0', c5 = carry51 tmp0 (c4 *! u64 19) in [@inline_let] let tmp1' = tmp1 +! c5 in (tmp0', tmp1', tmp2, tmp3, tmp4) inline_for_extraction noextract val subtract_p5: f:felem5{felem_fits5 f (1, 1, 1, 1, 1)} -> Pure felem5 (requires True) (ensures fun out -> as_nat5 out == feval f /\ felem_fits5 out (1, 1, 1, 1, 1) /\ as_nat5 out < prime) let subtract_p5 (f0, f1, f2, f3, f4) = let m0 = gte_mask f0 (u64 0x7ffffffffffed) in let m1 = eq_mask f1 (u64 0x7ffffffffffff) in let m2 = eq_mask f2 (u64 0x7ffffffffffff) in let m3 = eq_mask f3 (u64 0x7ffffffffffff) in let m4 = eq_mask f4 (u64 0x7ffffffffffff) in let mask = m0 &. m1 &. m2 &. m3 &. m4 in let f0' = f0 -. (mask &. u64 0x7ffffffffffed) in let f1' = f1 -. (mask &. u64 0x7ffffffffffff) in let f2' = f2 -. (mask &. u64 0x7ffffffffffff) in let f3' = f3 -. (mask &. u64 0x7ffffffffffff) in let f4' = f4 -. (mask &. u64 0x7ffffffffffff) in logand_lemma mask (u64 0x7ffffffffffed); logand_lemma mask (u64 0x7ffffffffffff); lemma_subtract_p (f0, f1, f2, f3, f4) (f0', f1', f2', f3', f4'); (f0', f1', f2', f3', f4') inline_for_extraction noextract val store_felem5: f:felem5{mul_inv_t f} -> Pure (uint64 & uint64 & uint64 & uint64) (requires True) (ensures fun (o0, o1, o2, o3) -> feval f == v o0 + v o1 * pow2 64 +
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Curve25519.Field51.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 2, "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
f: Hacl.Spec.Curve25519.Field51.Definition.felem5{Hacl.Spec.Curve25519.Field51.mul_inv_t f} -> Prims.Pure (((Lib.IntTypes.uint64 * Lib.IntTypes.uint64) * Lib.IntTypes.uint64) * Lib.IntTypes.uint64)
Prims.Pure
[]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.mul_inv_t", "Lib.IntTypes.uint64", "FStar.Pervasives.Native.Mktuple4", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_store_felem", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Bar_Dot", "Lib.IntTypes.op_Greater_Greater_Dot", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.op_Less_Less_Dot", "FStar.Pervasives.Native.tuple4", "Hacl.Spec.Curve25519.Field51.subtract_p5", "Prims.l_and", "Prims.eq2", "Spec.Curve25519.elem", "Hacl.Spec.Curve25519.Field51.Definition.feval", "Hacl.Spec.Curve25519.Field51.Definition.felem_fits5", "Prims.nat", "Hacl.Spec.Curve25519.Field51.carry_felem5_full" ]
[]
false
false
false
false
false
let store_felem5 (f0, f1, f2, f3, f4) =
let f0, f1, f2, f3, f4 = carry_felem5_full (f0, f1, f2, f3, f4) in let f0, f1, f2, f3, f4 = subtract_p5 (f0, f1, f2, f3, f4) in let o0 = f0 |. (f1 <<. 51ul) in let o1 = (f1 >>. 13ul) |. (f2 <<. 38ul) in let o2 = (f2 >>. 26ul) |. (f3 <<. 25ul) in let o3 = (f3 >>. 39ul) |. (f4 <<. 12ul) in lemma_store_felem (f0, f1, f2, f3, f4); (o0, o1, o2, o3)
false
Vale.AES.GF128.fsti
Vale.AES.GF128.shift_key_1
val shift_key_1 (n: pos) (f h: poly) : poly
val shift_key_1 (n: pos) (f h: poly) : poly
let shift_key_1 (n:pos) (f h:poly) : poly = let g = monomial n +. f in let h1 = shift h 1 in let offset = reverse (shift g (-1)) (n - 1) in mask h1 n +. (if h1.[n] then offset else zero)
{ "file_name": "vale/code/crypto/aes/Vale.AES.GF128.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 48, "end_line": 191, "start_col": 0, "start_line": 187 }
module Vale.AES.GF128 open FStar.Seq open FStar.Mul open Vale.Def.Words_s open Vale.Def.Words.Four_s open Vale.Def.Types_s open Vale.Arch.Types open Vale.AES.GF128_s open Vale.Math.Poly2_s open Vale.Math.Poly2.Bits_s open Vale.Math.Poly2 open Vale.Math.Poly2.Lemmas let quad32_shift_left_1 (q:quad32) : quad32 = let l = four_map (fun (i:nat32) -> ishl i 1) q in let r = four_map (fun (i:nat32) -> ishr i 31) q in let Mkfour r0 r1 r2 r3 = r in quad32_xor l (Mkfour 0 r0 r1 r2) let quad32_shift_2_left_1 (qa qb:quad32) : quad32 & quad32 = let la = four_map (fun (i:nat32) -> ishl i 1) qa in let lb = four_map (fun (i:nat32) -> ishl i 1) qb in let ra = four_map (fun (i:nat32) -> ishr i 31) qa in let rb = four_map (fun (i:nat32) -> ishr i 31) qb in let Mkfour ra0 ra1 ra2 ra3 = ra in let Mkfour rb0 rb1 rb2 rb3 = rb in let qa' = quad32_xor la (Mkfour 0 ra0 ra1 ra2) in let qb' = quad32_xor lb (quad32_xor (Mkfour ra3 0 0 0) (Mkfour 0 rb0 rb1 rb2)) in (qa', qb') val lemma_shift_left_1 (a:poly) : Lemma (requires degree a < 128) (ensures to_quad32 (shift a 1) == quad32_shift_left_1 (to_quad32 a)) val lemma_shift_2_left_1 (lo hi:poly) : Lemma (requires degree hi < 127 /\ degree lo < 128) (ensures ( let n = monomial 128 in let a = hi *. n +. lo in let a' = shift a 1 in let (lo', hi') = quad32_shift_2_left_1 (to_quad32 lo) (to_quad32 hi) in lo' == to_quad32 (a' %. n) /\ hi' == to_quad32 (a' /. n) )) // TODO: move this to Poly library val lemma_reverse_reverse (a:poly) (n:nat) : Lemma (requires degree a <= n) (ensures reverse (reverse a n) n == a) [SMTPat (reverse (reverse a n) n)] val lemma_gf128_degree (_:unit) : Lemma (ensures degree gf128_modulus_low_terms == 7 /\ degree (monomial 128) == 128 /\ degree gf128_modulus == 128 ) val lemma_gf128_constant_rev (q:quad32) : Lemma (ensures to_quad32 (reverse gf128_modulus_low_terms 127) == Mkfour 0 0 0 0xe1000000 /\ quad32_xor q q == Mkfour 0 0 0 0 ) val lemma_quad32_double_hi_rev (a:poly) : Lemma (requires degree a <= 127 /\ degree (reverse a 127) <= 63) (ensures of_double32 (quad32_double_hi (to_quad32 a)) == reverse (reverse a 127) 63) // Compute 128-bit multiply in terms of 64-bit multiplies val lemma_gf128_mul (a b c d:poly) (n:nat) : Lemma (ensures ( let m = monomial n in let ab = a *. m +. b in let cd = c *. m +. d in let ac = a *. c in let ad = a *. d in let bc = b *. c in let bd = b *. d in ab *. cd == shift (ac +. bc /. m +. ad /. m) (n + n) +. ((bc %. m) *. m +. (ad %. m) *. m +. bd) )) // Compute (a * b) % g, where g = n + h and %. n is easy to compute (e.g. n = x^128) val lemma_gf128_reduce (a b g n h:poly) : Lemma (requires degree h >= 0 /\ degree n > 2 * degree h /\ degree g == degree n /\ degree a <= degree n /\ degree b <= degree n /\ g == n +. h ) (ensures ( let d = (a *. b) /. n in let dh = d *. h in degree ((dh /. n) *. h) <= 2 * degree h /\ (a *. b) %. g == (dh /. n) *. h +. dh %. n +. (a *. b) %. n )) val lemma_gf128_reduce_rev (a b h:poly) (n:pos) : Lemma (requires degree h >= 0 /\ n > 2 * degree h /\ degree (monomial n +. h) == n /\ degree a < n /\ degree b < n ) (ensures ( let m = monomial n in let g = m +. h in let r x = reverse x (n - 1) in let rr x = reverse x (2 * n - 1) in let rab = rr (a *. b) in let rd = rab %. m in let rdh = rr (r rd *. h) in let rdhL = rdh %. m in let rdhLh = r (r rdhL *. h) in degree (r rdhL) <= 2 * degree h /\ degree (r rdhLh) <= 2 * degree h /\ r ((a *. b) %. g) == rdhLh +. rdh /. m +. rab /. m )) val lemma_reduce_rev (a0 a1 a2 h:poly) (n:pos) : Lemma (requires n == 64 /\ // verification times out unless n is known degree a0 < n + n /\ degree a1 < n + n /\ degree a2 < n + n /\ degree (monomial (n + n) +. h) == n + n /\ degree h < n /\ h.[0] ) (ensures ( let nn = n + n in let mm = monomial nn in let m = monomial n in let g = mm +. h in let c = reverse (shift h (-1)) (n - 1) in let y_10 = a0 +. shift (mask a1 64) 64 in let y_0 = mask y_10 64 in let y_10c = swap y_10 64 +. y_0 *. c in let a = a0 +. shift a1 64 +. shift a2 128 in let x = reverse a (nn + nn - 1) in reverse (x %. g) (nn - 1) == swap y_10c 64 +. (a2 +. shift a1 (-64)) +. mask y_10c 64 *. c )) // of_fun 8 (fun (i:nat) -> i = 0 || i = 1 || i = 6) let gf128_low_shift : poly = shift gf128_modulus_low_terms (-1) // of_fun 8 (fun (i:nat) -> i = 127 || i = 126 || i = 121) let gf128_rev_shift : poly = reverse gf128_low_shift 127 val lemma_gf128_low_shift (_:unit) : Lemma (shift (of_quad32 (Mkfour 0 0 0 0xc2000000)) (-64) == reverse gf128_low_shift 63) val lemma_gf128_high_bit (_:unit) : Lemma (of_quad32 (Mkfour 0 0 0 0x80000000) == monomial 127) val lemma_gf128_low_shift_1 (_:unit) : Lemma (of_quad32 (Mkfour 1 0 0 0xc2000000) == reverse (shift (monomial 128 +. gf128_modulus_low_terms) (-1)) 127) let gf128_mul_rev (a b:poly) : poly = reverse (gf128_mul (reverse a 127) (reverse b 127)) 127 let ( *~ ) = gf128_mul_rev val lemma_gf128_mul_rev_commute (a b:poly) : Lemma (a *~ b == b *~ a) val lemma_gf128_mul_rev_associate (a b c:poly) : Lemma (a *~ (b *~ c) == (a *~ b) *~ c) val lemma_gf128_mul_rev_distribute_left (a b c:poly) : Lemma ((a +. b) *~ c == a *~ c +. b *~ c) val lemma_gf128_mul_rev_distribute_right (a b c:poly) : Lemma (a *~ (b +. c) == a *~ b +. a *~ c) // TODO: change definition of reverse from (reverse a 127) to (reverse 128 a) let mod_rev (n:pos) (a b:poly) : poly = reverse (reverse a (n + n - 1) %. b) (n - 1) val lemma_add_mod_rev (n:pos) (a1 a2 b:poly) : Lemma (requires degree b >= 0) (ensures mod_rev n (a1 +. a2) b == mod_rev n a1 b +. mod_rev n a2 b)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2_s.fsti.checked", "Vale.Math.Poly2.Lemmas.fsti.checked", "Vale.Math.Poly2.Bits_s.fsti.checked", "Vale.Math.Poly2.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Types.fsti.checked", "Vale.AES.GF128_s.fsti.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Vale.AES.GF128.fsti" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2.Bits_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES.GF128_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.Types", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words.Four_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "Vale.AES", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> f: Vale.Math.Poly2_s.poly -> h: Vale.Math.Poly2_s.poly -> Vale.Math.Poly2_s.poly
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Vale.Math.Poly2_s.poly", "Vale.Math.Poly2.op_Plus_Dot", "Vale.Math.Poly2.mask", "Vale.Math.Poly2_s.op_String_Access", "Prims.bool", "Vale.Math.Poly2_s.zero", "Vale.Math.Poly2_s.reverse", "Vale.Math.Poly2_s.shift", "Prims.op_Minus", "Prims.op_Subtraction", "Vale.Math.Poly2_s.monomial" ]
[]
false
false
false
true
false
let shift_key_1 (n: pos) (f h: poly) : poly =
let g = monomial n +. f in let h1 = shift h 1 in let offset = reverse (shift g (- 1)) (n - 1) in mask h1 n +. (if h1.[ n ] then offset else zero)
false
Hacl.K256.PrecompTable.fst
Hacl.K256.PrecompTable.precomp_g_pow2_128_table_w4
val precomp_g_pow2_128_table_w4: x:glbuffer uint64 240ul{witnessed x precomp_g_pow2_128_table_lseq_w4 /\ recallable x}
val precomp_g_pow2_128_table_w4: x:glbuffer uint64 240ul{witnessed x precomp_g_pow2_128_table_lseq_w4 /\ recallable x}
let precomp_g_pow2_128_table_w4: x:glbuffer uint64 240ul{witnessed x precomp_g_pow2_128_table_lseq_w4 /\ recallable x} = createL_global precomp_g_pow2_128_table_list_w4
{ "file_name": "code/k256/Hacl.K256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 49, "end_line": 255, "start_col": 0, "start_line": 253 }
module Hacl.K256.PrecompTable open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module LE = Lib.Exponentiation module SE = Spec.Exponentiation module SPT = Hacl.Spec.PrecompBaseTable module SPT256 = Hacl.Spec.PrecompBaseTable256 module SPTK = Hacl.Spec.K256.PrecompTable module S = Spec.K256 module SL = Spec.K256.Lemmas open Hacl.Impl.K256.Point include Hacl.Impl.K256.Group #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let proj_point_to_list p = SPTK.proj_point_to_list_lemma p; SPTK.proj_point_to_list p let lemma_refl x = SPTK.proj_point_to_list_lemma x //----------------- inline_for_extraction noextract let proj_g_pow2_64 : S.proj_point = [@inline_let] let rX : S.felem = 0x46ec0aa60b0b98c37b29371784676ad967b7beb1a941ddb6fbbff95b44cb788b in [@inline_let] let rY : S.felem = 0x6b946755bbc6b677576579c990a1ccf14a710545251a1428fabbf02f40268e63 in [@inline_let] let rZ : S.felem = 0x3c114b2ac17c199ec9eba9f7cc64dc459ca2e53f5bbead2b4e618b318ffcc00e in (rX, rY, rZ) val lemma_proj_g_pow2_64_eval : unit -> Lemma (SE.exp_pow2 S.mk_k256_concrete_ops S.g 64 == proj_g_pow2_64) let lemma_proj_g_pow2_64_eval () = SPT256.exp_pow2_rec_is_exp_pow2 S.mk_k256_concrete_ops S.g 64; let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops S.g 64) in normalize_term_spec (SPT256.exp_pow2_rec S.mk_k256_concrete_ops S.g 64); let rX : S.felem = 0x46ec0aa60b0b98c37b29371784676ad967b7beb1a941ddb6fbbff95b44cb788b in let rY : S.felem = 0x6b946755bbc6b677576579c990a1ccf14a710545251a1428fabbf02f40268e63 in let rZ : S.felem = 0x3c114b2ac17c199ec9eba9f7cc64dc459ca2e53f5bbead2b4e618b318ffcc00e in assert_norm (qX == rX /\ qY == rY /\ qZ == rZ) inline_for_extraction noextract let proj_g_pow2_128 : S.proj_point = [@inline_let] let rX : S.felem = 0x98299efbc8e459915404ae015b48cac3b929e0158665f3c7fa5489fbd25c4297 in [@inline_let] let rY : S.felem = 0xf1e5cbc9579e7d11a31681e947c2959ae0298a006d1c06ab1ad93d6716ea50cc in [@inline_let] let rZ : S.felem = 0x5c53ffe15001674a2eacb60c9327a8b0ddbd93a0fa6d90309de6cc124133938b in (rX, rY, rZ) val lemma_proj_g_pow2_128_eval : unit -> Lemma (SE.exp_pow2 S.mk_k256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128) let lemma_proj_g_pow2_128_eval () = SPT256.exp_pow2_rec_is_exp_pow2 S.mk_k256_concrete_ops proj_g_pow2_64 64; let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_64 64) in normalize_term_spec (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_64 64); let rX : S.felem = 0x98299efbc8e459915404ae015b48cac3b929e0158665f3c7fa5489fbd25c4297 in let rY : S.felem = 0xf1e5cbc9579e7d11a31681e947c2959ae0298a006d1c06ab1ad93d6716ea50cc in let rZ : S.felem = 0x5c53ffe15001674a2eacb60c9327a8b0ddbd93a0fa6d90309de6cc124133938b in assert_norm (qX == rX /\ qY == rY /\ qZ == rZ) inline_for_extraction noextract let proj_g_pow2_192 : S.proj_point = [@inline_let] let rX : S.felem = 0xbd382b67d20492b1480ca58a6d7d617ba413a9bc7c2f1cff51301ef960fb245c in [@inline_let] let rY : S.felem = 0x0b232afcf692673aa714357c524c07867a64ea3b9dfab53f0e74622159e86b0d in [@inline_let] let rZ : S.felem = 0x028a1380449aede5df8219420b458d464a6a4773ac91e8305237878cef1cffa6 in (rX, rY, rZ) val lemma_proj_g_pow2_192_eval : unit -> Lemma (SE.exp_pow2 S.mk_k256_concrete_ops proj_g_pow2_128 64 == proj_g_pow2_192) let lemma_proj_g_pow2_192_eval () = SPT256.exp_pow2_rec_is_exp_pow2 S.mk_k256_concrete_ops proj_g_pow2_128 64; let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_128 64) in normalize_term_spec (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_128 64); let rX : S.felem = 0xbd382b67d20492b1480ca58a6d7d617ba413a9bc7c2f1cff51301ef960fb245c in let rY : S.felem = 0x0b232afcf692673aa714357c524c07867a64ea3b9dfab53f0e74622159e86b0d in let rZ : S.felem = 0x028a1380449aede5df8219420b458d464a6a4773ac91e8305237878cef1cffa6 in assert_norm (qX == rX /\ qY == rY /\ qZ == rZ) // let proj_g_pow2_64 : S.proj_point = // normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops S.g 64) // let proj_g_pow2_128 : S.proj_point = // normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_64 64) // let proj_g_pow2_192 : S.proj_point = // normalize_term (SPT256.exp_pow2_rec S.mk_k256_concrete_ops proj_g_pow2_128 64) inline_for_extraction noextract let proj_g_pow2_64_list : SPTK.point_list = normalize_term (SPTK.proj_point_to_list proj_g_pow2_64) inline_for_extraction noextract let proj_g_pow2_128_list : SPTK.point_list = normalize_term (SPTK.proj_point_to_list proj_g_pow2_128) inline_for_extraction noextract let proj_g_pow2_192_list : SPTK.point_list = normalize_term (SPTK.proj_point_to_list proj_g_pow2_192) let proj_g_pow2_64_lseq : LSeq.lseq uint64 15 = normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64); Seq.seq_of_list proj_g_pow2_64_list let proj_g_pow2_128_lseq : LSeq.lseq uint64 15 = normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128); Seq.seq_of_list proj_g_pow2_128_list let proj_g_pow2_192_lseq : LSeq.lseq uint64 15 = normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192); Seq.seq_of_list proj_g_pow2_192_list val proj_g_pow2_64_lemma: unit -> Lemma (S.to_aff_point proj_g_pow2_64 == pow_point (pow2 64) g_aff) let proj_g_pow2_64_lemma () = lemma_proj_g_pow2_64_eval (); SPT256.a_pow2_64_lemma S.mk_k256_concrete_ops S.g val proj_g_pow2_128_lemma: unit -> Lemma (S.to_aff_point proj_g_pow2_128 == pow_point (pow2 128) g_aff) let proj_g_pow2_128_lemma () = lemma_proj_g_pow2_128_eval (); lemma_proj_g_pow2_64_eval (); SPT256.a_pow2_128_lemma S.mk_k256_concrete_ops S.g val proj_g_pow2_192_lemma: unit -> Lemma (S.to_aff_point proj_g_pow2_192 == pow_point (pow2 192) g_aff) let proj_g_pow2_192_lemma () = lemma_proj_g_pow2_192_eval (); lemma_proj_g_pow2_128_eval (); lemma_proj_g_pow2_64_eval (); SPT256.a_pow2_192_lemma S.mk_k256_concrete_ops S.g let proj_g_pow2_64_lseq_lemma () = normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64); proj_g_pow2_64_lemma (); SPTK.proj_point_to_list_lemma proj_g_pow2_64 let proj_g_pow2_128_lseq_lemma () = normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128); proj_g_pow2_128_lemma (); SPTK.proj_point_to_list_lemma proj_g_pow2_128 let proj_g_pow2_192_lseq_lemma () = normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192); proj_g_pow2_192_lemma (); SPTK.proj_point_to_list_lemma proj_g_pow2_192 let mk_proj_g_pow2_64 () = createL proj_g_pow2_64_list let mk_proj_g_pow2_128 () = createL proj_g_pow2_128_list let mk_proj_g_pow2_192 () = createL proj_g_pow2_192_list //---------------- /// window size = 4; precomputed table = [[0]G, [1]G, ..., [15]G] inline_for_extraction noextract let precomp_basepoint_table_list_w4: x:list uint64{FStar.List.Tot.length x = 240} = normalize_term (SPT.precomp_base_table_list mk_k256_precomp_base_table S.g 15) let precomp_basepoint_table_lseq_w4 : LSeq.lseq uint64 240 = normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table S.g 15); Seq.seq_of_list precomp_basepoint_table_list_w4 let precomp_basepoint_table_lemma_w4 () = normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table S.g 15); SPT.precomp_base_table_lemma mk_k256_precomp_base_table S.g 16 precomp_basepoint_table_lseq_w4 let precomp_basepoint_table_w4: x:glbuffer uint64 240ul{witnessed x precomp_basepoint_table_lseq_w4 /\ recallable x} = createL_global precomp_basepoint_table_list_w4 /// window size = 4; precomputed table = [[0]([pow2 64]G), [1]([pow2 64]G), ..., [15]([pow2 64]G)] inline_for_extraction noextract let precomp_g_pow2_64_table_list_w4: x:list uint64{FStar.List.Tot.length x = 240} = normalize_term (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_64 15) let precomp_g_pow2_64_table_lseq_w4 : LSeq.lseq uint64 240 = normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_64 15); Seq.seq_of_list precomp_g_pow2_64_table_list_w4 let precomp_g_pow2_64_table_lemma_w4 () = normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_64 15); SPT.precomp_base_table_lemma mk_k256_precomp_base_table proj_g_pow2_64 16 precomp_g_pow2_64_table_lseq_w4; proj_g_pow2_64_lemma () let precomp_g_pow2_64_table_w4: x:glbuffer uint64 240ul{witnessed x precomp_g_pow2_64_table_lseq_w4 /\ recallable x} = createL_global precomp_g_pow2_64_table_list_w4 /// window size = 4; precomputed table = [[0]([pow2 128]G), [1]([pow2 128]G),...,[15]([pow2 128]G)] inline_for_extraction noextract let precomp_g_pow2_128_table_list_w4: x:list uint64{FStar.List.Tot.length x = 240} = normalize_term (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_128 15) let precomp_g_pow2_128_table_lseq_w4 : LSeq.lseq uint64 240 = normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_128 15); Seq.seq_of_list precomp_g_pow2_128_table_list_w4 let precomp_g_pow2_128_table_lemma_w4 () = normalize_term_spec (SPT.precomp_base_table_list mk_k256_precomp_base_table proj_g_pow2_128 15); SPT.precomp_base_table_lemma mk_k256_precomp_base_table proj_g_pow2_128 16 precomp_g_pow2_64_table_lseq_w4; proj_g_pow2_128_lemma ()
{ "checked_file": "/", "dependencies": [ "Spec.K256.Lemmas.fsti.checked", "Spec.K256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.K256.PrecompTable.fsti.checked", "Hacl.Impl.K256.Point.fsti.checked", "Hacl.Impl.K256.Group.fst.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.fst.checked" ], "interface_file": true, "source_file": "Hacl.K256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Spec.K256.Lemmas", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Spec.K256.PrecompTable", "short_module": "SPTK" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable256", "short_module": "SPT256" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Impl.K256.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.K256.Point", "short_module": null }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.K256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.K256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Lib.Buffer.glbuffer Lib.IntTypes.uint64 240ul { Lib.Buffer.witnessed x Hacl.K256.PrecompTable.precomp_g_pow2_128_table_lseq_w4 /\ Lib.Buffer.recallable x }
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_global", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Hacl.K256.PrecompTable.precomp_g_pow2_128_table_list_w4", "Lib.Buffer.glbuffer", "Lib.IntTypes.size", "FStar.Pervasives.normalize_term", "Lib.IntTypes.size_nat", "FStar.List.Tot.Base.length", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Prims.l_and", "Lib.Buffer.witnessed", "Hacl.K256.PrecompTable.precomp_g_pow2_128_table_lseq_w4", "Lib.Buffer.recallable", "Lib.Buffer.CONST" ]
[]
false
false
false
false
false
let precomp_g_pow2_128_table_w4:x: glbuffer uint64 240ul {witnessed x precomp_g_pow2_128_table_lseq_w4 /\ recallable x} =
createL_global precomp_g_pow2_128_table_list_w4
false
Hacl.Curve25519_51.fst
Hacl.Curve25519_51.encode_point
val encode_point : Hacl.Meta.Curve25519.generic_encode_point_higher_t Prims.l_True
let encode_point = generic_encode_point_higher #M51 True C.store_felem C.fmul finv
{ "file_name": "code/curve25519/Hacl.Curve25519_51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 82, "end_line": 21, "start_col": 0, "start_line": 21 }
module Hacl.Curve25519_51 friend Hacl.Meta.Curve25519 open Hacl.Meta.Curve25519 // The Hacl core. module C = Hacl.Impl.Curve25519.Field51 let g25519: g25519_t = Lib.Buffer.createL_global Spec.Curve25519.basepoint_list #set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100" let point_add_and_double = addanddouble_point_add_and_double_higher #M51 True C.fmul C.fsqr2 C.fmul1 C.fmul2 C.fsub C.fadd let point_double = addanddouble_point_double_higher #M51 True C.fmul2 C.fmul1 C.fsqr2 C.fsub C.fadd let montgomery_ladder = generic_montgomery_ladder_higher #M51 True point_double C.cswap2 point_add_and_double let fsquare_times = finv_fsquare_times_higher #M51 True C.fsqr
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Curve25519.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Curve25519_51.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "C" }, { "abbrev": false, "full_module": "Hacl.Meta.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Meta.Curve25519.generic_encode_point_higher_t Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Curve25519.generic_encode_point_higher", "Hacl.Impl.Curve25519.Fields.Core.M51", "Prims.l_True", "Hacl.Impl.Curve25519.Field51.store_felem", "Hacl.Impl.Curve25519.Field51.fmul", "Hacl.Curve25519_51.finv" ]
[]
false
false
false
true
false
let encode_point =
generic_encode_point_higher #M51 True C.store_felem C.fmul finv
false
Hacl.Impl.Frodo.KEM.Encaps.fst
Hacl.Impl.Frodo.KEM.Encaps.crypto_kem_enc_ct_pack_c1
val crypto_kem_enc_ct_pack_c1: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> c1:lbytes (ct1bytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h c1 /\ disjoint seed_a c1 /\ disjoint ep_matrix c1 /\ disjoint sp_matrix c1) (ensures fun h0 _ h1 -> modifies (loc c1) h0 h1 /\ as_seq h1 c1 == S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix))
val crypto_kem_enc_ct_pack_c1: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> c1:lbytes (ct1bytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h c1 /\ disjoint seed_a c1 /\ disjoint ep_matrix c1 /\ disjoint sp_matrix c1) (ensures fun h0 _ h1 -> modifies (loc c1) h0 h1 /\ as_seq h1 c1 == S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix))
let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix c1 = push_frame (); let bp_matrix = matrix_create params_nbar (params_n a) in frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix; frodo_pack (params_logq a) bp_matrix c1; pop_frame ()
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 77, "start_col": 0, "start_line": 72 }
module Hacl.Impl.Frodo.KEM.Encaps open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Encode open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module LB = Lib.ByteSequence module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.Encaps module M = Spec.Matrix module KG = Hacl.Impl.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_mul_add_sa_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> bp_matrix:matrix_t params_nbar (params_n a) -> Stack unit (requires fun h -> live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h bp_matrix /\ disjoint bp_matrix seed_a /\ disjoint bp_matrix ep_matrix /\ disjoint bp_matrix sp_matrix) (ensures fun h0 _ h1 -> modifies (loc bp_matrix) h0 h1 /\ as_matrix h1 bp_matrix == S.frodo_mul_add_sa_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix)) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix = push_frame (); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul sp_matrix a_matrix bp_matrix; matrix_add bp_matrix ep_matrix; pop_frame () inline_for_extraction noextract val crypto_kem_enc_ct_pack_c1: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> c1:lbytes (ct1bytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h c1 /\ disjoint seed_a c1 /\ disjoint ep_matrix c1 /\ disjoint sp_matrix c1) (ensures fun h0 _ h1 -> modifies (loc c1) h0 h1 /\ as_seq h1 c1 == S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix))
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.Encaps.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Impl.Frodo.Encode.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.Frodo.KEM.Encaps", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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.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": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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": 100, "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{Hacl.Impl.Frodo.Params.is_supported gen_a} -> seed_a: Hacl.Impl.Matrix.lbytes Hacl.Impl.Frodo.Params.bytes_seed_a -> sp_matrix: Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar (Hacl.Impl.Frodo.Params.params_n a) -> ep_matrix: Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar (Hacl.Impl.Frodo.Params.params_n a) -> c1: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.ct1bytes_len a) -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Prims.b2t", "Hacl.Impl.Frodo.Params.is_supported", "Hacl.Impl.Matrix.lbytes", "Hacl.Impl.Frodo.Params.bytes_seed_a", "Hacl.Impl.Matrix.matrix_t", "Hacl.Impl.Frodo.Params.params_nbar", "Hacl.Impl.Frodo.Params.params_n", "Hacl.Impl.Frodo.Params.ct1bytes_len", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Frodo.Pack.frodo_pack", "Hacl.Impl.Frodo.Params.params_logq", "Hacl.Impl.Frodo.KEM.Encaps.frodo_mul_add_sa_plus_e", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Lib.IntTypes.mul", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Matrix.matrix_create", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix c1 =
push_frame (); let bp_matrix = matrix_create params_nbar (params_n a) in frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix; frodo_pack (params_logq a) bp_matrix c1; pop_frame ()
false
EverParse3d.InputStream.Extern.Type.fst
EverParse3d.InputStream.Extern.Type.make_input_buffer_with_length
val make_input_buffer_with_length (base: t) (position: B.pointer (Ghost.erased LPE.pos_t)) (length: LPE.pos_t) : HST.Stack input_buffer (requires (fun h -> B.loc_disjoint (footprint base) (B.loc_buffer position) /\ B.live h position /\ U64.v length <= U64.v (len_all base))) (ensures (fun h _ h' -> B.modifies (B.loc_buffer position) h h'))
val make_input_buffer_with_length (base: t) (position: B.pointer (Ghost.erased LPE.pos_t)) (length: LPE.pos_t) : HST.Stack input_buffer (requires (fun h -> B.loc_disjoint (footprint base) (B.loc_buffer position) /\ B.live h position /\ U64.v length <= U64.v (len_all base))) (ensures (fun h _ h' -> B.modifies (B.loc_buffer position) h h'))
let make_input_buffer_with_length (base: t) (position: B.pointer (Ghost.erased LPE.pos_t)) (length: LPE.pos_t) : HST.Stack input_buffer (requires (fun h -> B.loc_disjoint (footprint base) (B.loc_buffer position) /\ B.live h position /\ U64.v length <= U64.v (len_all base) )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer position) h h' )) = position *= 0uL; { base = base; has_length = true; length = length; position = position; prf = (); }
{ "file_name": "src/3d/prelude/extern/EverParse3d.InputStream.Extern.Type.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 66, "start_col": 0, "start_line": 46 }
module EverParse3d.InputStream.Extern.Type include EverParse3d.InputStream.Extern.Base module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module U32 = FStar.UInt32 module U8 = FStar.UInt8 module LPE = EverParse3d.ErrorCode module U64 = FStar.UInt64 noeq type input_buffer = { base: t; has_length: bool; length: LPE.pos_t; position: B.pointer (Ghost.erased LPE.pos_t); prf: squash ( B.loc_disjoint (footprint base) (B.loc_buffer position) /\ (has_length == true ==> U64.v length <= U64.v (len_all base)) ); } open LowStar.BufferOps let make_input_buffer (base: t) (position: B.pointer (Ghost.erased LPE.pos_t)) : HST.Stack input_buffer (requires (fun h -> B.loc_disjoint (footprint base) (B.loc_buffer position) /\ B.live h position )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer position) h h' )) = position *= 0uL; { base = base; has_length = false; length = 0uL; position = position; prf = (); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.InputStream.Extern.Base.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": false, "source_file": "EverParse3d.InputStream.Extern.Type.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Extern.Base", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Extern", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Extern", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
base: EverParse3d.InputStream.Extern.Base.t -> position: LowStar.Buffer.pointer (FStar.Ghost.erased EverParse3d.ErrorCode.pos_t) -> length: EverParse3d.ErrorCode.pos_t -> FStar.HyperStack.ST.Stack EverParse3d.InputStream.Extern.Type.input_buffer
FStar.HyperStack.ST.Stack
[]
[]
[ "EverParse3d.InputStream.Extern.Base.t", "LowStar.Buffer.pointer", "FStar.Ghost.erased", "EverParse3d.ErrorCode.pos_t", "EverParse3d.InputStream.Extern.Type.Mkinput_buffer", "EverParse3d.InputStream.Extern.Type.input_buffer", "Prims.unit", "LowStar.BufferOps.op_Star_Equals", "LowStar.Buffer.trivial_preorder", "FStar.Ghost.hide", "FStar.UInt64.__uint_to_t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.loc_disjoint", "EverParse3d.InputStream.Extern.Base.footprint", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Monotonic.Buffer.live", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt64.v", "EverParse3d.InputStream.Extern.Base.len_all", "LowStar.Monotonic.Buffer.modifies" ]
[]
false
true
false
false
false
let make_input_buffer_with_length (base: t) (position: B.pointer (Ghost.erased LPE.pos_t)) (length: LPE.pos_t) : HST.Stack input_buffer (requires (fun h -> B.loc_disjoint (footprint base) (B.loc_buffer position) /\ B.live h position /\ U64.v length <= U64.v (len_all base))) (ensures (fun h _ h' -> B.modifies (B.loc_buffer position) h h')) =
position *= 0uL; { base = base; has_length = true; length = length; position = position; prf = () }
false
EverParse3d.InputStream.Extern.Type.fst
EverParse3d.InputStream.Extern.Type.default_error_handler
val default_error_handler (typename_s fieldname reason: string) (error_code: U64.t) (context: B.pointer LPE.error_frame) (input: input_buffer) (start_pos: U64.t) : HST.Stack unit (requires (fun h -> B.live h context)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer context) h h'))
val default_error_handler (typename_s fieldname reason: string) (error_code: U64.t) (context: B.pointer LPE.error_frame) (input: input_buffer) (start_pos: U64.t) : HST.Stack unit (requires (fun h -> B.live h context)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer context) h h'))
let default_error_handler (typename_s: string) (fieldname: string) (reason: string) (error_code: U64.t) (context: B.pointer LPE.error_frame) (input: input_buffer) (start_pos: U64.t) : HST.Stack unit (requires (fun h -> B.live h context)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer context) h h')) = if not ( !* context ).LPE.filled then begin context *= { LPE.filled = true; LPE.start_pos = start_pos; LPE.typename_s = typename_s; LPE.fieldname = fieldname; LPE.reason = reason; LPE.error_code = error_code; } end
{ "file_name": "src/3d/prelude/extern/EverParse3d.InputStream.Extern.Type.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 89, "start_col": 0, "start_line": 68 }
module EverParse3d.InputStream.Extern.Type include EverParse3d.InputStream.Extern.Base module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module U32 = FStar.UInt32 module U8 = FStar.UInt8 module LPE = EverParse3d.ErrorCode module U64 = FStar.UInt64 noeq type input_buffer = { base: t; has_length: bool; length: LPE.pos_t; position: B.pointer (Ghost.erased LPE.pos_t); prf: squash ( B.loc_disjoint (footprint base) (B.loc_buffer position) /\ (has_length == true ==> U64.v length <= U64.v (len_all base)) ); } open LowStar.BufferOps let make_input_buffer (base: t) (position: B.pointer (Ghost.erased LPE.pos_t)) : HST.Stack input_buffer (requires (fun h -> B.loc_disjoint (footprint base) (B.loc_buffer position) /\ B.live h position )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer position) h h' )) = position *= 0uL; { base = base; has_length = false; length = 0uL; position = position; prf = (); } let make_input_buffer_with_length (base: t) (position: B.pointer (Ghost.erased LPE.pos_t)) (length: LPE.pos_t) : HST.Stack input_buffer (requires (fun h -> B.loc_disjoint (footprint base) (B.loc_buffer position) /\ B.live h position /\ U64.v length <= U64.v (len_all base) )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer position) h h' )) = position *= 0uL; { base = base; has_length = true; length = length; position = position; prf = (); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.InputStream.Extern.Base.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": false, "source_file": "EverParse3d.InputStream.Extern.Type.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Extern.Base", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Extern", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Extern", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
typename_s: Prims.string -> fieldname: Prims.string -> reason: Prims.string -> error_code: FStar.UInt64.t -> context: LowStar.Buffer.pointer EverParse3d.ErrorCode.error_frame -> input: EverParse3d.InputStream.Extern.Type.input_buffer -> start_pos: FStar.UInt64.t -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Prims.string", "FStar.UInt64.t", "LowStar.Buffer.pointer", "EverParse3d.ErrorCode.error_frame", "EverParse3d.InputStream.Extern.Type.input_buffer", "LowStar.BufferOps.op_Star_Equals", "LowStar.Buffer.trivial_preorder", "EverParse3d.ErrorCode.Mkerror_frame", "Prims.unit", "Prims.bool", "Prims.op_Negation", "EverParse3d.ErrorCode.__proj__Mkerror_frame__item__filled", "LowStar.BufferOps.op_Bang_Star", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer" ]
[]
false
true
false
false
false
let default_error_handler (typename_s fieldname reason: string) (error_code: U64.t) (context: B.pointer LPE.error_frame) (input: input_buffer) (start_pos: U64.t) : HST.Stack unit (requires (fun h -> B.live h context)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer context) h h')) =
if not (!*context).LPE.filled then context *= { LPE.filled = true; LPE.start_pos = start_pos; LPE.typename_s = typename_s; LPE.fieldname = fieldname; LPE.reason = reason; LPE.error_code = error_code }
false
Hacl.Curve25519_51.fst
Hacl.Curve25519_51.g25519
val g25519:g25519_t
val g25519:g25519_t
let g25519: g25519_t = Lib.Buffer.createL_global Spec.Curve25519.basepoint_list
{ "file_name": "code/curve25519/Hacl.Curve25519_51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 10, "start_col": 0, "start_line": 9 }
module Hacl.Curve25519_51 friend Hacl.Meta.Curve25519 open Hacl.Meta.Curve25519 // The Hacl core. module C = Hacl.Impl.Curve25519.Field51
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Buffer.fsti.checked", "Hacl.Meta.Curve25519.fst.checked", "Hacl.Impl.Curve25519.Field51.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Curve25519_51.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Field51", "short_module": "C" }, { "abbrev": false, "full_module": "Hacl.Meta.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Hacl.Impl.Curve25519.Generic.g25519_t
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_global", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.PUB", "Spec.Curve25519.basepoint_list", "Lib.Buffer.glbuffer", "Lib.IntTypes.size", "FStar.Pervasives.normalize_term", "Lib.IntTypes.size_nat", "FStar.List.Tot.Base.length" ]
[]
false
false
false
true
false
let g25519:g25519_t =
Lib.Buffer.createL_global Spec.Curve25519.basepoint_list
false
EverParse3d.InputStream.Extern.Type.fst
EverParse3d.InputStream.Extern.Type.make_input_buffer
val make_input_buffer (base: t) (position: B.pointer (Ghost.erased LPE.pos_t)) : HST.Stack input_buffer (requires (fun h -> B.loc_disjoint (footprint base) (B.loc_buffer position) /\ B.live h position)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer position) h h'))
val make_input_buffer (base: t) (position: B.pointer (Ghost.erased LPE.pos_t)) : HST.Stack input_buffer (requires (fun h -> B.loc_disjoint (footprint base) (B.loc_buffer position) /\ B.live h position)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer position) h h'))
let make_input_buffer (base: t) (position: B.pointer (Ghost.erased LPE.pos_t)) : HST.Stack input_buffer (requires (fun h -> B.loc_disjoint (footprint base) (B.loc_buffer position) /\ B.live h position )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer position) h h' )) = position *= 0uL; { base = base; has_length = false; length = 0uL; position = position; prf = (); }
{ "file_name": "src/3d/prelude/extern/EverParse3d.InputStream.Extern.Type.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 44, "start_col": 0, "start_line": 26 }
module EverParse3d.InputStream.Extern.Type include EverParse3d.InputStream.Extern.Base module B = LowStar.Buffer module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module U32 = FStar.UInt32 module U8 = FStar.UInt8 module LPE = EverParse3d.ErrorCode module U64 = FStar.UInt64 noeq type input_buffer = { base: t; has_length: bool; length: LPE.pos_t; position: B.pointer (Ghost.erased LPE.pos_t); prf: squash ( B.loc_disjoint (footprint base) (B.loc_buffer position) /\ (has_length == true ==> U64.v length <= U64.v (len_all base)) ); } open LowStar.BufferOps
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverParse3d.InputStream.Extern.Base.fsti.checked", "EverParse3d.ErrorCode.fst.checked" ], "interface_file": false, "source_file": "EverParse3d.InputStream.Extern.Type.fst" }
[ { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Extern.Base", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Extern", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.InputStream.Extern", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=100" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 8, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
base: EverParse3d.InputStream.Extern.Base.t -> position: LowStar.Buffer.pointer (FStar.Ghost.erased EverParse3d.ErrorCode.pos_t) -> FStar.HyperStack.ST.Stack EverParse3d.InputStream.Extern.Type.input_buffer
FStar.HyperStack.ST.Stack
[]
[]
[ "EverParse3d.InputStream.Extern.Base.t", "LowStar.Buffer.pointer", "FStar.Ghost.erased", "EverParse3d.ErrorCode.pos_t", "EverParse3d.InputStream.Extern.Type.Mkinput_buffer", "FStar.UInt64.__uint_to_t", "EverParse3d.InputStream.Extern.Type.input_buffer", "Prims.unit", "LowStar.BufferOps.op_Star_Equals", "LowStar.Buffer.trivial_preorder", "FStar.Ghost.hide", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.loc_disjoint", "EverParse3d.InputStream.Extern.Base.footprint", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.modifies" ]
[]
false
true
false
false
false
let make_input_buffer (base: t) (position: B.pointer (Ghost.erased LPE.pos_t)) : HST.Stack input_buffer (requires (fun h -> B.loc_disjoint (footprint base) (B.loc_buffer position) /\ B.live h position)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer position) h h')) =
position *= 0uL; { base = base; has_length = false; length = 0uL; position = position; prf = () }
false
Hacl.Impl.Frodo.KEM.Encaps.fst
Hacl.Impl.Frodo.KEM.Encaps.crypto_kem_enc_ct0
val crypto_kem_enc_ct0: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> b:lbytes (publicmatrixbytes_len a) -> mu:lbytes (bytes_mu a) -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> ct:lbytes (crypto_ciphertextbytes a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h mu /\ live h ct /\ live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\ disjoint ct seed_a /\ disjoint ct b /\ disjoint ct mu /\ disjoint ct sp_matrix /\ disjoint ct ep_matrix /\ disjoint ct epp_matrix) (ensures fun h0 _ h1 -> modifies (loc ct) h0 h1 /\ (let c1:LB.lbytes (FP.ct1bytes_len a) = S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_seq h0 sp_matrix) (as_seq h0 ep_matrix) in let c2:LB.lbytes (FP.ct2bytes_len a) = S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_seq h0 sp_matrix) (as_seq h0 epp_matrix) in v (crypto_ciphertextbytes a) == FP.ct1bytes_len a + FP.ct2bytes_len a /\ as_seq h1 ct `Seq.equal` LSeq.concat #_ #(FP.ct1bytes_len a) #(FP.ct2bytes_len a) c1 c2))
val crypto_kem_enc_ct0: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> b:lbytes (publicmatrixbytes_len a) -> mu:lbytes (bytes_mu a) -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> ct:lbytes (crypto_ciphertextbytes a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h mu /\ live h ct /\ live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\ disjoint ct seed_a /\ disjoint ct b /\ disjoint ct mu /\ disjoint ct sp_matrix /\ disjoint ct ep_matrix /\ disjoint ct epp_matrix) (ensures fun h0 _ h1 -> modifies (loc ct) h0 h1 /\ (let c1:LB.lbytes (FP.ct1bytes_len a) = S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_seq h0 sp_matrix) (as_seq h0 ep_matrix) in let c2:LB.lbytes (FP.ct2bytes_len a) = S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_seq h0 sp_matrix) (as_seq h0 epp_matrix) in v (crypto_ciphertextbytes a) == FP.ct1bytes_len a + FP.ct2bytes_len a /\ as_seq h1 ct `Seq.equal` LSeq.concat #_ #(FP.ct1bytes_len a) #(FP.ct2bytes_len a) c1 c2))
let crypto_kem_enc_ct0 a gen_a seed_a b mu sp_matrix ep_matrix epp_matrix ct = let c1 = sub ct 0ul (ct1bytes_len a) in let c2 = sub ct (ct1bytes_len a) (ct2bytes_len a) in let h0 = ST.get () in crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix c1; let h1 = ST.get () in crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix c2; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 ct) 0 (v (ct1bytes_len a))) (LSeq.sub (as_seq h1 ct) 0 (v (ct1bytes_len a))); LSeq.lemma_concat2 (v (ct1bytes_len a)) (LSeq.sub (as_seq h1 ct) 0 (v (ct1bytes_len a))) (v (ct2bytes_len a)) (LSeq.sub (as_seq h2 ct) (v (ct1bytes_len a)) (v (ct2bytes_len a))) (as_seq h2 ct)
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 107, "end_line": 225, "start_col": 0, "start_line": 212 }
module Hacl.Impl.Frodo.KEM.Encaps open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Encode open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module LB = Lib.ByteSequence module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.Encaps module M = Spec.Matrix module KG = Hacl.Impl.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_mul_add_sa_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> bp_matrix:matrix_t params_nbar (params_n a) -> Stack unit (requires fun h -> live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h bp_matrix /\ disjoint bp_matrix seed_a /\ disjoint bp_matrix ep_matrix /\ disjoint bp_matrix sp_matrix) (ensures fun h0 _ h1 -> modifies (loc bp_matrix) h0 h1 /\ as_matrix h1 bp_matrix == S.frodo_mul_add_sa_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix)) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix = push_frame (); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul sp_matrix a_matrix bp_matrix; matrix_add bp_matrix ep_matrix; pop_frame () inline_for_extraction noextract val crypto_kem_enc_ct_pack_c1: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> c1:lbytes (ct1bytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h c1 /\ disjoint seed_a c1 /\ disjoint ep_matrix c1 /\ disjoint sp_matrix c1) (ensures fun h0 _ h1 -> modifies (loc c1) h0 h1 /\ as_seq h1 c1 == S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix)) let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix c1 = push_frame (); let bp_matrix = matrix_create params_nbar (params_n a) in frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix; frodo_pack (params_logq a) bp_matrix c1; pop_frame () inline_for_extraction noextract val frodo_mul_add_sb_plus_e: a:FP.frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> v_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h b /\ live h epp_matrix /\ live h v_matrix /\ live h sp_matrix /\ disjoint v_matrix b /\ disjoint v_matrix epp_matrix /\ disjoint v_matrix sp_matrix) (ensures fun h0 _ h1 -> modifies (loc v_matrix) h0 h1 /\ as_matrix h1 v_matrix == S.frodo_mul_add_sb_plus_e a (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix)) let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix v_matrix = push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_unpack (params_n a) params_nbar (params_logq a) b b_matrix; matrix_mul sp_matrix b_matrix v_matrix; matrix_add v_matrix epp_matrix; pop_frame () inline_for_extraction noextract val frodo_mul_add_sb_plus_e_plus_mu: a:FP.frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> v_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h b /\ live h mu /\ live h v_matrix /\ live h sp_matrix /\ live h epp_matrix /\ disjoint v_matrix b /\ disjoint v_matrix sp_matrix /\ disjoint v_matrix mu /\ disjoint v_matrix epp_matrix) (ensures fun h0 _ h1 -> modifies (loc v_matrix) h0 h1 /\ as_matrix h1 v_matrix == S.frodo_mul_add_sb_plus_e_plus_mu a (as_seq h0 mu) (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix)) let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix v_matrix = push_frame (); frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix v_matrix; let mu_encode = matrix_create params_nbar params_nbar in frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu mu_encode; matrix_add v_matrix mu_encode; clear_matrix mu_encode; pop_frame () inline_for_extraction noextract val crypto_kem_enc_ct_pack_c2: a:FP.frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> c2:lbytes (ct2bytes_len a) -> Stack unit (requires fun h -> live h mu /\ live h b /\ live h sp_matrix /\ live h epp_matrix /\ live h c2 /\ disjoint mu c2 /\ disjoint b c2 /\ disjoint sp_matrix c2 /\ disjoint epp_matrix c2) (ensures fun h0 _ h1 -> modifies (loc c2) h0 h1 /\ as_seq h1 c2 == S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix)) #push-options "--z3rlimit 200" let crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix c2 = push_frame (); let v_matrix = matrix_create params_nbar params_nbar in frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix v_matrix; frodo_pack (params_logq a) v_matrix c2; clear_matrix v_matrix; pop_frame () #pop-options inline_for_extraction noextract val get_sp_ep_epp_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\ disjoint seed_se sp_matrix /\ disjoint seed_se ep_matrix /\ disjoint seed_se epp_matrix /\ disjoint sp_matrix ep_matrix /\ disjoint sp_matrix epp_matrix /\ disjoint ep_matrix epp_matrix) (ensures fun h0 _ h1 -> modifies (loc sp_matrix |+| loc ep_matrix |+| loc epp_matrix) h0 h1 /\ (as_matrix h1 sp_matrix, as_matrix h1 ep_matrix, as_matrix h1 epp_matrix) == S.get_sp_ep_epp_matrices a (as_seq h0 seed_se)) let get_sp_ep_epp_matrices a seed_se sp_matrix ep_matrix epp_matrix = push_frame (); [@inline_let] let s_bytes_len = secretmatrixbytes_len a in let r = create (2ul *! s_bytes_len +! 2ul *! params_nbar *! params_nbar) (u8 0) in KG.frodo_shake_r a (u8 0x96) seed_se (2ul *! s_bytes_len +! 2ul *! params_nbar *! params_nbar) r; frodo_sample_matrix a params_nbar (params_n a) (sub r 0ul s_bytes_len) sp_matrix; frodo_sample_matrix a params_nbar (params_n a) (sub r s_bytes_len s_bytes_len) ep_matrix; frodo_sample_matrix a params_nbar params_nbar (sub r (2ul *! s_bytes_len) (2ul *! params_nbar *! params_nbar)) epp_matrix; pop_frame () inline_for_extraction noextract val crypto_kem_enc_ct0: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> b:lbytes (publicmatrixbytes_len a) -> mu:lbytes (bytes_mu a) -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> ct:lbytes (crypto_ciphertextbytes a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h mu /\ live h ct /\ live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\ disjoint ct seed_a /\ disjoint ct b /\ disjoint ct mu /\ disjoint ct sp_matrix /\ disjoint ct ep_matrix /\ disjoint ct epp_matrix) (ensures fun h0 _ h1 -> modifies (loc ct) h0 h1 /\ (let c1:LB.lbytes (FP.ct1bytes_len a) = S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_seq h0 sp_matrix) (as_seq h0 ep_matrix) in let c2:LB.lbytes (FP.ct2bytes_len a) = S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_seq h0 sp_matrix) (as_seq h0 epp_matrix) in v (crypto_ciphertextbytes a) == FP.ct1bytes_len a + FP.ct2bytes_len a /\ as_seq h1 ct `Seq.equal` LSeq.concat #_ #(FP.ct1bytes_len a) #(FP.ct2bytes_len a) c1 c2))
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.Encaps.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Impl.Frodo.Encode.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.Frodo.KEM.Encaps", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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.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": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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": 100, "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{Hacl.Impl.Frodo.Params.is_supported gen_a} -> seed_a: Hacl.Impl.Matrix.lbytes Hacl.Impl.Frodo.Params.bytes_seed_a -> b: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.publicmatrixbytes_len a) -> mu: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.bytes_mu a) -> sp_matrix: Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar (Hacl.Impl.Frodo.Params.params_n a) -> ep_matrix: Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar (Hacl.Impl.Frodo.Params.params_n a) -> epp_matrix: Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar Hacl.Impl.Frodo.Params.params_nbar -> ct: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_ciphertextbytes a) -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Prims.b2t", "Hacl.Impl.Frodo.Params.is_supported", "Hacl.Impl.Matrix.lbytes", "Hacl.Impl.Frodo.Params.bytes_seed_a", "Hacl.Impl.Frodo.Params.publicmatrixbytes_len", "Hacl.Impl.Frodo.Params.bytes_mu", "Hacl.Impl.Matrix.matrix_t", "Hacl.Impl.Frodo.Params.params_nbar", "Hacl.Impl.Frodo.Params.params_n", "Hacl.Impl.Frodo.Params.crypto_ciphertextbytes", "Lib.Sequence.lemma_concat2", "Lib.IntTypes.uint8", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Frodo.Params.ct1bytes_len", "Lib.Sequence.sub", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Hacl.Impl.Frodo.Params.ct2bytes_len", "Prims.unit", "Lib.Sequence.eq_intro", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.Frodo.KEM.Encaps.crypto_kem_enc_ct_pack_c2", "Hacl.Impl.Frodo.KEM.Encaps.crypto_kem_enc_ct_pack_c1", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Buffer.sub", "FStar.UInt32.__uint_to_t" ]
[]
false
true
false
false
false
let crypto_kem_enc_ct0 a gen_a seed_a b mu sp_matrix ep_matrix epp_matrix ct =
let c1 = sub ct 0ul (ct1bytes_len a) in let c2 = sub ct (ct1bytes_len a) (ct2bytes_len a) in let h0 = ST.get () in crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix c1; let h1 = ST.get () in crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix c2; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 ct) 0 (v (ct1bytes_len a))) (LSeq.sub (as_seq h1 ct) 0 (v (ct1bytes_len a))); LSeq.lemma_concat2 (v (ct1bytes_len a)) (LSeq.sub (as_seq h1 ct) 0 (v (ct1bytes_len a))) (v (ct2bytes_len a)) (LSeq.sub (as_seq h2 ct) (v (ct1bytes_len a)) (v (ct2bytes_len a))) (as_seq h2 ct)
false
Hacl.Impl.Frodo.KEM.Encaps.fst
Hacl.Impl.Frodo.KEM.Encaps.crypto_kem_enc_ct_pack_c2
val crypto_kem_enc_ct_pack_c2: a:FP.frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> c2:lbytes (ct2bytes_len a) -> Stack unit (requires fun h -> live h mu /\ live h b /\ live h sp_matrix /\ live h epp_matrix /\ live h c2 /\ disjoint mu c2 /\ disjoint b c2 /\ disjoint sp_matrix c2 /\ disjoint epp_matrix c2) (ensures fun h0 _ h1 -> modifies (loc c2) h0 h1 /\ as_seq h1 c2 == S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix))
val crypto_kem_enc_ct_pack_c2: a:FP.frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> c2:lbytes (ct2bytes_len a) -> Stack unit (requires fun h -> live h mu /\ live h b /\ live h sp_matrix /\ live h epp_matrix /\ live h c2 /\ disjoint mu c2 /\ disjoint b c2 /\ disjoint sp_matrix c2 /\ disjoint epp_matrix c2) (ensures fun h0 _ h1 -> modifies (loc c2) h0 h1 /\ as_seq h1 c2 == S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix))
let crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix c2 = push_frame (); let v_matrix = matrix_create params_nbar params_nbar in frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix v_matrix; frodo_pack (params_logq a) v_matrix c2; clear_matrix v_matrix; pop_frame ()
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 157, "start_col": 0, "start_line": 151 }
module Hacl.Impl.Frodo.KEM.Encaps open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Encode open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module LB = Lib.ByteSequence module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.Encaps module M = Spec.Matrix module KG = Hacl.Impl.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_mul_add_sa_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> bp_matrix:matrix_t params_nbar (params_n a) -> Stack unit (requires fun h -> live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h bp_matrix /\ disjoint bp_matrix seed_a /\ disjoint bp_matrix ep_matrix /\ disjoint bp_matrix sp_matrix) (ensures fun h0 _ h1 -> modifies (loc bp_matrix) h0 h1 /\ as_matrix h1 bp_matrix == S.frodo_mul_add_sa_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix)) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix = push_frame (); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul sp_matrix a_matrix bp_matrix; matrix_add bp_matrix ep_matrix; pop_frame () inline_for_extraction noextract val crypto_kem_enc_ct_pack_c1: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> c1:lbytes (ct1bytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h c1 /\ disjoint seed_a c1 /\ disjoint ep_matrix c1 /\ disjoint sp_matrix c1) (ensures fun h0 _ h1 -> modifies (loc c1) h0 h1 /\ as_seq h1 c1 == S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix)) let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix c1 = push_frame (); let bp_matrix = matrix_create params_nbar (params_n a) in frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix; frodo_pack (params_logq a) bp_matrix c1; pop_frame () inline_for_extraction noextract val frodo_mul_add_sb_plus_e: a:FP.frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> v_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h b /\ live h epp_matrix /\ live h v_matrix /\ live h sp_matrix /\ disjoint v_matrix b /\ disjoint v_matrix epp_matrix /\ disjoint v_matrix sp_matrix) (ensures fun h0 _ h1 -> modifies (loc v_matrix) h0 h1 /\ as_matrix h1 v_matrix == S.frodo_mul_add_sb_plus_e a (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix)) let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix v_matrix = push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_unpack (params_n a) params_nbar (params_logq a) b b_matrix; matrix_mul sp_matrix b_matrix v_matrix; matrix_add v_matrix epp_matrix; pop_frame () inline_for_extraction noextract val frodo_mul_add_sb_plus_e_plus_mu: a:FP.frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> v_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h b /\ live h mu /\ live h v_matrix /\ live h sp_matrix /\ live h epp_matrix /\ disjoint v_matrix b /\ disjoint v_matrix sp_matrix /\ disjoint v_matrix mu /\ disjoint v_matrix epp_matrix) (ensures fun h0 _ h1 -> modifies (loc v_matrix) h0 h1 /\ as_matrix h1 v_matrix == S.frodo_mul_add_sb_plus_e_plus_mu a (as_seq h0 mu) (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix)) let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix v_matrix = push_frame (); frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix v_matrix; let mu_encode = matrix_create params_nbar params_nbar in frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu mu_encode; matrix_add v_matrix mu_encode; clear_matrix mu_encode; pop_frame () inline_for_extraction noextract val crypto_kem_enc_ct_pack_c2: a:FP.frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> c2:lbytes (ct2bytes_len a) -> Stack unit (requires fun h -> live h mu /\ live h b /\ live h sp_matrix /\ live h epp_matrix /\ live h c2 /\ disjoint mu c2 /\ disjoint b c2 /\ disjoint sp_matrix c2 /\ disjoint epp_matrix c2) (ensures fun h0 _ h1 -> modifies (loc c2) h0 h1 /\ as_seq h1 c2 == S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix))
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.Encaps.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Impl.Frodo.Encode.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.Frodo.KEM.Encaps", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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.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": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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": 200, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Frodo.Params.frodo_alg -> mu: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.bytes_mu a) -> b: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.publicmatrixbytes_len a) -> sp_matrix: Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar (Hacl.Impl.Frodo.Params.params_n a) -> epp_matrix: Hacl.Impl.Matrix.matrix_t Hacl.Impl.Frodo.Params.params_nbar Hacl.Impl.Frodo.Params.params_nbar -> c2: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.ct2bytes_len a) -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Spec.Frodo.Params.frodo_alg", "Hacl.Impl.Matrix.lbytes", "Hacl.Impl.Frodo.Params.bytes_mu", "Hacl.Impl.Frodo.Params.publicmatrixbytes_len", "Hacl.Impl.Matrix.matrix_t", "Hacl.Impl.Frodo.Params.params_nbar", "Hacl.Impl.Frodo.Params.params_n", "Hacl.Impl.Frodo.Params.ct2bytes_len", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Hacl.Impl.Frodo.KEM.clear_matrix", "Hacl.Impl.Frodo.Pack.frodo_pack", "Hacl.Impl.Frodo.Params.params_logq", "Hacl.Impl.Frodo.KEM.Encaps.frodo_mul_add_sb_plus_e_plus_mu", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Lib.IntTypes.mul", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Matrix.matrix_create", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix c2 =
push_frame (); let v_matrix = matrix_create params_nbar params_nbar in frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix v_matrix; frodo_pack (params_logq a) v_matrix c2; clear_matrix v_matrix; pop_frame ()
false
Hacl.Impl.Ed25519.Ladder.fst
Hacl.Impl.Ed25519.Ladder.point_mul_g_double_vartime_noalloc
val point_mul_g_double_vartime_noalloc: out:point -> scalar1:lbuffer uint64 4ul -> q1:point -> scalar2:lbuffer uint64 4ul -> q2:point -> table2: lbuffer uint64 640ul -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ live h table2 /\ eq_or_disjoint q1 q2 /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out scalar1 /\ disjoint out scalar2 /\ disjoint out table2 /\ BD.bn_v h scalar1 < pow2 256 /\ BD.bn_v h scalar2 < pow2 256 /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c /\ table_inv_w5 (as_seq h q2) (as_seq h table2)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h0 scalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h0 scalar2) 5)
val point_mul_g_double_vartime_noalloc: out:point -> scalar1:lbuffer uint64 4ul -> q1:point -> scalar2:lbuffer uint64 4ul -> q2:point -> table2: lbuffer uint64 640ul -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ live h table2 /\ eq_or_disjoint q1 q2 /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out scalar1 /\ disjoint out scalar2 /\ disjoint out table2 /\ BD.bn_v h scalar1 < pow2 256 /\ BD.bn_v h scalar2 < pow2 256 /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c /\ table_inv_w5 (as_seq h q2) (as_seq h table2)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h0 scalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h0 scalar2) 5)
let point_mul_g_double_vartime_noalloc out scalar1 q1 scalar2 q2 table2 = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 5ul in [@inline_let] let table_len = 32ul in [@inline_let] let bLen = 4ul in [@inline_let] let bBits = 256ul in assert_norm (pow2 (v l) == v table_len); let h0 = ST.get () in recall_contents precomp_basepoint_table_w5 precomp_basepoint_table_lseq_w5; let h1 = ST.get () in precomp_basepoint_table_lemma_w5 (); assert (table_inv_w5 (as_seq h1 q1) (as_seq h1 precomp_basepoint_table_w5)); assert (table_inv_w5 (as_seq h1 q2) (as_seq h1 table2)); ME.mk_lexp_double_fw_tables len ctx_len k l table_len table_inv_w5 table_inv_w5 (BE.lprecomp_get_vartime len ctx_len k l table_len) (BE.lprecomp_get_vartime len ctx_len k l table_len) (null uint64) q1 bLen bBits scalar1 q2 scalar2 (to_const precomp_basepoint_table_w5) (to_const table2) out
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Ladder.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 63, "end_line": 297, "start_col": 0, "start_line": 276 }
module Hacl.Impl.Ed25519.Ladder module ST = FStar.HyperStack.ST open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum25519 module F51 = Hacl.Impl.Ed25519.Field51 module BSeq = Lib.ByteSequence module LE = Lib.Exponentiation module SE = Spec.Exponentiation module BE = Hacl.Impl.Exponentiation module ME = Hacl.Impl.MultiExponentiation module PT = Hacl.Impl.PrecompTable module SPT256 = Hacl.Spec.PrecompBaseTable256 module BD = Hacl.Bignum.Definitions module SD = Hacl.Spec.Bignum.Definitions module S = Spec.Ed25519 open Hacl.Impl.Ed25519.PointConstants include Hacl.Impl.Ed25519.Group include Hacl.Ed25519.PrecompTable #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let table_inv_w4 : BE.table_inv_t U64 20ul 16ul = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 4ul in [@inline_let] let table_len = 16ul in BE.table_inv_precomp len ctx_len k l table_len inline_for_extraction noextract let table_inv_w5 : BE.table_inv_t U64 20ul 32ul = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 5ul in [@inline_let] let table_len = 32ul in assert_norm (pow2 (v l) = v table_len); BE.table_inv_precomp len ctx_len k l table_len inline_for_extraction noextract val convert_scalar: scalar:lbuffer uint8 32ul -> bscalar:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h scalar /\ live h bscalar /\ disjoint scalar bscalar) (ensures fun h0 _ h1 -> modifies (loc bscalar) h0 h1 /\ BD.bn_v h1 bscalar == BSeq.nat_from_bytes_le (as_seq h0 scalar)) let convert_scalar scalar bscalar = let h0 = ST.get () in Hacl.Spec.Bignum.Convert.bn_from_bytes_le_lemma #U64 32 (as_seq h0 scalar); Hacl.Bignum.Convert.mk_bn_from_bytes_le true 32ul scalar bscalar inline_for_extraction noextract val point_mul_noalloc: out:point -> bscalar:lbuffer uint64 4ul -> q:point -> Stack unit (requires fun h -> live h bscalar /\ live h q /\ live h out /\ disjoint q out /\ disjoint q bscalar /\ disjoint out bscalar /\ F51.point_inv_t h q /\ F51.inv_ext_point (as_seq h q) /\ BD.bn_v h bscalar < pow2 256) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_fw S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q)) 256 (BD.bn_v h0 bscalar) 4) let point_mul_noalloc out bscalar q = BE.lexp_fw_consttime 20ul 0ul mk_ed25519_concrete_ops 4ul (null uint64) q 4ul 256ul bscalar out let point_mul out scalar q = let h0 = ST.get () in SE.exp_fw_lemma S.mk_ed25519_concrete_ops (F51.point_eval h0 q) 256 (BSeq.nat_from_bytes_le (as_seq h0 scalar)) 4; push_frame (); let bscalar = create 4ul (u64 0) in convert_scalar scalar bscalar; point_mul_noalloc out bscalar q; pop_frame () val precomp_get_consttime: BE.pow_a_to_small_b_st U64 20ul 0ul mk_ed25519_concrete_ops 4ul 16ul (BE.table_inv_precomp 20ul 0ul mk_ed25519_concrete_ops 4ul 16ul) [@CInline] let precomp_get_consttime ctx a table bits_l tmp = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 4ul in [@inline_let] let table_len = 16ul in BE.lprecomp_get_consttime len ctx_len k l table_len ctx a table bits_l tmp inline_for_extraction noextract val point_mul_g_noalloc: out:point -> bscalar:lbuffer uint64 4ul -> q1:point -> q2:point -> q3:point -> q4:point -> Stack unit (requires fun h -> live h bscalar /\ live h out /\ live h q1 /\ live h q2 /\ live h q3 /\ live h q4 /\ disjoint out bscalar /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out q3 /\ disjoint out q4 /\ disjoint q1 q2 /\ disjoint q1 q3 /\ disjoint q1 q4 /\ disjoint q2 q3 /\ disjoint q2 q4 /\ disjoint q3 q4 /\ BD.bn_v h bscalar < pow2 256 /\ F51.linv (as_seq h q1) /\ refl (as_seq h q1) == g_aff /\ F51.linv (as_seq h q2) /\ refl (as_seq h q2) == g_pow2_64 /\ F51.linv (as_seq h q3) /\ refl (as_seq h q3) == g_pow2_128 /\ F51.linv (as_seq h q4) /\ refl (as_seq h q4) == g_pow2_192) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ (let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 (BD.bn_v h0 bscalar) in S.to_aff_point (F51.point_eval h1 out) == LE.exp_four_fw S.mk_ed25519_comm_monoid g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4)) let point_mul_g_noalloc out bscalar q1 q2 q3 q4 = [@inline_let] let len = 20ul in [@inline_let] let ctx_len = 0ul in [@inline_let] let k = mk_ed25519_concrete_ops in [@inline_let] let l = 4ul in [@inline_let] let table_len = 16ul in [@inline_let] let bLen = 1ul in [@inline_let] let bBits = 64ul in let h0 = ST.get () in recall_contents precomp_basepoint_table_w4 precomp_basepoint_table_lseq_w4; let h1 = ST.get () in precomp_basepoint_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q1) (as_seq h1 precomp_basepoint_table_w4)); recall_contents precomp_g_pow2_64_table_w4 precomp_g_pow2_64_table_lseq_w4; let h1 = ST.get () in precomp_g_pow2_64_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q2) (as_seq h1 precomp_g_pow2_64_table_w4)); recall_contents precomp_g_pow2_128_table_w4 precomp_g_pow2_128_table_lseq_w4; let h1 = ST.get () in precomp_g_pow2_128_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q3) (as_seq h1 precomp_g_pow2_128_table_w4)); recall_contents precomp_g_pow2_192_table_w4 precomp_g_pow2_192_table_lseq_w4; let h1 = ST.get () in precomp_g_pow2_192_table_lemma_w4 (); assert (table_inv_w4 (as_seq h1 q4) (as_seq h1 precomp_g_pow2_192_table_w4)); let r1 = sub bscalar 0ul 1ul in let r2 = sub bscalar 1ul 1ul in let r3 = sub bscalar 2ul 1ul in let r4 = sub bscalar 3ul 1ul in SPT256.lemma_decompose_nat256_as_four_u64_lbignum (as_seq h0 bscalar); ME.mk_lexp_four_fw_tables len ctx_len k l table_len table_inv_w4 table_inv_w4 table_inv_w4 table_inv_w4 precomp_get_consttime precomp_get_consttime precomp_get_consttime precomp_get_consttime (null uint64) q1 bLen bBits r1 q2 r2 q3 r3 q4 r4 (to_const precomp_basepoint_table_w4) (to_const precomp_g_pow2_64_table_w4) (to_const precomp_g_pow2_128_table_w4) (to_const precomp_g_pow2_192_table_w4) out; LowStar.Ignore.ignore q2; // q2, q3, q4 are unused variables LowStar.Ignore.ignore q3; LowStar.Ignore.ignore q4 inline_for_extraction noextract val point_mul_g_mk_q1234: out:point -> bscalar:lbuffer uint64 4ul -> q1:point -> Stack unit (requires fun h -> live h bscalar /\ live h out /\ live h q1 /\ disjoint out bscalar /\ disjoint out q1 /\ BD.bn_v h bscalar < pow2 256 /\ F51.linv (as_seq h q1) /\ refl (as_seq h q1) == g_aff) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ (let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 (BD.bn_v h0 bscalar) in S.to_aff_point (F51.point_eval h1 out) == LE.exp_four_fw S.mk_ed25519_comm_monoid g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4)) let point_mul_g_mk_q1234 out bscalar q1 = push_frame (); let q2 = mk_ext_g_pow2_64 () in let q3 = mk_ext_g_pow2_128 () in let q4 = mk_ext_g_pow2_192 () in ext_g_pow2_64_lseq_lemma (); ext_g_pow2_128_lseq_lemma (); ext_g_pow2_192_lseq_lemma (); point_mul_g_noalloc out bscalar q1 q2 q3 q4; pop_frame () val lemma_exp_four_fw_local: b:BSeq.lbytes 32 -> Lemma (let bn = BSeq.nat_from_bytes_le b in let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 bn in let cm = S.mk_ed25519_comm_monoid in LE.exp_four_fw cm g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4 == S.to_aff_point (S.point_mul_g b)) let lemma_exp_four_fw_local b = let bn = BSeq.nat_from_bytes_le b in let (b0, b1, b2, b3) = SPT256.decompose_nat256_as_four_u64 bn in let cm = S.mk_ed25519_comm_monoid in let res = LE.exp_four_fw cm g_aff 64 b0 g_pow2_64 b1 g_pow2_128 b2 g_pow2_192 b3 4 in assert (res == SPT256.exp_as_exp_four_nat256_precomp cm g_aff bn); SPT256.lemma_point_mul_base_precomp4 cm g_aff bn; assert (res == LE.pow cm g_aff bn); SE.exp_fw_lemma S.mk_ed25519_concrete_ops g_c 256 bn 4; LE.exp_fw_lemma cm g_aff 256 bn 4; assert (S.to_aff_point (S.point_mul_g b) == LE.pow cm g_aff bn) [@CInline] let point_mul_g out scalar = push_frame (); let h0 = ST.get () in let bscalar = create 4ul (u64 0) in convert_scalar scalar bscalar; let q1 = create 20ul (u64 0) in make_g q1; point_mul_g_mk_q1234 out bscalar q1; lemma_exp_four_fw_local (as_seq h0 scalar); pop_frame () inline_for_extraction noextract val point_mul_g_double_vartime_noalloc: out:point -> scalar1:lbuffer uint64 4ul -> q1:point -> scalar2:lbuffer uint64 4ul -> q2:point -> table2: lbuffer uint64 640ul -> Stack unit (requires fun h -> live h out /\ live h scalar1 /\ live h q1 /\ live h scalar2 /\ live h q2 /\ live h table2 /\ eq_or_disjoint q1 q2 /\ disjoint out q1 /\ disjoint out q2 /\ disjoint out scalar1 /\ disjoint out scalar2 /\ disjoint out table2 /\ BD.bn_v h scalar1 < pow2 256 /\ BD.bn_v h scalar2 < pow2 256 /\ F51.linv (as_seq h q1) /\ F51.linv (as_seq h q2) /\ F51.point_eval h q1 == g_c /\ table_inv_w5 (as_seq h q2) (as_seq h table2)) (ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ F51.linv (as_seq h1 out) /\ S.to_aff_point (F51.point_eval h1 out) == LE.exp_double_fw #S.aff_point_c S.mk_ed25519_comm_monoid (S.to_aff_point (F51.point_eval h0 q1)) 256 (BD.bn_v h0 scalar1) (S.to_aff_point (F51.point_eval h0 q2)) (BD.bn_v h0 scalar2) 5)
{ "checked_file": "/", "dependencies": [ "Spec.Exponentiation.fsti.checked", "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "LowStar.Ignore.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Impl.PrecompTable.fsti.checked", "Hacl.Impl.MultiExponentiation.fsti.checked", "Hacl.Impl.Exponentiation.fsti.checked", "Hacl.Impl.Ed25519.PointNegate.fst.checked", "Hacl.Impl.Ed25519.PointConstants.fst.checked", "Hacl.Impl.Ed25519.Group.fst.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Ed25519.PrecompTable.fsti.checked", "Hacl.Bignum25519.fsti.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Convert.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked" ], "interface_file": true, "source_file": "Hacl.Impl.Ed25519.Ladder.fst" }
[ { "abbrev": false, "full_module": "Hacl.Ed25519.PrecompTable", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519.PointConstants", "short_module": null }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable256", "short_module": "SPT256" }, { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Impl.MultiExponentiation", "short_module": "ME" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "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": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Spec.Ed25519", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "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": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
out: Hacl.Bignum25519.point -> scalar1: Lib.Buffer.lbuffer Lib.IntTypes.uint64 4ul -> q1: Hacl.Bignum25519.point -> scalar2: Lib.Buffer.lbuffer Lib.IntTypes.uint64 4ul -> q2: Hacl.Bignum25519.point -> table2: Lib.Buffer.lbuffer Lib.IntTypes.uint64 640ul -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum25519.point", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Hacl.Impl.MultiExponentiation.mk_lexp_double_fw_tables", "Lib.IntTypes.U64", "Hacl.Impl.Ed25519.Ladder.table_inv_w5", "Hacl.Impl.Exponentiation.lprecomp_get_vartime", "Lib.Buffer.null", "Lib.Buffer.MUT", "Lib.Buffer.to_const", "Lib.Buffer.CONST", "Hacl.Ed25519.PrecompTable.precomp_basepoint_table_w5", "Prims.unit", "Prims._assert", "Lib.Buffer.as_seq", "Hacl.Ed25519.PrecompTable.precomp_basepoint_table_lemma_w5", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.recall_contents", "Hacl.Ed25519.PrecompTable.precomp_basepoint_table_lseq_w5", "FStar.Pervasives.assert_norm", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.range", "Lib.IntTypes.U32", "Prims.pow2", "Lib.IntTypes.v", "Lib.IntTypes.PUB", "FStar.UInt32.t", "Hacl.Impl.Exponentiation.Definitions.concrete_ops", "FStar.UInt32.uint_to_t", "Hacl.Impl.Ed25519.Group.mk_ed25519_concrete_ops" ]
[]
false
true
false
false
false
let point_mul_g_double_vartime_noalloc out scalar1 q1 scalar2 q2 table2 =
[@@ inline_let ]let len = 20ul in [@@ inline_let ]let ctx_len = 0ul in [@@ inline_let ]let k = mk_ed25519_concrete_ops in [@@ inline_let ]let l = 5ul in [@@ inline_let ]let table_len = 32ul in [@@ inline_let ]let bLen = 4ul in [@@ inline_let ]let bBits = 256ul in assert_norm (pow2 (v l) == v table_len); let h0 = ST.get () in recall_contents precomp_basepoint_table_w5 precomp_basepoint_table_lseq_w5; let h1 = ST.get () in precomp_basepoint_table_lemma_w5 (); assert (table_inv_w5 (as_seq h1 q1) (as_seq h1 precomp_basepoint_table_w5)); assert (table_inv_w5 (as_seq h1 q2) (as_seq h1 table2)); ME.mk_lexp_double_fw_tables len ctx_len k l table_len table_inv_w5 table_inv_w5 (BE.lprecomp_get_vartime len ctx_len k l table_len) (BE.lprecomp_get_vartime len ctx_len k l table_len) (null uint64) q1 bLen bBits scalar1 q2 scalar2 (to_const precomp_basepoint_table_w5) (to_const table2) out
false
Hacl.Impl.Frodo.KEM.Encaps.fst
Hacl.Impl.Frodo.KEM.Encaps.crypto_kem_enc_ct
val crypto_kem_enc_ct: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> seed_se:lbytes (crypto_bytes a) -> ct:lbytes (crypto_ciphertextbytes a) -> Stack unit (requires fun h -> live h mu /\ live h pk /\ live h seed_se /\ live h ct /\ disjoint ct mu /\ disjoint ct pk /\ disjoint ct seed_se) (ensures fun h0 _ h1 -> modifies (loc ct) h0 h1 /\ as_seq h1 ct == S.crypto_kem_enc_ct a gen_a (as_seq h0 mu) (as_seq h0 pk) (as_seq h0 seed_se))
val crypto_kem_enc_ct: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> seed_se:lbytes (crypto_bytes a) -> ct:lbytes (crypto_ciphertextbytes a) -> Stack unit (requires fun h -> live h mu /\ live h pk /\ live h seed_se /\ live h ct /\ disjoint ct mu /\ disjoint ct pk /\ disjoint ct seed_se) (ensures fun h0 _ h1 -> modifies (loc ct) h0 h1 /\ as_seq h1 ct == S.crypto_kem_enc_ct a gen_a (as_seq h0 mu) (as_seq h0 pk) (as_seq h0 seed_se))
let crypto_kem_enc_ct a gen_a mu pk seed_se ct = push_frame (); let h0 = ST.get () in FP.expand_crypto_publickeybytes a; let seed_a = sub pk 0ul bytes_seed_a in let b = sub pk bytes_seed_a (publicmatrixbytes_len a) in let sp_matrix = matrix_create params_nbar (params_n a) in let ep_matrix = matrix_create params_nbar (params_n a) in let epp_matrix = matrix_create params_nbar params_nbar in get_sp_ep_epp_matrices a seed_se sp_matrix ep_matrix epp_matrix; crypto_kem_enc_ct0 a gen_a seed_a b mu sp_matrix ep_matrix epp_matrix ct; clear_matrix3 a sp_matrix ep_matrix epp_matrix; let h1 = ST.get () in LSeq.eq_intro (as_seq h1 ct) (S.crypto_kem_enc_ct a gen_a (as_seq h0 mu) (as_seq h0 pk) (as_seq h0 seed_se)); pop_frame ()
{ "file_name": "code/frodo/Hacl.Impl.Frodo.KEM.Encaps.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 281, "start_col": 0, "start_line": 263 }
module Hacl.Impl.Frodo.KEM.Encaps open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open LowStar.Buffer open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Matrix open Hacl.Impl.Frodo.Params open Hacl.Impl.Frodo.KEM open Hacl.Impl.Frodo.Encode open Hacl.Impl.Frodo.Pack open Hacl.Impl.Frodo.Sample open Hacl.Frodo.Random module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module LB = Lib.ByteSequence module FP = Spec.Frodo.Params module S = Spec.Frodo.KEM.Encaps module M = Spec.Matrix module KG = Hacl.Impl.Frodo.KEM.KeyGen #set-options "--z3rlimit 100 --fuel 0 --ifuel 0" inline_for_extraction noextract val frodo_mul_add_sa_plus_e: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> bp_matrix:matrix_t params_nbar (params_n a) -> Stack unit (requires fun h -> live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h bp_matrix /\ disjoint bp_matrix seed_a /\ disjoint bp_matrix ep_matrix /\ disjoint bp_matrix sp_matrix) (ensures fun h0 _ h1 -> modifies (loc bp_matrix) h0 h1 /\ as_matrix h1 bp_matrix == S.frodo_mul_add_sa_plus_e a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix)) let frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix = push_frame (); let a_matrix = matrix_create (params_n a) (params_n a) in frodo_gen_matrix gen_a (params_n a) seed_a a_matrix; matrix_mul sp_matrix a_matrix bp_matrix; matrix_add bp_matrix ep_matrix; pop_frame () inline_for_extraction noextract val crypto_kem_enc_ct_pack_c1: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> c1:lbytes (ct1bytes_len a) -> Stack unit (requires fun h -> live h seed_a /\ live h ep_matrix /\ live h sp_matrix /\ live h c1 /\ disjoint seed_a c1 /\ disjoint ep_matrix c1 /\ disjoint sp_matrix c1) (ensures fun h0 _ h1 -> modifies (loc c1) h0 h1 /\ as_seq h1 c1 == S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_matrix h0 sp_matrix) (as_matrix h0 ep_matrix)) let crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix c1 = push_frame (); let bp_matrix = matrix_create params_nbar (params_n a) in frodo_mul_add_sa_plus_e a gen_a seed_a sp_matrix ep_matrix bp_matrix; frodo_pack (params_logq a) bp_matrix c1; pop_frame () inline_for_extraction noextract val frodo_mul_add_sb_plus_e: a:FP.frodo_alg -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> v_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h b /\ live h epp_matrix /\ live h v_matrix /\ live h sp_matrix /\ disjoint v_matrix b /\ disjoint v_matrix epp_matrix /\ disjoint v_matrix sp_matrix) (ensures fun h0 _ h1 -> modifies (loc v_matrix) h0 h1 /\ as_matrix h1 v_matrix == S.frodo_mul_add_sb_plus_e a (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix)) let frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix v_matrix = push_frame (); let b_matrix = matrix_create (params_n a) params_nbar in frodo_unpack (params_n a) params_nbar (params_logq a) b b_matrix; matrix_mul sp_matrix b_matrix v_matrix; matrix_add v_matrix epp_matrix; pop_frame () inline_for_extraction noextract val frodo_mul_add_sb_plus_e_plus_mu: a:FP.frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> v_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h b /\ live h mu /\ live h v_matrix /\ live h sp_matrix /\ live h epp_matrix /\ disjoint v_matrix b /\ disjoint v_matrix sp_matrix /\ disjoint v_matrix mu /\ disjoint v_matrix epp_matrix) (ensures fun h0 _ h1 -> modifies (loc v_matrix) h0 h1 /\ as_matrix h1 v_matrix == S.frodo_mul_add_sb_plus_e_plus_mu a (as_seq h0 mu) (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix)) let frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix v_matrix = push_frame (); frodo_mul_add_sb_plus_e a b sp_matrix epp_matrix v_matrix; let mu_encode = matrix_create params_nbar params_nbar in frodo_key_encode (params_logq a) (params_extracted_bits a) params_nbar mu mu_encode; matrix_add v_matrix mu_encode; clear_matrix mu_encode; pop_frame () inline_for_extraction noextract val crypto_kem_enc_ct_pack_c2: a:FP.frodo_alg -> mu:lbytes (bytes_mu a) -> b:lbytes (publicmatrixbytes_len a) -> sp_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> c2:lbytes (ct2bytes_len a) -> Stack unit (requires fun h -> live h mu /\ live h b /\ live h sp_matrix /\ live h epp_matrix /\ live h c2 /\ disjoint mu c2 /\ disjoint b c2 /\ disjoint sp_matrix c2 /\ disjoint epp_matrix c2) (ensures fun h0 _ h1 -> modifies (loc c2) h0 h1 /\ as_seq h1 c2 == S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_matrix h0 sp_matrix) (as_matrix h0 epp_matrix)) #push-options "--z3rlimit 200" let crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix c2 = push_frame (); let v_matrix = matrix_create params_nbar params_nbar in frodo_mul_add_sb_plus_e_plus_mu a mu b sp_matrix epp_matrix v_matrix; frodo_pack (params_logq a) v_matrix c2; clear_matrix v_matrix; pop_frame () #pop-options inline_for_extraction noextract val get_sp_ep_epp_matrices: a:FP.frodo_alg -> seed_se:lbytes (crypto_bytes a) -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h seed_se /\ live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\ disjoint seed_se sp_matrix /\ disjoint seed_se ep_matrix /\ disjoint seed_se epp_matrix /\ disjoint sp_matrix ep_matrix /\ disjoint sp_matrix epp_matrix /\ disjoint ep_matrix epp_matrix) (ensures fun h0 _ h1 -> modifies (loc sp_matrix |+| loc ep_matrix |+| loc epp_matrix) h0 h1 /\ (as_matrix h1 sp_matrix, as_matrix h1 ep_matrix, as_matrix h1 epp_matrix) == S.get_sp_ep_epp_matrices a (as_seq h0 seed_se)) let get_sp_ep_epp_matrices a seed_se sp_matrix ep_matrix epp_matrix = push_frame (); [@inline_let] let s_bytes_len = secretmatrixbytes_len a in let r = create (2ul *! s_bytes_len +! 2ul *! params_nbar *! params_nbar) (u8 0) in KG.frodo_shake_r a (u8 0x96) seed_se (2ul *! s_bytes_len +! 2ul *! params_nbar *! params_nbar) r; frodo_sample_matrix a params_nbar (params_n a) (sub r 0ul s_bytes_len) sp_matrix; frodo_sample_matrix a params_nbar (params_n a) (sub r s_bytes_len s_bytes_len) ep_matrix; frodo_sample_matrix a params_nbar params_nbar (sub r (2ul *! s_bytes_len) (2ul *! params_nbar *! params_nbar)) epp_matrix; pop_frame () inline_for_extraction noextract val crypto_kem_enc_ct0: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> seed_a:lbytes bytes_seed_a -> b:lbytes (publicmatrixbytes_len a) -> mu:lbytes (bytes_mu a) -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> ct:lbytes (crypto_ciphertextbytes a) -> Stack unit (requires fun h -> live h seed_a /\ live h b /\ live h mu /\ live h ct /\ live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\ disjoint ct seed_a /\ disjoint ct b /\ disjoint ct mu /\ disjoint ct sp_matrix /\ disjoint ct ep_matrix /\ disjoint ct epp_matrix) (ensures fun h0 _ h1 -> modifies (loc ct) h0 h1 /\ (let c1:LB.lbytes (FP.ct1bytes_len a) = S.crypto_kem_enc_ct_pack_c1 a gen_a (as_seq h0 seed_a) (as_seq h0 sp_matrix) (as_seq h0 ep_matrix) in let c2:LB.lbytes (FP.ct2bytes_len a) = S.crypto_kem_enc_ct_pack_c2 a (as_seq h0 mu) (as_seq h0 b) (as_seq h0 sp_matrix) (as_seq h0 epp_matrix) in v (crypto_ciphertextbytes a) == FP.ct1bytes_len a + FP.ct2bytes_len a /\ as_seq h1 ct `Seq.equal` LSeq.concat #_ #(FP.ct1bytes_len a) #(FP.ct2bytes_len a) c1 c2)) let crypto_kem_enc_ct0 a gen_a seed_a b mu sp_matrix ep_matrix epp_matrix ct = let c1 = sub ct 0ul (ct1bytes_len a) in let c2 = sub ct (ct1bytes_len a) (ct2bytes_len a) in let h0 = ST.get () in crypto_kem_enc_ct_pack_c1 a gen_a seed_a sp_matrix ep_matrix c1; let h1 = ST.get () in crypto_kem_enc_ct_pack_c2 a mu b sp_matrix epp_matrix c2; let h2 = ST.get () in LSeq.eq_intro (LSeq.sub (as_seq h2 ct) 0 (v (ct1bytes_len a))) (LSeq.sub (as_seq h1 ct) 0 (v (ct1bytes_len a))); LSeq.lemma_concat2 (v (ct1bytes_len a)) (LSeq.sub (as_seq h1 ct) 0 (v (ct1bytes_len a))) (v (ct2bytes_len a)) (LSeq.sub (as_seq h2 ct) (v (ct1bytes_len a)) (v (ct2bytes_len a))) (as_seq h2 ct) inline_for_extraction noextract val clear_matrix3: a:FP.frodo_alg -> sp_matrix:matrix_t params_nbar (params_n a) -> ep_matrix:matrix_t params_nbar (params_n a) -> epp_matrix:matrix_t params_nbar params_nbar -> Stack unit (requires fun h -> live h sp_matrix /\ live h ep_matrix /\ live h epp_matrix /\ disjoint sp_matrix ep_matrix /\ disjoint sp_matrix epp_matrix /\ disjoint ep_matrix epp_matrix) (ensures fun h0 _ h1 -> modifies (loc sp_matrix |+| loc ep_matrix |+| loc epp_matrix) h0 h1) let clear_matrix3 a sp_matrix ep_matrix epp_matrix = clear_matrix sp_matrix; clear_matrix ep_matrix; clear_matrix epp_matrix inline_for_extraction noextract val crypto_kem_enc_ct: a:FP.frodo_alg -> gen_a:FP.frodo_gen_a{is_supported gen_a} -> mu:lbytes (bytes_mu a) -> pk:lbytes (crypto_publickeybytes a) -> seed_se:lbytes (crypto_bytes a) -> ct:lbytes (crypto_ciphertextbytes a) -> Stack unit (requires fun h -> live h mu /\ live h pk /\ live h seed_se /\ live h ct /\ disjoint ct mu /\ disjoint ct pk /\ disjoint ct seed_se) (ensures fun h0 _ h1 -> modifies (loc ct) h0 h1 /\ as_seq h1 ct == S.crypto_kem_enc_ct a gen_a (as_seq h0 mu) (as_seq h0 pk) (as_seq h0 seed_se))
{ "checked_file": "/", "dependencies": [ "Spec.Matrix.fst.checked", "Spec.Frodo.Params.fst.checked", "Spec.Frodo.KEM.Encaps.fst.checked", "prims.fst.checked", "LowStar.Buffer.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.Matrix.fst.checked", "Hacl.Impl.Frodo.Sample.fst.checked", "Hacl.Impl.Frodo.Params.fst.checked", "Hacl.Impl.Frodo.Pack.fst.checked", "Hacl.Impl.Frodo.KEM.KeyGen.fst.checked", "Hacl.Impl.Frodo.KEM.fst.checked", "Hacl.Impl.Frodo.Encode.fst.checked", "Hacl.Frodo.Random.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Frodo.KEM.Encaps.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Frodo.KEM.KeyGen", "short_module": "KG" }, { "abbrev": true, "full_module": "Spec.Matrix", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.Frodo.KEM.Encaps", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Frodo.Params", "short_module": "FP" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "LB" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Frodo.Random", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Sample", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Pack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Encode", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Frodo.Params", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Matrix", "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.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": "Hacl.Impl.Frodo.KEM", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.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": 200, "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{Hacl.Impl.Frodo.Params.is_supported gen_a} -> mu: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.bytes_mu a) -> pk: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_publickeybytes a) -> seed_se: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_bytes a) -> ct: Hacl.Impl.Matrix.lbytes (Hacl.Impl.Frodo.Params.crypto_ciphertextbytes a) -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Spec.Frodo.Params.frodo_alg", "Spec.Frodo.Params.frodo_gen_a", "Prims.b2t", "Hacl.Impl.Frodo.Params.is_supported", "Hacl.Impl.Matrix.lbytes", "Hacl.Impl.Frodo.Params.bytes_mu", "Hacl.Impl.Frodo.Params.crypto_publickeybytes", "Hacl.Impl.Frodo.Params.crypto_bytes", "Hacl.Impl.Frodo.Params.crypto_ciphertextbytes", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "Lib.Sequence.eq_intro", "Lib.IntTypes.uint8", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Spec.Frodo.KEM.Encaps.crypto_kem_enc_ct", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.Frodo.KEM.Encaps.clear_matrix3", "Hacl.Impl.Frodo.KEM.Encaps.crypto_kem_enc_ct0", "Hacl.Impl.Frodo.KEM.Encaps.get_sp_ep_epp_matrices", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U16", "Lib.IntTypes.SEC", "Lib.IntTypes.mul", "Hacl.Impl.Frodo.Params.params_nbar", "Hacl.Impl.Matrix.matrix_create", "Hacl.Impl.Matrix.matrix_t", "Hacl.Impl.Frodo.Params.params_n", "Lib.IntTypes.U8", "Hacl.Impl.Frodo.Params.publicmatrixbytes_len", "Lib.Buffer.sub", "Hacl.Impl.Frodo.Params.bytes_seed_a", "FStar.UInt32.__uint_to_t", "Spec.Frodo.Params.expand_crypto_publickeybytes", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let crypto_kem_enc_ct a gen_a mu pk seed_se ct =
push_frame (); let h0 = ST.get () in FP.expand_crypto_publickeybytes a; let seed_a = sub pk 0ul bytes_seed_a in let b = sub pk bytes_seed_a (publicmatrixbytes_len a) in let sp_matrix = matrix_create params_nbar (params_n a) in let ep_matrix = matrix_create params_nbar (params_n a) in let epp_matrix = matrix_create params_nbar params_nbar in get_sp_ep_epp_matrices a seed_se sp_matrix ep_matrix epp_matrix; crypto_kem_enc_ct0 a gen_a seed_a b mu sp_matrix ep_matrix epp_matrix ct; clear_matrix3 a sp_matrix ep_matrix epp_matrix; let h1 = ST.get () in LSeq.eq_intro (as_seq h1 ct) (S.crypto_kem_enc_ct a gen_a (as_seq h0 mu) (as_seq h0 pk) (as_seq h0 seed_se)); pop_frame ()
false
Hacl.Spec.P256.Montgomery.fst
Hacl.Spec.P256.Montgomery.bn_qmont_reduction_lemma
val bn_qmont_reduction_lemma: x:LSeq.lseq uint64 8 -> n:LSeq.lseq uint64 4 -> Lemma (requires BD.bn_v n = S.order /\ BD.bn_v x < S.order * S.order) (ensures BD.bn_v (SBM.bn_mont_reduction n (u64 0xccd1c8aaee00bc4f) x) == BD.bn_v x * qmont_R_inv % S.order)
val bn_qmont_reduction_lemma: x:LSeq.lseq uint64 8 -> n:LSeq.lseq uint64 4 -> Lemma (requires BD.bn_v n = S.order /\ BD.bn_v x < S.order * S.order) (ensures BD.bn_v (SBM.bn_mont_reduction n (u64 0xccd1c8aaee00bc4f) x) == BD.bn_v x * qmont_R_inv % S.order)
let bn_qmont_reduction_lemma x n = let k0 = 0xccd1c8aaee00bc4f in lemma_order_mont (); assert (SBM.bn_mont_pre n (u64 k0)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 k0) x in assert_norm (S.order * S.order < S.order * pow2 256); assert (BD.bn_v x < S.order * pow2 256); SBM.bn_mont_reduction_lemma n (u64 k0) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) k0 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) k0 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.order); calc (==) { (BD.bn_v x) * d % S.order; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.order } (BD.bn_v x) * (d % S.order) % S.order; (==) { } (BD.bn_v x) * qmont_R_inv % S.order; }
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Montgomery.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 279, "start_col": 0, "start_line": 259 }
module Hacl.Spec.P256.Montgomery open FStar.Mul open Lib.IntTypes module S = Spec.P256 module M = Lib.NatMod module BD = Hacl.Spec.Bignum.Definitions module SBM = Hacl.Spec.Bignum.Montgomery module SBML = Hacl.Spec.Montgomery.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// Montgomery arithmetic for a base field val lemma_abc_is_acb (a b c:nat) : Lemma (a * b * c = a * c * b) let lemma_abc_is_acb a b c = Math.Lemmas.paren_mul_right a b c; Math.Lemmas.swap_mul b c; Math.Lemmas.paren_mul_right a c b val lemma_mod_mul_assoc (n:pos) (a b c:nat) : Lemma ((a * b % n) * c % n == (a * (b * c % n)) % n) let lemma_mod_mul_assoc m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } val lemma_to_from_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R * mont_R_inv % n = 1) (ensures (a * mont_R % n) * mont_R_inv % n == a) let lemma_to_from_mont_id_gen n mont_R mont_R_inv a = lemma_mod_mul_assoc n a mont_R mont_R_inv; Math.Lemmas.modulo_lemma a n val lemma_from_to_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R_inv * mont_R % n = 1) (ensures (a * mont_R_inv % n) * mont_R % n == a) let lemma_from_to_mont_id_gen n mont_R mont_R_inv a = lemma_to_from_mont_id_gen n mont_R_inv mont_R a val mont_mul_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma (((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n == ((a * b * mont_R_inv) % n) * mont_R_inv % n) let mont_mul_lemma_gen n mont_R_inv a b = calc (==) { ((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R_inv) (b * mont_R_inv % n) n } (a * mont_R_inv * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R_inv (b * mont_R_inv) } (a * (mont_R_inv * (b * mont_R_inv))) % n; (==) { Math.Lemmas.paren_mul_right mont_R_inv b mont_R_inv } (a * (mont_R_inv * b * mont_R_inv)) % n; (==) { Math.Lemmas.swap_mul mont_R_inv b } (a * (b * mont_R_inv * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a (b * mont_R_inv) mont_R_inv } (a * (b * mont_R_inv) * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right a b mont_R_inv } (a * b * mont_R_inv * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b * mont_R_inv) mont_R_inv n } ((a * b * mont_R_inv) % n) * mont_R_inv % n; } val mont_add_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n + b * mont_R_inv % n) % n == (a + b) % n * mont_R_inv % n) let mont_add_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n + b * mont_R_inv % n) % n; (==) { Math.Lemmas.modulo_distributivity (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv + b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_add_left a b mont_R_inv } (a + b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a + b) mont_R_inv n } (a + b) % n * mont_R_inv % n; } val mont_sub_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n - b * mont_R_inv % n) % n == (a - b) % n * mont_R_inv % n) let mont_sub_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n - b * mont_R_inv % n) % n; (==) { Math.Lemmas.lemma_mod_sub_distr (a * mont_R_inv % n) (b * mont_R_inv) n } (a * mont_R_inv % n - b * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * mont_R_inv) (- b * mont_R_inv) n } (a * mont_R_inv - b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_sub_left a b mont_R_inv } (a - b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a - b) mont_R_inv n } (a - b) % n * mont_R_inv % n; } val lemma_mont_inv_gen (n:pos{1 < n}) (mont_R:pos) (mont_R_inv:nat{mont_R_inv < n}) (a:nat{a < n}) : Lemma (requires M.pow_mod #n mont_R_inv (n - 2) == mont_R % n) (ensures M.pow_mod #n (a * mont_R_inv % n) (n - 2) == M.pow_mod #n a (n - 2) * mont_R % n) let lemma_mont_inv_gen n mont_R mont_R_inv k = M.lemma_pow_mod #n (k * mont_R_inv % n) (n - 2); // assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == // M.pow (k * mont_R_inv % n) (n - 2) % n); M.lemma_pow_mod_base (k * mont_R_inv) (n - 2) n; // == M.pow (k * mont_R_inv) (n - 2) % n M.lemma_pow_mul_base k mont_R_inv (n - 2); // == M.pow k (n - 2) * M.pow mont_R_inv (n - 2) % n Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) (M.pow mont_R_inv (n - 2)) n; // == M.pow k (n - 2) * (M.pow mont_R_inv (n - 2) % n) % n M.lemma_pow_mod #n mont_R_inv (n - 2); assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == M.pow k (n - 2) * (mont_R % n) % n); Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) * mont_R % n Math.Lemmas.lemma_mod_mul_distr_l (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) % n * mont_R % n M.lemma_pow_mod #n k (n - 2) let mont_cancel_lemma_gen n mont_R mont_R_inv a b = calc (==) { (a * mont_R % n * b * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right (a * mont_R % n) b mont_R_inv } (a * mont_R % n * (b * mont_R_inv)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R) (b * mont_R_inv) n } (a * mont_R * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R (b * mont_R_inv); Math.Lemmas.swap_mul mont_R (b * mont_R_inv) } (a * (b * mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.paren_mul_right b mont_R_inv mont_R } (a * (b * (mont_R_inv * mont_R))) % n; (==) { Math.Lemmas.paren_mul_right a b (mont_R_inv * mont_R) } (a * b * (mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * b) (mont_R_inv * mont_R) n } (a * b * (mont_R_inv * mont_R % n)) % n; (==) { assert (mont_R_inv * mont_R % n = 1) } (a * b) % n; } let fmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.prime in d % S.prime let mul_fmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.prime in SBML.mont_preconditions_d 64 4 S.prime; assert (d * pow2 256 % S.prime = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.prime //--------------------------------------// // bn_mont_reduction is x * fmont_R_inv // //--------------------------------------// val lemma_prime_mont: unit -> Lemma (S.prime % 2 = 1 /\ S.prime < pow2 256 /\ (1 + S.prime) % pow2 64 = 0) let lemma_prime_mont () = assert_norm (S.prime % 2 = 1); assert_norm (S.prime < pow2 256); assert_norm ((1 + S.prime) % pow2 64 = 0) let bn_mont_reduction_lemma x n = lemma_prime_mont (); assert (SBM.bn_mont_pre n (u64 1)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 1) x in assert_norm (S.prime * S.prime < S.prime * pow2 256); assert (BD.bn_v x < S.prime * pow2 256); SBM.bn_mont_reduction_lemma n (u64 1) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) 1 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) 1 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.prime); calc (==) { BD.bn_v x * d % S.prime; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.prime } BD.bn_v x * (d % S.prime) % S.prime; (==) { } BD.bn_v x * fmont_R_inv % S.prime; } //--------------------------- let lemma_from_mont_zero a = Spec.P256.Lemmas.prime_lemma (); Lib.NatMod.lemma_mul_mod_prime_zero #S.prime a fmont_R_inv let lemma_to_from_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.prime fmont_R fmont_R_inv a let lemma_from_to_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_from_to_mont_id_gen S.prime fmont_R fmont_R_inv a let fmont_mul_lemma a b = mont_mul_lemma_gen S.prime fmont_R_inv a b let fmont_add_lemma a b = mont_add_lemma_gen S.prime fmont_R_inv a b let fmont_sub_lemma a b = mont_sub_lemma_gen S.prime fmont_R_inv a b /// Montgomery arithmetic for a scalar field let qmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.order in d % S.order let mul_qmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.order in SBML.mont_preconditions_d 64 4 S.order; assert (d * pow2 256 % S.order = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.order; assert (d % S.order * pow2 256 % S.order = 1) //--------------------------------------// // bn_mont_reduction is x * qmont_R_inv // //--------------------------------------// val lemma_order_mont: unit -> Lemma (S.order % 2 = 1 /\ S.order < pow2 256 /\ (1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let lemma_order_mont () = assert_norm (S.order % 2 = 1); assert_norm (S.order < pow2 256); assert_norm ((1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0)
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.fst.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.Montgomery.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "SBML" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SBM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Lib.Sequence.lseq Lib.IntTypes.uint64 8 -> n: Lib.Sequence.lseq Lib.IntTypes.uint64 4 -> FStar.Pervasives.Lemma (requires Hacl.Spec.Bignum.Definitions.bn_v n = Spec.P256.PointOps.order /\ Hacl.Spec.Bignum.Definitions.bn_v x < Spec.P256.PointOps.order * Spec.P256.PointOps.order) (ensures Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.Montgomery.bn_mont_reduction n (Lib.IntTypes.u64 0xccd1c8aaee00bc4f) x) == Hacl.Spec.Bignum.Definitions.bn_v x * Hacl.Spec.P256.Montgomery.qmont_R_inv % Spec.P256.PointOps.order)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.Sequence.lseq", "Lib.IntTypes.uint64", "Prims.int", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.IntTypes.U64", "Spec.P256.PointOps.order", "Hacl.Spec.P256.Montgomery.qmont_R_inv", "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", "Prims.squash", "Prims._assert", "Hacl.Spec.Montgomery.Lemmas.mont_reduction_lemma", "Prims.nat", "Hacl.Spec.Montgomery.Lemmas.mont_reduction", "Hacl.Spec.Bignum.Montgomery.bn_mont_reduction_lemma", "Lib.IntTypes.u64", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "FStar.Pervasives.assert_norm", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Montgomery.bn_mont_reduction", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Montgomery.Lemmas.eea_pow2_odd", "Hacl.Spec.Bignum.Montgomery.bn_mont_pre", "Hacl.Spec.P256.Montgomery.lemma_order_mont" ]
[]
false
false
true
false
false
let bn_qmont_reduction_lemma x n =
let k0 = 0xccd1c8aaee00bc4f in lemma_order_mont (); assert (SBM.bn_mont_pre n (u64 k0)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 k0) x in assert_norm (S.order * S.order < S.order * pow2 256); assert (BD.bn_v x < S.order * pow2 256); SBM.bn_mont_reduction_lemma n (u64 k0) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) k0 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) k0 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.order); calc ( == ) { (BD.bn_v x) * d % S.order; ( == ) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.order } (BD.bn_v x) * (d % S.order) % S.order; ( == ) { () } (BD.bn_v x) * qmont_R_inv % S.order; }
false
Hacl.Spec.P256.Montgomery.fst
Hacl.Spec.P256.Montgomery.qmont_inv_mul_lemma
val qmont_inv_mul_lemma: s:S.qelem -> sinv:S.qelem -> b:S.qelem -> Lemma (requires from_qmont sinv == S.qinv (from_qmont s)) // post-condition of qinv (ensures S.qinv s * b % S.order == from_qmont (sinv * from_qmont b))
val qmont_inv_mul_lemma: s:S.qelem -> sinv:S.qelem -> b:S.qelem -> Lemma (requires from_qmont sinv == S.qinv (from_qmont s)) // post-condition of qinv (ensures S.qinv s * b % S.order == from_qmont (sinv * from_qmont b))
let qmont_inv_mul_lemma s sinv b = let s_mont = from_qmont s in let b_mont = from_qmont b in calc (==) { (sinv * b_mont * qmont_R_inv) % S.order; (==) { lemma_from_to_qmont_id sinv } (S.qinv s_mont * qmont_R % S.order * b_mont * qmont_R_inv) % S.order; (==) { qmont_cancel_lemma1 (S.qinv s_mont) b_mont } S.qinv s_mont * b_mont % S.order; (==) { qmont_inv_lemma s } (S.qinv s * qmont_R % S.order * (b * qmont_R_inv % S.order)) % S.order; (==) { qmont_cancel_lemma2 (S.qinv s) b } S.qinv s * b % S.order; }
{ "file_name": "code/ecdsap256/Hacl.Spec.P256.Montgomery.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 351, "start_col": 0, "start_line": 338 }
module Hacl.Spec.P256.Montgomery open FStar.Mul open Lib.IntTypes module S = Spec.P256 module M = Lib.NatMod module BD = Hacl.Spec.Bignum.Definitions module SBM = Hacl.Spec.Bignum.Montgomery module SBML = Hacl.Spec.Montgomery.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// Montgomery arithmetic for a base field val lemma_abc_is_acb (a b c:nat) : Lemma (a * b * c = a * c * b) let lemma_abc_is_acb a b c = Math.Lemmas.paren_mul_right a b c; Math.Lemmas.swap_mul b c; Math.Lemmas.paren_mul_right a c b val lemma_mod_mul_assoc (n:pos) (a b c:nat) : Lemma ((a * b % n) * c % n == (a * (b * c % n)) % n) let lemma_mod_mul_assoc m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } val lemma_to_from_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R * mont_R_inv % n = 1) (ensures (a * mont_R % n) * mont_R_inv % n == a) let lemma_to_from_mont_id_gen n mont_R mont_R_inv a = lemma_mod_mul_assoc n a mont_R mont_R_inv; Math.Lemmas.modulo_lemma a n val lemma_from_to_mont_id_gen (n mont_R mont_R_inv:pos) (a:nat{a < n}) : Lemma (requires mont_R_inv * mont_R % n = 1) (ensures (a * mont_R_inv % n) * mont_R % n == a) let lemma_from_to_mont_id_gen n mont_R mont_R_inv a = lemma_to_from_mont_id_gen n mont_R_inv mont_R a val mont_mul_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma (((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n == ((a * b * mont_R_inv) % n) * mont_R_inv % n) let mont_mul_lemma_gen n mont_R_inv a b = calc (==) { ((a * mont_R_inv % n) * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R_inv) (b * mont_R_inv % n) n } (a * mont_R_inv * (b * mont_R_inv % n)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R_inv (b * mont_R_inv) } (a * (mont_R_inv * (b * mont_R_inv))) % n; (==) { Math.Lemmas.paren_mul_right mont_R_inv b mont_R_inv } (a * (mont_R_inv * b * mont_R_inv)) % n; (==) { Math.Lemmas.swap_mul mont_R_inv b } (a * (b * mont_R_inv * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a (b * mont_R_inv) mont_R_inv } (a * (b * mont_R_inv) * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right a b mont_R_inv } (a * b * mont_R_inv * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b * mont_R_inv) mont_R_inv n } ((a * b * mont_R_inv) % n) * mont_R_inv % n; } val mont_add_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n + b * mont_R_inv % n) % n == (a + b) % n * mont_R_inv % n) let mont_add_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n + b * mont_R_inv % n) % n; (==) { Math.Lemmas.modulo_distributivity (a * mont_R_inv) (b * mont_R_inv) n } (a * mont_R_inv + b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_add_left a b mont_R_inv } (a + b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a + b) mont_R_inv n } (a + b) % n * mont_R_inv % n; } val mont_sub_lemma_gen (n:pos) (mont_R_inv a b: nat) : Lemma ((a * mont_R_inv % n - b * mont_R_inv % n) % n == (a - b) % n * mont_R_inv % n) let mont_sub_lemma_gen n mont_R_inv a b = calc (==) { (a * mont_R_inv % n - b * mont_R_inv % n) % n; (==) { Math.Lemmas.lemma_mod_sub_distr (a * mont_R_inv % n) (b * mont_R_inv) n } (a * mont_R_inv % n - b * mont_R_inv) % n; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * mont_R_inv) (- b * mont_R_inv) n } (a * mont_R_inv - b * mont_R_inv) % n; (==) { Math.Lemmas.distributivity_sub_left a b mont_R_inv } (a - b) * mont_R_inv % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a - b) mont_R_inv n } (a - b) % n * mont_R_inv % n; } val lemma_mont_inv_gen (n:pos{1 < n}) (mont_R:pos) (mont_R_inv:nat{mont_R_inv < n}) (a:nat{a < n}) : Lemma (requires M.pow_mod #n mont_R_inv (n - 2) == mont_R % n) (ensures M.pow_mod #n (a * mont_R_inv % n) (n - 2) == M.pow_mod #n a (n - 2) * mont_R % n) let lemma_mont_inv_gen n mont_R mont_R_inv k = M.lemma_pow_mod #n (k * mont_R_inv % n) (n - 2); // assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == // M.pow (k * mont_R_inv % n) (n - 2) % n); M.lemma_pow_mod_base (k * mont_R_inv) (n - 2) n; // == M.pow (k * mont_R_inv) (n - 2) % n M.lemma_pow_mul_base k mont_R_inv (n - 2); // == M.pow k (n - 2) * M.pow mont_R_inv (n - 2) % n Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) (M.pow mont_R_inv (n - 2)) n; // == M.pow k (n - 2) * (M.pow mont_R_inv (n - 2) % n) % n M.lemma_pow_mod #n mont_R_inv (n - 2); assert (M.pow_mod #n (k * mont_R_inv % n) (n - 2) == M.pow k (n - 2) * (mont_R % n) % n); Math.Lemmas.lemma_mod_mul_distr_r (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) * mont_R % n Math.Lemmas.lemma_mod_mul_distr_l (M.pow k (n - 2)) mont_R n; // == M.pow k (n - 2) % n * mont_R % n M.lemma_pow_mod #n k (n - 2) let mont_cancel_lemma_gen n mont_R mont_R_inv a b = calc (==) { (a * mont_R % n * b * mont_R_inv) % n; (==) { Math.Lemmas.paren_mul_right (a * mont_R % n) b mont_R_inv } (a * mont_R % n * (b * mont_R_inv)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * mont_R) (b * mont_R_inv) n } (a * mont_R * (b * mont_R_inv)) % n; (==) { Math.Lemmas.paren_mul_right a mont_R (b * mont_R_inv); Math.Lemmas.swap_mul mont_R (b * mont_R_inv) } (a * (b * mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.paren_mul_right b mont_R_inv mont_R } (a * (b * (mont_R_inv * mont_R))) % n; (==) { Math.Lemmas.paren_mul_right a b (mont_R_inv * mont_R) } (a * b * (mont_R_inv * mont_R)) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * b) (mont_R_inv * mont_R) n } (a * b * (mont_R_inv * mont_R % n)) % n; (==) { assert (mont_R_inv * mont_R % n = 1) } (a * b) % n; } let fmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.prime in d % S.prime let mul_fmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.prime in SBML.mont_preconditions_d 64 4 S.prime; assert (d * pow2 256 % S.prime = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.prime //--------------------------------------// // bn_mont_reduction is x * fmont_R_inv // //--------------------------------------// val lemma_prime_mont: unit -> Lemma (S.prime % 2 = 1 /\ S.prime < pow2 256 /\ (1 + S.prime) % pow2 64 = 0) let lemma_prime_mont () = assert_norm (S.prime % 2 = 1); assert_norm (S.prime < pow2 256); assert_norm ((1 + S.prime) % pow2 64 = 0) let bn_mont_reduction_lemma x n = lemma_prime_mont (); assert (SBM.bn_mont_pre n (u64 1)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 1) x in assert_norm (S.prime * S.prime < S.prime * pow2 256); assert (BD.bn_v x < S.prime * pow2 256); SBM.bn_mont_reduction_lemma n (u64 1) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) 1 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) 1 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.prime); calc (==) { BD.bn_v x * d % S.prime; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.prime } BD.bn_v x * (d % S.prime) % S.prime; (==) { } BD.bn_v x * fmont_R_inv % S.prime; } //--------------------------- let lemma_from_mont_zero a = Spec.P256.Lemmas.prime_lemma (); Lib.NatMod.lemma_mul_mod_prime_zero #S.prime a fmont_R_inv let lemma_to_from_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.prime fmont_R fmont_R_inv a let lemma_from_to_mont_id a = mul_fmont_R_and_R_inv_is_one (); lemma_from_to_mont_id_gen S.prime fmont_R fmont_R_inv a let fmont_mul_lemma a b = mont_mul_lemma_gen S.prime fmont_R_inv a b let fmont_add_lemma a b = mont_add_lemma_gen S.prime fmont_R_inv a b let fmont_sub_lemma a b = mont_sub_lemma_gen S.prime fmont_R_inv a b /// Montgomery arithmetic for a scalar field let qmont_R_inv = let d, _ = SBML.eea_pow2_odd 256 S.order in d % S.order let mul_qmont_R_and_R_inv_is_one () = let d, k = SBML.eea_pow2_odd 256 S.order in SBML.mont_preconditions_d 64 4 S.order; assert (d * pow2 256 % S.order = 1); Math.Lemmas.lemma_mod_mul_distr_l d (pow2 256) S.order; assert (d % S.order * pow2 256 % S.order = 1) //--------------------------------------// // bn_mont_reduction is x * qmont_R_inv // //--------------------------------------// val lemma_order_mont: unit -> Lemma (S.order % 2 = 1 /\ S.order < pow2 256 /\ (1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let lemma_order_mont () = assert_norm (S.order % 2 = 1); assert_norm (S.order < pow2 256); assert_norm ((1 + S.order * 0xccd1c8aaee00bc4f) % pow2 64 = 0) let bn_qmont_reduction_lemma x n = let k0 = 0xccd1c8aaee00bc4f in lemma_order_mont (); assert (SBM.bn_mont_pre n (u64 k0)); let d, _ = SBML.eea_pow2_odd 256 (BD.bn_v n) in let res = SBM.bn_mont_reduction n (u64 k0) x in assert_norm (S.order * S.order < S.order * pow2 256); assert (BD.bn_v x < S.order * pow2 256); SBM.bn_mont_reduction_lemma n (u64 k0) x; assert (BD.bn_v res == SBML.mont_reduction 64 4 (BD.bn_v n) k0 (BD.bn_v x)); SBML.mont_reduction_lemma 64 4 (BD.bn_v n) k0 (BD.bn_v x); assert (BD.bn_v res == BD.bn_v x * d % S.order); calc (==) { (BD.bn_v x) * d % S.order; (==) { Math.Lemmas.lemma_mod_mul_distr_r (BD.bn_v x) d S.order } (BD.bn_v x) * (d % S.order) % S.order; (==) { } (BD.bn_v x) * qmont_R_inv % S.order; } //-------------------------- let lemma_to_from_qmont_id a = mul_qmont_R_and_R_inv_is_one (); lemma_to_from_mont_id_gen S.order qmont_R qmont_R_inv a let lemma_from_to_qmont_id a = mul_qmont_R_and_R_inv_is_one (); Math.Lemmas.swap_mul qmont_R qmont_R_inv; lemma_from_to_mont_id_gen S.order qmont_R qmont_R_inv a let qmont_add_lemma a b = mont_add_lemma_gen S.order qmont_R_inv a b let qmont_mul_lemma a b = mont_mul_lemma_gen S.order qmont_R_inv a b let qmont_inv_lemma k = assert_norm (M.pow_mod_ #S.order qmont_R_inv (S.order - 2) == qmont_R % S.order); M.pow_mod_def #S.order qmont_R_inv (S.order - 2); assert (M.pow_mod #S.order qmont_R_inv (S.order - 2) == qmont_R % S.order); lemma_mont_inv_gen S.order qmont_R qmont_R_inv k; assert (M.pow_mod #S.order (k * qmont_R_inv % S.order) (S.order - 2) == M.pow_mod #S.order k (S.order - 2) * qmont_R % S.order); assert (S.qinv (k * qmont_R_inv % S.order) == S.qinv k * qmont_R % S.order) val qmont_cancel_lemma1: a:S.qelem -> b:S.qelem -> Lemma ((a * qmont_R % S.order * b * qmont_R_inv) % S.order = a * b % S.order) let qmont_cancel_lemma1 a b = mul_qmont_R_and_R_inv_is_one (); mont_cancel_lemma_gen S.order qmont_R qmont_R_inv a b val qmont_cancel_lemma2: a:S.qelem -> b:S.qelem -> Lemma (to_qmont a * from_qmont b % S.order = a * b % S.order) let qmont_cancel_lemma2 a b = calc (==) { to_qmont a * from_qmont b % S.order; (==) { } (a * qmont_R % S.order * (b * qmont_R_inv % S.order)) % S.order; (==) { Math.Lemmas.lemma_mod_mul_distr_r (a * qmont_R % S.order) (b * qmont_R_inv) S.order } (a * qmont_R % S.order * (b * qmont_R_inv)) % S.order; (==) { Math.Lemmas.paren_mul_right (a * qmont_R % S.order) b qmont_R_inv } (a * qmont_R % S.order * b * qmont_R_inv) % S.order; (==) { qmont_cancel_lemma1 a b } a * b % S.order; }
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.fst.checked", "prims.fst.checked", "Lib.NatMod.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Montgomery.Lemmas.fst.checked", "Hacl.Spec.Bignum.Montgomery.fsti.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.P256.Montgomery.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Montgomery.Lemmas", "short_module": "SBML" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Montgomery", "short_module": "SBM" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.NatMod", "short_module": "M" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Spec.P256.PointOps.qelem -> sinv: Spec.P256.PointOps.qelem -> b: Spec.P256.PointOps.qelem -> FStar.Pervasives.Lemma (requires Hacl.Spec.P256.Montgomery.from_qmont sinv == Spec.P256.PointOps.qinv (Hacl.Spec.P256.Montgomery.from_qmont s)) (ensures Spec.P256.PointOps.qinv s * b % Spec.P256.PointOps.order == Hacl.Spec.P256.Montgomery.from_qmont (sinv * Hacl.Spec.P256.Montgomery.from_qmont b))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.qelem", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Hacl.Spec.P256.Montgomery.qmont_R_inv", "Spec.P256.PointOps.order", "Spec.P256.PointOps.qinv", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Hacl.Spec.P256.Montgomery.qmont_R", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.P256.Montgomery.lemma_from_to_qmont_id", "Prims.squash", "Hacl.Spec.P256.Montgomery.qmont_cancel_lemma1", "Hacl.Spec.P256.Montgomery.qmont_inv_lemma", "Hacl.Spec.P256.Montgomery.qmont_cancel_lemma2", "Hacl.Spec.P256.Montgomery.from_qmont" ]
[]
false
false
true
false
false
let qmont_inv_mul_lemma s sinv b =
let s_mont = from_qmont s in let b_mont = from_qmont b in calc ( == ) { ((sinv * b_mont) * qmont_R_inv) % S.order; ( == ) { lemma_from_to_qmont_id sinv } (((S.qinv s_mont * qmont_R % S.order) * b_mont) * qmont_R_inv) % S.order; ( == ) { qmont_cancel_lemma1 (S.qinv s_mont) b_mont } S.qinv s_mont * b_mont % S.order; ( == ) { qmont_inv_lemma s } ((S.qinv s * qmont_R % S.order) * (b * qmont_R_inv % S.order)) % S.order; ( == ) { qmont_cancel_lemma2 (S.qinv s) b } S.qinv s * b % S.order; }
false
LowParse.Spec.List.fst
LowParse.Spec.List.parse_list
val parse_list (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (parser parse_list_kind (list t))
val parse_list (#k: parser_kind) (#t: Type) (p: parser k t) : Tot (parser parse_list_kind (list t))
let parse_list #k #t p = parse_list_bare_injective p; parse_list_bare_consumes_all p; parser_kind_prop_equiv parse_list_kind (parse_list_bare p); parse_list_bare p
{ "file_name": "src/lowparse/LowParse.Spec.List.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 19, "end_line": 59, "start_col": 0, "start_line": 55 }
module LowParse.Spec.List include LowParse.Spec.Combinators // for seq_slice_append_l module Seq = FStar.Seq module L = FStar.List.Tot module U32 = FStar.UInt32 module Classical = FStar.Classical (* Parse a list, until there is nothing left to read. This parser will mostly fail EXCEPT if the whole size is known and the slice has been suitably truncated beforehand, or if the elements of the list all have a known constant size. *) #push-options "--z3rlimit 16" let parse_list_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) : Lemma (ensures (injective (parse_list_bare p))) = parser_kind_prop_equiv k p; let f () : Lemma (injective p) = () in let rec aux (b1: bytes) (b2: bytes) : Lemma (requires (injective_precond (parse_list_bare p) b1 b2)) (ensures (injective_postcond (parse_list_bare p) b1 b2)) (decreases (Seq.length b1 + Seq.length b2)) = if Seq.length b1 = 0 then begin () // assert (Seq.equal b1 b2) end else begin assert (injective_precond p b1 b2); f (); assert (injective_postcond p b1 b2); let (Some (_, len1)) = parse p b1 in let (Some (_, len2)) = parse p b2 in assert ((len1 <: nat) == (len2 <: nat)); let b1' : bytes = Seq.slice b1 len1 (Seq.length b1) in let b2' : bytes = Seq.slice b2 len2 (Seq.length b2) in aux b1' b2'; let (Some (_, len1')) = parse (parse_list_bare p) b1' in let (Some (_, len2')) = parse (parse_list_bare p) b2' in Seq.lemma_split (Seq.slice b1 0 (len1 + len1')) len1; Seq.lemma_split (Seq.slice b2 0 (len2 + len2')) len2; assert (injective_postcond (parse_list_bare p) b1 b2) end in Classical.forall_intro_2 (fun b -> Classical.move_requires (aux b)) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.List.fst" }
[ { "abbrev": true, "full_module": "FStar.Classical", "short_module": "Classical" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParse.Spec.Base.parser k t -> LowParse.Spec.Base.parser LowParse.Spec.List.parse_list_kind (Prims.list t)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.List.parse_list_bare", "Prims.unit", "LowParse.Spec.Base.parser_kind_prop_equiv", "Prims.list", "LowParse.Spec.List.parse_list_kind", "LowParse.Spec.List.parse_list_bare_consumes_all", "LowParse.Spec.List.parse_list_bare_injective" ]
[]
false
false
false
false
false
let parse_list #k #t p =
parse_list_bare_injective p; parse_list_bare_consumes_all p; parser_kind_prop_equiv parse_list_kind (parse_list_bare p); parse_list_bare p
false
Spec.Blake2.Definitions.fst
Spec.Blake2.Definitions.wt
val wt (a: alg) : t: inttype{unsigned t}
val wt (a: alg) : t: inttype{unsigned t}
let wt (a:alg) : t:inttype{unsigned t} = match a with | Blake2S -> U32 | Blake2B -> U64
{ "file_name": "specs/Spec.Blake2.Definitions.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 21, "start_col": 0, "start_line": 18 }
module Spec.Blake2.Definitions open FStar.Mul open Lib.IntTypes open Lib.RawIntTypes open Lib.Sequence open Lib.ByteSequence #set-options "--z3rlimit 50" type alg = | Blake2S | Blake2B let alg_inversion_lemma (a:alg) : Lemma (a == Blake2S \/ a == Blake2B) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Spec.Blake2.Definitions.fst" }
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.RawIntTypes", "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.Blake2", "short_module": null }, { "abbrev": false, "full_module": "Spec.Blake2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Blake2.Definitions.alg -> t: Lib.IntTypes.inttype{Lib.IntTypes.unsigned t}
Prims.Tot
[ "total" ]
[]
[ "Spec.Blake2.Definitions.alg", "Lib.IntTypes.U32", "Lib.IntTypes.U64", "Lib.IntTypes.inttype", "Prims.b2t", "Lib.IntTypes.unsigned" ]
[]
false
false
false
false
false
let wt (a: alg) : t: inttype{unsigned t} =
match a with | Blake2S -> U32 | Blake2B -> U64
false
LowParse.Spec.List.fst
LowParse.Spec.List.tot_parse_list_aux
val tot_parse_list_aux (#k: parser_kind) (#t: Type) (p: tot_parser k t) (b: bytes) : Pure (option (list t * (consumed_length b))) (requires True) (ensures (fun y -> y == parse_list_aux #k p b)) (decreases (Seq.length b))
val tot_parse_list_aux (#k: parser_kind) (#t: Type) (p: tot_parser k t) (b: bytes) : Pure (option (list t * (consumed_length b))) (requires True) (ensures (fun y -> y == parse_list_aux #k p b)) (decreases (Seq.length b))
let rec tot_parse_list_aux (#k: parser_kind) (#t: Type) (p: tot_parser k t) (b: bytes) : Pure (option (list t * (consumed_length b))) (requires True) (ensures (fun y -> y == parse_list_aux #k p b)) (decreases (Seq.length b)) = if Seq.length b = 0 then Some ([], (0 <: consumed_length b)) else match p b with | None -> None | Some (v, n) -> if n = 0 then None (* elements cannot be empty *) else match tot_parse_list_aux p (Seq.slice b n (Seq.length b)) with | Some (l, n') -> Some (v :: l, (n + n' <: consumed_length b)) | _ -> None
{ "file_name": "src/lowparse/LowParse.Spec.List.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 12, "end_line": 127, "start_col": 0, "start_line": 106 }
module LowParse.Spec.List include LowParse.Spec.Combinators // for seq_slice_append_l module Seq = FStar.Seq module L = FStar.List.Tot module U32 = FStar.UInt32 module Classical = FStar.Classical (* Parse a list, until there is nothing left to read. This parser will mostly fail EXCEPT if the whole size is known and the slice has been suitably truncated beforehand, or if the elements of the list all have a known constant size. *) #push-options "--z3rlimit 16" let parse_list_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) : Lemma (ensures (injective (parse_list_bare p))) = parser_kind_prop_equiv k p; let f () : Lemma (injective p) = () in let rec aux (b1: bytes) (b2: bytes) : Lemma (requires (injective_precond (parse_list_bare p) b1 b2)) (ensures (injective_postcond (parse_list_bare p) b1 b2)) (decreases (Seq.length b1 + Seq.length b2)) = if Seq.length b1 = 0 then begin () // assert (Seq.equal b1 b2) end else begin assert (injective_precond p b1 b2); f (); assert (injective_postcond p b1 b2); let (Some (_, len1)) = parse p b1 in let (Some (_, len2)) = parse p b2 in assert ((len1 <: nat) == (len2 <: nat)); let b1' : bytes = Seq.slice b1 len1 (Seq.length b1) in let b2' : bytes = Seq.slice b2 len2 (Seq.length b2) in aux b1' b2'; let (Some (_, len1')) = parse (parse_list_bare p) b1' in let (Some (_, len2')) = parse (parse_list_bare p) b2' in Seq.lemma_split (Seq.slice b1 0 (len1 + len1')) len1; Seq.lemma_split (Seq.slice b2 0 (len2 + len2')) len2; assert (injective_postcond (parse_list_bare p) b1 b2) end in Classical.forall_intro_2 (fun b -> Classical.move_requires (aux b)) #pop-options let parse_list #k #t p = parse_list_bare_injective p; parse_list_bare_consumes_all p; parser_kind_prop_equiv parse_list_kind (parse_list_bare p); parse_list_bare p let parse_list_eq (#k: parser_kind) (#t: Type) (p: parser k t) (b: bytes) : Lemma (parse (parse_list p) b == ( if Seq.length b = 0 then Some ([], (0 <: consumed_length b)) else match parse p b with | None -> None | Some (v, n) -> if n = 0 then None (* elements cannot be empty *) else match parse (parse_list p) (Seq.slice b n (Seq.length b)) with | Some (l, n') -> Some (v :: l, (n + n' <: consumed_length b)) | _ -> None )) = () let parse_list_eq' (#k: parser_kind) (#t: Type) (p: parser k t) (b: bytes) : Lemma (requires (k.parser_kind_low > 0)) (ensures (parse (parse_list p) b == ( if Seq.length b = 0 then Some ([], (0 <: consumed_length b)) else match parse p b with | None -> None | Some (v, n) -> begin match parse (parse_list p) (Seq.slice b n (Seq.length b)) with | Some (l, n') -> Some (v :: l, (n + n' <: consumed_length b)) | _ -> None end ))) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.List.fst" }
[ { "abbrev": true, "full_module": "FStar.Classical", "short_module": "Classical" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": true, "full_module": "FStar.Classical", "short_module": "Classical" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParse.Spec.Base.tot_parser k t -> b: LowParse.Bytes.bytes -> Prims.Pure (FStar.Pervasives.Native.option (Prims.list t * LowParse.Spec.Base.consumed_length b))
Prims.Pure
[ "" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.tot_parser", "LowParse.Bytes.bytes", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "Prims.list", "LowParse.Spec.Base.consumed_length", "FStar.Pervasives.Native.Mktuple2", "Prims.Nil", "Prims.bool", "FStar.Pervasives.Native.None", "LowParse.Spec.List.tot_parse_list_aux", "FStar.Seq.Base.slice", "Prims.Cons", "Prims.op_Addition", "FStar.Pervasives.Native.option", "Prims.l_True", "Prims.eq2", "LowParse.Spec.List.parse_list_aux" ]
[ "recursion" ]
false
false
false
false
false
let rec tot_parse_list_aux (#k: parser_kind) (#t: Type) (p: tot_parser k t) (b: bytes) : Pure (option (list t * (consumed_length b))) (requires True) (ensures (fun y -> y == parse_list_aux #k p b)) (decreases (Seq.length b)) =
if Seq.length b = 0 then Some ([], (0 <: consumed_length b)) else match p b with | None -> None | Some (v, n) -> if n = 0 then None else match tot_parse_list_aux p (Seq.slice b n (Seq.length b)) with | Some (l, n') -> Some (v :: l, (n + n' <: consumed_length b)) | _ -> None
false
LowParse.Spec.List.fst
LowParse.Spec.List.serialize_list
val serialize_list (#k: parser_kind) (#t: Type) (p: parser k t) (s: serializer p) : Pure (serializer (parse_list p)) (requires ( serialize_list_precond k )) (ensures (fun _ -> True))
val serialize_list (#k: parser_kind) (#t: Type) (p: parser k t) (s: serializer p) : Pure (serializer (parse_list p)) (requires ( serialize_list_precond k )) (ensures (fun _ -> True))
let serialize_list (#k: parser_kind) (#t: Type) (p: parser k t) (s: serializer p) : Pure (serializer (parse_list p)) (requires ( serialize_list_precond k )) (ensures (fun _ -> True)) = bare_serialize_list_correct p s; bare_serialize_list p s
{ "file_name": "src/lowparse/LowParse.Spec.List.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 25, "end_line": 180, "start_col": 0, "start_line": 169 }
module LowParse.Spec.List include LowParse.Spec.Combinators // for seq_slice_append_l module Seq = FStar.Seq module L = FStar.List.Tot module U32 = FStar.UInt32 module Classical = FStar.Classical (* Parse a list, until there is nothing left to read. This parser will mostly fail EXCEPT if the whole size is known and the slice has been suitably truncated beforehand, or if the elements of the list all have a known constant size. *) #push-options "--z3rlimit 16" let parse_list_bare_injective (#k: parser_kind) (#t: Type) (p: parser k t) : Lemma (ensures (injective (parse_list_bare p))) = parser_kind_prop_equiv k p; let f () : Lemma (injective p) = () in let rec aux (b1: bytes) (b2: bytes) : Lemma (requires (injective_precond (parse_list_bare p) b1 b2)) (ensures (injective_postcond (parse_list_bare p) b1 b2)) (decreases (Seq.length b1 + Seq.length b2)) = if Seq.length b1 = 0 then begin () // assert (Seq.equal b1 b2) end else begin assert (injective_precond p b1 b2); f (); assert (injective_postcond p b1 b2); let (Some (_, len1)) = parse p b1 in let (Some (_, len2)) = parse p b2 in assert ((len1 <: nat) == (len2 <: nat)); let b1' : bytes = Seq.slice b1 len1 (Seq.length b1) in let b2' : bytes = Seq.slice b2 len2 (Seq.length b2) in aux b1' b2'; let (Some (_, len1')) = parse (parse_list_bare p) b1' in let (Some (_, len2')) = parse (parse_list_bare p) b2' in Seq.lemma_split (Seq.slice b1 0 (len1 + len1')) len1; Seq.lemma_split (Seq.slice b2 0 (len2 + len2')) len2; assert (injective_postcond (parse_list_bare p) b1 b2) end in Classical.forall_intro_2 (fun b -> Classical.move_requires (aux b)) #pop-options let parse_list #k #t p = parse_list_bare_injective p; parse_list_bare_consumes_all p; parser_kind_prop_equiv parse_list_kind (parse_list_bare p); parse_list_bare p let parse_list_eq (#k: parser_kind) (#t: Type) (p: parser k t) (b: bytes) : Lemma (parse (parse_list p) b == ( if Seq.length b = 0 then Some ([], (0 <: consumed_length b)) else match parse p b with | None -> None | Some (v, n) -> if n = 0 then None (* elements cannot be empty *) else match parse (parse_list p) (Seq.slice b n (Seq.length b)) with | Some (l, n') -> Some (v :: l, (n + n' <: consumed_length b)) | _ -> None )) = () let parse_list_eq' (#k: parser_kind) (#t: Type) (p: parser k t) (b: bytes) : Lemma (requires (k.parser_kind_low > 0)) (ensures (parse (parse_list p) b == ( if Seq.length b = 0 then Some ([], (0 <: consumed_length b)) else match parse p b with | None -> None | Some (v, n) -> begin match parse (parse_list p) (Seq.slice b n (Seq.length b)) with | Some (l, n') -> Some (v :: l, (n + n' <: consumed_length b)) | _ -> None end ))) = () let rec tot_parse_list_aux (#k: parser_kind) (#t: Type) (p: tot_parser k t) (b: bytes) : Pure (option (list t * (consumed_length b))) (requires True) (ensures (fun y -> y == parse_list_aux #k p b)) (decreases (Seq.length b)) = if Seq.length b = 0 then Some ([], (0 <: consumed_length b)) else match p b with | None -> None | Some (v, n) -> if n = 0 then None (* elements cannot be empty *) else match tot_parse_list_aux p (Seq.slice b n (Seq.length b)) with | Some (l, n') -> Some (v :: l, (n + n' <: consumed_length b)) | _ -> None let tot_parse_list #k #t p = parser_kind_prop_ext parse_list_kind (parse_list #k p) (tot_parse_list_aux p); tot_parse_list_aux p let bare_serialize_list_correct (#k: parser_kind) (#t: Type) (p: parser k t) (s: serializer p) : Lemma (requires (serialize_list_precond k)) (ensures (serializer_correct (parse_list p) (bare_serialize_list p s))) = parser_kind_prop_equiv k p; let f () : Lemma (serialize_list_precond k) = () in let rec prf (l: list t) : Lemma (parse (parse_list p) (bare_serialize_list p s l) == Some (l, Seq.length (bare_serialize_list p s l))) = match l with | [] -> () | a :: q -> let pa = parse p (bare_serialize_list p s l) in f (); parser_kind_prop_equiv k p; assert (no_lookahead_on p (serialize s a) (bare_serialize_list p s l)); seq_slice_append_l (serialize s a) (bare_serialize_list p s q); assert (no_lookahead_on_precond p (serialize s a) (bare_serialize_list p s l)); assert (no_lookahead_on_postcond p (serialize s a) (bare_serialize_list p s l)); assert (Some? pa); assert (injective_precond p (serialize s a) (bare_serialize_list p s l)); assert (injective_postcond p (serialize s a) (bare_serialize_list p s l)); let (Some (a', lena)) = pa in assert (a == a'); assert (lena == Seq.length (serialize s a)); assert (lena > 0); prf q; seq_slice_append_r (serialize s a) (bare_serialize_list p s q) in Classical.forall_intro prf
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.List.fst" }
[ { "abbrev": true, "full_module": "FStar.Classical", "short_module": "Classical" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParse.Spec.Base.parser k t -> s: LowParse.Spec.Base.serializer p -> Prims.Pure (LowParse.Spec.Base.serializer (LowParse.Spec.List.parse_list p))
Prims.Pure
[]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.Spec.List.bare_serialize_list", "Prims.unit", "LowParse.Spec.List.bare_serialize_list_correct", "LowParse.Spec.List.parse_list_kind", "Prims.list", "LowParse.Spec.List.parse_list", "Prims.b2t", "LowParse.Spec.List.serialize_list_precond", "Prims.l_True" ]
[]
false
false
false
false
false
let serialize_list (#k: parser_kind) (#t: Type) (p: parser k t) (s: serializer p) : Pure (serializer (parse_list p)) (requires (serialize_list_precond k)) (ensures (fun _ -> True)) =
bare_serialize_list_correct p s; bare_serialize_list p s
false