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
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_basetype
val print_basetype : t: Vale.Arch.HeapTypes_s.base_typ -> Prims.string
let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR"
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 23, "end_line": 23, "start_col": 0, "start_line": 18 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t"
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
t: Vale.Arch.HeapTypes_s.base_typ -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.Arch.HeapTypes_s.base_typ", "Prims.string" ]
[]
false
false
false
true
false
let print_basetype (t: base_typ) =
match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR"
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_ins
val print_ins (ins: ins) (p: P.printer) : string
val print_ins (ins: ins) (p: P.printer) : string
let print_ins (ins:ins) (p:P.printer) : string = match ins with | Instr _ _ (AnnotateComment s) -> " // " ^ s | Instr _ _ (AnnotateLargeComment s) -> "\n /////// " ^ s ^ " ////// \n" | Instr _ _ (AnnotateSpace n) -> print_spaces n | _ -> " \"" ^ P.print_ins ins p ^ ";\""
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 256, "start_col": 0, "start_line": 251 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter // Print the list of modified registers, + memory and cc let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15] // Prints "register uint64_t *argi_r __asm__("[reg]") = argi;\n" let print_explicit_register_arg (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = let ty = match a with | TD_Base _ -> "uint64_t " | _ -> "uint64_t *" in if reserved (of_arg i) then // If the associated register is reserved, we really this argument in it. For instance if it is Rdx and we have Mul(x) instructions true, " register " ^ ty ^ names i ^ "_r __asm__(\"" ^ P.print_reg_name (of_arg i) ^ "\") = " ^ names i ^ ";\n" else false, "" let rec print_explicit_register_args (n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = match args with | [] -> false, "" | a::q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i+1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str // If we have a return parameter with a reserved register, print "register uint64_t [name] __asm__("rax");\n" let print_register_ret (reserved:reg_64 -> bool) = function | None -> "" | Some name -> if reserved rRax then " register uint64_t " ^ name ^ " __asm__(\"rax\");\n" else " uint64_t " ^ name ^ ";\n" (* This is a copy from X64.Print_s, and should remain in sync. The difference is that each line should be in quotes, and end by a semicolon in inline assembly *) let print_cmp (c:ocmp) (counter:int) (p:P.printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.P.op_order (P.print_operand o1 p) (P.print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> " \"" ^ print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ ";\"\n" | ONe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ ";\"\n" | OLe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ ";\"\n" | OGe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ ";\"\n" | OLt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ ";\"\n" | OGt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ ";\"\n" let rec print_spaces (n:nat) : string = match n with | 0 -> "" | n -> " " ^ print_spaces (n-1)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
ins: Vale.X64.Machine_Semantics_s.ins -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_Semantics_s.ins", "Vale.X64.Print_s.printer", "Vale.X64.Instruction_s.instr_t_record", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args", "Prims.string", "Prims.eq2", "Vale.X64.Instruction_s.InstrTypeRecord", "Prims.Nil", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.PreserveFlags", "Vale.X64.Instructions_s.ins_Comment", "Prims.op_Hat", "Vale.X64.Instructions_s.ins_LargeComment", "Prims.nat", "Vale.X64.Instructions_s.ins_Space", "Vale.X64.Print_Inline_s.print_spaces", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Print_s.print_ins" ]
[]
false
false
false
true
false
let print_ins (ins: ins) (p: P.printer) : string =
match ins with | Instr _ _ (AnnotateComment s) -> " // " ^ s | Instr _ _ (AnnotateLargeComment s) -> "\n /////// " ^ s ^ " ////// \n" | Instr _ _ (AnnotateSpace n) -> print_spaces n | _ -> " \"" ^ P.print_ins ins p ^ ";\""
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.build_reserved_args_outs
val build_reserved_args_outs (l: list instr_out) (reserved: (reg_64 -> bool)) : Tot (reg_64 -> bool) (decreases l)
val build_reserved_args_outs (l: list instr_out) (reserved: (reg_64 -> bool)) : Tot (reg_64 -> bool) (decreases l)
let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 50, "start_col": 0, "start_line": 36 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list Vale.X64.Instruction_s.instr_out -> reserved: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> Prims.Tot (_: Vale.X64.Machine_s.reg_64 -> Prims.bool)
Prims.Tot
[ "total", "" ]
[]
[ "Prims.list", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Vale.X64.Instruction_s.instr_operand_inout", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Print_Inline_s.build_reserved_args_outs", "Prims.op_Equality" ]
[ "recursion" ]
false
false
false
false
false
let rec build_reserved_args_outs (l: list instr_out) (reserved: (reg_64 -> bool)) : Tot (reg_64 -> bool) (decreases l) =
fun r -> match l with | [] -> reserved r | hd :: tl -> let _, op = hd in let reserved:(reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r
false
Steel.Effect.Atomic.fst
Steel.Effect.Atomic.elim_vdep
val elim_vdep (#opened:inames) (v: vprop) (p: (t_of v -> Tot vprop)) : SteelGhost (Ghost.erased (t_of v)) opened (vdep v p) (fun res -> v `star` p (Ghost.reveal res)) (requires (fun _ -> True)) (ensures (fun h res h' -> let fs = h' v in let sn : t_of (p (Ghost.reveal res)) = h' (p (Ghost.reveal res)) in let x2 = h (vdep v p) in Ghost.reveal res == fs /\ dfst x2 == fs /\ dsnd x2 == sn ))
val elim_vdep (#opened:inames) (v: vprop) (p: (t_of v -> Tot vprop)) : SteelGhost (Ghost.erased (t_of v)) opened (vdep v p) (fun res -> v `star` p (Ghost.reveal res)) (requires (fun _ -> True)) (ensures (fun h res h' -> let fs = h' v in let sn : t_of (p (Ghost.reveal res)) = h' (p (Ghost.reveal res)) in let x2 = h (vdep v p) in Ghost.reveal res == fs /\ dfst x2 == fs /\ dsnd x2 == sn ))
let elim_vdep v p = let r = gget (vdep v p) in let res = Ghost.hide (dfst #(t_of v) #(vdep_payload v p) (Ghost.reveal r)) in elim_vdep0 v p (p (Ghost.reveal res)); res
{ "file_name": "lib/steel/Steel.Effect.Atomic.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 5, "end_line": 840, "start_col": 0, "start_line": 835 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Effect.Atomic open Steel.Effect friend Steel.Effect #set-options "--warn_error -330" //turn off the experimental feature warning let _ : squash (forall (pre:pre_t) (m0:mem{interp (hp_of pre) m0}) (m1:mem{disjoint m0 m1}). mk_rmem pre m0 == mk_rmem pre (join m0 m1)) = Classical.forall_intro rmem_depends_only_on let req_to_act_req (#pre:vprop) (req:req_t pre) : mprop (hp_of pre) = fun m -> rmem_depends_only_on pre; interp (hp_of pre) m /\ req (mk_rmem pre m) unfold let to_post (#a:Type) (post:post_t a) = fun x -> (hp_of (post x)) let ens_to_act_ens (#pre:pre_t) (#a:Type) (#post:post_t a) (ens:ens_t pre a post) : mprop2 (hp_of pre) (to_post post) = fun m0 x m1 -> interp (hp_of pre) m0 /\ interp (hp_of (post x)) m1 /\ ens (mk_rmem pre m0) x (mk_rmem (post x) m1) let repr a framed opened f pre post req ens = action_except_full a opened (hp_of pre) (to_post post) (req_to_act_req req) (ens_to_act_ens ens) let return_ a x opened #p = fun _ -> let m0:full_mem = NMSTTotal.get () in let h0 = mk_rmem (p x) (core_mem m0) in lemma_frame_equalities_refl (p x) h0; x #push-options "--fuel 0 --ifuel 0" #push-options "--z3rlimit 20 --fuel 1 --ifuel 1" val frame00 (#a:Type) (#framed:bool) (#opened:inames) (#obs:observability) (#pre:pre_t) (#post:post_t a) (#req:req_t pre) (#ens:ens_t pre a post) ($f:repr a framed opened obs pre post req ens) (frame:vprop) : repr a true opened obs (pre `star` frame) (fun x -> post x `star` frame) (fun h -> req (focus_rmem h pre)) (fun h0 r h1 -> req (focus_rmem h0 pre) /\ ens (focus_rmem h0 pre) r (focus_rmem h1 (post r)) /\ frame_opaque frame (focus_rmem h0 frame) (focus_rmem h1 frame)) module Sem = Steel.Semantics.Hoare.MST module Mem = Steel.Memory let equiv_middle_left_assoc (a b c d:slprop) : Lemma (((a `Mem.star` b) `Mem.star` c `Mem.star` d) `Mem.equiv` (a `Mem.star` (b `Mem.star` c) `Mem.star` d)) = let open Steel.Memory in star_associative a b c; star_congruence ((a `star` b) `star` c) d (a `star` (b `star` c)) d let frame00 #a #framed #opened #obs #pre #post #req #ens f frame = fun frame' -> let m0:full_mem = NMSTTotal.get () in let snap:rmem frame = mk_rmem frame (core_mem m0) in // Need to define it with type annotation, although unused, for it to trigger // the pattern on the framed ensures in the def of MstTot let aux:mprop (hp_of frame `Mem.star` frame') = req_frame frame snap in focus_is_restrict_mk_rmem (pre `star` frame) pre (core_mem m0); assert (interp (hp_of (pre `star` frame) `Mem.star` frame' `Mem.star` locks_invariant opened m0) m0); equiv_middle_left_assoc (hp_of pre) (hp_of frame) frame' (locks_invariant opened m0); assert (interp (hp_of pre `Mem.star` (hp_of frame `Mem.star` frame') `Mem.star` locks_invariant opened m0) m0); let x = f (hp_of frame `Mem.star` frame') in let m1:full_mem = NMSTTotal.get () in assert (interp (hp_of (post x) `Mem.star` (hp_of frame `Mem.star` frame') `Mem.star` locks_invariant opened m1) m1); equiv_middle_left_assoc (hp_of (post x)) (hp_of frame) frame' (locks_invariant opened m1); assert (interp ((hp_of (post x) `Mem.star` hp_of frame) `Mem.star` frame' `Mem.star` locks_invariant opened m1) m1); focus_is_restrict_mk_rmem (pre `star` frame) frame (core_mem m0); focus_is_restrict_mk_rmem (post x `star` frame) frame (core_mem m1); let h0:rmem (pre `star` frame) = mk_rmem (pre `star` frame) (core_mem m0) in let h1:rmem (post x `star` frame) = mk_rmem (post x `star` frame) (core_mem m1) in assert (focus_rmem h0 frame == focus_rmem h1 frame); focus_is_restrict_mk_rmem (post x `star` frame) (post x) (core_mem m1); lemma_frame_opaque_refl frame (focus_rmem h0 frame); x unfold let bind_req_opaque (#a:Type) (#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (#pre_g:a -> pre_t) (#pr:a -> prop) (req_g:(x:a -> req_t (pre_g x))) (frame_f:vprop) (frame_g:a -> vprop) (_:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x))) : req_t (pre_f `star` frame_f) = fun m0 -> req_f (focus_rmem m0 pre_f) /\ (forall (x:a) (h1:hmem (post_f x `star` frame_f)). (ens_f (focus_rmem m0 pre_f) x (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (post_f x)) /\ frame_opaque frame_f (focus_rmem m0 frame_f) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) frame_f)) ==> pr x /\ (can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x); (req_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (pre_g x)))) unfold let bind_ens_opaque (#a:Type) (#b:Type) (#pre_f:pre_t) (#post_f:post_t a) (req_f:req_t pre_f) (ens_f:ens_t pre_f a post_f) (#pre_g:a -> pre_t) (#post_g:a -> post_t b) (#pr:a -> prop) (ens_g:(x:a -> ens_t (pre_g x) b (post_g x))) (frame_f:vprop) (frame_g:a -> vprop) (post:post_t b) (_:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x))) (_:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post)) : ens_t (pre_f `star` frame_f) b post = fun m0 y m2 -> req_f (focus_rmem m0 pre_f) /\ (exists (x:a) (h1:hmem (post_f x `star` frame_f)). pr x /\ ( can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x); can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (frame_g x); can_be_split_trans (post y) (post_g x y `star` frame_g x) (post_g x y); can_be_split_trans (post y) (post_g x y `star` frame_g x) (frame_g x); frame_opaque frame_f (focus_rmem m0 frame_f) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) frame_f) /\ frame_opaque (frame_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (frame_g x)) (focus_rmem m2 (frame_g x)) /\ ens_f (focus_rmem m0 pre_f) x (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (post_f x)) /\ (ens_g x) (focus_rmem (mk_rmem (post_f x `star` frame_f) h1) (pre_g x)) y (focus_rmem m2 (post_g x y)))) val bind_opaque (a:Type) (b:Type) (opened_invariants:inames) (o1:eqtype_as_type observability) (o2:eqtype_as_type observability) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#pre_f:pre_t) (#post_f:post_t a) (#req_f:req_t pre_f) (#ens_f:ens_t pre_f a post_f) (#pre_g:a -> pre_t) (#post_g:a -> post_t b) (#req_g:(x:a -> req_t (pre_g x))) (#ens_g:(x:a -> ens_t (pre_g x) b (post_g x))) (#frame_f:vprop) (#frame_g:a -> vprop) (#post:post_t b) (# _ : squash (maybe_emp framed_f frame_f)) (# _ : squash (maybe_emp_dep framed_g frame_g)) (#pr:a -> prop) (#p1:squash (can_be_split_forall_dep pr (fun x -> post_f x `star` frame_f) (fun x -> pre_g x `star` frame_g x))) (#p2:squash (can_be_split_post (fun x y -> post_g x y `star` frame_g x) post)) (f:repr a framed_f opened_invariants o1 pre_f post_f req_f ens_f) (g:(x:a -> repr b framed_g opened_invariants o2 (pre_g x) (post_g x) (req_g x) (ens_g x))) : Pure (repr b true opened_invariants (join_obs o1 o2) (pre_f `star` frame_f) post (bind_req_opaque req_f ens_f req_g frame_f frame_g p1) (bind_ens_opaque req_f ens_f ens_g frame_f frame_g post p1 p2) ) (requires obs_at_most_one o1 o2) (ensures fun _ -> True) #push-options "--z3rlimit 20" let bind_opaque a b opened o1 o2 #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #frame_f #frame_g #post #_ #_ #p #p2 f g = fun frame -> let m0:full_mem = NMSTTotal.get () in let h0 = mk_rmem (pre_f `star` frame_f) (core_mem m0) in let x = frame00 f frame_f frame in let m1:full_mem = NMSTTotal.get () in let h1 = mk_rmem (post_f x `star` frame_f) (core_mem m1) in let h1' = mk_rmem (pre_g x `star` frame_g x) (core_mem m1) in can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x); focus_is_restrict_mk_rmem (post_f x `star` frame_f) (pre_g x `star` frame_g x) (core_mem m1); focus_focus_is_focus (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x) (core_mem m1); assert (focus_rmem h1' (pre_g x) == focus_rmem h1 (pre_g x)); can_be_split_3_interp (hp_of (post_f x `star` frame_f)) (hp_of (pre_g x `star` frame_g x)) frame (locks_invariant opened m1) m1; let y = frame00 (g x) (frame_g x) frame in let m2:full_mem = NMSTTotal.get () in can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (pre_g x); can_be_split_trans (post_f x `star` frame_f) (pre_g x `star` frame_g x) (frame_g x); can_be_split_trans (post y) (post_g x y `star` frame_g x) (post_g x y); can_be_split_trans (post y) (post_g x y `star` frame_g x) (frame_g x); let h2' = mk_rmem (post_g x y `star` frame_g x) (core_mem m2) in let h2 = mk_rmem (post y) (core_mem m2) in // assert (focus_rmem h1' (pre_g x) == focus_rmem h1 (pre_g x)); focus_focus_is_focus (post_f x `star` frame_f) (pre_g x `star` frame_g x) (frame_g x) (core_mem m1); focus_is_restrict_mk_rmem (post_g x y `star` frame_g x) (post y) (core_mem m2); focus_focus_is_focus (post_g x y `star` frame_g x) (post y) (frame_g x) (core_mem m2); focus_focus_is_focus (post_g x y `star` frame_g x) (post y) (post_g x y) (core_mem m2); can_be_split_3_interp (hp_of (post_g x y `star` frame_g x)) (hp_of (post y)) frame (locks_invariant opened m2) m2; y let norm_repr (#a:Type) (#framed:bool) (#opened:inames) (#obs:observability) (#pre:pre_t) (#post:post_t a) (#req:req_t pre) (#ens:ens_t pre a post) (f:repr a framed opened obs pre post req ens) : repr a framed opened obs pre post (fun h -> norm_opaque (req h)) (fun h0 x h1 -> norm_opaque (ens h0 x h1)) = f let bind a b opened o1 o2 #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #frame_f #frame_g #post #_ #_ #p #p2 f g = norm_repr (bind_opaque a b opened o1 o2 #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #frame_f #frame_g #post #_ #_ #p #p2 f g) val subcomp_opaque (a:Type) (opened:inames) (o1:eqtype_as_type observability) (o2:eqtype_as_type observability) (#framed_f:eqtype_as_type bool) (#framed_g:eqtype_as_type bool) (#[@@@ framing_implicit] pre_f:pre_t) (#[@@@ framing_implicit] post_f:post_t a) (#[@@@ framing_implicit] req_f:req_t pre_f) (#[@@@ framing_implicit] ens_f:ens_t pre_f a post_f) (#[@@@ framing_implicit] pre_g:pre_t) (#[@@@ framing_implicit] post_g:post_t a) (#[@@@ framing_implicit] req_g:req_t pre_g) (#[@@@ framing_implicit] ens_g:ens_t pre_g a post_g) (#[@@@ framing_implicit] frame:vprop) (#[@@@ framing_implicit] pr : prop) (#[@@@ framing_implicit] _ : squash (maybe_emp framed_f frame)) (#[@@@ framing_implicit] p1:squash (can_be_split_dep pr pre_g (pre_f `star` frame))) (#[@@@ framing_implicit] p2:squash (equiv_forall post_g (fun x -> post_f x `star` frame))) (f:repr a framed_f opened o1 pre_f post_f req_f ens_f) : Pure (repr a framed_g opened o2 pre_g post_g req_g ens_g) (requires (o1 = Unobservable || o2 = Observable) /\ subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2) (ensures fun _ -> True) let subcomp_opaque a opened o1 o2 #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #fr #pr #_ #p1 #p2 f = fun frame -> let m0:full_mem = NMSTTotal.get () in let h0 = mk_rmem pre_g (core_mem m0) in can_be_split_trans pre_g (pre_f `star` fr) pre_f; can_be_split_trans pre_g (pre_f `star` fr) fr; can_be_split_3_interp (hp_of pre_g) (hp_of (pre_f `star` fr)) frame (locks_invariant opened m0) m0; focus_replace pre_g (pre_f `star` fr) pre_f (core_mem m0); let x = frame00 f fr frame in let m1:full_mem = NMSTTotal.get () in let h1 = mk_rmem (post_g x) (core_mem m1) in let h0' = mk_rmem (pre_f `star` fr) (core_mem m0) in let h1' = mk_rmem (post_f x `star` fr) (core_mem m1) in // From frame00 assert (frame_opaque fr (focus_rmem h0' fr) (focus_rmem h1' fr)); // Replace h0'/h1' by h0/h1 focus_replace pre_g (pre_f `star` fr) fr (core_mem m0); focus_replace (post_g x) (post_f x `star` fr) fr (core_mem m1); assert (frame_opaque fr (focus_rmem h0 fr) (focus_rmem h1 fr)); can_be_split_trans (post_g x) (post_f x `star` fr) (post_f x); can_be_split_trans (post_g x) (post_f x `star` fr) fr; can_be_split_3_interp (hp_of (post_f x `star` fr)) (hp_of (post_g x)) frame (locks_invariant opened m1) m1; focus_replace (post_g x) (post_f x `star` fr) (post_f x) (core_mem m1); x let subcomp a opened o1 o2 #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #fr #_ #pr #p1 #p2 f = lemma_subcomp_pre_opaque req_f ens_f req_g ens_g p1 p2; subcomp_opaque a opened o1 o2 #framed_f #framed_g #pre_f #post_f #req_f #ens_f #pre_g #post_g #req_g #ens_g #fr #pr #_ #p1 #p2 f #pop-options let bind_pure_steela_ a b opened o #wp f g = FStar.Monotonic.Pure.elim_pure_wp_monotonicity wp; fun frame -> let x = f () in g x frame let lift_ghost_atomic a o f = f let lift_atomic_steel a o f = f let as_atomic_action f = SteelAtomic?.reflect f let as_atomic_action_ghost f = SteelGhost?.reflect f let as_atomic_unobservable_action f = SteelAtomicU?.reflect f (* Some helpers *) let get0 (#opened:inames) (#p:vprop) (_:unit) : repr (erased (rmem p)) true opened Unobservable p (fun _ -> p) (requires fun _ -> True) (ensures fun h0 r h1 -> frame_equalities p h0 h1 /\ frame_equalities p r h1) = fun frame -> let m0:full_mem = NMSTTotal.get () in let h0 = mk_rmem p (core_mem m0) in lemma_frame_equalities_refl p h0; h0 let get () = SteelGhost?.reflect (get0 ()) let intro_star (p q:vprop) (r:slprop) (vp:erased (t_of p)) (vq:erased (t_of q)) (m:mem) (proof:(m:mem) -> Lemma (requires interp (hp_of p) m /\ sel_of p m == reveal vp) (ensures interp (hp_of q) m) ) : Lemma (requires interp ((hp_of p) `Mem.star` r) m /\ sel_of p m == reveal vp) (ensures interp ((hp_of q) `Mem.star` r) m) = let p = hp_of p in let q = hp_of q in let intro (ml mr:mem) : Lemma (requires interp q ml /\ interp r mr /\ disjoint ml mr) (ensures disjoint ml mr /\ interp (q `Mem.star` r) (Mem.join ml mr)) = Mem.intro_star q r ml mr in elim_star p r m; Classical.forall_intro (Classical.move_requires proof); Classical.forall_intro_2 (Classical.move_requires_2 intro) #push-options "--z3rlimit 20 --fuel 1 --ifuel 0" let rewrite_slprop0 (#opened:inames) (p q:vprop) (proof:(m:mem) -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m) ) : repr unit false opened Unobservable p (fun _ -> q) (fun _ -> True) (fun _ _ _ -> True) = fun frame -> let m:full_mem = NMSTTotal.get () in proof (core_mem m); Classical.forall_intro (Classical.move_requires proof); Mem.star_associative (hp_of p) frame (locks_invariant opened m); intro_star p q (frame `Mem.star` locks_invariant opened m) (sel_of p m) (sel_of q m) m proof; Mem.star_associative (hp_of q) frame (locks_invariant opened m) #pop-options let rewrite_slprop p q l = SteelGhost?.reflect (rewrite_slprop0 p q l) #push-options "--z3rlimit 20 --fuel 1 --ifuel 0" let change_slprop0 (#opened:inames) (p q:vprop) (vp:erased (t_of p)) (vq:erased (t_of q)) (proof:(m:mem) -> Lemma (requires interp (hp_of p) m /\ sel_of p m == reveal vp) (ensures interp (hp_of q) m /\ sel_of q m == reveal vq) ) : repr unit false opened Unobservable p (fun _ -> q) (fun h -> h p == reveal vp) (fun _ _ h1 -> h1 q == reveal vq) = fun frame -> let m:full_mem = NMSTTotal.get () in Classical.forall_intro_3 reveal_mk_rmem; proof (core_mem m); Classical.forall_intro (Classical.move_requires proof); Mem.star_associative (hp_of p) frame (locks_invariant opened m); intro_star p q (frame `Mem.star` locks_invariant opened m) vp vq m proof; Mem.star_associative (hp_of q) frame (locks_invariant opened m) #pop-options let change_slprop p q vp vq l = SteelGhost?.reflect (change_slprop0 p q vp vq l) let change_equal_slprop p q = let m = get () in let x : Ghost.erased (t_of p) = hide ((reveal m) p) in let y : Ghost.erased (t_of q) = Ghost.hide (Ghost.reveal x) in change_slprop p q x y (fun _ -> ()) #push-options "--z3rlimit 20 --fuel 1 --ifuel 0" let change_slprop_20 (#opened:inames) (p q:vprop) (vq:erased (t_of q)) (proof:(m:mem) -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of q) m /\ sel_of q m == reveal vq) ) : repr unit false opened Unobservable p (fun _ -> q) (fun _ -> True) (fun _ _ h1 -> h1 q == reveal vq) = fun frame -> let m:full_mem = NMSTTotal.get () in Classical.forall_intro_3 reveal_mk_rmem; proof (core_mem m); Classical.forall_intro (Classical.move_requires proof); Mem.star_associative (hp_of p) frame (locks_invariant opened m); intro_star p q (frame `Mem.star` locks_invariant opened m) (sel_of p m) vq m proof; Mem.star_associative (hp_of q) frame (locks_invariant opened m) #pop-options let change_slprop_2 p q vq l = SteelGhost?.reflect (change_slprop_20 p q vq l) let change_slprop_rel0 (#opened:inames) (p q:vprop) (rel : normal (t_of p) -> normal (t_of q) -> prop) (proof:(m:mem) -> Lemma (requires interp (hp_of p) m) (ensures interp (hp_of p) m /\ interp (hp_of q) m /\ rel (sel_of p m) (sel_of q m)) ) : repr unit false opened Unobservable p (fun _ -> q) (fun _ -> True) (fun h0 _ h1 -> rel (h0 p) (h1 q)) = fun frame -> let m:full_mem = NMSTTotal.get () in Classical.forall_intro_3 reveal_mk_rmem; proof (core_mem m); let h0 = mk_rmem p (core_mem m) in let h1 = mk_rmem q (core_mem m) in reveal_mk_rmem p (core_mem m) p; reveal_mk_rmem q (core_mem m) q; Mem.star_associative (hp_of p) frame (locks_invariant opened m); intro_star p q (frame `Mem.star` locks_invariant opened m) (sel_of p (core_mem m)) (sel_of q (core_mem m)) m proof; Mem.star_associative (hp_of q) frame (locks_invariant opened m) let change_slprop_rel p q rel proof = SteelGhost?.reflect (change_slprop_rel0 p q rel proof) let change_slprop_rel_with_cond0 (#opened:inames) (p q:vprop) (cond: t_of p -> prop) (rel : (t_of p) -> (t_of q) -> prop) (proof:(m:mem) -> Lemma (requires interp (hp_of p) m /\ cond (sel_of p m)) (ensures interp (hp_of p) m /\ interp (hp_of q) m /\ rel (sel_of p m) (sel_of q m)) ) : repr unit false opened Unobservable p (fun _ -> q) (fun m -> cond (m p)) (fun h0 _ h1 -> rel (h0 p) (h1 q)) = fun frame -> let m:full_mem = NMSTTotal.get () in Classical.forall_intro_3 reveal_mk_rmem; proof (core_mem m); let h0 = mk_rmem p (core_mem m) in let h1 = mk_rmem q (core_mem m) in reveal_mk_rmem p (core_mem m) p; reveal_mk_rmem q (core_mem m) q; Mem.star_associative (hp_of p) frame (locks_invariant opened m); intro_star p q (frame `Mem.star` locks_invariant opened m) (sel_of p (core_mem m)) (sel_of q (core_mem m)) m proof; Mem.star_associative (hp_of q) frame (locks_invariant opened m) let change_slprop_rel_with_cond p q cond rel proof = SteelGhost?.reflect (change_slprop_rel_with_cond0 p q cond rel proof) let extract_info0 (#opened:inames) (p:vprop) (vp:erased (normal (t_of p))) (fact:prop) (l:(m:mem) -> Lemma (requires interp (hp_of p) m /\ sel_of p m == reveal vp) (ensures fact) ) : repr unit false opened Unobservable p (fun _ -> p) (fun h -> h p == reveal vp) (fun h0 _ h1 -> frame_equalities p h0 h1 /\ fact) = fun frame -> let m0:full_mem = NMSTTotal.get () in Classical.forall_intro_3 reveal_mk_rmem; let h0 = mk_rmem p (core_mem m0) in lemma_frame_equalities_refl p h0; l (core_mem m0) let extract_info p vp fact l = SteelGhost?.reflect (extract_info0 p vp fact l) let extract_info_raw0 (#opened:inames) (p:vprop) (fact:prop) (l:(m:mem) -> Lemma (requires interp (hp_of p) m) (ensures fact) ) : repr unit false opened Unobservable p (fun _ -> p) (fun h -> True) (fun h0 _ h1 -> frame_equalities p h0 h1 /\ fact) = fun frame -> let m0:full_mem = NMSTTotal.get () in let h0 = mk_rmem p (core_mem m0) in lemma_frame_equalities_refl p h0; l (core_mem m0) let extract_info_raw p fact l = SteelGhost?.reflect (extract_info_raw0 p fact l) let noop _ = change_slprop_rel emp emp (fun _ _ -> True) (fun _ -> ()) let sladmit _ = SteelGhostF?.reflect (fun _ -> NMSTTotal.nmst_tot_admit ()) let slassert0 (#opened:inames) (p:vprop) : repr unit false opened Unobservable p (fun _ -> p) (requires fun _ -> True) (ensures fun h0 r h1 -> frame_equalities p h0 h1) = fun frame -> let m0:full_mem = NMSTTotal.get () in let h0 = mk_rmem p (core_mem m0) in lemma_frame_equalities_refl p h0 let slassert p = SteelGhost?.reflect (slassert0 p) let drop p = rewrite_slprop p emp (fun m -> emp_unit (hp_of p); affine_star (hp_of p) Mem.emp m; reveal_emp()) let reveal_star0 (#opened:inames) (p1 p2:vprop) : repr unit false opened Unobservable (p1 `star` p2) (fun _ -> p1 `star` p2) (fun _ -> True) (fun h0 _ h1 -> h0 p1 == h1 p1 /\ h0 p2 == h1 p2 /\ h0 (p1 `star` p2) == (h0 p1, h0 p2) /\ h1 (p1 `star` p2) == (h1 p1, h1 p2) ) = fun frame -> let m:full_mem = NMSTTotal.get () in Classical.forall_intro_3 reveal_mk_rmem let reveal_star p1 p2 = SteelGhost?.reflect (reveal_star0 p1 p2) let reveal_star_30 (#opened:inames) (p1 p2 p3:vprop) : repr unit false opened Unobservable (p1 `star` p2 `star` p3) (fun _ -> p1 `star` p2 `star` p3) (requires fun _ -> True) (ensures fun h0 _ h1 -> can_be_split (p1 `star` p2 `star` p3) p1 /\ can_be_split (p1 `star` p2 `star` p3) p2 /\ h0 p1 == h1 p1 /\ h0 p2 == h1 p2 /\ h0 p3 == h1 p3 /\ h0 (p1 `star` p2 `star` p3) == ((h0 p1, h0 p2), h0 p3) /\ h1 (p1 `star` p2 `star` p3) == ((h1 p1, h1 p2), h1 p3) ) = fun frame -> let m:full_mem = NMSTTotal.get () in Classical.forall_intro_3 reveal_mk_rmem; let h0 = mk_rmem (p1 `star` p2 `star` p3) (core_mem m) in can_be_split_trans (p1 `star` p2 `star` p3) (p1 `star` p2) p1; can_be_split_trans (p1 `star` p2 `star` p3) (p1 `star` p2) p2; reveal_mk_rmem (p1 `star` p2 `star` p3) m (p1 `star` p2 `star` p3); reveal_mk_rmem (p1 `star` p2 `star` p3) m (p1 `star` p2); reveal_mk_rmem (p1 `star` p2 `star` p3) m p3 let reveal_star_3 p1 p2 p3 = SteelGhost?.reflect (reveal_star_30 p1 p2 p3) let intro_pure p = rewrite_slprop emp (pure p) (fun m -> pure_interp p m) let elim_pure_aux #uses (p:prop) : SteelGhostT (_:unit{p}) uses (pure p) (fun _ -> to_vprop Mem.emp) = as_atomic_action_ghost (Steel.Memory.elim_pure #uses p) let elim_pure #uses p = let _ = elim_pure_aux p in rewrite_slprop (to_vprop Mem.emp) emp (fun _ -> reveal_emp ()) let return #a #opened #p x = SteelAtomicBase?.reflect (return_ a x opened #p) let intro_exists #a #opened x p = rewrite_slprop (p x) (h_exists p) (fun m -> Steel.Memory.intro_h_exists x (h_exists_sl' p) m) let intro_exists_erased #a #opened x p = rewrite_slprop (p x) (h_exists p) (fun m -> Steel.Memory.intro_h_exists (Ghost.reveal x) (h_exists_sl' p) m) let witness_exists #a #u #p _ = SteelGhost?.reflect (Steel.Memory.witness_h_exists #u (fun x -> hp_of (p x))) let lift_exists #a #u p = as_atomic_action_ghost (Steel.Memory.lift_h_exists #u (fun x -> hp_of (p x))) let exists_equiv p q = Classical.forall_intro_2 reveal_equiv; h_exists_cong (h_exists_sl' p) (h_exists_sl' q) let exists_cong p q = rewrite_slprop (h_exists p) (h_exists q) (fun m -> reveal_equiv (h_exists p) (h_exists q); exists_equiv p q) let fresh_invariant #uses p ctxt = rewrite_slprop p (to_vprop (hp_of p)) (fun _ -> ()); let i = as_atomic_unobservable_action (fresh_invariant uses (hp_of p) ctxt) in rewrite_slprop (to_vprop Mem.emp) emp (fun _ -> reveal_emp ()); return i let new_invariant #uses p = let i = fresh_invariant #uses p [] in return i (* * AR: SteelAtomic and SteelGhost are not marked reifiable since we intend to run Steel programs natively * However to implement the with_inv combinators we need to reify their thunks to reprs * We could implement it better by having support for reification only in the .fst file * But for now assuming a function *) assume val reify_steel_atomic_comp (#a:Type) (#framed:bool) (#opened_invariants:inames) (#g:observability) (#pre:pre_t) (#post:post_t a) (#req:req_t pre) (#ens:ens_t pre a post) ($f:unit -> SteelAtomicBase a framed opened_invariants g pre post req ens) : repr a framed opened_invariants g pre post req ens [@@warn_on_use "as_unobservable_atomic_action is a trusted primitive"] let as_atomic_o_action (#a:Type u#a) (#opened_invariants:inames) (#fp:slprop) (#fp': a -> slprop) (o:observability) (f:action_except a opened_invariants fp fp') : SteelAtomicBaseT a opened_invariants o (to_vprop fp) (fun x -> to_vprop (fp' x)) = SteelAtomicBaseT?.reflect f let with_invariant #a #fp #fp' #obs #opened #p i f = rewrite_slprop fp (to_vprop (hp_of fp)) (fun _ -> ()); let x = as_atomic_o_action obs (Steel.Memory.with_invariant #a #(hp_of fp) #(fun x -> hp_of (fp' x)) #opened #(hp_of p) i (reify_steel_atomic_comp f)) in rewrite_slprop (to_vprop (hp_of (fp' x))) (fp' x) (fun _ -> ()); return x assume val reify_steel_ghost_comp (#a:Type) (#framed:bool) (#opened_invariants:inames) (#pre:pre_t) (#post:post_t a) (#req:req_t pre) (#ens:ens_t pre a post) ($f:unit -> SteelGhostBase a framed opened_invariants Unobservable pre post req ens) : repr a framed opened_invariants Unobservable pre post req ens let with_invariant_g #a #fp #fp' #opened #p i f = rewrite_slprop fp (to_vprop (hp_of fp)) (fun _ -> ()); let x = as_atomic_unobservable_action (Steel.Memory.with_invariant #a #(hp_of fp) #(fun x -> hp_of (fp' x)) #opened #(hp_of p) i (reify_steel_ghost_comp f)) in rewrite_slprop (to_vprop (hp_of (fp' x))) (fp' x) (fun _ -> ()); return (hide x) let intro_vrefine v p = let m = get () in let x : Ghost.erased (t_of v) = gget v in let x' : Ghost.erased (vrefine_t v p) = Ghost.hide (Ghost.reveal x) in change_slprop v (vrefine v p) x x' (fun m -> interp_vrefine_hp v p m; vrefine_sel_eq v p m ) let elim_vrefine v p = let h = get() in let x : Ghost.erased (vrefine_t v p) = gget (vrefine v p) in let x' : Ghost.erased (t_of v) = Ghost.hide (Ghost.reveal x) in change_slprop (vrefine v p) v x x' (fun m -> interp_vrefine_hp v p m; vrefine_sel_eq v p m ) let vdep_cond (v: vprop) (q: vprop) (p: (t_of v -> Tot vprop)) (x1: t_of (v `star` q)) : Tot prop = q == p (fst x1) let vdep_rel (v: vprop) (q: vprop) (p: (t_of v -> Tot vprop)) (x1: t_of (v `star` q)) (x2: (t_of (vdep v p))) : Tot prop = q == p (fst x1) /\ dfst (x2 <: (dtuple2 (t_of v) (vdep_payload v p))) == fst x1 /\ dsnd (x2 <: (dtuple2 (t_of v) (vdep_payload v p))) == snd x1 let intro_vdep_lemma (v: vprop) (q: vprop) (p: (t_of v -> Tot vprop)) (m: mem) : Lemma (requires ( interp (hp_of (v `star` q)) m /\ q == p (fst (sel_of (v `star` q) m)) )) (ensures ( interp (hp_of (v `star` q)) m /\ interp (hp_of (vdep v p)) m /\ vdep_rel v q p (sel_of (v `star` q) m) (sel_of (vdep v p) m) )) = Mem.interp_star (hp_of v) (hp_of q) m; interp_vdep_hp v p m; vdep_sel_eq v p m let intro_vdep v q p = reveal_star v q; change_slprop_rel_with_cond (v `star` q) (vdep v p) (vdep_cond v q p) (vdep_rel v q p) (fun m -> intro_vdep_lemma v q p m) let vdep_cond_recip (v: vprop) (p: (t_of v -> Tot vprop)) (q: vprop) (x2: t_of (vdep v p)) : Tot prop = q == p (dfst (x2 <: dtuple2 (t_of v) (vdep_payload v p))) let vdep_rel_recip (v: vprop) (q: vprop) (p: (t_of v -> Tot vprop)) (x2: (t_of (vdep v p))) (x1: t_of (v `star` q)) : Tot prop = vdep_rel v q p x1 x2 let elim_vdep_lemma (v: vprop) (q: vprop) (p: (t_of v -> Tot vprop)) (m: mem) : Lemma (requires ( interp (hp_of (vdep v p)) m /\ q == p (dfst (sel_of (vdep v p) m <: dtuple2 (t_of v) (vdep_payload v p))) )) (ensures ( interp (hp_of (v `star` q)) m /\ interp (hp_of (vdep v p)) m /\ vdep_rel v q p (sel_of (v `star` q) m) (sel_of (vdep v p) m) )) = Mem.interp_star (hp_of v) (hp_of q) m; interp_vdep_hp v p m; vdep_sel_eq v p m let elim_vdep0 (#opened:inames) (v: vprop) (p: (t_of v -> Tot vprop)) (q: vprop) : SteelGhost unit opened (vdep v p) (fun _ -> v `star` q) (requires (fun h -> q == p (dfst (h (vdep v p))))) (ensures (fun h _ h' -> let fs = h' v in let sn = h' q in let x2 = h (vdep v p) in q == p fs /\ dfst x2 == fs /\ dsnd x2 == sn )) = change_slprop_rel_with_cond (vdep v p) (v `star` q) (vdep_cond_recip v p q) (vdep_rel_recip v q p) (fun m -> elim_vdep_lemma v q p m); reveal_star v q
{ "checked_file": "/", "dependencies": [ "Steel.Semantics.Hoare.MST.fst.checked", "Steel.Memory.fsti.checked", "Steel.Effect.fst.checked", "Steel.Effect.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.NMSTTotal.fst.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.Effect.Atomic.fst" }
[ { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "Steel.Semantics.Hoare.MST", "short_module": "Sem" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Common", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: Steel.Effect.Common.vprop -> p: (_: Steel.Effect.Common.t_of v -> Steel.Effect.Common.vprop) -> Steel.Effect.Atomic.SteelGhost (FStar.Ghost.erased (Steel.Effect.Common.t_of v))
Steel.Effect.Atomic.SteelGhost
[]
[]
[ "Steel.Memory.inames", "Steel.Effect.Common.vprop", "Steel.Effect.Common.t_of", "FStar.Ghost.erased", "Prims.unit", "Steel.Effect.Atomic.elim_vdep0", "FStar.Ghost.reveal", "FStar.Ghost.hide", "FStar.Pervasives.dfst", "Steel.Effect.Common.vdep_payload", "Steel.Effect.Common.vdep", "Steel.Effect.Atomic.gget" ]
[]
false
true
false
false
false
let elim_vdep v p =
let r = gget (vdep v p) in let res = Ghost.hide (dfst #(t_of v) #(vdep_payload v p) (Ghost.reveal r)) in elim_vdep0 v p (p (Ghost.reveal res)); res
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.build_reserved_args_ins
val build_reserved_args_ins (l: list instr_operand) (reserved: (reg_64 -> bool)) : Tot (reg_64 -> bool) (decreases l)
val build_reserved_args_ins (l: list instr_operand) (reserved: (reg_64 -> bool)) : Tot (reg_64 -> bool) (decreases l)
let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 65, "start_col": 0, "start_line": 52 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list Vale.X64.Instruction_s.instr_operand -> reserved: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> Prims.Tot (_: Vale.X64.Machine_s.reg_64 -> Prims.bool)
Prims.Tot
[ "total", "" ]
[]
[ "Prims.list", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Vale.X64.Print_Inline_s.build_reserved_args_ins", "Prims.op_Equality" ]
[ "recursion" ]
false
false
false
false
false
let rec build_reserved_args_ins (l: list instr_operand) (reserved: (reg_64 -> bool)) : Tot (reg_64 -> bool) (decreases l) =
fun r -> match l with | [] -> reserved r | hd :: tl -> let reserved:(reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_modified_input
val print_modified_input (n: nat) (a: td) (i: nat{i < n}) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_regs: (reg_64 -> bool)) (reg_names: (reg_64 -> string)) (counter: nat) (arg_names: (nat -> string)) : list string & (reg_64 -> string) & nat
val print_modified_input (n: nat) (a: td) (i: nat{i < n}) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_regs: (reg_64 -> bool)) (reg_names: (reg_64 -> string)) (counter: nat) (arg_names: (nat -> string)) : list string & (reg_64 -> string) & nat
let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter)
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 117, "start_col": 0, "start_line": 110 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.nat -> a: Vale.Interop.Base.td -> i: Prims.nat{i < n} -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> regs_mod: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> reserved_regs: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> reg_names: (_: Vale.X64.Machine_s.reg_64 -> Prims.string) -> counter: Prims.nat -> arg_names: (_: Prims.nat -> Prims.string) -> (Prims.list Prims.string * (_: Vale.X64.Machine_s.reg_64 -> Prims.string)) * Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Vale.Interop.Base.td", "Prims.b2t", "Prims.op_LessThan", "Vale.Interop.X64.reg_nat", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Prims.string", "FStar.Pervasives.Native.Mktuple3", "Prims.list", "Prims.Cons", "Prims.op_Hat", "Prims.Nil", "Prims.op_AmpAmp", "Prims.op_Equality", "Prims.op_Negation", "Prims.string_of_int", "Prims.op_Addition", "FStar.Pervasives.Native.tuple3" ]
[]
false
false
false
false
false
let print_modified_input (n: nat) (a: td) (i: nat{i < n}) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_regs: (reg_64 -> bool)) (reg_names: (reg_64 -> string)) (counter: nat) (arg_names: (nat -> string)) : list string & (reg_64 -> string) & nat =
if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) else ([], reg_names, counter)
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_nonmodified_input
val print_nonmodified_input (n: nat) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_regs: (reg_64 -> bool)) (a: td) (i: nat{i < n}) (reg_names: (reg_64 -> string)) (counter: nat) (arg_names: (nat -> string)) : list string & (reg_64 -> string) & nat
val print_nonmodified_input (n: nat) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_regs: (reg_64 -> bool)) (a: td) (i: nat{i < n}) (reg_names: (reg_64 -> string)) (counter: nat) (arg_names: (nat -> string)) : list string & (reg_64 -> string) & nat
let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1)
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 157, "start_col": 0, "start_line": 151 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.nat -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> regs_mod: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> reserved_regs: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> a: Vale.Interop.Base.td -> i: Prims.nat{i < n} -> reg_names: (_: Vale.X64.Machine_s.reg_64 -> Prims.string) -> counter: Prims.nat -> arg_names: (_: Prims.nat -> Prims.string) -> (Prims.list Prims.string * (_: Vale.X64.Machine_s.reg_64 -> Prims.string)) * Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Vale.Interop.X64.reg_nat", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Vale.Interop.Base.td", "Prims.b2t", "Prims.op_LessThan", "Prims.string", "FStar.Pervasives.Native.Mktuple3", "Prims.list", "Prims.Nil", "Prims.Cons", "Prims.op_Hat", "Prims.op_AmpAmp", "Prims.op_Equality", "Prims.op_Negation", "Prims.string_of_int", "Prims.op_Addition", "FStar.Pervasives.Native.tuple3" ]
[]
false
false
false
false
false
let print_nonmodified_input (n: nat) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_regs: (reg_64 -> bool)) (a: td) (i: nat{i < n}) (reg_names: (reg_64 -> string)) (counter: nat) (arg_names: (nat -> string)) : list string & (reg_64 -> string) & nat =
if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1)
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_modified_inputs
val print_modified_inputs : n: Prims.nat -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> regs_mod: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> reserved_regs: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> args: Prims.list Vale.Interop.Base.td {FStar.List.Tot.Base.length args <= n} -> ret_val: FStar.Pervasives.Native.option Prims.string -> reg_names: (_: Vale.X64.Machine_s.reg_64 -> Prims.string) -> counter: Prims.nat -> arg_names: (_: Prims.nat -> Prims.string) -> (Prims.string * (_: Vale.X64.Machine_s.reg_64 -> Prims.string)) * Prims.nat
let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 148, "start_col": 0, "start_line": 132 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.nat -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> regs_mod: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> reserved_regs: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> args: Prims.list Vale.Interop.Base.td {FStar.List.Tot.Base.length args <= n} -> ret_val: FStar.Pervasives.Native.option Prims.string -> reg_names: (_: Vale.X64.Machine_s.reg_64 -> Prims.string) -> counter: Prims.nat -> arg_names: (_: Prims.nat -> Prims.string) -> (Prims.string * (_: Vale.X64.Machine_s.reg_64 -> Prims.string)) * Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Vale.Interop.X64.reg_nat", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Prims.list", "Vale.Interop.Base.td", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.List.Tot.Base.length", "FStar.Pervasives.Native.option", "Prims.string", "FStar.Pervasives.Native.Mktuple3", "FStar.Pervasives.Native.tuple3", "Vale.X64.Print_Inline_s.get_modified_input_strings", "Prims.op_Hat" ]
[]
false
false
false
false
false
let print_modified_inputs (n: nat) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_regs: (reg_64 -> bool)) (args: list td {List.Tot.length args <= n}) (ret_val: option string) (reg_names: (reg_64 -> string)) (counter: nat) (arg_names: (nat -> string)) =
let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.build_reserved_args_block
val build_reserved_args_block (l: list code) (reserved: (reg_64 -> bool)) : Tot (reg_64 -> bool) (decreases l)
val build_reserved_args_block (l: list code) (reserved: (reg_64 -> bool)) : Tot (reg_64 -> bool) (decreases l)
let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r )
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 98, "start_col": 0, "start_line": 69 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers.
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list Vale.X64.Machine_Semantics_s.code -> reserved: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> Prims.Tot (_: Vale.X64.Machine_s.reg_64 -> Prims.bool)
Prims.Tot
[ "total", "" ]
[ "build_reserved_args", "build_reserved_args_block" ]
[ "Prims.list", "Vale.X64.Machine_Semantics_s.code", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Vale.X64.Print_Inline_s.build_reserved_args_block", "Vale.X64.Print_Inline_s.build_reserved_args" ]
[ "mutual recursion" ]
false
false
false
false
false
let rec build_reserved_args_block (l: list code) (reserved: (reg_64 -> bool)) : Tot (reg_64 -> bool) (decreases l) =
fun r -> (match l with | [] -> reserved r | hd :: tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r)
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.get_modified_input_strings
val get_modified_input_strings (n: nat) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_regs: (reg_64 -> bool)) (args: list td) (i: nat{i + List.Tot.length args <= n}) (ret_val: option string) (reg_names: (reg_64 -> string)) (counter: nat) (arg_names: (nat -> string)) : list string & (reg_64 -> string) & nat
val get_modified_input_strings (n: nat) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_regs: (reg_64 -> bool)) (args: list td) (i: nat{i + List.Tot.length args <= n}) (ret_val: option string) (reg_names: (reg_64 -> string)) (counter: nat) (arg_names: (nat -> string)) : list string & (reg_64 -> string) & nat
let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 129, "start_col": 0, "start_line": 120 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.nat -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> regs_mod: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> reserved_regs: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> args: Prims.list Vale.Interop.Base.td -> i: Prims.nat{i + FStar.List.Tot.Base.length args <= n} -> ret_val: FStar.Pervasives.Native.option Prims.string -> reg_names: (_: Vale.X64.Machine_s.reg_64 -> Prims.string) -> counter: Prims.nat -> arg_names: (_: Prims.nat -> Prims.string) -> (Prims.list Prims.string * (_: Vale.X64.Machine_s.reg_64 -> Prims.string)) * Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Vale.Interop.X64.reg_nat", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Prims.list", "Vale.Interop.Base.td", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.List.Tot.Base.length", "FStar.Pervasives.Native.option", "Prims.string", "Vale.X64.Print_Inline_s.print_output_ret", "FStar.Pervasives.Native.Mktuple3", "FStar.List.Tot.Base.op_At", "FStar.Pervasives.Native.tuple3", "Vale.X64.Print_Inline_s.get_modified_input_strings", "Vale.X64.Print_Inline_s.print_modified_input" ]
[ "recursion" ]
false
false
false
false
false
let rec get_modified_input_strings (n: nat) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_regs: (reg_64 -> bool)) (args: list td) (i: nat{i + List.Tot.length args <= n}) (ret_val: option string) (reg_names: (reg_64 -> string)) (counter: nat) (arg_names: (nat -> string)) : list string & (reg_64 -> string) & nat =
match args with | [] -> print_output_ret ret_val reg_names counter | a :: q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i + 1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.build_reserved_args
val build_reserved_args (c: code) (reserved: (reg_64 -> bool)) : Tot (reg_64 -> bool) (decreases c)
val build_reserved_args (c: code) (reserved: (reg_64 -> bool)) : Tot (reg_64 -> bool) (decreases c)
let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r )
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 98, "start_col": 0, "start_line": 69 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers.
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
c: Vale.X64.Machine_Semantics_s.code -> reserved: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> Prims.Tot (_: Vale.X64.Machine_s.reg_64 -> Prims.bool)
Prims.Tot
[ "total", "" ]
[ "build_reserved_args", "build_reserved_args_block" ]
[ "Vale.X64.Machine_Semantics_s.code", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Instruction_s.instr_t_record", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args", "Vale.X64.Print_Inline_s.build_reserved_args_ins", "Vale.X64.Print_Inline_s.build_reserved_args_outs", "Prims.list", "Vale.X64.Machine_s.precode", "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.Print_Inline_s.build_reserved_args_block", "Vale.X64.Print_Inline_s.build_reserved_args" ]
[ "mutual recursion" ]
false
false
false
false
false
let rec build_reserved_args (c: code) (reserved: (reg_64 -> bool)) : Tot (reg_64 -> bool) (decreases c) =
fun r -> (match c with | Ins ins -> (match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r) | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r)
false
Hacl.P256.PrecompTable.fst
Hacl.P256.PrecompTable.precomp_g_pow2_64_table_list_w4
val precomp_g_pow2_64_table_list_w4:x: list uint64 {FStar.List.Tot.length x = 192}
val precomp_g_pow2_64_table_list_w4:x: list uint64 {FStar.List.Tot.length x = 192}
let precomp_g_pow2_64_table_list_w4: x:list uint64{FStar.List.Tot.length x = 192} = normalize_term (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_64 15)
{ "file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 91, "end_line": 220, "start_col": 0, "start_line": 219 }
module Hacl.P256.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.P256.PrecompTable module S = Spec.P256 module SL = Spec.P256.Lemmas open Hacl.Impl.P256.Point include Hacl.Impl.P256.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 = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in [@inline_let] let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in [@inline_let] let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in (rX, rY, rZ) val lemma_proj_g_pow2_64_eval : unit -> Lemma (SE.exp_pow2 S.mk_p256_concrete_ops S.base_point 64 == proj_g_pow2_64) let lemma_proj_g_pow2_64_eval () = SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops S.base_point 64; let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64) in normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64); let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b 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 = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in [@inline_let] let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in [@inline_let] let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in (rX, rY, rZ) val lemma_proj_g_pow2_128_eval : unit -> Lemma (SE.exp_pow2 S.mk_p256_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_p256_concrete_ops proj_g_pow2_64 64; let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64); let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 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 = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in [@inline_let] let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in [@inline_let] let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in (rX, rY, rZ) val lemma_proj_g_pow2_192_eval : unit -> Lemma (SE.exp_pow2 S.mk_p256_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_p256_concrete_ops proj_g_pow2_128 64; let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64) in normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64); let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 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_p256_concrete_ops S.base_point 64) // let proj_g_pow2_128 : S.proj_point = // normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) // let proj_g_pow2_192 : S.proj_point = // normalize_term (SPT256.exp_pow2_rec S.mk_p256_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 12 = 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 12 = 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 12 = 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_p256_concrete_ops S.base_point 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_p256_concrete_ops S.base_point 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_p256_concrete_ops S.base_point 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 = 192} = normalize_term (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 15) let precomp_basepoint_table_lseq_w4 : LSeq.lseq uint64 192 = normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 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_p256_precomp_base_table S.base_point 15); SPT.precomp_base_table_lemma mk_p256_precomp_base_table S.base_point 16 precomp_basepoint_table_lseq_w4 let precomp_basepoint_table_w4: x:glbuffer uint64 192ul{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)]
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.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.P256.PrecompTable.fsti.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.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.P256.PrecompTable.fst" }
[ { "abbrev": false, "full_module": "Hacl.Impl.P256.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Point", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "SL" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.P256.PrecompTable", "short_module": "SPTK" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable256", "short_module": "SPT256" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "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.Impl.P256.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Point", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "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.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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: Prims.list (Lib.IntTypes.int_t Lib.IntTypes.U64 Lib.IntTypes.SEC) {FStar.List.Tot.Base.length x = 192}
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.normalize_term", "Prims.list", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.List.Tot.Base.length", "Hacl.Spec.PrecompBaseTable.precomp_base_table_list", "Spec.P256.PointOps.proj_point", "FStar.UInt32.uint_to_t", "Hacl.P256.PrecompTable.mk_p256_precomp_base_table", "Hacl.P256.PrecompTable.proj_g_pow2_64" ]
[]
false
false
false
false
false
let precomp_g_pow2_64_table_list_w4:x: list uint64 {FStar.List.Tot.length x = 192} =
normalize_term (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_64 15)
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_spaces
val print_spaces (n: nat) : string
val print_spaces (n: nat) : string
let rec print_spaces (n:nat) : string = match n with | 0 -> "" | n -> " " ^ print_spaces (n-1)
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 248, "start_col": 0, "start_line": 245 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter // Print the list of modified registers, + memory and cc let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15] // Prints "register uint64_t *argi_r __asm__("[reg]") = argi;\n" let print_explicit_register_arg (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = let ty = match a with | TD_Base _ -> "uint64_t " | _ -> "uint64_t *" in if reserved (of_arg i) then // If the associated register is reserved, we really this argument in it. For instance if it is Rdx and we have Mul(x) instructions true, " register " ^ ty ^ names i ^ "_r __asm__(\"" ^ P.print_reg_name (of_arg i) ^ "\") = " ^ names i ^ ";\n" else false, "" let rec print_explicit_register_args (n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = match args with | [] -> false, "" | a::q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i+1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str // If we have a return parameter with a reserved register, print "register uint64_t [name] __asm__("rax");\n" let print_register_ret (reserved:reg_64 -> bool) = function | None -> "" | Some name -> if reserved rRax then " register uint64_t " ^ name ^ " __asm__(\"rax\");\n" else " uint64_t " ^ name ^ ";\n" (* This is a copy from X64.Print_s, and should remain in sync. The difference is that each line should be in quotes, and end by a semicolon in inline assembly *) let print_cmp (c:ocmp) (counter:int) (p:P.printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.P.op_order (P.print_operand o1 p) (P.print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> " \"" ^ print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ ";\"\n" | ONe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ ";\"\n" | OLe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ ";\"\n" | OGe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ ";\"\n" | OLt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ ";\"\n" | OGt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ ";\"\n"
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.nat -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.int", "Prims.op_Hat", "Vale.X64.Print_Inline_s.print_spaces", "Prims.op_Subtraction", "Prims.string" ]
[ "recursion" ]
false
false
false
true
false
let rec print_spaces (n: nat) : string =
match n with | 0 -> "" | n -> " " ^ print_spaces (n - 1)
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.max
val max : x: Prims.int -> y: Prims.int -> z: Prims.int{(x >= y ==> z = x) /\ (x < y ==> z = y)}
let max = FStar.Math.Lib.max
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 6, "start_col": 7, "start_line": 6 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> y: Prims.int -> z: Prims.int{(x >= y ==> z = x) /\ (x < y ==> z = y)}
Prims.Tot
[ "total" ]
[]
[ "FStar.Math.Lib.max" ]
[]
false
false
false
false
false
let max =
FStar.Math.Lib.max
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.get_nonmodified_input_strings
val get_nonmodified_input_strings : n: Prims.nat -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> regs_mod: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> reserved_regs: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> args: Prims.list Vale.Interop.Base.td -> i: Prims.nat{FStar.List.Tot.Base.length args + i <= n} -> reg_names: (_: Vale.X64.Machine_s.reg_64 -> Prims.string) -> counter: Prims.nat -> arg_names: (_: Prims.nat -> Prims.string) -> (Prims.list Prims.string * (_: Vale.X64.Machine_s.reg_64 -> Prims.string)) * Prims.nat
let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 168, "start_col": 0, "start_line": 160 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1)
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.nat -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> regs_mod: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> reserved_regs: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> args: Prims.list Vale.Interop.Base.td -> i: Prims.nat{FStar.List.Tot.Base.length args + i <= n} -> reg_names: (_: Vale.X64.Machine_s.reg_64 -> Prims.string) -> counter: Prims.nat -> arg_names: (_: Prims.nat -> Prims.string) -> (Prims.list Prims.string * (_: Vale.X64.Machine_s.reg_64 -> Prims.string)) * Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Vale.Interop.X64.reg_nat", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Prims.list", "Vale.Interop.Base.td", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.List.Tot.Base.length", "Prims.string", "FStar.Pervasives.Native.Mktuple3", "Prims.Nil", "FStar.List.Tot.Base.op_At", "FStar.Pervasives.Native.tuple3", "Vale.X64.Print_Inline_s.get_nonmodified_input_strings", "Vale.X64.Print_Inline_s.print_nonmodified_input" ]
[ "recursion" ]
false
false
false
false
false
let rec get_nonmodified_input_strings (n: nat) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_regs: (reg_64 -> bool)) (args: list td) (i: nat{List.Tot.length args + i <= n}) (reg_names: (reg_64 -> string)) (counter: nat) (arg_names: (nat -> string)) =
match args with | [] -> [], reg_names, counter | a :: q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i + 1) reg_names counter arg_names in input @ inputs, reg_names, counter
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.poly_equal
val poly_equal (a b: poly) : prop0
val poly_equal (a b: poly) : prop0
let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i])
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 59, "end_line": 11, "start_col": 0, "start_line": 10 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10"
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> Vale.Def.Prop_s.prop0
Prims.Tot
[ "total" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "Prims.l_Forall", "Prims.nat", "Prims.eq2", "Prims.bool", "Vale.Math.Poly2.Defs_s.op_String_Access", "Vale.Def.Prop_s.prop0" ]
[]
false
false
false
true
false
let poly_equal (a b: poly) : prop0 =
(forall (i: nat). {:pattern a.[ i ]\/b.[ i ]} a.[ i ] == b.[ i ])
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_register_ret
val print_register_ret : reserved: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> _: FStar.Pervasives.Native.option Prims.string -> Prims.string
let print_register_ret (reserved:reg_64 -> bool) = function | None -> "" | Some name -> if reserved rRax then " register uint64_t " ^ name ^ " __asm__(\"rax\");\n" else " uint64_t " ^ name ^ ";\n"
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 127, "end_line": 228, "start_col": 0, "start_line": 226 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter // Print the list of modified registers, + memory and cc let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15] // Prints "register uint64_t *argi_r __asm__("[reg]") = argi;\n" let print_explicit_register_arg (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = let ty = match a with | TD_Base _ -> "uint64_t " | _ -> "uint64_t *" in if reserved (of_arg i) then // If the associated register is reserved, we really this argument in it. For instance if it is Rdx and we have Mul(x) instructions true, " register " ^ ty ^ names i ^ "_r __asm__(\"" ^ P.print_reg_name (of_arg i) ^ "\") = " ^ names i ^ ";\n" else false, "" let rec print_explicit_register_args (n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = match args with | [] -> false, "" | a::q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i+1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
reserved: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> _: FStar.Pervasives.Native.option Prims.string -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_s.reg_64", "Prims.bool", "FStar.Pervasives.Native.option", "Prims.string", "Vale.X64.Machine_s.rRax", "Prims.op_Hat" ]
[]
false
false
false
true
false
let print_register_ret (reserved: (reg_64 -> bool)) =
function | None -> "" | Some name -> if reserved rRax then " register uint64_t " ^ name ^ " __asm__(\"rax\");\n" else " uint64_t " ^ name ^ ";\n"
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_nonmodified_inputs
val print_nonmodified_inputs : n: Prims.nat -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> regs_mod: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> reserved_regs: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> args: Prims.list Vale.Interop.Base.td {FStar.List.Tot.Base.length args <= n} -> reg_names: (_: Vale.X64.Machine_s.reg_64 -> Prims.string) -> counter: Prims.nat -> arg_names: (_: Prims.nat -> Prims.string) -> (Prims.string * (_: Vale.X64.Machine_s.reg_64 -> Prims.string)) * Prims.nat
let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 179, "start_col": 0, "start_line": 170 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.nat -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> regs_mod: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> reserved_regs: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> args: Prims.list Vale.Interop.Base.td {FStar.List.Tot.Base.length args <= n} -> reg_names: (_: Vale.X64.Machine_s.reg_64 -> Prims.string) -> counter: Prims.nat -> arg_names: (_: Prims.nat -> Prims.string) -> (Prims.string * (_: Vale.X64.Machine_s.reg_64 -> Prims.string)) * Prims.nat
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Vale.Interop.X64.reg_nat", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Prims.list", "Vale.Interop.Base.td", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.List.Tot.Base.length", "Prims.string", "FStar.Pervasives.Native.Mktuple3", "FStar.Pervasives.Native.tuple3", "Vale.X64.Print_Inline_s.get_nonmodified_input_strings", "Prims.op_Hat" ]
[]
false
false
false
false
false
let print_nonmodified_inputs (n: nat) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_regs: (reg_64 -> bool)) (args: list td {List.Tot.length args <= n}) (reg_names: (reg_64 -> string)) (counter: nat) (arg_names: (nat -> string)) =
let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_explicit_register_args
val print_explicit_register_args : n: Prims.nat -> args: Prims.list Vale.Interop.Base.td -> i: Prims.nat{i + FStar.List.Tot.Base.length args = n} -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> reserved: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> names: (_: Prims.nat -> Prims.string) -> Prims.bool * Prims.string
let rec print_explicit_register_args (n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = match args with | [] -> false, "" | a::q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i+1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 223, "start_col": 0, "start_line": 217 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter // Print the list of modified registers, + memory and cc let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15] // Prints "register uint64_t *argi_r __asm__("[reg]") = argi;\n" let print_explicit_register_arg (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = let ty = match a with | TD_Base _ -> "uint64_t " | _ -> "uint64_t *" in if reserved (of_arg i) then // If the associated register is reserved, we really this argument in it. For instance if it is Rdx and we have Mul(x) instructions true, " register " ^ ty ^ names i ^ "_r __asm__(\"" ^ P.print_reg_name (of_arg i) ^ "\") = " ^ names i ^ ";\n" else false, ""
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.nat -> args: Prims.list Vale.Interop.Base.td -> i: Prims.nat{i + FStar.List.Tot.Base.length args = n} -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> reserved: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> names: (_: Prims.nat -> Prims.string) -> Prims.bool * Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.list", "Vale.Interop.Base.td", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Addition", "FStar.List.Tot.Base.length", "Vale.Interop.X64.reg_nat", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Prims.string", "FStar.Pervasives.Native.Mktuple2", "Prims.op_BarBar", "Prims.op_Hat", "FStar.Pervasives.Native.tuple2", "Vale.X64.Print_Inline_s.print_explicit_register_args", "Vale.X64.Print_Inline_s.print_explicit_register_arg" ]
[ "recursion" ]
false
false
false
false
false
let rec print_explicit_register_args (n: nat) (args: list td) (i: nat{i + List.length args = n}) (of_arg: (reg_nat n -> reg_64)) (reserved: (reg_64 -> bool)) (names: (nat -> string)) =
match args with | [] -> false, "" | a :: q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i + 1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_modified_registers
val print_modified_registers : n: Prims.nat -> ret_val: FStar.Pervasives.Native.option Prims.string -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> regs_mod: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> reserved_args: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> args: Prims.list Vale.Interop.Base.td -> Prims.string
let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15]
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 103, "end_line": 204, "start_col": 0, "start_line": 182 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.nat -> ret_val: FStar.Pervasives.Native.option Prims.string -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> regs_mod: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> reserved_args: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> args: Prims.list Vale.Interop.Base.td -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.Pervasives.Native.option", "Prims.string", "Vale.Interop.X64.reg_nat", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Prims.list", "Vale.Interop.Base.td", "Prims.Cons", "Vale.X64.Machine_s.rRax", "Vale.X64.Machine_s.rRbx", "Vale.X64.Machine_s.rRcx", "Vale.X64.Machine_s.rRdx", "Vale.X64.Machine_s.rRsi", "Vale.X64.Machine_s.rRdi", "Vale.X64.Machine_s.rRbp", "Vale.X64.Machine_s.rRsp", "Vale.X64.Machine_s.rR8", "Vale.X64.Machine_s.rR9", "Vale.X64.Machine_s.rR10", "Vale.X64.Machine_s.rR11", "Vale.X64.Machine_s.rR12", "Vale.X64.Machine_s.rR13", "Vale.X64.Machine_s.rR14", "Vale.X64.Machine_s.rR15", "Prims.Nil", "Prims.op_BarBar", "Prims.op_Negation", "Prims.op_Hat", "Vale.X64.Print_s.print_reg_name", "Prims.op_Subtraction", "Prims.op_GreaterThanOrEqual", "Prims.op_Equality", "Prims.op_Addition", "Prims.op_AmpAmp", "FStar.Pervasives.Native.uu___is_Some" ]
[]
false
false
false
false
false
let print_modified_registers (n: nat) (ret_val: option string) (of_arg: (reg_nat n -> reg_64)) (regs_mod reserved_args: (reg_64 -> bool)) (args: list td) =
let output_register a = Some? ret_val && a = rRax in let rec input_register (i: nat) (a: reg_64) : Tot bool (decreases (n - i)) = if i >= n then false else a = of_arg i || input_register (i + 1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a :: q -> if not (regs_mod a) || input_register 0 a || output_register a then aux q else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15]
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_fn_comments
val print_fn_comments : _: Prims.list Prims.string -> Prims.string
let rec print_fn_comments = function | [] -> "" | hd::tl -> "// " ^ hd ^ "\n" ^ print_fn_comments tl
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 54, "end_line": 302, "start_col": 0, "start_line": 300 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter // Print the list of modified registers, + memory and cc let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15] // Prints "register uint64_t *argi_r __asm__("[reg]") = argi;\n" let print_explicit_register_arg (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = let ty = match a with | TD_Base _ -> "uint64_t " | _ -> "uint64_t *" in if reserved (of_arg i) then // If the associated register is reserved, we really this argument in it. For instance if it is Rdx and we have Mul(x) instructions true, " register " ^ ty ^ names i ^ "_r __asm__(\"" ^ P.print_reg_name (of_arg i) ^ "\") = " ^ names i ^ ";\n" else false, "" let rec print_explicit_register_args (n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = match args with | [] -> false, "" | a::q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i+1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str // If we have a return parameter with a reserved register, print "register uint64_t [name] __asm__("rax");\n" let print_register_ret (reserved:reg_64 -> bool) = function | None -> "" | Some name -> if reserved rRax then " register uint64_t " ^ name ^ " __asm__(\"rax\");\n" else " uint64_t " ^ name ^ ";\n" (* This is a copy from X64.Print_s, and should remain in sync. The difference is that each line should be in quotes, and end by a semicolon in inline assembly *) let print_cmp (c:ocmp) (counter:int) (p:P.printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.P.op_order (P.print_operand o1 p) (P.print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> " \"" ^ print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ ";\"\n" | ONe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ ";\"\n" | OLe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ ";\"\n" | OGe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ ";\"\n" | OLt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ ";\"\n" | OGt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ ";\"\n" let rec print_spaces (n:nat) : string = match n with | 0 -> "" | n -> " " ^ print_spaces (n-1) (* Overriding printer for formatting instructions *) let print_ins (ins:ins) (p:P.printer) : string = match ins with | Instr _ _ (AnnotateComment s) -> " // " ^ s | Instr _ _ (AnnotateLargeComment s) -> "\n /////// " ^ s ^ " ////// \n" | Instr _ _ (AnnotateSpace n) -> print_spaces n | _ -> " \"" ^ P.print_ins ins p ^ ";\"" let rec print_block (b:codes) (n:int) (p:P.printer) : string & int = match b with | Nil -> "", n | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins (Instr _ _ (AnnotateComment s)) :: tail -> let head_str = " // " ^ s ^ "\n" in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins i :: tail -> let head_str = print_ins i p in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateNewline _)) :: tail -> let rest, n' = print_block tail n p in "\n" ^ rest, n' | head :: tail -> let head_str, n' = print_code head n p in let rest, n'' = print_block tail n' p in head_str ^ rest, n'' and print_code (c:code) (n:int) (p:P.printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (P.cmp_not cond) n1 p in let true_str, n' = print_code true_code (n + 2) p in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"L" ^ string_of_int n1 ^ ":\"\n" in let false_str, n' = print_code false_code n' p in let label2 = " \"L" ^ string_of_int n2 ^ ":\"\n" in cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n' | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\"\n" in let body_str, n' = print_code body (n + 2) p in let label2 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\"\n" in let cmp = print_cmp cond n1 p in jmp ^ label1 ^ body_str ^ label2 ^ cmp, n'
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
_: Prims.list Prims.string -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Prims.string", "Prims.op_Hat", "Vale.X64.Print_Inline_s.print_fn_comments" ]
[ "recursion" ]
false
false
false
true
false
let rec print_fn_comments =
function | [] -> "" | hd :: tl -> "// " ^ hd ^ "\n" ^ print_fn_comments tl
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_pointwise_equal
val lemma_pointwise_equal (a b: poly) (pf: (i: int -> Lemma (a.[ i ] == b.[ i ]))) : Lemma (a == b)
val lemma_pointwise_equal (a b: poly) (pf: (i: int -> Lemma (a.[ i ] == b.[ i ]))) : Lemma (a == b)
let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 33, "start_col": 0, "start_line": 31 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> pf: (i: Prims.int -> FStar.Pervasives.Lemma (ensures a.[ i ] == b.[ i ])) -> FStar.Pervasives.Lemma (ensures a == b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "Prims.int", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.bool", "Vale.Math.Poly2.Defs_s.op_String_Access", "Prims.Nil", "FStar.Pervasives.pattern", "Vale.Math.Poly2.Defs.lemma_poly_equal_elim", "FStar.Classical.forall_intro" ]
[]
false
false
true
false
false
let lemma_pointwise_equal (a b: poly) (pf: (i: int -> Lemma (a.[ i ] == b.[ i ]))) : Lemma (a == b) =
FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_sum_of_zero
val lemma_sum_of_zero (j k: int) (f: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j))
val lemma_sum_of_zero (j k: int) (f: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j))
let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 64, "start_col": 0, "start_line": 59 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = ()
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.int -> k: Prims.int -> f: (_: Prims.int -> Prims.bool) -> FStar.Pervasives.Lemma (requires forall (i: Prims.int). {:pattern f i} j <= i /\ i < k ==> Prims.op_Negation (f i)) (ensures Prims.op_Negation (Vale.Math.Poly2.Defs_s.sum_of_bools j k f)) (decreases k - j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.int", "Prims.bool", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.lemma_sum_of_zero", "Prims.op_Subtraction", "Prims.unit", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Negation", "Prims.squash", "Vale.Math.Poly2.Defs_s.sum_of_bools", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_sum_of_zero (j k: int) (f: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) =
if j < k then lemma_sum_of_zero j (k - 1) f
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_add_move
val lemma_add_move (a b: poly) : Lemma (ensures a == (a +. b) +. b)
val lemma_add_move (a b: poly) : Lemma (ensures a == (a +. b) +. b)
let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 47, "start_col": 0, "start_line": 44 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = ()
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> FStar.Pervasives.Lemma (ensures a == a +. b +. b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "Vale.Math.Poly2.Defs.lemma_add_zero", "Prims.unit", "Vale.Math.Poly2.Defs.lemma_add_cancel", "Vale.Math.Poly2.Defs.lemma_add_associate", "Prims.l_True", "Prims.squash", "Prims.eq2", "Vale.Math.Poly2.Defs.op_Plus_Dot", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_add_move (a b: poly) : Lemma (ensures a == (a +. b) +. b) =
lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_poly_equal_elim
val lemma_poly_equal_elim (a b: poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)]
val lemma_poly_equal_elim (a b: poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)]
let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 20, "end_line": 29, "start_col": 0, "start_line": 19 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> FStar.Pervasives.Lemma (requires a =. b) (ensures a == b) (decreases FStar.Seq.Base.length a + FStar.Seq.Base.length b) [SMTPat (Vale.Math.Poly2.Defs.poly_equal a b)]
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "Prims._assert", "FStar.Seq.Base.equal", "Prims.bool", "Prims.unit", "Prims.l_Forall", "Prims.nat", "Prims.eq2", "Vale.Math.Poly2.Defs_s.op_String_Access", "FStar.Seq.Base.index", "FStar.Seq.Base.length", "Prims.l_imp", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_Subtraction", "Prims.int", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Prims.op_Equality", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.max", "Prims.op_Addition", "Vale.Math.Poly2.Defs.op_Equals_Dot", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Vale.Def.Prop_s.prop0", "Vale.Math.Poly2.Defs.poly_equal", "Prims.Nil" ]
[]
false
false
true
false
false
let lemma_poly_equal_elim (a b: poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] =
let len = max (length a) (length b) in assert (len > 0 ==> a.[ len - 1 ] == b.[ len - 1 ]); assert (length a == length b); assert (forall (i: nat). {:pattern (index a i)\/(index b i)} a.[ i ] == b.[ i ]); assert (equal a b)
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_sum_join
val lemma_sum_join (i j k: int) (f: (int -> bool)) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j))
val lemma_sum_join (i j k: int) (f: (int -> bool)) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j))
let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 71, "start_col": 0, "start_line": 66 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.int -> j: Prims.int -> k: Prims.int -> f: (_: Prims.int -> Prims.bool) -> FStar.Pervasives.Lemma (requires i <= j /\ j <= k) (ensures Vale.Math.Poly2.Defs_s.sum_of_bools i k f == (Vale.Math.Poly2.Defs_s.sum_of_bools i j f <> Vale.Math.Poly2.Defs_s.sum_of_bools j k f)) (decreases k - j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.int", "Prims.bool", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.lemma_sum_join", "Prims.op_Subtraction", "Prims.unit", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "Prims.eq2", "Vale.Math.Poly2.Defs_s.sum_of_bools", "Prims.op_disEquality", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_sum_join (i j k: int) (f: (int -> bool)) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) =
if j < k then lemma_sum_join i j (k - 1) f
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_mul_commute
val lemma_mul_commute (a b: poly) : Lemma ((a *. b) =. (b *. a))
val lemma_mul_commute (a b: poly) : Lemma ((a *. b) =. (b *. a))
let lemma_mul_commute (a b:poly) : Lemma ((a *. b) =. (b *. a)) = let f (k:nat) : Lemma (mul_element a b k == mul_element b a k) = lemma_sum_reverse 0 (k + 1) (mul_element_fun a b k) (mul_element_fun b a k) in FStar.Classical.forall_intro f
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 246, "start_col": 0, "start_line": 242 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k) let lemma_mul_zero (a:poly) : Lemma ((a *. zero) =. zero) = let f (k:nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f let lemma_mul_one (a:poly) : Lemma ((a *. one) =. a) = let f (k:nat) : Lemma (mul_element a one k == a.[k]) = lemma_sum_of_zero 0 k (mul_element_fun a one k) in FStar.Classical.forall_intro f
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> FStar.Pervasives.Lemma (ensures a *. b =. b *. a)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "FStar.Classical.forall_intro", "Prims.nat", "Prims.eq2", "Prims.bool", "Vale.Math.Poly2.Defs_s.mul_element", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Vale.Math.Poly2.Defs.lemma_sum_reverse", "Prims.op_Addition", "Vale.Math.Poly2.Defs_s.mul_element_fun", "Vale.Math.Poly2.Defs.op_Equals_Dot", "Vale.Math.Poly2.Defs.op_Star_Dot" ]
[]
false
false
true
false
false
let lemma_mul_commute (a b: poly) : Lemma ((a *. b) =. (b *. a)) =
let f (k: nat) : Lemma (mul_element a b k == mul_element b a k) = lemma_sum_reverse 0 (k + 1) (mul_element_fun a b k) (mul_element_fun b a k) in FStar.Classical.forall_intro f
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_cmp
val print_cmp (c: ocmp) (counter: int) (p: P.printer) : string
val print_cmp (c: ocmp) (counter: int) (p: P.printer) : string
let print_cmp (c:ocmp) (counter:int) (p:P.printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.P.op_order (P.print_operand o1 p) (P.print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> " \"" ^ print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ ";\"\n" | ONe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ ";\"\n" | OLe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ ";\"\n" | OGe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ ";\"\n" | OLt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ ";\"\n" | OGt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ ";\"\n"
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 93, "end_line": 243, "start_col": 0, "start_line": 232 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter // Print the list of modified registers, + memory and cc let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15] // Prints "register uint64_t *argi_r __asm__("[reg]") = argi;\n" let print_explicit_register_arg (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = let ty = match a with | TD_Base _ -> "uint64_t " | _ -> "uint64_t *" in if reserved (of_arg i) then // If the associated register is reserved, we really this argument in it. For instance if it is Rdx and we have Mul(x) instructions true, " register " ^ ty ^ names i ^ "_r __asm__(\"" ^ P.print_reg_name (of_arg i) ^ "\") = " ^ names i ^ ";\n" else false, "" let rec print_explicit_register_args (n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = match args with | [] -> false, "" | a::q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i+1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str // If we have a return parameter with a reserved register, print "register uint64_t [name] __asm__("rax");\n" let print_register_ret (reserved:reg_64 -> bool) = function | None -> "" | Some name -> if reserved rRax then " register uint64_t " ^ name ^ " __asm__(\"rax\");\n" else " uint64_t " ^ name ^ ";\n" (* This is a copy from X64.Print_s, and should remain in sync. The difference is that
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
c: Vale.X64.Machine_Semantics_s.ocmp -> counter: Prims.int -> p: Vale.X64.Print_s.printer -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Vale.X64.Machine_Semantics_s.ocmp", "Prims.int", "Vale.X64.Print_s.printer", "Vale.X64.Machine_s.operand64", "Prims.b2t", "Prims.op_Negation", "Prims.op_BarBar", "Vale.X64.Machine_s.uu___is_OMem", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.uu___is_OStack", "Prims.op_Hat", "Prims.string_of_int", "Prims.string", "FStar.Pervasives.Native.tuple2", "Vale.X64.Print_s.__proj__Mkprinter__item__op_order", "Vale.X64.Print_s.print_operand" ]
[]
false
false
false
true
false
let print_cmp (c: ocmp) (counter: int) (p: P.printer) : string =
let print_ops (o1 o2: operand64) : string = let first, second = p.P.op_order (P.print_operand o1 p) (P.print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> " \"" ^ print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ ";\"\n" | ONe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jne " ^ "L" ^ string_of_int counter ^ ";\"\n" | OLe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jbe " ^ "L" ^ string_of_int counter ^ ";\"\n" | OGe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jae " ^ "L" ^ string_of_int counter ^ ";\"\n" | OLt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ ";\"\n" | OGt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ ";\"\n"
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_sum_extend
val lemma_sum_extend (j' j k k': int) (f: (int -> bool)) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i: int). {:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i: int). {:pattern (f i)} k <= i /\ i < k' ==> not (f i))) (ensures sum_of_bools j' k' f == sum_of_bools j k f)
val lemma_sum_extend (j' j k k': int) (f: (int -> bool)) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i: int). {:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i: int). {:pattern (f i)} k <= i /\ i < k' ==> not (f i))) (ensures sum_of_bools j' k' f == sum_of_bools j k f)
let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 84, "start_col": 0, "start_line": 73 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j': Prims.int -> j: Prims.int -> k: Prims.int -> k': Prims.int -> f: (_: Prims.int -> Prims.bool) -> FStar.Pervasives.Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i: Prims.int). {:pattern f i} j' <= i /\ i < j ==> Prims.op_Negation (f i)) /\ (forall (i: Prims.int). {:pattern f i} k <= i /\ i < k' ==> Prims.op_Negation (f i))) (ensures Vale.Math.Poly2.Defs_s.sum_of_bools j' k' f == Vale.Math.Poly2.Defs_s.sum_of_bools j k f)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.bool", "Vale.Math.Poly2.Defs.lemma_sum_join", "Prims.unit", "Vale.Math.Poly2.Defs.lemma_sum_of_zero", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.l_Forall", "Prims.l_imp", "Prims.op_LessThan", "Prims.op_Negation", "Prims.squash", "Prims.eq2", "Vale.Math.Poly2.Defs_s.sum_of_bools", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_sum_extend (j' j k k': int) (f: (int -> bool)) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i: int). {:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i: int). {:pattern (f i)} k <= i /\ i < k' ==> not (f i))) (ensures sum_of_bools j' k' f == sum_of_bools j k f) =
lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_sum_shift
val lemma_sum_shift (j k shift: int) (f g: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j))
val lemma_sum_shift (j k shift: int) (f g: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j))
let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 51, "end_line": 98, "start_col": 0, "start_line": 93 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.int -> k: Prims.int -> shift: Prims.int -> f: (_: Prims.int -> Prims.bool) -> g: (_: Prims.int -> Prims.bool) -> FStar.Pervasives.Lemma (requires forall (i: Prims.int). {:pattern f i} j <= i /\ i < k ==> f i == g (i + shift)) (ensures Vale.Math.Poly2.Defs_s.sum_of_bools j k f == Vale.Math.Poly2.Defs_s.sum_of_bools (j + shift) (k + shift) g) (decreases k - j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.int", "Prims.bool", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.lemma_sum_shift", "Prims.op_Subtraction", "Prims.unit", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.eq2", "Prims.op_Addition", "Prims.squash", "Vale.Math.Poly2.Defs_s.sum_of_bools", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_sum_shift (j k shift: int) (f g: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) =
if j < k then lemma_sum_shift j (k - 1) shift f g
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_sum_mul
val lemma_sum_mul (j k: int) (b: bool) (f g: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j))
val lemma_sum_mul (j k: int) (b: bool) (f g: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j))
let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 130, "start_col": 0, "start_line": 125 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f'
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.int -> k: Prims.int -> b: Prims.bool -> f: (_: Prims.int -> Prims.bool) -> g: (_: Prims.int -> Prims.bool) -> FStar.Pervasives.Lemma (requires forall (i: Prims.int). {:pattern f i} j <= i /\ i < k ==> f i == (b && g i)) (ensures Vale.Math.Poly2.Defs_s.sum_of_bools j k f == (b && Vale.Math.Poly2.Defs_s.sum_of_bools j k g)) (decreases k - j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.int", "Prims.bool", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.lemma_sum_mul", "Prims.op_Subtraction", "Prims.unit", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.eq2", "Prims.op_AmpAmp", "Prims.squash", "Vale.Math.Poly2.Defs_s.sum_of_bools", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_sum_mul (j k: int) (b: bool) (f g: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) =
if j < k then lemma_sum_mul j (k - 1) b f g
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_sum_of_pairs
val lemma_sum_of_pairs (j k: int) (f g h: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j))
val lemma_sum_of_pairs (j k: int) (f g h: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j))
let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 91, "start_col": 0, "start_line": 86 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.int -> k: Prims.int -> f: (_: Prims.int -> Prims.bool) -> g: (_: Prims.int -> Prims.bool) -> h: (_: Prims.int -> Prims.bool) -> FStar.Pervasives.Lemma (requires forall (i: Prims.int). {:pattern f i} j <= i /\ i < k ==> f i == (g i <> h i)) (ensures Vale.Math.Poly2.Defs_s.sum_of_bools j k f == (Vale.Math.Poly2.Defs_s.sum_of_bools j k g <> Vale.Math.Poly2.Defs_s.sum_of_bools j k h)) (decreases k - j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.int", "Prims.bool", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.lemma_sum_of_pairs", "Prims.op_Subtraction", "Prims.unit", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.eq2", "Prims.op_disEquality", "Prims.squash", "Vale.Math.Poly2.Defs_s.sum_of_bools", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_sum_of_pairs (j k: int) (f g h: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) =
if j < k then lemma_sum_of_pairs j (k - 1) f g h
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_mul_element
val lemma_mul_element (a b: poly) (k: int) : Lemma (requires True) (ensures (a *. b).[ k ] == mul_element a b k) [SMTPat (a *. b).[ k ]]
val lemma_mul_element (a b: poly) (k: int) : Lemma (requires True) (ensures (a *. b).[ k ] == mul_element a b k) [SMTPat (a *. b).[ k ]]
let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k)
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 86, "end_line": 228, "start_col": 0, "start_line": 223 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> k: Prims.int -> FStar.Pervasives.Lemma (ensures (a *. b).[ k ] == Vale.Math.Poly2.Defs_s.mul_element a b k) [SMTPat (a *. b).[ k ]]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "Prims.int", "Prims.op_GreaterThanOrEqual", "Prims.op_Addition", "FStar.Seq.Base.length", "Prims.bool", "Vale.Math.Poly2.Defs.lemma_sum_of_zero", "Vale.Math.Poly2.Defs_s.mul_element_fun", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Vale.Math.Poly2.Defs_s.op_String_Access", "Vale.Math.Poly2.Defs.op_Star_Dot", "Vale.Math.Poly2.Defs_s.mul_element", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
false
false
true
false
false
let lemma_mul_element (a b: poly) (k: int) : Lemma (requires True) (ensures (a *. b).[ k ] == mul_element a b k) [SMTPat (a *. b).[ k ]] =
if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k)
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_sum_invert
val lemma_sum_invert (j k: int) (f g: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == g (- i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g)
val lemma_sum_invert (j k: int) (f g: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == g (- i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g)
let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 115, "start_col": 0, "start_line": 111 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.int -> k: Prims.int -> f: (_: Prims.int -> Prims.bool) -> g: (_: Prims.int -> Prims.bool) -> FStar.Pervasives.Lemma (requires forall (i: Prims.int). {:pattern f i} j <= i /\ i < k ==> f i == g (- i)) (ensures Vale.Math.Poly2.Defs_s.sum_of_bools j k f == Vale.Math.Poly2.Defs_s.sum_of_bools (1 - k) (1 - j) g)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.bool", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.lemma_sum_invert_rec", "Prims.unit", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.eq2", "Prims.op_Minus", "Prims.squash", "Vale.Math.Poly2.Defs_s.sum_of_bools", "Prims.op_Subtraction", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_sum_invert (j k: int) (f g: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == g (- i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) =
if j < k then lemma_sum_invert_rec j k k f g
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_sum_invert_rec
val lemma_sum_invert_rec (j m k: int) (f g: (int -> bool)) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == g (- i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j))
val lemma_sum_invert_rec (j m k: int) (f g: (int -> bool)) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == g (- i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j))
let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 109, "start_col": 0, "start_line": 100 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.int -> m: Prims.int -> k: Prims.int -> f: (_: Prims.int -> Prims.bool) -> g: (_: Prims.int -> Prims.bool) -> FStar.Pervasives.Lemma (requires j <= m /\ m <= k /\ Vale.Math.Poly2.Defs_s.sum_of_bools j k f == (Vale.Math.Poly2.Defs_s.sum_of_bools j m f <> Vale.Math.Poly2.Defs_s.sum_of_bools (1 - k) (1 - m) g) /\ (forall (i: Prims.int). {:pattern f i} j <= i /\ i < k ==> f i == g (- i))) (ensures Vale.Math.Poly2.Defs_s.sum_of_bools j k f == Vale.Math.Poly2.Defs_s.sum_of_bools (1 - k) (1 - j) g) (decreases m - j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.int", "Prims.bool", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.lemma_sum_invert_rec", "Prims.op_Subtraction", "Prims.unit", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.eq2", "Vale.Math.Poly2.Defs_s.sum_of_bools", "Prims.op_disEquality", "Prims.l_Forall", "Prims.l_imp", "Prims.op_Minus", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_sum_invert_rec (j m k: int) (f g: (int -> bool)) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == g (- i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) =
if j < m then lemma_sum_invert_rec j (m - 1) k f g
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_sum_pointwise_equal
val lemma_sum_pointwise_equal (j k: int) (f g: (int -> bool)) (pf: (i: int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j))
val lemma_sum_pointwise_equal (j k: int) (f g: (int -> bool)) (pf: (i: int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j))
let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf )
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 218, "start_col": 0, "start_line": 210 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; ()
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.int -> k: Prims.int -> f: (_: Prims.int -> Prims.bool) -> g: (_: Prims.int -> Prims.bool) -> pf: (i: Prims.int -> FStar.Pervasives.Lemma (ensures f i == g i)) -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Defs_s.sum_of_bools j k f == Vale.Math.Poly2.Defs_s.sum_of_bools j k g) (decreases k - j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.int", "Prims.bool", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.lemma_sum_pointwise_equal", "Prims.op_Subtraction", "Vale.Math.Poly2.Defs_s.sum_of_bools" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_sum_pointwise_equal (j k: int) (f g: (int -> bool)) (pf: (i: int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) =
if j < k then (pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf)
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.remove_blanks
val remove_blanks (b: codes) : codes
val remove_blanks (b: codes) : codes
let rec remove_blank (c:code) : code = match c with | Ins _ -> c | Block b -> Block (remove_blanks b) | IfElse cond ct cf -> IfElse cond (remove_blank ct) (remove_blank cf) | While cond cb -> While cond (remove_blank cb) and remove_blanks (b:codes) : codes = match b with | [] -> [] | Ins (Instr _ _ (AnnotateGhost _)) :: cs -> remove_blanks cs | Block b :: cs -> ( match remove_blanks b with | [] -> remove_blanks cs | b -> Block b :: remove_blanks cs ) | c :: cs -> c :: remove_blanks cs
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 320, "start_col": 0, "start_line": 304 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter // Print the list of modified registers, + memory and cc let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15] // Prints "register uint64_t *argi_r __asm__("[reg]") = argi;\n" let print_explicit_register_arg (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = let ty = match a with | TD_Base _ -> "uint64_t " | _ -> "uint64_t *" in if reserved (of_arg i) then // If the associated register is reserved, we really this argument in it. For instance if it is Rdx and we have Mul(x) instructions true, " register " ^ ty ^ names i ^ "_r __asm__(\"" ^ P.print_reg_name (of_arg i) ^ "\") = " ^ names i ^ ";\n" else false, "" let rec print_explicit_register_args (n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = match args with | [] -> false, "" | a::q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i+1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str // If we have a return parameter with a reserved register, print "register uint64_t [name] __asm__("rax");\n" let print_register_ret (reserved:reg_64 -> bool) = function | None -> "" | Some name -> if reserved rRax then " register uint64_t " ^ name ^ " __asm__(\"rax\");\n" else " uint64_t " ^ name ^ ";\n" (* This is a copy from X64.Print_s, and should remain in sync. The difference is that each line should be in quotes, and end by a semicolon in inline assembly *) let print_cmp (c:ocmp) (counter:int) (p:P.printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.P.op_order (P.print_operand o1 p) (P.print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> " \"" ^ print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ ";\"\n" | ONe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ ";\"\n" | OLe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ ";\"\n" | OGe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ ";\"\n" | OLt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ ";\"\n" | OGt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ ";\"\n" let rec print_spaces (n:nat) : string = match n with | 0 -> "" | n -> " " ^ print_spaces (n-1) (* Overriding printer for formatting instructions *) let print_ins (ins:ins) (p:P.printer) : string = match ins with | Instr _ _ (AnnotateComment s) -> " // " ^ s | Instr _ _ (AnnotateLargeComment s) -> "\n /////// " ^ s ^ " ////// \n" | Instr _ _ (AnnotateSpace n) -> print_spaces n | _ -> " \"" ^ P.print_ins ins p ^ ";\"" let rec print_block (b:codes) (n:int) (p:P.printer) : string & int = match b with | Nil -> "", n | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins (Instr _ _ (AnnotateComment s)) :: tail -> let head_str = " // " ^ s ^ "\n" in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins i :: tail -> let head_str = print_ins i p in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateNewline _)) :: tail -> let rest, n' = print_block tail n p in "\n" ^ rest, n' | head :: tail -> let head_str, n' = print_code head n p in let rest, n'' = print_block tail n' p in head_str ^ rest, n'' and print_code (c:code) (n:int) (p:P.printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (P.cmp_not cond) n1 p in let true_str, n' = print_code true_code (n + 2) p in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"L" ^ string_of_int n1 ^ ":\"\n" in let false_str, n' = print_code false_code n' p in let label2 = " \"L" ^ string_of_int n2 ^ ":\"\n" in cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n' | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\"\n" in let body_str, n' = print_code body (n + 2) p in let label2 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\"\n" in let cmp = print_cmp cond n1 p in jmp ^ label1 ^ body_str ^ label2 ^ cmp, n' let rec print_fn_comments = function | [] -> "" | hd::tl -> "// " ^ hd ^ "\n" ^ print_fn_comments tl
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
b: Vale.X64.Machine_Semantics_s.codes -> Vale.X64.Machine_Semantics_s.codes
Prims.Tot
[ "total" ]
[ "remove_blank", "remove_blanks" ]
[ "Vale.X64.Machine_Semantics_s.codes", "Prims.Nil", "Vale.X64.Bytes_Code_s.code_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Vale.X64.Instruction_s.instr_t_record", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args", "Vale.X64.Machine_Semantics_s.equals_instr", "Vale.X64.Instruction_s.InstrTypeRecord", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.PreserveFlags", "Vale.X64.Instructions_s.ins_Ghost", "Prims.list", "Vale.X64.Print_Inline_s.remove_blanks", "Vale.X64.Machine_s.precode", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Bytes_Code_s.ocmp", "Prims.Cons", "Vale.X64.Machine_s.Block" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec remove_blanks (b: codes) : codes =
match b with | [] -> [] | Ins (Instr _ _ (AnnotateGhost _)) :: cs -> remove_blanks cs | Block b :: cs -> (match remove_blanks b with | [] -> remove_blanks cs | b -> Block b :: remove_blanks cs) | c :: cs -> c :: remove_blanks cs
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_sum_swap_mul_associate
val lemma_sum_swap_mul_associate (k: int) (ff gg: (int -> int -> bool)) (f g: (int -> bool)) : Lemma (requires k > 0 /\ (forall (x: nat). {:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y: nat). {:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x: int) (y: int). {:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x: int) (y: int). {:pattern (ff x y)\/(gg y x)} ff x y == gg y x)) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g)
val lemma_sum_swap_mul_associate (k: int) (ff gg: (int -> int -> bool)) (f g: (int -> bool)) : Lemma (requires k > 0 /\ (forall (x: nat). {:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y: nat). {:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x: int) (y: int). {:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x: int) (y: int). {:pattern (ff x y)\/(gg y x)} ff x y == gg y x)) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g)
let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; ()
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 208, "start_col": 0, "start_line": 161 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g )
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Prims.int -> ff: (_: Prims.int -> _: Prims.int -> Prims.bool) -> gg: (_: Prims.int -> _: Prims.int -> Prims.bool) -> f: (_: Prims.int -> Prims.bool) -> g: (_: Prims.int -> Prims.bool) -> FStar.Pervasives.Lemma (requires k > 0 /\ (forall (x: Prims.nat). {:pattern f x} f x == Vale.Math.Poly2.Defs_s.sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y: Prims.nat). {:pattern g y} g y == Vale.Math.Poly2.Defs_s.sum_of_bools y k (gg y) ) /\ (forall (x: Prims.int) (y: Prims.int). {:pattern ff x y} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x: Prims.int) (y: Prims.int). {:pattern ff x y\/gg y x} ff x y == gg y x)) (ensures Vale.Math.Poly2.Defs_s.sum_of_bools 0 k f == Vale.Math.Poly2.Defs_s.sum_of_bools 0 k g)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.bool", "Prims.unit", "Vale.Math.Poly2.Defs.lemma_sum_extend", "Vale.Math.Poly2.Defs.lemma_sum_swap", "FStar.Classical.forall_intro", "Prims.nat", "Prims.l_and", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Negation", "Prims.op_LessThan", "Prims.eq2", "Vale.Math.Poly2.Defs_s.sum_of_bools", "Prims.op_Subtraction", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Vale.Math.Poly2.Defs.lemma_sum_of_zero", "Prims.op_Addition", "Vale.Math.Poly2.Defs.lemma_sum_join", "Prims.op_GreaterThan", "Prims.l_Forall" ]
[]
false
false
true
false
false
let lemma_sum_swap_mul_associate (k: int) (ff gg: (int -> int -> bool)) (f g: (int -> bool)) : Lemma (requires k > 0 /\ (forall (x: nat). {:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y: nat). {:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x: int) (y: int). {:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x: int) (y: int). {:pattern (ff x y)\/(gg y x)} ff x y == gg y x)) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) =
let k' = k + k - 1 in let lemma_f (x: nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x))) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y: nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y))) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; ()
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_mul_zero
val lemma_mul_zero (a: poly) : Lemma ((a *. zero) =. zero)
val lemma_mul_zero (a: poly) : Lemma ((a *. zero) =. zero)
let lemma_mul_zero (a:poly) : Lemma ((a *. zero) =. zero) = let f (k:nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 234, "start_col": 0, "start_line": 230 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k)
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> FStar.Pervasives.Lemma (ensures a *. Vale.Math.Poly2.Defs_s.zero =. Vale.Math.Poly2.Defs_s.zero)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "FStar.Classical.forall_intro", "Prims.nat", "Prims.b2t", "Prims.op_Negation", "Vale.Math.Poly2.Defs_s.mul_element", "Vale.Math.Poly2.Defs_s.zero", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Vale.Math.Poly2.Defs.lemma_sum_of_zero", "Prims.op_Addition", "Vale.Math.Poly2.Defs_s.mul_element_fun", "Vale.Math.Poly2.Defs.op_Equals_Dot", "Vale.Math.Poly2.Defs.op_Star_Dot" ]
[]
false
false
true
false
false
let lemma_mul_zero (a: poly) : Lemma ((a *. zero) =. zero) =
let f (k: nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_sum_reverse
val lemma_sum_reverse (j k: int) (f g: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g)
val lemma_sum_reverse (j k: int) (f g: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g)
let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f'
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 123, "start_col": 0, "start_line": 117 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.int -> k: Prims.int -> f: (_: Prims.int -> Prims.bool) -> g: (_: Prims.int -> Prims.bool) -> FStar.Pervasives.Lemma (requires forall (i: Prims.int). {:pattern f i} j <= i /\ i < k ==> f i == g (k + j - i - 1)) (ensures Vale.Math.Poly2.Defs_s.sum_of_bools j k f == Vale.Math.Poly2.Defs_s.sum_of_bools j k g)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.bool", "Vale.Math.Poly2.Defs.lemma_sum_shift", "Prims.op_Subtraction", "Prims.op_Addition", "Prims.unit", "Vale.Math.Poly2.Defs.lemma_sum_invert", "Prims.op_Minus", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "Prims.eq2", "Prims.squash", "Vale.Math.Poly2.Defs_s.sum_of_bools", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_sum_reverse (j k: int) (f g: (int -> bool)) : Lemma (requires (forall (i: int). {:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) =
let f' (i: int) = f (- i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f'
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_mul_distribute
val lemma_mul_distribute (a b c: poly) : Lemma (a *. (b +. c) =. (a *. b) +. (a *. c))
val lemma_mul_distribute (a b c: poly) : Lemma (a *. (b +. c) =. (a *. b) +. (a *. c))
let lemma_mul_distribute (a b c:poly) : Lemma (a *. (b +. c) =. (a *. b) +. (a *. c)) = let f (k:nat) : Lemma (ensures mul_element a (b +. c) k == (mul_element a b k <> mul_element a c k)) = lemma_sum_of_pairs 0 (k + 1) (mul_element_fun a (b +. c) k) (mul_element_fun a b k) (mul_element_fun a c k) in FStar.Classical.forall_intro f
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 291, "start_col": 0, "start_line": 282 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k) let lemma_mul_zero (a:poly) : Lemma ((a *. zero) =. zero) = let f (k:nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f let lemma_mul_one (a:poly) : Lemma ((a *. one) =. a) = let f (k:nat) : Lemma (mul_element a one k == a.[k]) = lemma_sum_of_zero 0 k (mul_element_fun a one k) in FStar.Classical.forall_intro f let lemma_mul_commute (a b:poly) : Lemma ((a *. b) =. (b *. a)) = let f (k:nat) : Lemma (mul_element a b k == mul_element b a k) = lemma_sum_reverse 0 (k + 1) (mul_element_fun a b k) (mul_element_fun b a k) in FStar.Classical.forall_intro f let lemma_mul_associate (a b c:poly) : Lemma (a *. (b *. c) =. (a *. b) *. c) = let f (k:nat) : Lemma (mul_element a (b *. c) k == mul_element (a *. b) c k) = let abc1 (i:int) (j:int) = a.[j] && b.[i - j] && c.[k - i] in let abc2 (j:int) (i:int) = a.[j] && b.[i - j] && c.[k - i] in let abc3 (j:int) (i:int) = a.[j] && b.[i] && c.[k - j - i] in let sum_abc1 (i:int) = sum_of_bools 0 (i + 1) (abc1 i) in let sum_abc2 (j:int) = sum_of_bools j (k + 1) (abc2 j) in let sum_abc3 (j:int) = sum_of_bools 0 (k + 1 - j) (abc3 j) in let l1 (i:int) : Lemma (mul_element_fun (a *. b) c k i == sum_abc1 i) = lemma_sum_mul 0 (i + 1) c.[k - i] (abc1 i) (mul_element_fun a b i) in let l2 (j:int) : Lemma (sum_abc2 j == sum_abc3 j) = lemma_sum_shift 0 (k + 1 - j) j (abc3 j) (abc2 j) in let l3 (j:int) : Lemma (mul_element_fun a (b *. c) k j == sum_abc3 j) = lemma_sum_mul 0 (k + 1 - j) a.[j] (abc3 j) (mul_element_fun b c (k - j)) in // mul_element (a *. b) c k // sum[0 <= i <= k] (a *. b)[i] * c[k - i] // sum[0 <= i <= k] (sum[0 <= j <= i] a[j] * b[i - j]) * c[k - i]) lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun (a *. b) c k) sum_abc1 l1; // sum[0 <= i <= k] sum[0 <= j <= i] a[j] * b[i - j] * c[k - i] lemma_sum_swap_mul_associate (k + 1) abc1 abc2 sum_abc1 sum_abc2; // sum[0 <= j <= k] sum[j <= i <= k] a[j] * b[i - j] * c[k - i] lemma_sum_pointwise_equal 0 (k + 1) sum_abc2 sum_abc3 l2; // sum[0 <= j <= k] sum[0 <= i <= k - j] a[j] * b[i] * c[k - j - i] lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun a (b *. c) k) sum_abc3 l3; // sum[0 <= j <= k] a[j] * (sum[0 <= i <= k - j] b[i] * c[k - j - i]) // sum[0 <= j <= k] (a[j] * (b *. c)[k - j]) // mul_element a (b *. c) k () in FStar.Classical.forall_intro f
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> c: Vale.Math.Poly2.Defs_s.poly -> FStar.Pervasives.Lemma (ensures a *. (b +. c) =. a *. b +. a *. c)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "FStar.Classical.forall_intro", "Prims.nat", "Prims.eq2", "Prims.bool", "Vale.Math.Poly2.Defs_s.mul_element", "Vale.Math.Poly2.Defs.op_Plus_Dot", "Prims.op_disEquality", "Prims.unit", "Prims.l_True", "Prims.squash", "Vale.Math.Poly2.Defs_s.add", "Prims.Nil", "FStar.Pervasives.pattern", "Vale.Math.Poly2.Defs.lemma_sum_of_pairs", "Prims.op_Addition", "Vale.Math.Poly2.Defs_s.mul_element_fun", "Vale.Math.Poly2.Defs.op_Equals_Dot", "Vale.Math.Poly2.Defs.op_Star_Dot" ]
[]
false
false
true
false
false
let lemma_mul_distribute (a b c: poly) : Lemma (a *. (b +. c) =. (a *. b) +. (a *. c)) =
let f (k: nat) : Lemma (ensures mul_element a (b +. c) k == (mul_element a b k <> mul_element a c k)) = lemma_sum_of_pairs 0 (k + 1) (mul_element_fun a (b +. c) k) (mul_element_fun a b k) (mul_element_fun a c k) in FStar.Classical.forall_intro f
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_block
val print_block (b: codes) (n: int) (p: P.printer) : string & int
val print_block (b: codes) (n: int) (p: P.printer) : string & int
let rec print_block (b:codes) (n:int) (p:P.printer) : string & int = match b with | Nil -> "", n | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins (Instr _ _ (AnnotateComment s)) :: tail -> let head_str = " // " ^ s ^ "\n" in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins i :: tail -> let head_str = print_ins i p in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateNewline _)) :: tail -> let rest, n' = print_block tail n p in "\n" ^ rest, n' | head :: tail -> let head_str, n' = print_code head n p in let rest, n'' = print_block tail n' p in head_str ^ rest, n'' and print_code (c:code) (n:int) (p:P.printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (P.cmp_not cond) n1 p in let true_str, n' = print_code true_code (n + 2) p in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"L" ^ string_of_int n1 ^ ":\"\n" in let false_str, n' = print_code false_code n' p in let label2 = " \"L" ^ string_of_int n2 ^ ":\"\n" in cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n' | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\"\n" in let body_str, n' = print_code body (n + 2) p in let label2 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\"\n" in let cmp = print_cmp cond n1 p in jmp ^ label1 ^ body_str ^ label2 ^ cmp, n'
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 298, "start_col": 0, "start_line": 258 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter // Print the list of modified registers, + memory and cc let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15] // Prints "register uint64_t *argi_r __asm__("[reg]") = argi;\n" let print_explicit_register_arg (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = let ty = match a with | TD_Base _ -> "uint64_t " | _ -> "uint64_t *" in if reserved (of_arg i) then // If the associated register is reserved, we really this argument in it. For instance if it is Rdx and we have Mul(x) instructions true, " register " ^ ty ^ names i ^ "_r __asm__(\"" ^ P.print_reg_name (of_arg i) ^ "\") = " ^ names i ^ ";\n" else false, "" let rec print_explicit_register_args (n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = match args with | [] -> false, "" | a::q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i+1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str // If we have a return parameter with a reserved register, print "register uint64_t [name] __asm__("rax");\n" let print_register_ret (reserved:reg_64 -> bool) = function | None -> "" | Some name -> if reserved rRax then " register uint64_t " ^ name ^ " __asm__(\"rax\");\n" else " uint64_t " ^ name ^ ";\n" (* This is a copy from X64.Print_s, and should remain in sync. The difference is that each line should be in quotes, and end by a semicolon in inline assembly *) let print_cmp (c:ocmp) (counter:int) (p:P.printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.P.op_order (P.print_operand o1 p) (P.print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> " \"" ^ print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ ";\"\n" | ONe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ ";\"\n" | OLe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ ";\"\n" | OGe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ ";\"\n" | OLt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ ";\"\n" | OGt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ ";\"\n" let rec print_spaces (n:nat) : string = match n with | 0 -> "" | n -> " " ^ print_spaces (n-1) (* Overriding printer for formatting instructions *) let print_ins (ins:ins) (p:P.printer) : string = match ins with | Instr _ _ (AnnotateComment s) -> " // " ^ s | Instr _ _ (AnnotateLargeComment s) -> "\n /////// " ^ s ^ " ////// \n" | Instr _ _ (AnnotateSpace n) -> print_spaces n | _ -> " \"" ^ P.print_ins ins p ^ ";\""
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
b: Vale.X64.Machine_Semantics_s.codes -> n: Prims.int -> p: Vale.X64.Print_s.printer -> Prims.string * Prims.int
Prims.Tot
[ "total" ]
[ "print_block", "print_code" ]
[ "Vale.X64.Machine_Semantics_s.codes", "Prims.int", "Vale.X64.Print_s.printer", "FStar.Pervasives.Native.Mktuple2", "Prims.string", "Vale.X64.Instruction_s.instr_t_record", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args", "Prims.nat", "Prims.eq2", "Vale.X64.Instruction_s.InstrTypeRecord", "Prims.Nil", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.PreserveFlags", "Vale.X64.Instructions_s.ins_Space", "Vale.X64.Instructions_s.ins_Comment", "Prims.list", "Vale.X64.Bytes_Code_s.code_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Prims.op_Hat", "Vale.X64.Print_Inline_s.print_spaces", "FStar.Pervasives.Native.tuple2", "Vale.X64.Print_Inline_s.print_block", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Print_Inline_s.print_ins", "Vale.X64.Machine_Semantics_s.equals_instr", "Vale.X64.Instructions_s.ins_Newline", "Vale.X64.Print_Inline_s.print_code" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec print_block (b: codes) (n: int) (p: P.printer) : string & int =
match b with | Nil -> "", n | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins (Instr _ _ (AnnotateComment s)) :: tail -> let head_str = " // " ^ s ^ "\n" in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins i :: tail -> let head_str = print_ins i p in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateNewline _)) :: tail -> let rest, n' = print_block tail n p in "\n" ^ rest, n' | head :: tail -> let head_str, n' = print_code head n p in let rest, n'' = print_block tail n' p in head_str ^ rest, n''
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.uses_rax
val uses_rax : args: Prims.list Vale.Interop.Base.td -> i: Prims.nat{i + FStar.List.Tot.Base.length args = n} -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> Prims.bool
let rec uses_rax (#n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) = match args with | [] -> false | a::q -> if of_arg i = rRax then true else uses_rax q (i+1) of_arg
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 69, "end_line": 326, "start_col": 0, "start_line": 323 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter // Print the list of modified registers, + memory and cc let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15] // Prints "register uint64_t *argi_r __asm__("[reg]") = argi;\n" let print_explicit_register_arg (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = let ty = match a with | TD_Base _ -> "uint64_t " | _ -> "uint64_t *" in if reserved (of_arg i) then // If the associated register is reserved, we really this argument in it. For instance if it is Rdx and we have Mul(x) instructions true, " register " ^ ty ^ names i ^ "_r __asm__(\"" ^ P.print_reg_name (of_arg i) ^ "\") = " ^ names i ^ ";\n" else false, "" let rec print_explicit_register_args (n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = match args with | [] -> false, "" | a::q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i+1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str // If we have a return parameter with a reserved register, print "register uint64_t [name] __asm__("rax");\n" let print_register_ret (reserved:reg_64 -> bool) = function | None -> "" | Some name -> if reserved rRax then " register uint64_t " ^ name ^ " __asm__(\"rax\");\n" else " uint64_t " ^ name ^ ";\n" (* This is a copy from X64.Print_s, and should remain in sync. The difference is that each line should be in quotes, and end by a semicolon in inline assembly *) let print_cmp (c:ocmp) (counter:int) (p:P.printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.P.op_order (P.print_operand o1 p) (P.print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> " \"" ^ print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ ";\"\n" | ONe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ ";\"\n" | OLe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ ";\"\n" | OGe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ ";\"\n" | OLt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ ";\"\n" | OGt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ ";\"\n" let rec print_spaces (n:nat) : string = match n with | 0 -> "" | n -> " " ^ print_spaces (n-1) (* Overriding printer for formatting instructions *) let print_ins (ins:ins) (p:P.printer) : string = match ins with | Instr _ _ (AnnotateComment s) -> " // " ^ s | Instr _ _ (AnnotateLargeComment s) -> "\n /////// " ^ s ^ " ////// \n" | Instr _ _ (AnnotateSpace n) -> print_spaces n | _ -> " \"" ^ P.print_ins ins p ^ ";\"" let rec print_block (b:codes) (n:int) (p:P.printer) : string & int = match b with | Nil -> "", n | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins (Instr _ _ (AnnotateComment s)) :: tail -> let head_str = " // " ^ s ^ "\n" in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins i :: tail -> let head_str = print_ins i p in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateNewline _)) :: tail -> let rest, n' = print_block tail n p in "\n" ^ rest, n' | head :: tail -> let head_str, n' = print_code head n p in let rest, n'' = print_block tail n' p in head_str ^ rest, n'' and print_code (c:code) (n:int) (p:P.printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (P.cmp_not cond) n1 p in let true_str, n' = print_code true_code (n + 2) p in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"L" ^ string_of_int n1 ^ ":\"\n" in let false_str, n' = print_code false_code n' p in let label2 = " \"L" ^ string_of_int n2 ^ ":\"\n" in cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n' | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\"\n" in let body_str, n' = print_code body (n + 2) p in let label2 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\"\n" in let cmp = print_cmp cond n1 p in jmp ^ label1 ^ body_str ^ label2 ^ cmp, n' let rec print_fn_comments = function | [] -> "" | hd::tl -> "// " ^ hd ^ "\n" ^ print_fn_comments tl let rec remove_blank (c:code) : code = match c with | Ins _ -> c | Block b -> Block (remove_blanks b) | IfElse cond ct cf -> IfElse cond (remove_blank ct) (remove_blank cf) | While cond cb -> While cond (remove_blank cb) and remove_blanks (b:codes) : codes = match b with | [] -> [] | Ins (Instr _ _ (AnnotateGhost _)) :: cs -> remove_blanks cs | Block b :: cs -> ( match remove_blanks b with | [] -> remove_blanks cs | b -> Block b :: remove_blanks cs ) | c :: cs -> c :: remove_blanks cs
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": true, "smtencoding_l_arith_repr": "native", "smtencoding_nl_arith_repr": "wrapped", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [ "smt.arith.nl=false", "smt.QI.EAGER_THRESHOLD=100", "smt.CASE_SPLIT=3" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
args: Prims.list Vale.Interop.Base.td -> i: Prims.nat{i + FStar.List.Tot.Base.length args = n} -> of_arg: (_: Vale.Interop.X64.reg_nat n -> Vale.X64.Machine_s.reg_64) -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.list", "Vale.Interop.Base.td", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.op_Addition", "FStar.List.Tot.Base.length", "Vale.Interop.X64.reg_nat", "Vale.X64.Machine_s.reg_64", "Vale.X64.Machine_s.rRax", "Prims.bool", "Vale.X64.Print_Inline_s.uses_rax" ]
[ "recursion" ]
false
false
false
false
false
let rec uses_rax (#n: nat) (args: list td) (i: nat{i + List.length args = n}) (of_arg: (reg_nat n -> reg_64)) =
match args with | [] -> false | a :: q -> if of_arg i = rRax then true else uses_rax q (i + 1) of_arg
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_mul_one
val lemma_mul_one (a: poly) : Lemma ((a *. one) =. a)
val lemma_mul_one (a: poly) : Lemma ((a *. one) =. a)
let lemma_mul_one (a:poly) : Lemma ((a *. one) =. a) = let f (k:nat) : Lemma (mul_element a one k == a.[k]) = lemma_sum_of_zero 0 k (mul_element_fun a one k) in FStar.Classical.forall_intro f
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 240, "start_col": 0, "start_line": 236 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k) let lemma_mul_zero (a:poly) : Lemma ((a *. zero) =. zero) = let f (k:nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> FStar.Pervasives.Lemma (ensures a *. Vale.Math.Poly2.Defs_s.one =. a)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "FStar.Classical.forall_intro", "Prims.nat", "Prims.eq2", "Prims.bool", "Vale.Math.Poly2.Defs_s.mul_element", "Vale.Math.Poly2.Defs_s.one", "Vale.Math.Poly2.Defs_s.op_String_Access", "Prims.unit", "Prims.l_True", "Prims.squash", "Vale.Math.Poly2.Defs_s.poly_index", "Prims.Nil", "FStar.Pervasives.pattern", "Vale.Math.Poly2.Defs.lemma_sum_of_zero", "Vale.Math.Poly2.Defs_s.mul_element_fun", "Vale.Math.Poly2.Defs.op_Equals_Dot", "Vale.Math.Poly2.Defs.op_Star_Dot" ]
[]
false
false
true
false
false
let lemma_mul_one (a: poly) : Lemma ((a *. one) =. a) =
let f (k: nat) : Lemma (mul_element a one k == a.[ k ]) = lemma_sum_of_zero 0 k (mul_element_fun a one k) in FStar.Classical.forall_intro f
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_div_degree
val lemma_div_degree (a b: poly) : Lemma (requires length b > 0) (ensures degree (a /. b) == (if degree a < degree b then - 1 else degree a - degree b)) (decreases (length a))
val lemma_div_degree (a b: poly) : Lemma (requires length b > 0) (ensures degree (a /. b) == (if degree a < degree b then - 1 else degree a - degree b)) (decreases (length a))
let rec lemma_div_degree (a b:poly) : Lemma (requires length b > 0) (ensures degree (a /. b) == (if degree a < degree b then -1 else degree a - degree b)) (decreases (length a)) = if length a >= length b then ( let _ = assert (a.[length a - 1]) in let n = length a - length b in let a' = add a (shift b n) in lemma_div_degree a' b; assert ((a /. b).[degree a - degree b]); () )
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 418, "start_col": 0, "start_line": 405 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k) let lemma_mul_zero (a:poly) : Lemma ((a *. zero) =. zero) = let f (k:nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f let lemma_mul_one (a:poly) : Lemma ((a *. one) =. a) = let f (k:nat) : Lemma (mul_element a one k == a.[k]) = lemma_sum_of_zero 0 k (mul_element_fun a one k) in FStar.Classical.forall_intro f let lemma_mul_commute (a b:poly) : Lemma ((a *. b) =. (b *. a)) = let f (k:nat) : Lemma (mul_element a b k == mul_element b a k) = lemma_sum_reverse 0 (k + 1) (mul_element_fun a b k) (mul_element_fun b a k) in FStar.Classical.forall_intro f let lemma_mul_associate (a b c:poly) : Lemma (a *. (b *. c) =. (a *. b) *. c) = let f (k:nat) : Lemma (mul_element a (b *. c) k == mul_element (a *. b) c k) = let abc1 (i:int) (j:int) = a.[j] && b.[i - j] && c.[k - i] in let abc2 (j:int) (i:int) = a.[j] && b.[i - j] && c.[k - i] in let abc3 (j:int) (i:int) = a.[j] && b.[i] && c.[k - j - i] in let sum_abc1 (i:int) = sum_of_bools 0 (i + 1) (abc1 i) in let sum_abc2 (j:int) = sum_of_bools j (k + 1) (abc2 j) in let sum_abc3 (j:int) = sum_of_bools 0 (k + 1 - j) (abc3 j) in let l1 (i:int) : Lemma (mul_element_fun (a *. b) c k i == sum_abc1 i) = lemma_sum_mul 0 (i + 1) c.[k - i] (abc1 i) (mul_element_fun a b i) in let l2 (j:int) : Lemma (sum_abc2 j == sum_abc3 j) = lemma_sum_shift 0 (k + 1 - j) j (abc3 j) (abc2 j) in let l3 (j:int) : Lemma (mul_element_fun a (b *. c) k j == sum_abc3 j) = lemma_sum_mul 0 (k + 1 - j) a.[j] (abc3 j) (mul_element_fun b c (k - j)) in // mul_element (a *. b) c k // sum[0 <= i <= k] (a *. b)[i] * c[k - i] // sum[0 <= i <= k] (sum[0 <= j <= i] a[j] * b[i - j]) * c[k - i]) lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun (a *. b) c k) sum_abc1 l1; // sum[0 <= i <= k] sum[0 <= j <= i] a[j] * b[i - j] * c[k - i] lemma_sum_swap_mul_associate (k + 1) abc1 abc2 sum_abc1 sum_abc2; // sum[0 <= j <= k] sum[j <= i <= k] a[j] * b[i - j] * c[k - i] lemma_sum_pointwise_equal 0 (k + 1) sum_abc2 sum_abc3 l2; // sum[0 <= j <= k] sum[0 <= i <= k - j] a[j] * b[i] * c[k - j - i] lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun a (b *. c) k) sum_abc3 l3; // sum[0 <= j <= k] a[j] * (sum[0 <= i <= k - j] b[i] * c[k - j - i]) // sum[0 <= j <= k] (a[j] * (b *. c)[k - j]) // mul_element a (b *. c) k () in FStar.Classical.forall_intro f let lemma_mul_distribute (a b c:poly) : Lemma (a *. (b +. c) =. (a *. b) +. (a *. c)) = let f (k:nat) : Lemma (ensures mul_element a (b +. c) k == (mul_element a b k <> mul_element a c k)) = lemma_sum_of_pairs 0 (k + 1) (mul_element_fun a (b +. c) k) (mul_element_fun a b k) (mul_element_fun a c k) in FStar.Classical.forall_intro f let lemma_mul_distribute_left (a b c:poly) : Lemma ((a +. b) *. c =. (a *. c) +. (b *. c)) = lemma_mul_commute (a +. b) c; lemma_mul_commute a c; lemma_mul_commute b c; lemma_mul_distribute c a b let lemma_shift_is_mul (a:poly) (n:nat) : Lemma (shift a n =. a *. (monomial n)) = let an = shift a n in let b = monomial n in let lem (k:nat) : Lemma (an.[k] == mul_element a b k) = if k < n then lemma_sum_of_zero 0 k (mul_element_fun a b k) else lemma_sum_extend 0 (k - n) (k - n + 1) (k + 1) (mul_element_fun a b k) in FStar.Classical.forall_intro lem let lemma_mul_degree (a b:poly) : Lemma (degree (a *. b) == (if degree a >= 0 && degree b >= 0 then degree a + degree b else -1)) = if degree a >= 0 && degree b >= 0 then ( let len = length a + length b in lemma_sum_of_zero 0 len (mul_element_fun a b (len - 1)); lemma_sum_extend 0 (length a - 1) (length a) (len - 1) (mul_element_fun a b (len - 2)); assert (not (a *. b).[len - 1]); assert ((a *. b).[len - 2]); () ) else if degree a < 0 then ( assert (a =. zero); lemma_mul_zero b; lemma_mul_commute b zero; () ) else ( assert (b =. zero); lemma_mul_zero a; () ) let lemma_mul_reverse (a b:poly) (n:nat) : Lemma (requires degree a <= n /\ degree b <= n) (ensures reverse (a *. b) (n + n) =. reverse a n *. reverse b n) = let ab = a *. b in let rab = reverse ab (n + n) in let ra = reverse a n in let rb = reverse b n in lemma_mul_degree a b; lemma_mul_degree ra rb; let f (k:int) : Lemma (rab.[k] == (ra *. rb).[k]) = if 0 <= k && k <= n + n then ( let f0 = mul_element_fun ra rb k in let f1 (i:int) : bool = a.[n + i] && b.[n - k - i] in let f2 = mul_element_fun a b (n + n - k) in // mul_element a b (n + n - k) == sum_of_bools 0 (n + n + 1 - k) f2 // mul_element ra rb k == sum_of_bools 0 (k + 1) f0 lemma_sum_invert 0 (k + 1) f0 f1; // mul_element ra rb k == sum_of_bools (-k) 1 f1 lemma_sum_shift (-k) 1 n f1 f2; // mul_element ra rb k == sum_of_bools (n - k) (n + 1) f2 let lo = min (n - k) 0 in let hi = max (n + 1) (n + n + 1 - k) in lemma_sum_extend lo 0 (n + n + 1 - k) hi f2; lemma_sum_extend lo (n - k) (n + 1) hi f2; () ) in lemma_pointwise_equal rab (ra *. rb) f // DIVISION, MOD let rec lemma_div_mod (a b:poly) : Lemma (requires length b > 0) (ensures a =. (a /. b) *. b +. (a %. b)) (decreases (length a)) = if length a < length b then ( lemma_mul_zero b; lemma_mul_commute b zero; () ) else ( let _ = assert (a.[length a - 1]) in let n = length a - length b in let a' = a +. (shift b n) in let xn = monomial n in lemma_shift_is_mul b n; lemma_mul_commute b xn; // a' == a +. xn *. b // (a /. b == a' /. b +. xn); lemma_add_move (a' /. b) xn; // (a' /. b == a /. b +. xn); lemma_div_mod a' b; // a' == (a' /. b) *. b +. (a' %. b) // a +. xn * b == (a /. b + xn) *. b +. (a %. b)) lemma_mul_distribute_left (a /. b) xn b; // a +. xn *. b == (a /. b) *. b +. xn *. b +. (a %. b) // a == (a /. b) *. b +. (a %. b) () )
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b > 0) (ensures Vale.Math.Poly2.Defs_s.degree (a /. b) == (match Vale.Math.Poly2.Defs_s.degree a < Vale.Math.Poly2.Defs_s.degree b with | true -> - 1 | _ -> Vale.Math.Poly2.Defs_s.degree a - Vale.Math.Poly2.Defs_s.degree b)) (decreases FStar.Seq.Base.length a)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "Prims.op_GreaterThanOrEqual", "FStar.Seq.Base.length", "Prims.bool", "Prims.unit", "Prims._assert", "Prims.b2t", "Vale.Math.Poly2.Defs_s.op_String_Access", "Vale.Math.Poly2.Defs.op_Slash_Dot", "Prims.op_Subtraction", "Vale.Math.Poly2.Defs_s.degree", "Vale.Math.Poly2.Defs.lemma_div_degree", "Vale.Math.Poly2.Defs_s.add", "Vale.Math.Poly2.Defs_s.shift", "Prims.int", "Prims.op_GreaterThan", "Prims.squash", "Prims.eq2", "Prims.op_LessThan", "Prims.op_Minus", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_div_degree (a b: poly) : Lemma (requires length b > 0) (ensures degree (a /. b) == (if degree a < degree b then - 1 else degree a - degree b)) (decreases (length a)) =
if length a >= length b then (let _ = assert (a.[ length a - 1 ]) in let n = length a - length b in let a' = add a (shift b n) in lemma_div_degree a' b; assert ((a /. b).[ degree a - degree b ]); ())
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_mul_degree
val lemma_mul_degree (a b: poly) : Lemma (degree (a *. b) == (if degree a >= 0 && degree b >= 0 then degree a + degree b else - 1))
val lemma_mul_degree (a b: poly) : Lemma (degree (a *. b) == (if degree a >= 0 && degree b >= 0 then degree a + degree b else - 1))
let lemma_mul_degree (a b:poly) : Lemma (degree (a *. b) == (if degree a >= 0 && degree b >= 0 then degree a + degree b else -1)) = if degree a >= 0 && degree b >= 0 then ( let len = length a + length b in lemma_sum_of_zero 0 len (mul_element_fun a b (len - 1)); lemma_sum_extend 0 (length a - 1) (length a) (len - 1) (mul_element_fun a b (len - 2)); assert (not (a *. b).[len - 1]); assert ((a *. b).[len - 2]); () ) else if degree a < 0 then ( assert (a =. zero); lemma_mul_zero b; lemma_mul_commute b zero; () ) else ( assert (b =. zero); lemma_mul_zero a; () )
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 334, "start_col": 0, "start_line": 310 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k) let lemma_mul_zero (a:poly) : Lemma ((a *. zero) =. zero) = let f (k:nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f let lemma_mul_one (a:poly) : Lemma ((a *. one) =. a) = let f (k:nat) : Lemma (mul_element a one k == a.[k]) = lemma_sum_of_zero 0 k (mul_element_fun a one k) in FStar.Classical.forall_intro f let lemma_mul_commute (a b:poly) : Lemma ((a *. b) =. (b *. a)) = let f (k:nat) : Lemma (mul_element a b k == mul_element b a k) = lemma_sum_reverse 0 (k + 1) (mul_element_fun a b k) (mul_element_fun b a k) in FStar.Classical.forall_intro f let lemma_mul_associate (a b c:poly) : Lemma (a *. (b *. c) =. (a *. b) *. c) = let f (k:nat) : Lemma (mul_element a (b *. c) k == mul_element (a *. b) c k) = let abc1 (i:int) (j:int) = a.[j] && b.[i - j] && c.[k - i] in let abc2 (j:int) (i:int) = a.[j] && b.[i - j] && c.[k - i] in let abc3 (j:int) (i:int) = a.[j] && b.[i] && c.[k - j - i] in let sum_abc1 (i:int) = sum_of_bools 0 (i + 1) (abc1 i) in let sum_abc2 (j:int) = sum_of_bools j (k + 1) (abc2 j) in let sum_abc3 (j:int) = sum_of_bools 0 (k + 1 - j) (abc3 j) in let l1 (i:int) : Lemma (mul_element_fun (a *. b) c k i == sum_abc1 i) = lemma_sum_mul 0 (i + 1) c.[k - i] (abc1 i) (mul_element_fun a b i) in let l2 (j:int) : Lemma (sum_abc2 j == sum_abc3 j) = lemma_sum_shift 0 (k + 1 - j) j (abc3 j) (abc2 j) in let l3 (j:int) : Lemma (mul_element_fun a (b *. c) k j == sum_abc3 j) = lemma_sum_mul 0 (k + 1 - j) a.[j] (abc3 j) (mul_element_fun b c (k - j)) in // mul_element (a *. b) c k // sum[0 <= i <= k] (a *. b)[i] * c[k - i] // sum[0 <= i <= k] (sum[0 <= j <= i] a[j] * b[i - j]) * c[k - i]) lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun (a *. b) c k) sum_abc1 l1; // sum[0 <= i <= k] sum[0 <= j <= i] a[j] * b[i - j] * c[k - i] lemma_sum_swap_mul_associate (k + 1) abc1 abc2 sum_abc1 sum_abc2; // sum[0 <= j <= k] sum[j <= i <= k] a[j] * b[i - j] * c[k - i] lemma_sum_pointwise_equal 0 (k + 1) sum_abc2 sum_abc3 l2; // sum[0 <= j <= k] sum[0 <= i <= k - j] a[j] * b[i] * c[k - j - i] lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun a (b *. c) k) sum_abc3 l3; // sum[0 <= j <= k] a[j] * (sum[0 <= i <= k - j] b[i] * c[k - j - i]) // sum[0 <= j <= k] (a[j] * (b *. c)[k - j]) // mul_element a (b *. c) k () in FStar.Classical.forall_intro f let lemma_mul_distribute (a b c:poly) : Lemma (a *. (b +. c) =. (a *. b) +. (a *. c)) = let f (k:nat) : Lemma (ensures mul_element a (b +. c) k == (mul_element a b k <> mul_element a c k)) = lemma_sum_of_pairs 0 (k + 1) (mul_element_fun a (b +. c) k) (mul_element_fun a b k) (mul_element_fun a c k) in FStar.Classical.forall_intro f let lemma_mul_distribute_left (a b c:poly) : Lemma ((a +. b) *. c =. (a *. c) +. (b *. c)) = lemma_mul_commute (a +. b) c; lemma_mul_commute a c; lemma_mul_commute b c; lemma_mul_distribute c a b let lemma_shift_is_mul (a:poly) (n:nat) : Lemma (shift a n =. a *. (monomial n)) = let an = shift a n in let b = monomial n in let lem (k:nat) : Lemma (an.[k] == mul_element a b k) = if k < n then lemma_sum_of_zero 0 k (mul_element_fun a b k) else lemma_sum_extend 0 (k - n) (k - n + 1) (k + 1) (mul_element_fun a b k) in FStar.Classical.forall_intro lem
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Defs_s.degree (a *. b) == (match Vale.Math.Poly2.Defs_s.degree a >= 0 && Vale.Math.Poly2.Defs_s.degree b >= 0 with | true -> Vale.Math.Poly2.Defs_s.degree a + Vale.Math.Poly2.Defs_s.degree b | _ -> - 1))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "Prims.op_AmpAmp", "Prims.op_GreaterThanOrEqual", "Vale.Math.Poly2.Defs_s.degree", "Prims.unit", "Prims._assert", "Prims.b2t", "Vale.Math.Poly2.Defs_s.op_String_Access", "Vale.Math.Poly2.Defs.op_Star_Dot", "Prims.op_Subtraction", "Prims.op_Negation", "Vale.Math.Poly2.Defs.lemma_sum_extend", "FStar.Seq.Base.length", "Prims.bool", "Vale.Math.Poly2.Defs_s.mul_element_fun", "Vale.Math.Poly2.Defs.lemma_sum_of_zero", "Prims.int", "Prims.op_Addition", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.lemma_mul_commute", "Vale.Math.Poly2.Defs_s.zero", "Vale.Math.Poly2.Defs.lemma_mul_zero", "Vale.Math.Poly2.Defs.op_Equals_Dot", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.op_Minus", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_mul_degree (a b: poly) : Lemma (degree (a *. b) == (if degree a >= 0 && degree b >= 0 then degree a + degree b else - 1)) =
if degree a >= 0 && degree b >= 0 then (let len = length a + length b in lemma_sum_of_zero 0 len (mul_element_fun a b (len - 1)); lemma_sum_extend 0 (length a - 1) (length a) (len - 1) (mul_element_fun a b (len - 2)); assert (not (a *. b).[ len - 1 ]); assert ((a *. b).[ len - 2 ]); ()) else if degree a < 0 then (assert (a =. zero); lemma_mul_zero b; lemma_mul_commute b zero; ()) else (assert (b =. zero); lemma_mul_zero a; ())
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_mul_associate
val lemma_mul_associate (a b c: poly) : Lemma (a *. (b *. c) =. (a *. b) *. c)
val lemma_mul_associate (a b c: poly) : Lemma (a *. (b *. c) =. (a *. b) *. c)
let lemma_mul_associate (a b c:poly) : Lemma (a *. (b *. c) =. (a *. b) *. c) = let f (k:nat) : Lemma (mul_element a (b *. c) k == mul_element (a *. b) c k) = let abc1 (i:int) (j:int) = a.[j] && b.[i - j] && c.[k - i] in let abc2 (j:int) (i:int) = a.[j] && b.[i - j] && c.[k - i] in let abc3 (j:int) (i:int) = a.[j] && b.[i] && c.[k - j - i] in let sum_abc1 (i:int) = sum_of_bools 0 (i + 1) (abc1 i) in let sum_abc2 (j:int) = sum_of_bools j (k + 1) (abc2 j) in let sum_abc3 (j:int) = sum_of_bools 0 (k + 1 - j) (abc3 j) in let l1 (i:int) : Lemma (mul_element_fun (a *. b) c k i == sum_abc1 i) = lemma_sum_mul 0 (i + 1) c.[k - i] (abc1 i) (mul_element_fun a b i) in let l2 (j:int) : Lemma (sum_abc2 j == sum_abc3 j) = lemma_sum_shift 0 (k + 1 - j) j (abc3 j) (abc2 j) in let l3 (j:int) : Lemma (mul_element_fun a (b *. c) k j == sum_abc3 j) = lemma_sum_mul 0 (k + 1 - j) a.[j] (abc3 j) (mul_element_fun b c (k - j)) in // mul_element (a *. b) c k // sum[0 <= i <= k] (a *. b)[i] * c[k - i] // sum[0 <= i <= k] (sum[0 <= j <= i] a[j] * b[i - j]) * c[k - i]) lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun (a *. b) c k) sum_abc1 l1; // sum[0 <= i <= k] sum[0 <= j <= i] a[j] * b[i - j] * c[k - i] lemma_sum_swap_mul_associate (k + 1) abc1 abc2 sum_abc1 sum_abc2; // sum[0 <= j <= k] sum[j <= i <= k] a[j] * b[i - j] * c[k - i] lemma_sum_pointwise_equal 0 (k + 1) sum_abc2 sum_abc3 l2; // sum[0 <= j <= k] sum[0 <= i <= k - j] a[j] * b[i] * c[k - j - i] lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun a (b *. c) k) sum_abc3 l3; // sum[0 <= j <= k] a[j] * (sum[0 <= i <= k - j] b[i] * c[k - j - i]) // sum[0 <= j <= k] (a[j] * (b *. c)[k - j]) // mul_element a (b *. c) k () in FStar.Classical.forall_intro f
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 280, "start_col": 0, "start_line": 248 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k) let lemma_mul_zero (a:poly) : Lemma ((a *. zero) =. zero) = let f (k:nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f let lemma_mul_one (a:poly) : Lemma ((a *. one) =. a) = let f (k:nat) : Lemma (mul_element a one k == a.[k]) = lemma_sum_of_zero 0 k (mul_element_fun a one k) in FStar.Classical.forall_intro f let lemma_mul_commute (a b:poly) : Lemma ((a *. b) =. (b *. a)) = let f (k:nat) : Lemma (mul_element a b k == mul_element b a k) = lemma_sum_reverse 0 (k + 1) (mul_element_fun a b k) (mul_element_fun b a k) in FStar.Classical.forall_intro f
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> c: Vale.Math.Poly2.Defs_s.poly -> FStar.Pervasives.Lemma (ensures a *. (b *. c) =. a *. b *. c)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "FStar.Classical.forall_intro", "Prims.nat", "Prims.eq2", "Prims.bool", "Vale.Math.Poly2.Defs_s.mul_element", "Vale.Math.Poly2.Defs.op_Star_Dot", "Prims.unit", "Prims.l_True", "Prims.squash", "Vale.Math.Poly2.Defs_s.mul", "Prims.Nil", "FStar.Pervasives.pattern", "Vale.Math.Poly2.Defs.lemma_sum_pointwise_equal", "Prims.op_Addition", "Vale.Math.Poly2.Defs_s.mul_element_fun", "Vale.Math.Poly2.Defs.lemma_sum_swap_mul_associate", "Prims.int", "Vale.Math.Poly2.Defs.lemma_sum_mul", "Prims.op_Subtraction", "Vale.Math.Poly2.Defs_s.op_String_Access", "Vale.Math.Poly2.Defs.lemma_sum_shift", "Vale.Math.Poly2.Defs_s.sum_of_bools", "Prims.op_AmpAmp", "Vale.Math.Poly2.Defs.op_Equals_Dot" ]
[]
false
false
true
false
false
let lemma_mul_associate (a b c: poly) : Lemma (a *. (b *. c) =. (a *. b) *. c) =
let f (k: nat) : Lemma (mul_element a (b *. c) k == mul_element (a *. b) c k) = let abc1 (i j: int) = a.[ j ] && b.[ i - j ] && c.[ k - i ] in let abc2 (j i: int) = a.[ j ] && b.[ i - j ] && c.[ k - i ] in let abc3 (j i: int) = a.[ j ] && b.[ i ] && c.[ k - j - i ] in let sum_abc1 (i: int) = sum_of_bools 0 (i + 1) (abc1 i) in let sum_abc2 (j: int) = sum_of_bools j (k + 1) (abc2 j) in let sum_abc3 (j: int) = sum_of_bools 0 (k + 1 - j) (abc3 j) in let l1 (i: int) : Lemma (mul_element_fun (a *. b) c k i == sum_abc1 i) = lemma_sum_mul 0 (i + 1) c.[ k - i ] (abc1 i) (mul_element_fun a b i) in let l2 (j: int) : Lemma (sum_abc2 j == sum_abc3 j) = lemma_sum_shift 0 (k + 1 - j) j (abc3 j) (abc2 j) in let l3 (j: int) : Lemma (mul_element_fun a (b *. c) k j == sum_abc3 j) = lemma_sum_mul 0 (k + 1 - j) a.[ j ] (abc3 j) (mul_element_fun b c (k - j)) in lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun (a *. b) c k) sum_abc1 l1; lemma_sum_swap_mul_associate (k + 1) abc1 abc2 sum_abc1 sum_abc2; lemma_sum_pointwise_equal 0 (k + 1) sum_abc2 sum_abc3 l2; lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun a (b *. c) k) sum_abc3 l3; () in FStar.Classical.forall_intro f
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_sum_swap
val lemma_sum_swap (j k: int) (ff gg: (int -> int -> bool)) (f g: (int -> bool)) : Lemma (requires (forall (x: int). {:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y: int). {:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x: int) (y: int). {:pattern (ff x y)} ff x y == gg y x)) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j))
val lemma_sum_swap (j k: int) (ff gg: (int -> int -> bool)) (f g: (int -> bool)) : Lemma (requires (forall (x: int). {:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y: int). {:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x: int) (y: int). {:pattern (ff x y)} ff x y == gg y x)) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j))
let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g )
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 158, "start_col": 0, "start_line": 132 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
j: Prims.int -> k: Prims.int -> ff: (_: Prims.int -> _: Prims.int -> Prims.bool) -> gg: (_: Prims.int -> _: Prims.int -> Prims.bool) -> f: (_: Prims.int -> Prims.bool) -> g: (_: Prims.int -> Prims.bool) -> FStar.Pervasives.Lemma (requires (forall (x: Prims.int). {:pattern f x} j <= x /\ x < k ==> f x == Vale.Math.Poly2.Defs_s.sum_of_bools j (j + k - x) (ff x)) /\ (forall (y: Prims.int). {:pattern g y} j <= y /\ y < k ==> g y == Vale.Math.Poly2.Defs_s.sum_of_bools j (j + k - y) (gg y)) /\ (forall (x: Prims.int) (y: Prims.int). {:pattern ff x y} ff x y == gg y x)) (ensures Vale.Math.Poly2.Defs_s.sum_of_bools j k f == Vale.Math.Poly2.Defs_s.sum_of_bools j k g) (decreases k - j)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.int", "Prims.bool", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.lemma_sum_of_pairs", "Prims.unit", "Vale.Math.Poly2.Defs.lemma_sum_swap", "Vale.Math.Poly2.Defs.lemma_sum_reverse", "Prims.op_Subtraction", "Prims.op_Addition", "Vale.Math.Poly2.Defs_s.sum_of_bools", "Prims.l_and", "Prims.l_Forall", "Prims.l_imp", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.eq2", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_sum_swap (j k: int) (ff gg: (int -> int -> bool)) (f g: (int -> bool)) : Lemma (requires (forall (x: int). {:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y: int). {:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x: int) (y: int). {:pattern (ff x y)} ff x y == gg y x)) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) =
if (j < k) then (let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; lemma_sum_swap j k1 ff gg f1 g1; lemma_sum_of_pairs j k1 f f1 f'; lemma_sum_of_pairs j k1 g g1 g')
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_mul_distribute_left
val lemma_mul_distribute_left (a b c: poly) : Lemma ((a +. b) *. c =. (a *. c) +. (b *. c))
val lemma_mul_distribute_left (a b c: poly) : Lemma ((a +. b) *. c =. (a *. c) +. (b *. c))
let lemma_mul_distribute_left (a b c:poly) : Lemma ((a +. b) *. c =. (a *. c) +. (b *. c)) = lemma_mul_commute (a +. b) c; lemma_mul_commute a c; lemma_mul_commute b c; lemma_mul_distribute c a b
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 28, "end_line": 297, "start_col": 0, "start_line": 293 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k) let lemma_mul_zero (a:poly) : Lemma ((a *. zero) =. zero) = let f (k:nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f let lemma_mul_one (a:poly) : Lemma ((a *. one) =. a) = let f (k:nat) : Lemma (mul_element a one k == a.[k]) = lemma_sum_of_zero 0 k (mul_element_fun a one k) in FStar.Classical.forall_intro f let lemma_mul_commute (a b:poly) : Lemma ((a *. b) =. (b *. a)) = let f (k:nat) : Lemma (mul_element a b k == mul_element b a k) = lemma_sum_reverse 0 (k + 1) (mul_element_fun a b k) (mul_element_fun b a k) in FStar.Classical.forall_intro f let lemma_mul_associate (a b c:poly) : Lemma (a *. (b *. c) =. (a *. b) *. c) = let f (k:nat) : Lemma (mul_element a (b *. c) k == mul_element (a *. b) c k) = let abc1 (i:int) (j:int) = a.[j] && b.[i - j] && c.[k - i] in let abc2 (j:int) (i:int) = a.[j] && b.[i - j] && c.[k - i] in let abc3 (j:int) (i:int) = a.[j] && b.[i] && c.[k - j - i] in let sum_abc1 (i:int) = sum_of_bools 0 (i + 1) (abc1 i) in let sum_abc2 (j:int) = sum_of_bools j (k + 1) (abc2 j) in let sum_abc3 (j:int) = sum_of_bools 0 (k + 1 - j) (abc3 j) in let l1 (i:int) : Lemma (mul_element_fun (a *. b) c k i == sum_abc1 i) = lemma_sum_mul 0 (i + 1) c.[k - i] (abc1 i) (mul_element_fun a b i) in let l2 (j:int) : Lemma (sum_abc2 j == sum_abc3 j) = lemma_sum_shift 0 (k + 1 - j) j (abc3 j) (abc2 j) in let l3 (j:int) : Lemma (mul_element_fun a (b *. c) k j == sum_abc3 j) = lemma_sum_mul 0 (k + 1 - j) a.[j] (abc3 j) (mul_element_fun b c (k - j)) in // mul_element (a *. b) c k // sum[0 <= i <= k] (a *. b)[i] * c[k - i] // sum[0 <= i <= k] (sum[0 <= j <= i] a[j] * b[i - j]) * c[k - i]) lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun (a *. b) c k) sum_abc1 l1; // sum[0 <= i <= k] sum[0 <= j <= i] a[j] * b[i - j] * c[k - i] lemma_sum_swap_mul_associate (k + 1) abc1 abc2 sum_abc1 sum_abc2; // sum[0 <= j <= k] sum[j <= i <= k] a[j] * b[i - j] * c[k - i] lemma_sum_pointwise_equal 0 (k + 1) sum_abc2 sum_abc3 l2; // sum[0 <= j <= k] sum[0 <= i <= k - j] a[j] * b[i] * c[k - j - i] lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun a (b *. c) k) sum_abc3 l3; // sum[0 <= j <= k] a[j] * (sum[0 <= i <= k - j] b[i] * c[k - j - i]) // sum[0 <= j <= k] (a[j] * (b *. c)[k - j]) // mul_element a (b *. c) k () in FStar.Classical.forall_intro f let lemma_mul_distribute (a b c:poly) : Lemma (a *. (b +. c) =. (a *. b) +. (a *. c)) = let f (k:nat) : Lemma (ensures mul_element a (b +. c) k == (mul_element a b k <> mul_element a c k)) = lemma_sum_of_pairs 0 (k + 1) (mul_element_fun a (b +. c) k) (mul_element_fun a b k) (mul_element_fun a c k) in FStar.Classical.forall_intro f
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> c: Vale.Math.Poly2.Defs_s.poly -> FStar.Pervasives.Lemma (ensures (a +. b) *. c =. a *. c +. b *. c)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "Vale.Math.Poly2.Defs.lemma_mul_distribute", "Prims.unit", "Vale.Math.Poly2.Defs.lemma_mul_commute", "Vale.Math.Poly2.Defs.op_Plus_Dot", "Prims.l_True", "Prims.squash", "Vale.Math.Poly2.Defs.op_Equals_Dot", "Vale.Math.Poly2.Defs.op_Star_Dot", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_mul_distribute_left (a b c: poly) : Lemma ((a +. b) *. c =. (a *. c) +. (b *. c)) =
lemma_mul_commute (a +. b) c; lemma_mul_commute a c; lemma_mul_commute b c; lemma_mul_distribute c a b
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_mod_degree
val lemma_mod_degree (a b: poly) : Lemma (requires length b > 0) (ensures degree (a %. b) < degree b) (decreases (length a))
val lemma_mod_degree (a b: poly) : Lemma (requires length b > 0) (ensures degree (a %. b) < degree b) (decreases (length a))
let rec lemma_mod_degree (a b:poly) : Lemma (requires length b > 0) (ensures degree (a %. b) < degree b) (decreases (length a)) = if length a >= length b then ( let _ = assert (a.[length a - 1]) in let n = length a - length b in let a' = add a (shift b n) in lemma_mod_degree a' b )
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 431, "start_col": 0, "start_line": 420 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k) let lemma_mul_zero (a:poly) : Lemma ((a *. zero) =. zero) = let f (k:nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f let lemma_mul_one (a:poly) : Lemma ((a *. one) =. a) = let f (k:nat) : Lemma (mul_element a one k == a.[k]) = lemma_sum_of_zero 0 k (mul_element_fun a one k) in FStar.Classical.forall_intro f let lemma_mul_commute (a b:poly) : Lemma ((a *. b) =. (b *. a)) = let f (k:nat) : Lemma (mul_element a b k == mul_element b a k) = lemma_sum_reverse 0 (k + 1) (mul_element_fun a b k) (mul_element_fun b a k) in FStar.Classical.forall_intro f let lemma_mul_associate (a b c:poly) : Lemma (a *. (b *. c) =. (a *. b) *. c) = let f (k:nat) : Lemma (mul_element a (b *. c) k == mul_element (a *. b) c k) = let abc1 (i:int) (j:int) = a.[j] && b.[i - j] && c.[k - i] in let abc2 (j:int) (i:int) = a.[j] && b.[i - j] && c.[k - i] in let abc3 (j:int) (i:int) = a.[j] && b.[i] && c.[k - j - i] in let sum_abc1 (i:int) = sum_of_bools 0 (i + 1) (abc1 i) in let sum_abc2 (j:int) = sum_of_bools j (k + 1) (abc2 j) in let sum_abc3 (j:int) = sum_of_bools 0 (k + 1 - j) (abc3 j) in let l1 (i:int) : Lemma (mul_element_fun (a *. b) c k i == sum_abc1 i) = lemma_sum_mul 0 (i + 1) c.[k - i] (abc1 i) (mul_element_fun a b i) in let l2 (j:int) : Lemma (sum_abc2 j == sum_abc3 j) = lemma_sum_shift 0 (k + 1 - j) j (abc3 j) (abc2 j) in let l3 (j:int) : Lemma (mul_element_fun a (b *. c) k j == sum_abc3 j) = lemma_sum_mul 0 (k + 1 - j) a.[j] (abc3 j) (mul_element_fun b c (k - j)) in // mul_element (a *. b) c k // sum[0 <= i <= k] (a *. b)[i] * c[k - i] // sum[0 <= i <= k] (sum[0 <= j <= i] a[j] * b[i - j]) * c[k - i]) lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun (a *. b) c k) sum_abc1 l1; // sum[0 <= i <= k] sum[0 <= j <= i] a[j] * b[i - j] * c[k - i] lemma_sum_swap_mul_associate (k + 1) abc1 abc2 sum_abc1 sum_abc2; // sum[0 <= j <= k] sum[j <= i <= k] a[j] * b[i - j] * c[k - i] lemma_sum_pointwise_equal 0 (k + 1) sum_abc2 sum_abc3 l2; // sum[0 <= j <= k] sum[0 <= i <= k - j] a[j] * b[i] * c[k - j - i] lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun a (b *. c) k) sum_abc3 l3; // sum[0 <= j <= k] a[j] * (sum[0 <= i <= k - j] b[i] * c[k - j - i]) // sum[0 <= j <= k] (a[j] * (b *. c)[k - j]) // mul_element a (b *. c) k () in FStar.Classical.forall_intro f let lemma_mul_distribute (a b c:poly) : Lemma (a *. (b +. c) =. (a *. b) +. (a *. c)) = let f (k:nat) : Lemma (ensures mul_element a (b +. c) k == (mul_element a b k <> mul_element a c k)) = lemma_sum_of_pairs 0 (k + 1) (mul_element_fun a (b +. c) k) (mul_element_fun a b k) (mul_element_fun a c k) in FStar.Classical.forall_intro f let lemma_mul_distribute_left (a b c:poly) : Lemma ((a +. b) *. c =. (a *. c) +. (b *. c)) = lemma_mul_commute (a +. b) c; lemma_mul_commute a c; lemma_mul_commute b c; lemma_mul_distribute c a b let lemma_shift_is_mul (a:poly) (n:nat) : Lemma (shift a n =. a *. (monomial n)) = let an = shift a n in let b = monomial n in let lem (k:nat) : Lemma (an.[k] == mul_element a b k) = if k < n then lemma_sum_of_zero 0 k (mul_element_fun a b k) else lemma_sum_extend 0 (k - n) (k - n + 1) (k + 1) (mul_element_fun a b k) in FStar.Classical.forall_intro lem let lemma_mul_degree (a b:poly) : Lemma (degree (a *. b) == (if degree a >= 0 && degree b >= 0 then degree a + degree b else -1)) = if degree a >= 0 && degree b >= 0 then ( let len = length a + length b in lemma_sum_of_zero 0 len (mul_element_fun a b (len - 1)); lemma_sum_extend 0 (length a - 1) (length a) (len - 1) (mul_element_fun a b (len - 2)); assert (not (a *. b).[len - 1]); assert ((a *. b).[len - 2]); () ) else if degree a < 0 then ( assert (a =. zero); lemma_mul_zero b; lemma_mul_commute b zero; () ) else ( assert (b =. zero); lemma_mul_zero a; () ) let lemma_mul_reverse (a b:poly) (n:nat) : Lemma (requires degree a <= n /\ degree b <= n) (ensures reverse (a *. b) (n + n) =. reverse a n *. reverse b n) = let ab = a *. b in let rab = reverse ab (n + n) in let ra = reverse a n in let rb = reverse b n in lemma_mul_degree a b; lemma_mul_degree ra rb; let f (k:int) : Lemma (rab.[k] == (ra *. rb).[k]) = if 0 <= k && k <= n + n then ( let f0 = mul_element_fun ra rb k in let f1 (i:int) : bool = a.[n + i] && b.[n - k - i] in let f2 = mul_element_fun a b (n + n - k) in // mul_element a b (n + n - k) == sum_of_bools 0 (n + n + 1 - k) f2 // mul_element ra rb k == sum_of_bools 0 (k + 1) f0 lemma_sum_invert 0 (k + 1) f0 f1; // mul_element ra rb k == sum_of_bools (-k) 1 f1 lemma_sum_shift (-k) 1 n f1 f2; // mul_element ra rb k == sum_of_bools (n - k) (n + 1) f2 let lo = min (n - k) 0 in let hi = max (n + 1) (n + n + 1 - k) in lemma_sum_extend lo 0 (n + n + 1 - k) hi f2; lemma_sum_extend lo (n - k) (n + 1) hi f2; () ) in lemma_pointwise_equal rab (ra *. rb) f // DIVISION, MOD let rec lemma_div_mod (a b:poly) : Lemma (requires length b > 0) (ensures a =. (a /. b) *. b +. (a %. b)) (decreases (length a)) = if length a < length b then ( lemma_mul_zero b; lemma_mul_commute b zero; () ) else ( let _ = assert (a.[length a - 1]) in let n = length a - length b in let a' = a +. (shift b n) in let xn = monomial n in lemma_shift_is_mul b n; lemma_mul_commute b xn; // a' == a +. xn *. b // (a /. b == a' /. b +. xn); lemma_add_move (a' /. b) xn; // (a' /. b == a /. b +. xn); lemma_div_mod a' b; // a' == (a' /. b) *. b +. (a' %. b) // a +. xn * b == (a /. b + xn) *. b +. (a %. b)) lemma_mul_distribute_left (a /. b) xn b; // a +. xn *. b == (a /. b) *. b +. xn *. b +. (a %. b) // a == (a /. b) *. b +. (a %. b) () ) let rec lemma_div_degree (a b:poly) : Lemma (requires length b > 0) (ensures degree (a /. b) == (if degree a < degree b then -1 else degree a - degree b)) (decreases (length a)) = if length a >= length b then ( let _ = assert (a.[length a - 1]) in let n = length a - length b in let a' = add a (shift b n) in lemma_div_degree a' b; assert ((a /. b).[degree a - degree b]); () )
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b > 0) (ensures Vale.Math.Poly2.Defs_s.degree (a %. b) < Vale.Math.Poly2.Defs_s.degree b) (decreases FStar.Seq.Base.length a)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "Prims.op_GreaterThanOrEqual", "FStar.Seq.Base.length", "Prims.bool", "Vale.Math.Poly2.Defs.lemma_mod_degree", "Vale.Math.Poly2.Defs_s.add", "Vale.Math.Poly2.Defs_s.shift", "Prims.int", "Prims.op_Subtraction", "Prims.unit", "Prims._assert", "Prims.b2t", "Vale.Math.Poly2.Defs_s.op_String_Access", "Prims.op_GreaterThan", "Prims.squash", "Prims.op_LessThan", "Vale.Math.Poly2.Defs_s.degree", "Vale.Math.Poly2.Defs.op_Percent_Dot", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_mod_degree (a b: poly) : Lemma (requires length b > 0) (ensures degree (a %. b) < degree b) (decreases (length a)) =
if length a >= length b then (let _ = assert (a.[ length a - 1 ]) in let n = length a - length b in let a' = add a (shift b n) in lemma_mod_degree a' b)
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_shift_is_mul
val lemma_shift_is_mul (a: poly) (n: nat) : Lemma (shift a n =. a *. (monomial n))
val lemma_shift_is_mul (a: poly) (n: nat) : Lemma (shift a n =. a *. (monomial n))
let lemma_shift_is_mul (a:poly) (n:nat) : Lemma (shift a n =. a *. (monomial n)) = let an = shift a n in let b = monomial n in let lem (k:nat) : Lemma (an.[k] == mul_element a b k) = if k < n then lemma_sum_of_zero 0 k (mul_element_fun a b k) else lemma_sum_extend 0 (k - n) (k - n + 1) (k + 1) (mul_element_fun a b k) in FStar.Classical.forall_intro lem
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 308, "start_col": 0, "start_line": 299 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k) let lemma_mul_zero (a:poly) : Lemma ((a *. zero) =. zero) = let f (k:nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f let lemma_mul_one (a:poly) : Lemma ((a *. one) =. a) = let f (k:nat) : Lemma (mul_element a one k == a.[k]) = lemma_sum_of_zero 0 k (mul_element_fun a one k) in FStar.Classical.forall_intro f let lemma_mul_commute (a b:poly) : Lemma ((a *. b) =. (b *. a)) = let f (k:nat) : Lemma (mul_element a b k == mul_element b a k) = lemma_sum_reverse 0 (k + 1) (mul_element_fun a b k) (mul_element_fun b a k) in FStar.Classical.forall_intro f let lemma_mul_associate (a b c:poly) : Lemma (a *. (b *. c) =. (a *. b) *. c) = let f (k:nat) : Lemma (mul_element a (b *. c) k == mul_element (a *. b) c k) = let abc1 (i:int) (j:int) = a.[j] && b.[i - j] && c.[k - i] in let abc2 (j:int) (i:int) = a.[j] && b.[i - j] && c.[k - i] in let abc3 (j:int) (i:int) = a.[j] && b.[i] && c.[k - j - i] in let sum_abc1 (i:int) = sum_of_bools 0 (i + 1) (abc1 i) in let sum_abc2 (j:int) = sum_of_bools j (k + 1) (abc2 j) in let sum_abc3 (j:int) = sum_of_bools 0 (k + 1 - j) (abc3 j) in let l1 (i:int) : Lemma (mul_element_fun (a *. b) c k i == sum_abc1 i) = lemma_sum_mul 0 (i + 1) c.[k - i] (abc1 i) (mul_element_fun a b i) in let l2 (j:int) : Lemma (sum_abc2 j == sum_abc3 j) = lemma_sum_shift 0 (k + 1 - j) j (abc3 j) (abc2 j) in let l3 (j:int) : Lemma (mul_element_fun a (b *. c) k j == sum_abc3 j) = lemma_sum_mul 0 (k + 1 - j) a.[j] (abc3 j) (mul_element_fun b c (k - j)) in // mul_element (a *. b) c k // sum[0 <= i <= k] (a *. b)[i] * c[k - i] // sum[0 <= i <= k] (sum[0 <= j <= i] a[j] * b[i - j]) * c[k - i]) lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun (a *. b) c k) sum_abc1 l1; // sum[0 <= i <= k] sum[0 <= j <= i] a[j] * b[i - j] * c[k - i] lemma_sum_swap_mul_associate (k + 1) abc1 abc2 sum_abc1 sum_abc2; // sum[0 <= j <= k] sum[j <= i <= k] a[j] * b[i - j] * c[k - i] lemma_sum_pointwise_equal 0 (k + 1) sum_abc2 sum_abc3 l2; // sum[0 <= j <= k] sum[0 <= i <= k - j] a[j] * b[i] * c[k - j - i] lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun a (b *. c) k) sum_abc3 l3; // sum[0 <= j <= k] a[j] * (sum[0 <= i <= k - j] b[i] * c[k - j - i]) // sum[0 <= j <= k] (a[j] * (b *. c)[k - j]) // mul_element a (b *. c) k () in FStar.Classical.forall_intro f let lemma_mul_distribute (a b c:poly) : Lemma (a *. (b +. c) =. (a *. b) +. (a *. c)) = let f (k:nat) : Lemma (ensures mul_element a (b +. c) k == (mul_element a b k <> mul_element a c k)) = lemma_sum_of_pairs 0 (k + 1) (mul_element_fun a (b +. c) k) (mul_element_fun a b k) (mul_element_fun a c k) in FStar.Classical.forall_intro f let lemma_mul_distribute_left (a b c:poly) : Lemma ((a +. b) *. c =. (a *. c) +. (b *. c)) = lemma_mul_commute (a +. b) c; lemma_mul_commute a c; lemma_mul_commute b c; lemma_mul_distribute c a b
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> n: Prims.nat -> FStar.Pervasives.Lemma (ensures Vale.Math.Poly2.Defs_s.shift a n =. a *. Vale.Math.Poly2.Defs_s.monomial n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "Prims.nat", "FStar.Classical.forall_intro", "Prims.eq2", "Prims.bool", "Vale.Math.Poly2.Defs_s.op_String_Access", "Vale.Math.Poly2.Defs_s.mul_element", "Prims.unit", "Prims.l_True", "Prims.squash", "Vale.Math.Poly2.Defs_s.poly_index", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.lemma_sum_of_zero", "Vale.Math.Poly2.Defs_s.mul_element_fun", "Vale.Math.Poly2.Defs.lemma_sum_extend", "Prims.op_Subtraction", "Prims.op_Addition", "Vale.Math.Poly2.Defs_s.monomial", "Vale.Math.Poly2.Defs_s.shift", "Vale.Math.Poly2.Defs.op_Equals_Dot", "Vale.Math.Poly2.Defs.op_Star_Dot" ]
[]
false
false
true
false
false
let lemma_shift_is_mul (a: poly) (n: nat) : Lemma (shift a n =. a *. (monomial n)) =
let an = shift a n in let b = monomial n in let lem (k: nat) : Lemma (an.[ k ] == mul_element a b k) = if k < n then lemma_sum_of_zero 0 k (mul_element_fun a b k) else lemma_sum_extend 0 (k - n) (k - n + 1) (k + 1) (mul_element_fun a b k) in FStar.Classical.forall_intro lem
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_div_mod
val lemma_div_mod (a b: poly) : Lemma (requires length b > 0) (ensures a =. (a /. b) *. b +. (a %. b)) (decreases (length a))
val lemma_div_mod (a b: poly) : Lemma (requires length b > 0) (ensures a =. (a /. b) *. b +. (a %. b)) (decreases (length a))
let rec lemma_div_mod (a b:poly) : Lemma (requires length b > 0) (ensures a =. (a /. b) *. b +. (a %. b)) (decreases (length a)) = if length a < length b then ( lemma_mul_zero b; lemma_mul_commute b zero; () ) else ( let _ = assert (a.[length a - 1]) in let n = length a - length b in let a' = a +. (shift b n) in let xn = monomial n in lemma_shift_is_mul b n; lemma_mul_commute b xn; // a' == a +. xn *. b // (a /. b == a' /. b +. xn); lemma_add_move (a' /. b) xn; // (a' /. b == a /. b +. xn); lemma_div_mod a' b; // a' == (a' /. b) *. b +. (a' %. b) // a +. xn * b == (a /. b + xn) *. b +. (a %. b)) lemma_mul_distribute_left (a /. b) xn b; // a +. xn *. b == (a /. b) *. b +. xn *. b +. (a %. b) // a == (a /. b) *. b +. (a %. b) () )
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 403, "start_col": 0, "start_line": 373 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k) let lemma_mul_zero (a:poly) : Lemma ((a *. zero) =. zero) = let f (k:nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f let lemma_mul_one (a:poly) : Lemma ((a *. one) =. a) = let f (k:nat) : Lemma (mul_element a one k == a.[k]) = lemma_sum_of_zero 0 k (mul_element_fun a one k) in FStar.Classical.forall_intro f let lemma_mul_commute (a b:poly) : Lemma ((a *. b) =. (b *. a)) = let f (k:nat) : Lemma (mul_element a b k == mul_element b a k) = lemma_sum_reverse 0 (k + 1) (mul_element_fun a b k) (mul_element_fun b a k) in FStar.Classical.forall_intro f let lemma_mul_associate (a b c:poly) : Lemma (a *. (b *. c) =. (a *. b) *. c) = let f (k:nat) : Lemma (mul_element a (b *. c) k == mul_element (a *. b) c k) = let abc1 (i:int) (j:int) = a.[j] && b.[i - j] && c.[k - i] in let abc2 (j:int) (i:int) = a.[j] && b.[i - j] && c.[k - i] in let abc3 (j:int) (i:int) = a.[j] && b.[i] && c.[k - j - i] in let sum_abc1 (i:int) = sum_of_bools 0 (i + 1) (abc1 i) in let sum_abc2 (j:int) = sum_of_bools j (k + 1) (abc2 j) in let sum_abc3 (j:int) = sum_of_bools 0 (k + 1 - j) (abc3 j) in let l1 (i:int) : Lemma (mul_element_fun (a *. b) c k i == sum_abc1 i) = lemma_sum_mul 0 (i + 1) c.[k - i] (abc1 i) (mul_element_fun a b i) in let l2 (j:int) : Lemma (sum_abc2 j == sum_abc3 j) = lemma_sum_shift 0 (k + 1 - j) j (abc3 j) (abc2 j) in let l3 (j:int) : Lemma (mul_element_fun a (b *. c) k j == sum_abc3 j) = lemma_sum_mul 0 (k + 1 - j) a.[j] (abc3 j) (mul_element_fun b c (k - j)) in // mul_element (a *. b) c k // sum[0 <= i <= k] (a *. b)[i] * c[k - i] // sum[0 <= i <= k] (sum[0 <= j <= i] a[j] * b[i - j]) * c[k - i]) lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun (a *. b) c k) sum_abc1 l1; // sum[0 <= i <= k] sum[0 <= j <= i] a[j] * b[i - j] * c[k - i] lemma_sum_swap_mul_associate (k + 1) abc1 abc2 sum_abc1 sum_abc2; // sum[0 <= j <= k] sum[j <= i <= k] a[j] * b[i - j] * c[k - i] lemma_sum_pointwise_equal 0 (k + 1) sum_abc2 sum_abc3 l2; // sum[0 <= j <= k] sum[0 <= i <= k - j] a[j] * b[i] * c[k - j - i] lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun a (b *. c) k) sum_abc3 l3; // sum[0 <= j <= k] a[j] * (sum[0 <= i <= k - j] b[i] * c[k - j - i]) // sum[0 <= j <= k] (a[j] * (b *. c)[k - j]) // mul_element a (b *. c) k () in FStar.Classical.forall_intro f let lemma_mul_distribute (a b c:poly) : Lemma (a *. (b +. c) =. (a *. b) +. (a *. c)) = let f (k:nat) : Lemma (ensures mul_element a (b +. c) k == (mul_element a b k <> mul_element a c k)) = lemma_sum_of_pairs 0 (k + 1) (mul_element_fun a (b +. c) k) (mul_element_fun a b k) (mul_element_fun a c k) in FStar.Classical.forall_intro f let lemma_mul_distribute_left (a b c:poly) : Lemma ((a +. b) *. c =. (a *. c) +. (b *. c)) = lemma_mul_commute (a +. b) c; lemma_mul_commute a c; lemma_mul_commute b c; lemma_mul_distribute c a b let lemma_shift_is_mul (a:poly) (n:nat) : Lemma (shift a n =. a *. (monomial n)) = let an = shift a n in let b = monomial n in let lem (k:nat) : Lemma (an.[k] == mul_element a b k) = if k < n then lemma_sum_of_zero 0 k (mul_element_fun a b k) else lemma_sum_extend 0 (k - n) (k - n + 1) (k + 1) (mul_element_fun a b k) in FStar.Classical.forall_intro lem let lemma_mul_degree (a b:poly) : Lemma (degree (a *. b) == (if degree a >= 0 && degree b >= 0 then degree a + degree b else -1)) = if degree a >= 0 && degree b >= 0 then ( let len = length a + length b in lemma_sum_of_zero 0 len (mul_element_fun a b (len - 1)); lemma_sum_extend 0 (length a - 1) (length a) (len - 1) (mul_element_fun a b (len - 2)); assert (not (a *. b).[len - 1]); assert ((a *. b).[len - 2]); () ) else if degree a < 0 then ( assert (a =. zero); lemma_mul_zero b; lemma_mul_commute b zero; () ) else ( assert (b =. zero); lemma_mul_zero a; () ) let lemma_mul_reverse (a b:poly) (n:nat) : Lemma (requires degree a <= n /\ degree b <= n) (ensures reverse (a *. b) (n + n) =. reverse a n *. reverse b n) = let ab = a *. b in let rab = reverse ab (n + n) in let ra = reverse a n in let rb = reverse b n in lemma_mul_degree a b; lemma_mul_degree ra rb; let f (k:int) : Lemma (rab.[k] == (ra *. rb).[k]) = if 0 <= k && k <= n + n then ( let f0 = mul_element_fun ra rb k in let f1 (i:int) : bool = a.[n + i] && b.[n - k - i] in let f2 = mul_element_fun a b (n + n - k) in // mul_element a b (n + n - k) == sum_of_bools 0 (n + n + 1 - k) f2 // mul_element ra rb k == sum_of_bools 0 (k + 1) f0 lemma_sum_invert 0 (k + 1) f0 f1; // mul_element ra rb k == sum_of_bools (-k) 1 f1 lemma_sum_shift (-k) 1 n f1 f2; // mul_element ra rb k == sum_of_bools (n - k) (n + 1) f2 let lo = min (n - k) 0 in let hi = max (n + 1) (n + n + 1 - k) in lemma_sum_extend lo 0 (n + n + 1 - k) hi f2; lemma_sum_extend lo (n - k) (n + 1) hi f2; () ) in lemma_pointwise_equal rab (ra *. rb) f // DIVISION, MOD
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.length b > 0) (ensures a =. a /. b *. b +. a %. b) (decreases FStar.Seq.Base.length a)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "Prims.op_LessThan", "FStar.Seq.Base.length", "Prims.bool", "Prims.unit", "Vale.Math.Poly2.Defs.lemma_mul_commute", "Vale.Math.Poly2.Defs_s.zero", "Vale.Math.Poly2.Defs.lemma_mul_zero", "Vale.Math.Poly2.Defs.lemma_mul_distribute_left", "Vale.Math.Poly2.Defs.op_Slash_Dot", "Vale.Math.Poly2.Defs.lemma_div_mod", "Vale.Math.Poly2.Defs.lemma_add_move", "Vale.Math.Poly2.Defs.lemma_shift_is_mul", "Vale.Math.Poly2.Defs_s.monomial", "Vale.Math.Poly2.Defs.op_Plus_Dot", "Vale.Math.Poly2.Defs_s.shift", "Prims.int", "Prims.op_Subtraction", "Prims._assert", "Prims.b2t", "Vale.Math.Poly2.Defs_s.op_String_Access", "Prims.op_GreaterThan", "Prims.squash", "Vale.Math.Poly2.Defs.op_Equals_Dot", "Vale.Math.Poly2.Defs.op_Star_Dot", "Vale.Math.Poly2.Defs.op_Percent_Dot", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_div_mod (a b: poly) : Lemma (requires length b > 0) (ensures a =. (a /. b) *. b +. (a %. b)) (decreases (length a)) =
if length a < length b then (lemma_mul_zero b; lemma_mul_commute b zero; ()) else (let _ = assert (a.[ length a - 1 ]) in let n = length a - length b in let a' = a +. (shift b n) in let xn = monomial n in lemma_shift_is_mul b n; lemma_mul_commute b xn; lemma_add_move (a' /. b) xn; lemma_div_mod a' b; lemma_mul_distribute_left (a /. b) xn b; ())
false
Vale.Math.Poly2.Defs.fst
Vale.Math.Poly2.Defs.lemma_mul_reverse
val lemma_mul_reverse (a b: poly) (n: nat) : Lemma (requires degree a <= n /\ degree b <= n) (ensures reverse (a *. b) (n + n) =. reverse a n *. reverse b n)
val lemma_mul_reverse (a b: poly) (n: nat) : Lemma (requires degree a <= n /\ degree b <= n) (ensures reverse (a *. b) (n + n) =. reverse a n *. reverse b n)
let lemma_mul_reverse (a b:poly) (n:nat) : Lemma (requires degree a <= n /\ degree b <= n) (ensures reverse (a *. b) (n + n) =. reverse a n *. reverse b n) = let ab = a *. b in let rab = reverse ab (n + n) in let ra = reverse a n in let rb = reverse b n in lemma_mul_degree a b; lemma_mul_degree ra rb; let f (k:int) : Lemma (rab.[k] == (ra *. rb).[k]) = if 0 <= k && k <= n + n then ( let f0 = mul_element_fun ra rb k in let f1 (i:int) : bool = a.[n + i] && b.[n - k - i] in let f2 = mul_element_fun a b (n + n - k) in // mul_element a b (n + n - k) == sum_of_bools 0 (n + n + 1 - k) f2 // mul_element ra rb k == sum_of_bools 0 (k + 1) f0 lemma_sum_invert 0 (k + 1) f0 f1; // mul_element ra rb k == sum_of_bools (-k) 1 f1 lemma_sum_shift (-k) 1 n f1 f2; // mul_element ra rb k == sum_of_bools (n - k) (n + 1) f2 let lo = min (n - k) 0 in let hi = max (n + 1) (n + n + 1 - k) in lemma_sum_extend lo 0 (n + n + 1 - k) hi f2; lemma_sum_extend lo (n - k) (n + 1) hi f2; () ) in lemma_pointwise_equal rab (ra *. rb) f
{ "file_name": "vale/code/lib/math/Vale.Math.Poly2.Defs.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 367, "start_col": 0, "start_line": 336 }
module Vale.Math.Poly2.Defs open FStar.Mul open Vale.Def.Prop_s open FStar.Seq open Vale.Math.Poly2.Defs_s unfold let max = FStar.Math.Lib.max #reset-options "--z3rlimit 10" let poly_equal (a b:poly) : prop0 = (forall (i:nat).{:pattern a.[i] \/ b.[i]} a.[i] == b.[i]) unfold let ( =. ) = poly_equal unfold let ( +. ) = add unfold let ( *. ) = mul unfold let ( /. ) = div unfold let ( %. ) = mod let lemma_poly_equal_elim (a b:poly) : Lemma (requires a =. b) (ensures a == b) (decreases (length a + length b)) [SMTPat (poly_equal a b)] = let len = max (length a) (length b) in assert (len > 0 ==> a.[len - 1] == b.[len - 1]); assert (length a == length b); assert (forall (i:nat).{:pattern (index a i) \/ (index b i)} a.[i] == b.[i]); assert (equal a b) let lemma_pointwise_equal (a b:poly) (pf:(i:int -> Lemma (a.[i] == b.[i]))) : Lemma (a == b) = FStar.Classical.forall_intro pf; lemma_poly_equal_elim a b // ADDITION let lemma_add_zero (a:poly) : Lemma ((a +. zero) =. a) = () let lemma_add_cancel (a:poly) : Lemma ((a +. a) =. zero) = () let lemma_add_cancel_eq (a b:poly) : Lemma (requires (a +. b) == zero) (ensures a =. b) = () let lemma_add_commute (a b:poly) : Lemma ((a +. b) =. (b +. a)) = () let lemma_add_associate (a b c:poly) : Lemma ((a +. (b +. c)) =. ((a +. b) +. c)) = () let lemma_add_move (a b:poly) : Lemma (ensures a == (a +. b) +. b) = lemma_add_associate a b b; lemma_add_cancel b; lemma_add_zero a // SUMMATION let lemma_sum_empty (j:int) (f:int -> bool) : Lemma (requires True) (ensures not (sum_of_bools j j f)) [SMTPat (sum_of_bools j j f)] = () let rec lemma_sum_of_zero (j k:int) (f:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> not (f i))) (ensures not (sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_of_zero j (k - 1) f let rec lemma_sum_join (i j k:int) (f:int -> bool) : Lemma (requires i <= j /\ j <= k) (ensures sum_of_bools i k f == (sum_of_bools i j f <> sum_of_bools j k f)) (decreases (k - j)) = if j < k then lemma_sum_join i j (k - 1) f let lemma_sum_extend (j' j k k':int) (f:int -> bool) : Lemma (requires j' <= j /\ j <= k /\ k <= k' /\ (forall (i:int).{:pattern (f i)} j' <= i /\ i < j ==> not (f i)) /\ (forall (i:int).{:pattern (f i)} k <= i /\ i < k' ==> not (f i)) ) (ensures sum_of_bools j' k' f == sum_of_bools j k f) = lemma_sum_of_zero j' j f; lemma_sum_of_zero k k' f; lemma_sum_join j' j k f; lemma_sum_join j' k k' f let rec lemma_sum_of_pairs (j k:int) (f g h:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (g i <> h i))) (ensures sum_of_bools j k f == (sum_of_bools j k g <> sum_of_bools j k h)) (decreases (k - j)) = if j < k then lemma_sum_of_pairs j (k - 1) f g h let rec lemma_sum_shift (j k:int) (shift:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (i + shift))) (ensures sum_of_bools j k f == sum_of_bools (j + shift) (k + shift) g) (decreases (k - j)) = if j < k then lemma_sum_shift j (k - 1) shift f g let rec lemma_sum_invert_rec (j m k:int) (f g:int -> bool) : Lemma (requires j <= m /\ m <= k /\ sum_of_bools j k f == (sum_of_bools j m f <> sum_of_bools (1 - k) (1 - m) g) /\ (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i)) ) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) (decreases (m - j)) = if j < m then lemma_sum_invert_rec j (m - 1) k f g let lemma_sum_invert (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (-i))) (ensures sum_of_bools j k f == sum_of_bools (1 - k) (1 - j) g) = if j < k then lemma_sum_invert_rec j k k f g let lemma_sum_reverse (j k:int) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == g (k + j - i - 1))) (ensures sum_of_bools j k f == sum_of_bools j k g) = let f' (i:int) = f (-i) in lemma_sum_invert j k f f'; lemma_sum_shift j k (1 - (k + j)) g f' let rec lemma_sum_mul (j k:int) (b:bool) (f g:int -> bool) : Lemma (requires (forall (i:int).{:pattern (f i)} j <= i /\ i < k ==> f i == (b && g i))) (ensures sum_of_bools j k f == (b && sum_of_bools j k g)) (decreases (k - j)) = if j < k then lemma_sum_mul j (k - 1) b f g let rec lemma_sum_swap (j k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires (forall (x:int).{:pattern (f x)} j <= x /\ x < k ==> f x == sum_of_bools j (j + k - x) (ff x)) /\ (forall (y:int).{:pattern (g y)} j <= y /\ y < k ==> g y == sum_of_bools j (j + k - y) (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y == gg y x) ) (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if (j < k) then ( let k1 = k - 1 in let f1 x = sum_of_bools j (j + k1 - x) (ff x) in let g1 y = sum_of_bools j (j + k1 - y) (gg y) in let f' x = ff x (j + k1 - x) in let g' y = gg y (j + k1 - y) in lemma_sum_reverse j k f' g'; // summing f' and g' gives same answer, computed in reverse order // sum_of_bools j k f' == sum_of_bools j k g' // sum_of_bools j k1 f' + ff k1 j == sum_of_bools j k1 g' + gg k1 j lemma_sum_swap j k1 ff gg f1 g1; // by induction: sum_of_bools j k1 f1 == sum_of_bools j k1 g1 // sum_of_bools j k1 f1 + (sum_of_bools j k1 f' + ff k1 j) == sum_of_bools j k1 g1 + (sum_of_bools j k1 g' + gg k1 j) // (sum_of_bools j k1 f1 + sum_of_bools j k1 f') + ff k1 j == (sum_of_bools j k1 g1 + sum_of_bools j k1 g') + gg k1 j lemma_sum_of_pairs j k1 f f1 f'; // sum_of_bools j k1 f1 + sum_of_bools j k1 f' == sum_of_bools j k1 f lemma_sum_of_pairs j k1 g g1 g' // sum_of_bools j k1 g1 + sum_of_bools j k1 g' == sum_of_bools j k1 g // sum_of_bools j k1 f + ff k1 j == sum_of_bools j k1 g + gg k1 j // sum_of_bools j k f == sum_of_bools j k g ) // Corollary for lemma_mul_associate let lemma_sum_swap_mul_associate (k:int) (ff gg:int -> int -> bool) (f g:int -> bool) : Lemma (requires k > 0 /\ (forall (x:nat).{:pattern (f x)} f x == sum_of_bools 0 (x + 1) (ff x)) /\ (forall (y:nat).{:pattern (g y)} g y == sum_of_bools y k (gg y)) /\ (forall (x y:int).{:pattern (ff x y)} ff x y ==> 0 <= x /\ x < k /\ 0 <= y /\ y <= x) /\ (forall (x y:int).{:pattern (ff x y) \/ (gg y x)} ff x y == gg y x) ) (ensures sum_of_bools 0 k f == sum_of_bools 0 k g) = // Example: k = 3, k' = 5, '#' shows non-zero elements of ff, '0'/'#' shows input to lemma_sum_swap: // 0 // 00 // /|\ 00# // | 0##0 // y ###00 // // x --> let k' = k + k - 1 in let lemma_f (x:nat) : Lemma (ensures (k <= x ==> not (f x)) /\ (x < k' ==> f x == sum_of_bools 0 (k' - x) (ff x)) ) = (if k <= x then lemma_sum_of_zero 0 (x + 1) (ff x)); lemma_sum_of_zero (if x < k then x + 1 else 0) (k' - x) (ff x); (if x < k then lemma_sum_join 0 (x + 1) (k' - x) (ff x)); () in let lemma_g (y:nat) : Lemma (ensures (k <= y ==> not (g y)) /\ (y < k' ==> g y == sum_of_bools 0 (k' - y) (gg y)) ) = (if k <= y then lemma_sum_of_zero 0 (y + 1) (gg y)); (if y < k then lemma_sum_of_zero 0 y (gg y)); lemma_sum_of_zero (if y < k then k else 0) (k' - y) (gg y); (if y < k then lemma_sum_extend 0 y k (k' - y) (gg y)); () in FStar.Classical.forall_intro lemma_f; FStar.Classical.forall_intro lemma_g; lemma_sum_swap 0 k' ff gg f g; lemma_sum_extend 0 0 k k' f; lemma_sum_extend 0 0 k k' g; () let rec lemma_sum_pointwise_equal (j k:int) (f g:int -> bool) (pf:(i:int -> Lemma (f i == g i))) : Lemma (ensures sum_of_bools j k f == sum_of_bools j k g) (decreases (k - j)) = if j < k then ( pf (k - 1); lemma_sum_pointwise_equal j (k - 1) f g pf ) // MULTIPLICATION let lemma_mul_element (a b:poly) (k:int) : Lemma (requires True) (ensures (a *. b).[k] == mul_element a b k) [SMTPat (a *. b).[k]] = if k >= length a + length b then lemma_sum_of_zero 0 (k + 1) (mul_element_fun a b k) let lemma_mul_zero (a:poly) : Lemma ((a *. zero) =. zero) = let f (k:nat) : Lemma (not (mul_element a zero k)) = lemma_sum_of_zero 0 (k + 1) (mul_element_fun a zero k) in FStar.Classical.forall_intro f let lemma_mul_one (a:poly) : Lemma ((a *. one) =. a) = let f (k:nat) : Lemma (mul_element a one k == a.[k]) = lemma_sum_of_zero 0 k (mul_element_fun a one k) in FStar.Classical.forall_intro f let lemma_mul_commute (a b:poly) : Lemma ((a *. b) =. (b *. a)) = let f (k:nat) : Lemma (mul_element a b k == mul_element b a k) = lemma_sum_reverse 0 (k + 1) (mul_element_fun a b k) (mul_element_fun b a k) in FStar.Classical.forall_intro f let lemma_mul_associate (a b c:poly) : Lemma (a *. (b *. c) =. (a *. b) *. c) = let f (k:nat) : Lemma (mul_element a (b *. c) k == mul_element (a *. b) c k) = let abc1 (i:int) (j:int) = a.[j] && b.[i - j] && c.[k - i] in let abc2 (j:int) (i:int) = a.[j] && b.[i - j] && c.[k - i] in let abc3 (j:int) (i:int) = a.[j] && b.[i] && c.[k - j - i] in let sum_abc1 (i:int) = sum_of_bools 0 (i + 1) (abc1 i) in let sum_abc2 (j:int) = sum_of_bools j (k + 1) (abc2 j) in let sum_abc3 (j:int) = sum_of_bools 0 (k + 1 - j) (abc3 j) in let l1 (i:int) : Lemma (mul_element_fun (a *. b) c k i == sum_abc1 i) = lemma_sum_mul 0 (i + 1) c.[k - i] (abc1 i) (mul_element_fun a b i) in let l2 (j:int) : Lemma (sum_abc2 j == sum_abc3 j) = lemma_sum_shift 0 (k + 1 - j) j (abc3 j) (abc2 j) in let l3 (j:int) : Lemma (mul_element_fun a (b *. c) k j == sum_abc3 j) = lemma_sum_mul 0 (k + 1 - j) a.[j] (abc3 j) (mul_element_fun b c (k - j)) in // mul_element (a *. b) c k // sum[0 <= i <= k] (a *. b)[i] * c[k - i] // sum[0 <= i <= k] (sum[0 <= j <= i] a[j] * b[i - j]) * c[k - i]) lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun (a *. b) c k) sum_abc1 l1; // sum[0 <= i <= k] sum[0 <= j <= i] a[j] * b[i - j] * c[k - i] lemma_sum_swap_mul_associate (k + 1) abc1 abc2 sum_abc1 sum_abc2; // sum[0 <= j <= k] sum[j <= i <= k] a[j] * b[i - j] * c[k - i] lemma_sum_pointwise_equal 0 (k + 1) sum_abc2 sum_abc3 l2; // sum[0 <= j <= k] sum[0 <= i <= k - j] a[j] * b[i] * c[k - j - i] lemma_sum_pointwise_equal 0 (k + 1) (mul_element_fun a (b *. c) k) sum_abc3 l3; // sum[0 <= j <= k] a[j] * (sum[0 <= i <= k - j] b[i] * c[k - j - i]) // sum[0 <= j <= k] (a[j] * (b *. c)[k - j]) // mul_element a (b *. c) k () in FStar.Classical.forall_intro f let lemma_mul_distribute (a b c:poly) : Lemma (a *. (b +. c) =. (a *. b) +. (a *. c)) = let f (k:nat) : Lemma (ensures mul_element a (b +. c) k == (mul_element a b k <> mul_element a c k)) = lemma_sum_of_pairs 0 (k + 1) (mul_element_fun a (b +. c) k) (mul_element_fun a b k) (mul_element_fun a c k) in FStar.Classical.forall_intro f let lemma_mul_distribute_left (a b c:poly) : Lemma ((a +. b) *. c =. (a *. c) +. (b *. c)) = lemma_mul_commute (a +. b) c; lemma_mul_commute a c; lemma_mul_commute b c; lemma_mul_distribute c a b let lemma_shift_is_mul (a:poly) (n:nat) : Lemma (shift a n =. a *. (monomial n)) = let an = shift a n in let b = monomial n in let lem (k:nat) : Lemma (an.[k] == mul_element a b k) = if k < n then lemma_sum_of_zero 0 k (mul_element_fun a b k) else lemma_sum_extend 0 (k - n) (k - n + 1) (k + 1) (mul_element_fun a b k) in FStar.Classical.forall_intro lem let lemma_mul_degree (a b:poly) : Lemma (degree (a *. b) == (if degree a >= 0 && degree b >= 0 then degree a + degree b else -1)) = if degree a >= 0 && degree b >= 0 then ( let len = length a + length b in lemma_sum_of_zero 0 len (mul_element_fun a b (len - 1)); lemma_sum_extend 0 (length a - 1) (length a) (len - 1) (mul_element_fun a b (len - 2)); assert (not (a *. b).[len - 1]); assert ((a *. b).[len - 2]); () ) else if degree a < 0 then ( assert (a =. zero); lemma_mul_zero b; lemma_mul_commute b zero; () ) else ( assert (b =. zero); lemma_mul_zero a; () )
{ "checked_file": "/", "dependencies": [ "Vale.Math.Poly2.Defs_s.fst.checked", "Vale.Def.Prop_s.fst.checked", "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lib.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "Vale.Math.Poly2.Defs.fst" }
[ { "abbrev": false, "full_module": "Vale.Math.Poly2.Defs_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Prop_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "Vale.Math.Poly2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 10, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Vale.Math.Poly2.Defs_s.poly -> b: Vale.Math.Poly2.Defs_s.poly -> n: Prims.nat -> FStar.Pervasives.Lemma (requires Vale.Math.Poly2.Defs_s.degree a <= n /\ Vale.Math.Poly2.Defs_s.degree b <= n) (ensures Vale.Math.Poly2.Defs_s.reverse (a *. b) (n + n) =. Vale.Math.Poly2.Defs_s.reverse a n *. Vale.Math.Poly2.Defs_s.reverse b n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Math.Poly2.Defs_s.poly", "Prims.nat", "Vale.Math.Poly2.Defs.lemma_pointwise_equal", "Vale.Math.Poly2.Defs.op_Star_Dot", "Prims.int", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.bool", "Vale.Math.Poly2.Defs_s.poly_index", "Vale.Math.Poly2.Defs_s.mul", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Vale.Math.Poly2.Defs.lemma_sum_extend", "Prims.op_Subtraction", "Prims.l_and", "Prims.l_imp", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_Equality", "Prims.op_LessThan", "Vale.Math.Poly2.Defs.max", "Prims.min", "Vale.Math.Poly2.Defs.lemma_sum_shift", "Prims.op_Minus", "Vale.Math.Poly2.Defs.lemma_sum_invert", "Vale.Math.Poly2.Defs_s.mul_element_fun", "Vale.Math.Poly2.Defs_s.op_String_Access", "Vale.Math.Poly2.Defs.lemma_mul_degree", "Vale.Math.Poly2.Defs_s.reverse", "Vale.Math.Poly2.Defs_s.degree", "Vale.Math.Poly2.Defs.op_Equals_Dot" ]
[]
false
false
true
false
false
let lemma_mul_reverse (a b: poly) (n: nat) : Lemma (requires degree a <= n /\ degree b <= n) (ensures reverse (a *. b) (n + n) =. reverse a n *. reverse b n) =
let ab = a *. b in let rab = reverse ab (n + n) in let ra = reverse a n in let rb = reverse b n in lemma_mul_degree a b; lemma_mul_degree ra rb; let f (k: int) : Lemma (rab.[ k ] == (ra *. rb).[ k ]) = if 0 <= k && k <= n + n then (let f0 = mul_element_fun ra rb k in let f1 (i: int) : bool = a.[ n + i ] && b.[ n - k - i ] in let f2 = mul_element_fun a b (n + n - k) in lemma_sum_invert 0 (k + 1) f0 f1; lemma_sum_shift (- k) 1 n f1 f2; let lo = min (n - k) 0 in let hi = max (n + 1) (n + n + 1 - k) in lemma_sum_extend lo 0 (n + n + 1 - k) hi f2; lemma_sum_extend lo (n - k) (n + 1) hi f2; ()) in lemma_pointwise_equal rab (ra *. rb) f
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_code
val print_code (c: code) (n: int) (p: P.printer) : string & int
val print_code (c: code) (n: int) (p: P.printer) : string & int
let rec print_block (b:codes) (n:int) (p:P.printer) : string & int = match b with | Nil -> "", n | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins (Instr _ _ (AnnotateComment s)) :: tail -> let head_str = " // " ^ s ^ "\n" in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins i :: tail -> let head_str = print_ins i p in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateNewline _)) :: tail -> let rest, n' = print_block tail n p in "\n" ^ rest, n' | head :: tail -> let head_str, n' = print_code head n p in let rest, n'' = print_block tail n' p in head_str ^ rest, n'' and print_code (c:code) (n:int) (p:P.printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (P.cmp_not cond) n1 p in let true_str, n' = print_code true_code (n + 2) p in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"L" ^ string_of_int n1 ^ ":\"\n" in let false_str, n' = print_code false_code n' p in let label2 = " \"L" ^ string_of_int n2 ^ ":\"\n" in cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n' | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\"\n" in let body_str, n' = print_code body (n + 2) p in let label2 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\"\n" in let cmp = print_cmp cond n1 p in jmp ^ label1 ^ body_str ^ label2 ^ cmp, n'
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 298, "start_col": 0, "start_line": 258 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter // Print the list of modified registers, + memory and cc let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15] // Prints "register uint64_t *argi_r __asm__("[reg]") = argi;\n" let print_explicit_register_arg (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = let ty = match a with | TD_Base _ -> "uint64_t " | _ -> "uint64_t *" in if reserved (of_arg i) then // If the associated register is reserved, we really this argument in it. For instance if it is Rdx and we have Mul(x) instructions true, " register " ^ ty ^ names i ^ "_r __asm__(\"" ^ P.print_reg_name (of_arg i) ^ "\") = " ^ names i ^ ";\n" else false, "" let rec print_explicit_register_args (n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = match args with | [] -> false, "" | a::q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i+1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str // If we have a return parameter with a reserved register, print "register uint64_t [name] __asm__("rax");\n" let print_register_ret (reserved:reg_64 -> bool) = function | None -> "" | Some name -> if reserved rRax then " register uint64_t " ^ name ^ " __asm__(\"rax\");\n" else " uint64_t " ^ name ^ ";\n" (* This is a copy from X64.Print_s, and should remain in sync. The difference is that each line should be in quotes, and end by a semicolon in inline assembly *) let print_cmp (c:ocmp) (counter:int) (p:P.printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.P.op_order (P.print_operand o1 p) (P.print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> " \"" ^ print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ ";\"\n" | ONe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ ";\"\n" | OLe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ ";\"\n" | OGe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ ";\"\n" | OLt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ ";\"\n" | OGt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ ";\"\n" let rec print_spaces (n:nat) : string = match n with | 0 -> "" | n -> " " ^ print_spaces (n-1) (* Overriding printer for formatting instructions *) let print_ins (ins:ins) (p:P.printer) : string = match ins with | Instr _ _ (AnnotateComment s) -> " // " ^ s | Instr _ _ (AnnotateLargeComment s) -> "\n /////// " ^ s ^ " ////// \n" | Instr _ _ (AnnotateSpace n) -> print_spaces n | _ -> " \"" ^ P.print_ins ins p ^ ";\""
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
c: Vale.X64.Machine_Semantics_s.code -> n: Prims.int -> p: Vale.X64.Print_s.printer -> Prims.string * Prims.int
Prims.Tot
[ "total" ]
[ "print_block", "print_code" ]
[ "Vale.X64.Machine_Semantics_s.code", "Prims.int", "Vale.X64.Print_s.printer", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "FStar.Pervasives.Native.Mktuple2", "Prims.string", "Prims.op_Hat", "Vale.X64.Print_Inline_s.print_ins", "Prims.list", "Vale.X64.Machine_s.precode", "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.Print_Inline_s.print_block", "Prims.string_of_int", "FStar.Pervasives.Native.tuple2", "Vale.X64.Print_Inline_s.print_code", "Prims.op_Addition", "Vale.X64.Print_Inline_s.print_cmp", "Vale.X64.Print_s.cmp_not", "Vale.X64.Print_s.__proj__Mkprinter__item__align" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec print_code (c: code) (n: int) (p: P.printer) : string & int =
match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (P.cmp_not cond) n1 p in let true_str, n' = print_code true_code (n + 2) p in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"L" ^ string_of_int n1 ^ ":\"\n" in let false_str, n' = print_code false_code n' p in let label2 = " \"L" ^ string_of_int n2 ^ ":\"\n" in cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n' | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"" ^ p.P.align () ^ " 16\nL" ^ string_of_int n1 ^ ":\"\n" in let body_str, n' = print_code body (n + 2) p in let label2 = " \"" ^ p.P.align () ^ " 16\nL" ^ string_of_int n2 ^ ":\"\n" in let cmp = print_cmp cond n1 p in jmp ^ label1 ^ body_str ^ label2 ^ cmp, n'
false
AuxPredicate.fst
AuxPredicate.my_inv
val my_inv (b: bool) (r: R.ref int) : vprop
val my_inv (b: bool) (r: R.ref int) : vprop
let my_inv (b:bool) (r:R.ref int) : vprop = exists* v. R.pts_to r v ** pure ( (v==0 \/ v == 1) /\ b == (v = 0) )
{ "file_name": "share/steel/examples/pulse/AuxPredicate.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 47, "end_line": 31, "start_col": 0, "start_line": 28 }
(* 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 AuxPredicate open Pulse.Lib.Pervasives module R = Pulse.Lib.Reference (* This example illustrates how to work with auxiliary predicates. The style is quite explicit, with folds and unfolds. It could be improved by automated support for foldig & unfolding in the prover *) // Defining a vprop using F* syntax. We do not yet allow
{ "checked_file": "/", "dependencies": [ "Pulse.Lib.Reference.fsti.checked", "Pulse.Lib.Pervasives.fst.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "AuxPredicate.fst" }
[ { "abbrev": true, "full_module": "Pulse.Lib.Reference", "short_module": "R" }, { "abbrev": false, "full_module": "Pulse.Lib.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.bool -> r: Pulse.Lib.Reference.ref Prims.int -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Pulse.Lib.Reference.ref", "Prims.int", "Pulse.Lib.Core.op_exists_Star", "Pulse.Lib.Core.op_Star_Star", "Pulse.Lib.Reference.pts_to", "PulseCore.FractionalPermission.full_perm", "Pulse.Lib.Core.pure", "Prims.l_and", "Prims.l_or", "Prims.eq2", "Prims.op_Equality", "Pulse.Lib.Core.vprop" ]
[]
false
false
false
true
false
let my_inv (b: bool) (r: R.ref int) : vprop =
exists* v. R.pts_to r v ** pure ((v == 0 \/ v == 1) /\ b == (v = 0))
false
Hacl.Chacha20Poly1305_128.fst
Hacl.Chacha20Poly1305_128.poly1305_do_128
val poly1305_do_128 : Hacl.Meta.Chacha20Poly1305.chacha20poly1305_poly1305_do_higher_t Prims.l_True
let poly1305_do_128 = chacha20poly1305_poly1305_do_higher #M128 True poly1305_finish poly1305_init poly1305_padded_128
{ "file_name": "code/chacha20poly1305/Hacl.Chacha20Poly1305_128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 118, "end_line": 16, "start_col": 0, "start_line": 16 }
module Hacl.Chacha20Poly1305_128 open Hacl.Meta.Chacha20Poly1305 open Hacl.Impl.Chacha20Poly1305 open Hacl.Impl.Poly1305.Fields open Hacl.Poly1305_128 #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@CInline] private let poly1305_padded_128 = Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded #M128 [@CInline]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Poly1305_128.fsti.checked", "Hacl.Meta.Chacha20Poly1305.fst.checked", "Hacl.Impl.Poly1305.Fields.fst.checked", "Hacl.Impl.Chacha20Poly1305.PolyCore.fst.checked", "Hacl.Impl.Chacha20Poly1305.fst.checked", "Hacl.Chacha20.Vec128.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Chacha20Poly1305_128.fst" }
[ { "abbrev": false, "full_module": "Hacl.Poly1305_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Meta.Chacha20Poly1305", "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Meta.Chacha20Poly1305.chacha20poly1305_poly1305_do_higher_t Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Chacha20Poly1305.chacha20poly1305_poly1305_do_higher", "Hacl.Impl.Poly1305.Fields.M128", "Prims.l_True", "Hacl.Poly1305_128.poly1305_finish", "Hacl.Poly1305_128.poly1305_init", "Hacl.Chacha20Poly1305_128.poly1305_padded_128" ]
[]
false
false
false
true
false
let poly1305_do_128 =
chacha20poly1305_poly1305_do_higher #M128 True poly1305_finish poly1305_init poly1305_padded_128
false
Hacl.Chacha20Poly1305_128.fst
Hacl.Chacha20Poly1305_128.poly1305_padded_128
val poly1305_padded_128 : Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded_st Hacl.Impl.Poly1305.Fields.M128
let poly1305_padded_128 = Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded #M128
{ "file_name": "code/chacha20poly1305/Hacl.Chacha20Poly1305_128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 83, "end_line": 13, "start_col": 0, "start_line": 13 }
module Hacl.Chacha20Poly1305_128 open Hacl.Meta.Chacha20Poly1305 open Hacl.Impl.Chacha20Poly1305 open Hacl.Impl.Poly1305.Fields open Hacl.Poly1305_128 #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@CInline]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Poly1305_128.fsti.checked", "Hacl.Meta.Chacha20Poly1305.fst.checked", "Hacl.Impl.Poly1305.Fields.fst.checked", "Hacl.Impl.Chacha20Poly1305.PolyCore.fst.checked", "Hacl.Impl.Chacha20Poly1305.fst.checked", "Hacl.Chacha20.Vec128.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Chacha20Poly1305_128.fst" }
[ { "abbrev": false, "full_module": "Hacl.Poly1305_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Meta.Chacha20Poly1305", "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded_st Hacl.Impl.Poly1305.Fields.M128
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded", "Hacl.Impl.Poly1305.Fields.M128" ]
[]
false
false
false
true
false
let poly1305_padded_128 =
Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded #M128
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.remove_blank
val remove_blank (c: code) : code
val remove_blank (c: code) : code
let rec remove_blank (c:code) : code = match c with | Ins _ -> c | Block b -> Block (remove_blanks b) | IfElse cond ct cf -> IfElse cond (remove_blank ct) (remove_blank cf) | While cond cb -> While cond (remove_blank cb) and remove_blanks (b:codes) : codes = match b with | [] -> [] | Ins (Instr _ _ (AnnotateGhost _)) :: cs -> remove_blanks cs | Block b :: cs -> ( match remove_blanks b with | [] -> remove_blanks cs | b -> Block b :: remove_blanks cs ) | c :: cs -> c :: remove_blanks cs
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 320, "start_col": 0, "start_line": 304 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter // Print the list of modified registers, + memory and cc let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15] // Prints "register uint64_t *argi_r __asm__("[reg]") = argi;\n" let print_explicit_register_arg (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = let ty = match a with | TD_Base _ -> "uint64_t " | _ -> "uint64_t *" in if reserved (of_arg i) then // If the associated register is reserved, we really this argument in it. For instance if it is Rdx and we have Mul(x) instructions true, " register " ^ ty ^ names i ^ "_r __asm__(\"" ^ P.print_reg_name (of_arg i) ^ "\") = " ^ names i ^ ";\n" else false, "" let rec print_explicit_register_args (n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = match args with | [] -> false, "" | a::q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i+1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str // If we have a return parameter with a reserved register, print "register uint64_t [name] __asm__("rax");\n" let print_register_ret (reserved:reg_64 -> bool) = function | None -> "" | Some name -> if reserved rRax then " register uint64_t " ^ name ^ " __asm__(\"rax\");\n" else " uint64_t " ^ name ^ ";\n" (* This is a copy from X64.Print_s, and should remain in sync. The difference is that each line should be in quotes, and end by a semicolon in inline assembly *) let print_cmp (c:ocmp) (counter:int) (p:P.printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.P.op_order (P.print_operand o1 p) (P.print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> " \"" ^ print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ ";\"\n" | ONe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ ";\"\n" | OLe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ ";\"\n" | OGe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ ";\"\n" | OLt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ ";\"\n" | OGt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ ";\"\n" let rec print_spaces (n:nat) : string = match n with | 0 -> "" | n -> " " ^ print_spaces (n-1) (* Overriding printer for formatting instructions *) let print_ins (ins:ins) (p:P.printer) : string = match ins with | Instr _ _ (AnnotateComment s) -> " // " ^ s | Instr _ _ (AnnotateLargeComment s) -> "\n /////// " ^ s ^ " ////// \n" | Instr _ _ (AnnotateSpace n) -> print_spaces n | _ -> " \"" ^ P.print_ins ins p ^ ";\"" let rec print_block (b:codes) (n:int) (p:P.printer) : string & int = match b with | Nil -> "", n | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins (Instr _ _ (AnnotateComment s)) :: tail -> let head_str = " // " ^ s ^ "\n" in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins i :: tail -> let head_str = print_ins i p in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateNewline _)) :: tail -> let rest, n' = print_block tail n p in "\n" ^ rest, n' | head :: tail -> let head_str, n' = print_code head n p in let rest, n'' = print_block tail n' p in head_str ^ rest, n'' and print_code (c:code) (n:int) (p:P.printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (P.cmp_not cond) n1 p in let true_str, n' = print_code true_code (n + 2) p in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"L" ^ string_of_int n1 ^ ":\"\n" in let false_str, n' = print_code false_code n' p in let label2 = " \"L" ^ string_of_int n2 ^ ":\"\n" in cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n' | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\"\n" in let body_str, n' = print_code body (n + 2) p in let label2 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\"\n" in let cmp = print_cmp cond n1 p in jmp ^ label1 ^ body_str ^ label2 ^ cmp, n' let rec print_fn_comments = function | [] -> "" | hd::tl -> "// " ^ hd ^ "\n" ^ print_fn_comments tl
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
c: Vale.X64.Machine_Semantics_s.code -> Vale.X64.Machine_Semantics_s.code
Prims.Tot
[ "total" ]
[ "remove_blank", "remove_blanks" ]
[ "Vale.X64.Machine_Semantics_s.code", "Vale.X64.Bytes_Code_s.instruction_t", "Vale.X64.Machine_Semantics_s.instr_annotation", "Prims.list", "Vale.X64.Machine_s.precode", "Vale.X64.Bytes_Code_s.ocmp", "Vale.X64.Machine_s.Block", "Vale.X64.Print_Inline_s.remove_blanks", "Vale.X64.Machine_s.IfElse", "Vale.X64.Print_Inline_s.remove_blank", "Vale.X64.Machine_s.While" ]
[ "mutual recursion" ]
false
false
false
true
false
let rec remove_blank (c: code) : code =
match c with | Ins _ -> c | Block b -> Block (remove_blanks b) | IfElse cond ct cf -> IfElse cond (remove_blank ct) (remove_blank cf) | While cond cb -> While cond (remove_blank cb)
false
Hacl.Chacha20Poly1305_128.fst
Hacl.Chacha20Poly1305_128.decrypt
val decrypt:aead_decrypt_st M128
val decrypt:aead_decrypt_st M128
let decrypt : aead_decrypt_st M128 = chacha20poly1305_aead_decrypt_higher #M128 True Hacl.Chacha20.Vec128.chacha20_encrypt_128 poly1305_do_128
{ "file_name": "code/chacha20poly1305/Hacl.Chacha20Poly1305_128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 107, "end_line": 53, "start_col": 0, "start_line": 52 }
module Hacl.Chacha20Poly1305_128 open Hacl.Meta.Chacha20Poly1305 open Hacl.Impl.Chacha20Poly1305 open Hacl.Impl.Poly1305.Fields open Hacl.Poly1305_128 #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@CInline] private let poly1305_padded_128 = Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded #M128 [@CInline] private let poly1305_do_128 = chacha20poly1305_poly1305_do_higher #M128 True poly1305_finish poly1305_init poly1305_padded_128 [@@ Comment "Encrypt a message `input` with key `key`. The arguments `key`, `nonce`, `data`, and `data_len` are same in encryption/decryption. Note: Encryption and decryption can be executed in-place, i.e., `input` and `output` can point to the same memory. @param output Pointer to `input_len` bytes of memory where the ciphertext is written to. @param tag Pointer to 16 bytes of memory where the mac is written to. @param input Pointer to `input_len` bytes of memory where the message is read from. @param input_len Length of the message. @param data Pointer to `data_len` bytes of memory where the associated data is read from. @param data_len Length of the associated data. @param key Pointer to 32 bytes of memory where the AEAD key is read from. @param nonce Pointer to 12 bytes of memory where the AEAD nonce is read from."] let encrypt : aead_encrypt_st M128 = chacha20poly1305_aead_encrypt_higher #M128 True poly1305_do_128 Hacl.Chacha20.Vec128.chacha20_encrypt_128 [@@ Comment "Decrypt a ciphertext `input` with key `key`. The arguments `key`, `nonce`, `data`, and `data_len` are same in encryption/decryption. Note: Encryption and decryption can be executed in-place, i.e., `input` and `output` can point to the same memory. If decryption succeeds, the resulting plaintext is stored in `output` and the function returns the success code 0. If decryption fails, the array `output` remains unchanged and the function returns the error code 1. @param output Pointer to `input_len` bytes of memory where the message is written to. @param input Pointer to `input_len` bytes of memory where the ciphertext is read from. @param input_len Length of the ciphertext. @param data Pointer to `data_len` bytes of memory where the associated data is read from. @param data_len Length of the associated data. @param key Pointer to 32 bytes of memory where the AEAD key is read from. @param nonce Pointer to 12 bytes of memory where the AEAD nonce is read from. @param tag Pointer to 16 bytes of memory where the mac is read from.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Poly1305_128.fsti.checked", "Hacl.Meta.Chacha20Poly1305.fst.checked", "Hacl.Impl.Poly1305.Fields.fst.checked", "Hacl.Impl.Chacha20Poly1305.PolyCore.fst.checked", "Hacl.Impl.Chacha20Poly1305.fst.checked", "Hacl.Chacha20.Vec128.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Chacha20Poly1305_128.fst" }
[ { "abbrev": false, "full_module": "Hacl.Poly1305_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Meta.Chacha20Poly1305", "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Chacha20Poly1305.aead_decrypt_st Hacl.Impl.Poly1305.Fields.M128
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Chacha20Poly1305.chacha20poly1305_aead_decrypt_higher", "Hacl.Impl.Poly1305.Fields.M128", "Prims.l_True", "Hacl.Chacha20.Vec128.chacha20_encrypt_128", "Hacl.Chacha20Poly1305_128.poly1305_do_128" ]
[]
false
false
false
true
false
let decrypt:aead_decrypt_st M128 =
chacha20poly1305_aead_decrypt_higher #M128 True Hacl.Chacha20.Vec128.chacha20_encrypt_128 poly1305_do_128
false
Vale.Arch.BufferFriend.fsti
Vale.Arch.BufferFriend.le_to_n_indexed
val le_to_n_indexed (b: FE.bytes) : nat
val le_to_n_indexed (b: FE.bytes) : nat
let le_to_n_indexed (b:FE.bytes) : nat = le_to_n_indexed_rec b (length b)
{ "file_name": "vale/code/arch/Vale.Arch.BufferFriend.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 34, "end_line": 89, "start_col": 0, "start_line": 88 }
module Vale.Arch.BufferFriend module B = LowStar.Buffer module LI = Lib.IntTypes module BS = Lib.ByteSequence module FE = FStar.Endianness module HS = FStar.HyperStack module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Mul open FStar.Seq.Base val to_bytes (s:seq UInt8.t) : Tot (b:BS.bytes{b === s /\ length b == length s}) val of_bytes (b:BS.bytes) : Tot (s:seq UInt8.t{b === s /\ length b == length s}) val lemma_to_bytes_slice (s:seq UInt8.t) (i j:nat) : Lemma (requires i <= j /\ j <= length s) (ensures to_bytes (slice s i j) == slice (to_bytes s) i j) [SMTPat (to_bytes (slice s i j))] val lemma_of_bytes_slice (b:BS.bytes) (i j:nat) : Lemma (requires i <= j /\ j <= length b) (ensures of_bytes (slice b i j) == slice (of_bytes b) i j) [SMTPat (of_bytes (slice b i j))] val lemma_up_as_seq_index (#b:_) (h:HS.mem) (vb:UV.buffer b) (i:nat) : Lemma (requires i < length (UV.as_seq h vb) /\ UV.View?.n (UV.get_view vb) == 8) // TODO: generalize this beyond n = 8 (ensures ( let s0 = DV.as_seq h (UV.as_down_buffer vb) in let v = UV.get_view vb in let n = UV.View?.n v in let start = i * n in 0 <= start /\ start + n <= length s0 /\ index (UV.as_seq h vb) i == UV.View?.get v (slice s0 start (start + n)) )) // TODO: this was copied out of Vale.SHA.Simplify_Sha.fst, but with the liveness requirement on b removed; we could consolidate the two versions val same_seq_downview8 (b:B.buffer UInt8.t) (h:HS.mem) : Lemma (DV.as_seq h (DV.mk_buffer_view b (Vale.Interop.Views.down_view8)) == B.as_seq h b) val lemma_le_to_n_is_nat_from_bytes (s:FE.bytes) : Lemma (ensures FE.le_to_n s == BS.nat_from_bytes_le (to_bytes s)) (decreases (length s)) val lemma_n_to_le_is_nat_to_bytes (len:nat) (n:nat) : Lemma (requires n < pow2 (8 * len)) (ensures FE.n_to_le len n == of_bytes (BS.nat_to_bytes_le len n)) (decreases len) val lemma_be_to_n_is_nat_from_bytes (s:FE.bytes) : Lemma (ensures FE.be_to_n s == BS.nat_from_bytes_be (to_bytes s)) (decreases (length s)) val lemma_n_to_be_is_nat_to_bytes (len:nat) (n:nat) : Lemma (requires n < pow2 (8 * len)) (ensures FE.n_to_be len n == of_bytes (BS.nat_to_bytes_be len n)) (decreases len) val nat_from_bytes_le_is_four_to_nat (b:BS.bytes) : Lemma (requires length b == 4) (ensures BS.nat_from_bytes_le b == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Four_s.four_map LI.uint_v (Vale.Def.Words.Seq_s.seq_to_four_LE b)) ) val nat_from_bytes_le_is_le_bytes_to_nat32 (b:BS.bytes) : Lemma (requires length b == 4) (ensures length (of_bytes b) == 4 /\ BS.nat_from_bytes_le b == le_bytes_to_nat32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (of_bytes b)) ) val nat_from_bytes_le_is_le_bytes_to_nat64 (b:BS.bytes) : Lemma (requires length b == 8) (ensures length (of_bytes b) == 8 /\ BS.nat_from_bytes_le b == le_bytes_to_nat64 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (of_bytes b)) ) // useful with norm_spec [iota; zeta; primops; delta_only [`%le_to_n_indexed_rec; `%pow2]] let rec le_to_n_indexed_rec (b:FE.bytes) (i:nat{i <= length b}) : nat = if i = 0 then 0 else UInt8.v (index b (length b - i)) + pow2 8 * le_to_n_indexed_rec b (i - 1)
{ "checked_file": "/", "dependencies": [ "Vale.Interop.Views.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked" ], "interface_file": false, "source_file": "Vale.Arch.BufferFriend.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "FE" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BS" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "LI" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
b: FStar.Endianness.bytes -> Prims.nat
Prims.Tot
[ "total" ]
[]
[ "FStar.Endianness.bytes", "Vale.Arch.BufferFriend.le_to_n_indexed_rec", "FStar.Seq.Base.length", "FStar.UInt8.t", "Prims.nat" ]
[]
false
false
false
true
false
let le_to_n_indexed (b: FE.bytes) : nat =
le_to_n_indexed_rec b (length b)
false
Vale.Arch.BufferFriend.fsti
Vale.Arch.BufferFriend.le_to_n_indexed_rec
val le_to_n_indexed_rec (b: FE.bytes) (i: nat{i <= length b}) : nat
val le_to_n_indexed_rec (b: FE.bytes) (i: nat{i <= length b}) : nat
let rec le_to_n_indexed_rec (b:FE.bytes) (i:nat{i <= length b}) : nat = if i = 0 then 0 else UInt8.v (index b (length b - i)) + pow2 8 * le_to_n_indexed_rec b (i - 1)
{ "file_name": "vale/code/arch/Vale.Arch.BufferFriend.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 80, "end_line": 86, "start_col": 0, "start_line": 84 }
module Vale.Arch.BufferFriend module B = LowStar.Buffer module LI = Lib.IntTypes module BS = Lib.ByteSequence module FE = FStar.Endianness module HS = FStar.HyperStack module DV = LowStar.BufferView.Down module UV = LowStar.BufferView.Up open Vale.Def.Words_s open Vale.Def.Types_s open FStar.Mul open FStar.Seq.Base val to_bytes (s:seq UInt8.t) : Tot (b:BS.bytes{b === s /\ length b == length s}) val of_bytes (b:BS.bytes) : Tot (s:seq UInt8.t{b === s /\ length b == length s}) val lemma_to_bytes_slice (s:seq UInt8.t) (i j:nat) : Lemma (requires i <= j /\ j <= length s) (ensures to_bytes (slice s i j) == slice (to_bytes s) i j) [SMTPat (to_bytes (slice s i j))] val lemma_of_bytes_slice (b:BS.bytes) (i j:nat) : Lemma (requires i <= j /\ j <= length b) (ensures of_bytes (slice b i j) == slice (of_bytes b) i j) [SMTPat (of_bytes (slice b i j))] val lemma_up_as_seq_index (#b:_) (h:HS.mem) (vb:UV.buffer b) (i:nat) : Lemma (requires i < length (UV.as_seq h vb) /\ UV.View?.n (UV.get_view vb) == 8) // TODO: generalize this beyond n = 8 (ensures ( let s0 = DV.as_seq h (UV.as_down_buffer vb) in let v = UV.get_view vb in let n = UV.View?.n v in let start = i * n in 0 <= start /\ start + n <= length s0 /\ index (UV.as_seq h vb) i == UV.View?.get v (slice s0 start (start + n)) )) // TODO: this was copied out of Vale.SHA.Simplify_Sha.fst, but with the liveness requirement on b removed; we could consolidate the two versions val same_seq_downview8 (b:B.buffer UInt8.t) (h:HS.mem) : Lemma (DV.as_seq h (DV.mk_buffer_view b (Vale.Interop.Views.down_view8)) == B.as_seq h b) val lemma_le_to_n_is_nat_from_bytes (s:FE.bytes) : Lemma (ensures FE.le_to_n s == BS.nat_from_bytes_le (to_bytes s)) (decreases (length s)) val lemma_n_to_le_is_nat_to_bytes (len:nat) (n:nat) : Lemma (requires n < pow2 (8 * len)) (ensures FE.n_to_le len n == of_bytes (BS.nat_to_bytes_le len n)) (decreases len) val lemma_be_to_n_is_nat_from_bytes (s:FE.bytes) : Lemma (ensures FE.be_to_n s == BS.nat_from_bytes_be (to_bytes s)) (decreases (length s)) val lemma_n_to_be_is_nat_to_bytes (len:nat) (n:nat) : Lemma (requires n < pow2 (8 * len)) (ensures FE.n_to_be len n == of_bytes (BS.nat_to_bytes_be len n)) (decreases len) val nat_from_bytes_le_is_four_to_nat (b:BS.bytes) : Lemma (requires length b == 4) (ensures BS.nat_from_bytes_le b == Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Four_s.four_map LI.uint_v (Vale.Def.Words.Seq_s.seq_to_four_LE b)) ) val nat_from_bytes_le_is_le_bytes_to_nat32 (b:BS.bytes) : Lemma (requires length b == 4) (ensures length (of_bytes b) == 4 /\ BS.nat_from_bytes_le b == le_bytes_to_nat32 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (of_bytes b)) ) val nat_from_bytes_le_is_le_bytes_to_nat64 (b:BS.bytes) : Lemma (requires length b == 8) (ensures length (of_bytes b) == 8 /\ BS.nat_from_bytes_le b == le_bytes_to_nat64 (Vale.Def.Words.Seq_s.seq_uint8_to_seq_nat8 (of_bytes b)) )
{ "checked_file": "/", "dependencies": [ "Vale.Interop.Views.fsti.checked", "Vale.Def.Words_s.fsti.checked", "Vale.Def.Words.Seq_s.fsti.checked", "Vale.Def.Words.Four_s.fsti.checked", "Vale.Def.Types_s.fst.checked", "prims.fst.checked", "LowStar.BufferView.Up.fsti.checked", "LowStar.BufferView.Down.fsti.checked", "LowStar.Buffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Seq.Base.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Endianness.fsti.checked" ], "interface_file": false, "source_file": "Vale.Arch.BufferFriend.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Types_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Def.Words_s", "short_module": null }, { "abbrev": true, "full_module": "LowStar.BufferView.Up", "short_module": "UV" }, { "abbrev": true, "full_module": "LowStar.BufferView.Down", "short_module": "DV" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Endianness", "short_module": "FE" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BS" }, { "abbrev": true, "full_module": "Lib.IntTypes", "short_module": "LI" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
b: FStar.Endianness.bytes -> i: Prims.nat{i <= FStar.Seq.Base.length b} -> Prims.nat
Prims.Tot
[ "total" ]
[]
[ "FStar.Endianness.bytes", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.length", "FStar.UInt8.t", "Prims.op_Equality", "Prims.int", "Prims.bool", "Prims.op_Addition", "FStar.UInt8.v", "FStar.Seq.Base.index", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Prims.pow2", "Vale.Arch.BufferFriend.le_to_n_indexed_rec" ]
[ "recursion" ]
false
false
false
false
false
let rec le_to_n_indexed_rec (b: FE.bytes) (i: nat{i <= length b}) : nat =
if i = 0 then 0 else UInt8.v (index b (length b - i)) + pow2 8 * le_to_n_indexed_rec b (i - 1)
false
Hacl.Chacha20Poly1305_128.fst
Hacl.Chacha20Poly1305_128.encrypt
val encrypt:aead_encrypt_st M128
val encrypt:aead_encrypt_st M128
let encrypt : aead_encrypt_st M128 = chacha20poly1305_aead_encrypt_higher #M128 True poly1305_do_128 Hacl.Chacha20.Vec128.chacha20_encrypt_128
{ "file_name": "code/chacha20poly1305/Hacl.Chacha20Poly1305_128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 107, "end_line": 32, "start_col": 0, "start_line": 31 }
module Hacl.Chacha20Poly1305_128 open Hacl.Meta.Chacha20Poly1305 open Hacl.Impl.Chacha20Poly1305 open Hacl.Impl.Poly1305.Fields open Hacl.Poly1305_128 #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" [@CInline] private let poly1305_padded_128 = Hacl.Impl.Chacha20Poly1305.PolyCore.poly1305_padded #M128 [@CInline] private let poly1305_do_128 = chacha20poly1305_poly1305_do_higher #M128 True poly1305_finish poly1305_init poly1305_padded_128 [@@ Comment "Encrypt a message `input` with key `key`. The arguments `key`, `nonce`, `data`, and `data_len` are same in encryption/decryption. Note: Encryption and decryption can be executed in-place, i.e., `input` and `output` can point to the same memory. @param output Pointer to `input_len` bytes of memory where the ciphertext is written to. @param tag Pointer to 16 bytes of memory where the mac is written to. @param input Pointer to `input_len` bytes of memory where the message is read from. @param input_len Length of the message. @param data Pointer to `data_len` bytes of memory where the associated data is read from. @param data_len Length of the associated data. @param key Pointer to 32 bytes of memory where the AEAD key is read from.
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Poly1305_128.fsti.checked", "Hacl.Meta.Chacha20Poly1305.fst.checked", "Hacl.Impl.Poly1305.Fields.fst.checked", "Hacl.Impl.Chacha20Poly1305.PolyCore.fst.checked", "Hacl.Impl.Chacha20Poly1305.fst.checked", "Hacl.Chacha20.Vec128.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Chacha20Poly1305_128.fst" }
[ { "abbrev": false, "full_module": "Hacl.Poly1305_128", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Chacha20Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Meta.Chacha20Poly1305", "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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Chacha20Poly1305.aead_encrypt_st Hacl.Impl.Poly1305.Fields.M128
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Chacha20Poly1305.chacha20poly1305_aead_encrypt_higher", "Hacl.Impl.Poly1305.Fields.M128", "Prims.l_True", "Hacl.Chacha20Poly1305_128.poly1305_do_128", "Hacl.Chacha20.Vec128.chacha20_encrypt_128" ]
[]
false
false
false
true
false
let encrypt:aead_encrypt_st M128 =
chacha20poly1305_aead_encrypt_higher #M128 True poly1305_do_128 Hacl.Chacha20.Vec128.chacha20_encrypt_128
false
Vale.X64.Print_Inline_s.fst
Vale.X64.Print_Inline_s.print_inline
val print_inline (name: string) (label: int) (ret_val: option string) (n: nat) (args: list td {List.length args = n}) (arg_names: (nat -> string)) (code: code) (of_arg: (reg_nat (List.length args) -> reg_64)) (regs_mod: (reg_64 -> bool)) (fn_comments: list string) : FStar.All.ML int
val print_inline (name: string) (label: int) (ret_val: option string) (n: nat) (args: list td {List.length args = n}) (arg_names: (nat -> string)) (code: code) (of_arg: (reg_nat (List.length args) -> reg_64)) (regs_mod: (reg_64 -> bool)) (fn_comments: list string) : FStar.All.ML int
let print_inline (name:string) (label:int) (ret_val:option string) (n:nat) (args:list td{List.length args = n}) (arg_names:nat -> string) (code:code) (of_arg:reg_nat (List.length args) -> reg_64) (regs_mod:reg_64 -> bool) (fn_comments:list string) : FStar.All.ML int = let comments = print_fn_comments fn_comments in let reserved_regs = build_reserved_args code (fun _ -> false) in let inputs_use_rax = uses_rax args 0 of_arg in if reserved_regs rRax && Some? ret_val then FStar.All.failwith "We require the annotation register uint64_t result(rax), but it would be ignored by gcc < 9"; if inputs_use_rax && Some? ret_val then FStar.All.failwith "inputs are not allowed to be passed in rax when there is a return argument"; // Signature: static inline (void | uint64_t) [name] (arg1, arg2???) { let header = "static inline " ^ print_rettype ret_val ^ " " ^ name ^ " (" ^ print_args args 0 arg_names ^ ") \n{\n" in // If we have a return value, declare a variable for it let ret_reg = print_register_ret reserved_regs ret_val in // Explicitly allocate registers when needed let has_explicit, explicit_regs = print_explicit_register_args n args 0 of_arg reserved_regs arg_names in // Start printing the code, need the __asm__ volatile header let start_code = (if Some? ret_val || has_explicit then "\n" else "") ^ " __asm__ volatile(\n" in // Initially, the register names are the same as in assembly // This function will be modified to address arguments by their number instead of explicitly allocating them let init_reg_names r = "%" ^ P.print_reg_name r in // Each *modified* input should be specified as "+r" (name) in the output line // If we have a return value, it should be written only and specified as "=r" (name) let output_str, output_reg_names, output_nbr = print_modified_inputs n of_arg regs_mod reserved_regs args ret_val init_reg_names 0 arg_names in let output_str = " : " ^ output_str in // Each *non-modified* input should be specified as `"r" (name)` in the input line let input_str, inlined_reg_names, _ = print_nonmodified_inputs n of_arg regs_mod reserved_regs args output_reg_names output_nbr arg_names in let input_str = " : " ^ input_str in // Propagating the "numbered", implicit registers to reg32 and small_reg let inlined_reg32_names r = if ("%" ^ P.print_reg_name r) = inlined_reg_names r then "%" ^ P.print_reg32_name r // In this case, this register is replaced by a number. // We add the "k" prefix for 32-bit operands else "k" ^ inlined_reg_names r in let inlined_small_reg_names r = if r > 3 then P.print_small_reg_name r else if ("%" ^ P.print_reg_name r) = inlined_reg_names r then "%" ^ P.print_small_reg_name r // In this case, this register is replaced by a number. // We add the "b" prefix for bytes else "b" ^ inlined_reg_names r in // In inline assembly, operands are prefixed by "%%" instead of "%" in regular GCC assembly let printer = {P.gcc with P.print_reg_name = inlined_reg_names; P.print_reg32_name = inlined_reg32_names; P.print_small_reg_name = inlined_small_reg_names } in // The assembly should be compliant with gcc let (code_str, final_label) = print_code (remove_blank code) label printer in // Every modified register that wasn't used for the inputs/outputs should be specified in the modified line let modified_str = " : " ^ print_modified_registers n ret_val of_arg regs_mod reserved_regs args in let close_code = " );\n" ^ (if Some? ret_val then "\n return " ^ Some?.v ret_val ^ ";\n" else "") ^ "}\n\n" in print_string (comments ^ header ^ ret_reg ^ explicit_regs ^ start_code ^ code_str ^ output_str ^ input_str ^ modified_str ^ close_code); final_label
{ "file_name": "vale/specs/hardware/Vale.X64.Print_Inline_s.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 407, "start_col": 0, "start_line": 328 }
module Vale.X64.Print_Inline_s open FStar.Mul open FStar.List.Tot open Vale.X64.Machine_s open Vale.X64.Bytes_Code_s open Vale.X64.Machine_Semantics_s open Vale.X64.Instruction_s open FStar.IO open Vale.Interop.Base open Vale.Interop.X64 module P = Vale.X64.Print_s let print_rettype (ret_val:option string) = match ret_val with | None -> "void" | Some _ -> "uint64_t" let print_basetype (t:base_typ) = match t with | TUInt8 -> "uint8_t" | TUInt16 -> "uint16_t" | TUInt32 -> "uint32_t" | TUInt64 -> "uint64_t" | TUInt128 -> "ERROR" // Returns "uint8_t arg2" or "uint64_t* arg0" for instance let print_arg (a:td) (i:nat) (names:nat -> string) = match a with | TD_Base src -> print_basetype src ^ " " ^ names i | TD_Buffer src _ _ | TD_ImmBuffer src _ _ -> print_basetype src ^ " *" ^ names i // Prints a list of args with their types, separated by a comma let rec print_args (args:list td) (i:nat) (names:nat -> string) = match args with | [] -> "" | [a] -> print_arg a i names | a::q -> print_arg a i names ^ ", " ^ print_args q (i+1) names let rec build_reserved_args_outs (l:list instr_out) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let (_, op) = hd in let reserved : (reg_64 -> bool) = (fun r -> match op with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_outs tl reserved r let rec build_reserved_args_ins (l:list instr_operand) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> match l with | [] -> reserved r | hd::tl -> let reserved : (reg_64 -> bool) = (fun r -> match hd with | IOpIm (IOp64One (OReg reg)) -> // Implicit register, adding it to "reserved" registers if r = reg then true else reserved r | _ -> reserved r) in build_reserved_args_ins tl reserved r // Traverses code, looking for instructions implicitly using registers. // When found, mark such registers as reserved so that they are not used during implicit allocation let rec build_reserved_args (c:code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases c) = fun r -> (match c with | Ins ins -> begin match ins with | Instr i _ _ -> let reserved = build_reserved_args_outs i.outs reserved in let reserved = build_reserved_args_ins (InstrTypeRecord?.args i) reserved in reserved r | _ -> reserved r end | Block l -> (build_reserved_args_block l reserved) r | IfElse cond ifTrue ifFalse -> let reservedT = build_reserved_args ifTrue reserved in build_reserved_args ifFalse reservedT r | While cond body -> build_reserved_args body reserved r ) and build_reserved_args_block (l:list code) (reserved:reg_64 -> bool) : Tot (reg_64 -> bool) (decreases l) = fun r -> ( match l with | [] -> reserved r | hd::tl -> let reserved = build_reserved_args hd reserved in build_reserved_args_block tl reserved r ) // Prints `"=&r" (name)` if an output is specified let print_output_ret ret_val (reg_names:reg_64 -> string) (counter:nat) : list string & (reg_64 -> string) & nat = match ret_val with | None -> [], reg_names, counter | Some name -> (["\"=&r\" (" ^ name ^ ")"], // If r = rax then address it as current arg number (fun r -> if r = 0 then string_of_int counter else reg_names r), counter + 1) // If the register in which a is passed is modified, we should specify `"+&r" (name)` let print_modified_input (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then (["\"+&r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1 ) else ([], reg_names, counter) // Get a list of strings corresponding to modified inputs let rec get_modified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{i + List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = match args with | [] -> print_output_ret ret_val reg_names counter | a::q -> let output, reg_names, counter = print_modified_input n a i of_arg regs_mod reserved_regs reg_names counter arg_names in let outputs, reg_names, counter = get_modified_input_strings n of_arg regs_mod reserved_regs q (i+1) ret_val reg_names counter arg_names in output @ outputs, reg_names, counter // Print the list of modified inputs, separated by commas let print_modified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (ret_val:option string) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let outputs, output_reg_names, output_nbr = get_modified_input_strings n of_arg regs_mod reserved_regs args 0 ret_val reg_names counter arg_names in aux outputs, output_reg_names, output_nbr // If the register in which an arg is passed is not modified, we should specify it as `"r" (name)` let print_nonmodified_input (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (a:td) (i:nat{i < n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) : list string & (reg_64 -> string) & nat = if regs_mod (of_arg i) then ([], reg_names, counter) else (["\"r\" (" ^ arg_names i ^ (if reserved_regs (of_arg i) then "_r)" else ")")], (fun r -> if r = of_arg i && not (reserved_regs r) then string_of_int counter else reg_names r), counter + 1) // Get a list of strings corresponding to modified inputs let rec get_nonmodified_input_strings (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td) (i:nat{List.Tot.length args + i <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = match args with | [] -> [], reg_names, counter | a::q -> let input, reg_names, counter = print_nonmodified_input n of_arg regs_mod reserved_regs a i reg_names counter arg_names in let inputs, reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs q (i+1) reg_names counter arg_names in input @ inputs, reg_names, counter let print_nonmodified_inputs (n:nat) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_regs:reg_64 -> bool) (args:list td{List.Tot.length args <= n}) (reg_names:reg_64 -> string) (counter:nat) (arg_names:nat -> string) = let rec aux = function | [] -> "\n" | [a] -> a ^ "\n" | a :: q -> a ^ ", " ^ aux q in let inputs, input_reg_names, counter = get_nonmodified_input_strings n of_arg regs_mod reserved_regs args 0 reg_names counter arg_names in aux inputs, input_reg_names, counter // Print the list of modified registers, + memory and cc let print_modified_registers (n:nat) (ret_val:option string) (of_arg:reg_nat n -> reg_64) (regs_mod:reg_64 -> bool) (reserved_args:reg_64 -> bool) (args:list td) = // This register was already specified as output let output_register a = Some? ret_val && a = rRax in let rec input_register (i:nat) (a:reg_64) : Tot bool (decreases (n-i)) = if i >= n then false else a = of_arg i // This register was already specified for the i-th argument || input_register (i+1) a in let rec aux = function | [] -> "\"memory\", \"cc\"\n" | a::q -> // This register is not modified, or was already specified as input or output: we skip it if not (regs_mod a) || input_register 0 a || output_register a then aux q // Register not modified or already specified in inputs, we add it else "\"%" ^ P.print_reg_name a ^ "\", " ^ aux q in aux [rRax; rRbx; rRcx; rRdx; rRsi; rRdi; rRbp; rRsp; rR8; rR9; rR10; rR11; rR12; rR13; rR14; rR15] // Prints "register uint64_t *argi_r __asm__("[reg]") = argi;\n" let print_explicit_register_arg (n:nat) (a:td) (i:nat{i < n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = let ty = match a with | TD_Base _ -> "uint64_t " | _ -> "uint64_t *" in if reserved (of_arg i) then // If the associated register is reserved, we really this argument in it. For instance if it is Rdx and we have Mul(x) instructions true, " register " ^ ty ^ names i ^ "_r __asm__(\"" ^ P.print_reg_name (of_arg i) ^ "\") = " ^ names i ^ ";\n" else false, "" let rec print_explicit_register_args (n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) (reserved:reg_64 -> bool) (names:nat -> string) = match args with | [] -> false, "" | a::q -> let was_explicit, explicit_str = print_explicit_register_arg n a i of_arg reserved names in let are_explicit, rest_str = print_explicit_register_args n q (i+1) of_arg reserved names in was_explicit || are_explicit, explicit_str ^ rest_str // If we have a return parameter with a reserved register, print "register uint64_t [name] __asm__("rax");\n" let print_register_ret (reserved:reg_64 -> bool) = function | None -> "" | Some name -> if reserved rRax then " register uint64_t " ^ name ^ " __asm__(\"rax\");\n" else " uint64_t " ^ name ^ ";\n" (* This is a copy from X64.Print_s, and should remain in sync. The difference is that each line should be in quotes, and end by a semicolon in inline assembly *) let print_cmp (c:ocmp) (counter:int) (p:P.printer) : string = let print_ops (o1:operand64) (o2:operand64) : string = let first, second = p.P.op_order (P.print_operand o1 p) (P.print_operand o2 p) in " cmp " ^ first ^ ", " ^ second ^ "\n" in match c with | OEq o1 o2 -> " \"" ^ print_ops o1 o2 ^ " je " ^ "L" ^ string_of_int counter ^ ";\"\n" | ONe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jne "^ "L" ^ string_of_int counter ^ ";\"\n" | OLe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jbe "^ "L" ^ string_of_int counter ^ ";\"\n" | OGe o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jae "^ "L" ^ string_of_int counter ^ ";\"\n" | OLt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " jb " ^ "L" ^ string_of_int counter ^ ";\"\n" | OGt o1 o2 -> " \"" ^ print_ops o1 o2 ^ " ja " ^ "L" ^ string_of_int counter ^ ";\"\n" let rec print_spaces (n:nat) : string = match n with | 0 -> "" | n -> " " ^ print_spaces (n-1) (* Overriding printer for formatting instructions *) let print_ins (ins:ins) (p:P.printer) : string = match ins with | Instr _ _ (AnnotateComment s) -> " // " ^ s | Instr _ _ (AnnotateLargeComment s) -> "\n /////// " ^ s ^ " ////// \n" | Instr _ _ (AnnotateSpace n) -> print_spaces n | _ -> " \"" ^ P.print_ins ins p ^ ";\"" let rec print_block (b:codes) (n:int) (p:P.printer) : string & int = match b with | Nil -> "", n | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins (Instr _ _ (AnnotateComment s)) :: tail -> let head_str = " // " ^ s ^ "\n" in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateSpace spaces)) :: Ins i :: tail -> let head_str = print_ins i p in let rest, n' = print_block tail n p in print_spaces spaces ^ head_str ^ rest, n' | Ins (Instr _ _ (AnnotateNewline _)) :: tail -> let rest, n' = print_block tail n p in "\n" ^ rest, n' | head :: tail -> let head_str, n' = print_code head n p in let rest, n'' = print_block tail n' p in head_str ^ rest, n'' and print_code (c:code) (n:int) (p:P.printer) : string & int = match c with | Ins ins -> (print_ins ins p ^ "\n", n) | Block b -> print_block b n p | IfElse cond true_code false_code -> let n1 = n in let n2 = n + 1 in let cmp = print_cmp (P.cmp_not cond) n1 p in let true_str, n' = print_code true_code (n + 2) p in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"L" ^ string_of_int n1 ^ ":\"\n" in let false_str, n' = print_code false_code n' p in let label2 = " \"L" ^ string_of_int n2 ^ ":\"\n" in cmp ^ true_str ^ jmp ^ label1 ^ false_str ^ label2, n' | While cond body -> let n1 = n in let n2 = n + 1 in let jmp = " \" jmp L" ^ string_of_int n2 ^ ";\"\n" in let label1 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n1 ^ ":\"\n" in let body_str, n' = print_code body (n + 2) p in let label2 = " \"" ^ p.P.align() ^ " 16\nL" ^ string_of_int n2 ^ ":\"\n" in let cmp = print_cmp cond n1 p in jmp ^ label1 ^ body_str ^ label2 ^ cmp, n' let rec print_fn_comments = function | [] -> "" | hd::tl -> "// " ^ hd ^ "\n" ^ print_fn_comments tl let rec remove_blank (c:code) : code = match c with | Ins _ -> c | Block b -> Block (remove_blanks b) | IfElse cond ct cf -> IfElse cond (remove_blank ct) (remove_blank cf) | While cond cb -> While cond (remove_blank cb) and remove_blanks (b:codes) : codes = match b with | [] -> [] | Ins (Instr _ _ (AnnotateGhost _)) :: cs -> remove_blanks cs | Block b :: cs -> ( match remove_blanks b with | [] -> remove_blanks cs | b -> Block b :: remove_blanks cs ) | c :: cs -> c :: remove_blanks cs // Check if any argument is passed in the rax register let rec uses_rax (#n:nat) (args:list td) (i:nat{i + List.length args = n}) (of_arg:reg_nat n -> reg_64) = match args with | [] -> false | a::q -> if of_arg i = rRax then true else uses_rax q (i+1) of_arg
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Interop.X64.fsti.checked", "Vale.Interop.Base.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked" ], "interface_file": false, "source_file": "Vale.X64.Print_Inline_s.fst" }
[ { "abbrev": true, "full_module": "Vale.X64.Print_s", "short_module": "P" }, { "abbrev": false, "full_module": "Vale.Interop.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.Interop.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.IO", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
name: Prims.string -> label: Prims.int -> ret_val: FStar.Pervasives.Native.option Prims.string -> n: Prims.nat -> args: Prims.list Vale.Interop.Base.td {FStar.List.Tot.Base.length args = n} -> arg_names: (_: Prims.nat -> Prims.string) -> code: Vale.X64.Machine_Semantics_s.code -> of_arg: (_: Vale.Interop.X64.reg_nat (FStar.List.Tot.Base.length args) -> Vale.X64.Machine_s.reg_64) -> regs_mod: (_: Vale.X64.Machine_s.reg_64 -> Prims.bool) -> fn_comments: Prims.list Prims.string -> FStar.All.ML Prims.int
FStar.All.ML
[ "ml" ]
[]
[ "Prims.string", "Prims.int", "FStar.Pervasives.Native.option", "Prims.nat", "Prims.list", "Vale.Interop.Base.td", "Prims.b2t", "Prims.op_Equality", "FStar.List.Tot.Base.length", "Vale.X64.Machine_Semantics_s.code", "Vale.Interop.X64.reg_nat", "Vale.X64.Machine_s.reg_64", "Prims.bool", "Prims.unit", "FStar.IO.print_string", "Prims.op_Hat", "FStar.Pervasives.Native.uu___is_Some", "FStar.Pervasives.Native.__proj__Some__item__v", "Vale.X64.Print_Inline_s.print_modified_registers", "FStar.Pervasives.Native.tuple2", "Vale.X64.Print_Inline_s.print_code", "Vale.X64.Print_Inline_s.remove_blank", "Vale.X64.Print_s.printer", "Vale.X64.Print_s.Mkprinter", "Vale.X64.Print_s.__proj__Mkprinter__item__reg_prefix", "Vale.X64.Print_s.gcc", "Vale.X64.Print_s.__proj__Mkprinter__item__mem_prefix", "Vale.X64.Print_s.__proj__Mkprinter__item__maddr", "Vale.X64.Print_s.__proj__Mkprinter__item__const", "Vale.X64.Print_s.__proj__Mkprinter__item__ins_name", "Vale.X64.Print_s.__proj__Mkprinter__item__op_order", "Vale.X64.Print_s.__proj__Mkprinter__item__align", "Vale.X64.Print_s.__proj__Mkprinter__item__header", "Vale.X64.Print_s.__proj__Mkprinter__item__footer", "Vale.X64.Print_s.__proj__Mkprinter__item__proc_name", "Vale.X64.Print_s.__proj__Mkprinter__item__ret", "Vale.X64.Print_s.__proj__Mkprinter__item__sha256rnds2_explicit_xmm0", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThan", "Prims.op_GreaterThan", "Vale.X64.Print_s.print_small_reg_name", "Vale.X64.Print_s.print_reg_name", "Vale.X64.Print_s.print_reg32_name", "FStar.Pervasives.Native.tuple3", "Vale.X64.Print_Inline_s.print_nonmodified_inputs", "Vale.X64.Print_Inline_s.print_modified_inputs", "Prims.op_BarBar", "Vale.X64.Print_Inline_s.print_explicit_register_args", "Vale.X64.Print_Inline_s.print_register_ret", "Vale.X64.Print_Inline_s.print_rettype", "Vale.X64.Print_Inline_s.print_args", "Prims.op_AmpAmp", "FStar.All.failwith", "Vale.X64.Machine_s.rRax", "Vale.X64.Print_Inline_s.uses_rax", "Vale.X64.Print_Inline_s.build_reserved_args", "Vale.X64.Print_Inline_s.print_fn_comments" ]
[]
false
true
false
false
false
let print_inline (name: string) (label: int) (ret_val: option string) (n: nat) (args: list td {List.length args = n}) (arg_names: (nat -> string)) (code: code) (of_arg: (reg_nat (List.length args) -> reg_64)) (regs_mod: (reg_64 -> bool)) (fn_comments: list string) : FStar.All.ML int =
let comments = print_fn_comments fn_comments in let reserved_regs = build_reserved_args code (fun _ -> false) in let inputs_use_rax = uses_rax args 0 of_arg in if reserved_regs rRax && Some? ret_val then FStar.All.failwith "We require the annotation register uint64_t result(rax), but it would be ignored by gcc < 9" ; if inputs_use_rax && Some? ret_val then FStar.All.failwith "inputs are not allowed to be passed in rax when there is a return argument"; let header = "static inline " ^ print_rettype ret_val ^ " " ^ name ^ " (" ^ print_args args 0 arg_names ^ ") \n{\n" in let ret_reg = print_register_ret reserved_regs ret_val in let has_explicit, explicit_regs = print_explicit_register_args n args 0 of_arg reserved_regs arg_names in let start_code = (if Some? ret_val || has_explicit then "\n" else "") ^ " __asm__ volatile(\n" in let init_reg_names r = "%" ^ P.print_reg_name r in let output_str, output_reg_names, output_nbr = print_modified_inputs n of_arg regs_mod reserved_regs args ret_val init_reg_names 0 arg_names in let output_str = " : " ^ output_str in let input_str, inlined_reg_names, _ = print_nonmodified_inputs n of_arg regs_mod reserved_regs args output_reg_names output_nbr arg_names in let input_str = " : " ^ input_str in let inlined_reg32_names r = if ("%" ^ P.print_reg_name r) = inlined_reg_names r then "%" ^ P.print_reg32_name r else "k" ^ inlined_reg_names r in let inlined_small_reg_names r = if r > 3 then P.print_small_reg_name r else if ("%" ^ P.print_reg_name r) = inlined_reg_names r then "%" ^ P.print_small_reg_name r else "b" ^ inlined_reg_names r in let printer = { P.gcc with P.print_reg_name = inlined_reg_names; P.print_reg32_name = inlined_reg32_names; P.print_small_reg_name = inlined_small_reg_names } in let code_str, final_label = print_code (remove_blank code) label printer in let modified_str = " : " ^ print_modified_registers n ret_val of_arg regs_mod reserved_regs args in let close_code = " );\n" ^ (if Some? ret_val then "\n return " ^ Some?.v ret_val ^ ";\n" else "") ^ "}\n\n" in print_string (comments ^ header ^ ret_reg ^ explicit_regs ^ start_code ^ code_str ^ output_str ^ input_str ^ modified_str ^ close_code); final_label
false
Spec.RSAPSS.fst
Spec.RSAPSS.hash_is_supported
val hash_is_supported (a: Hash.hash_alg) : Tot bool
val hash_is_supported (a: Hash.hash_alg) : Tot bool
let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 36, "start_col": 0, "start_line": 31 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.bool" ]
[]
false
false
false
true
false
let hash_is_supported (a: Hash.hash_alg) : Tot bool =
match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false
false
MiniParse.Impl.Int.fst
MiniParse.Impl.Int.parse_u16_impl
val parse_u16_impl:parser_impl parse_u16
val parse_u16_impl:parser_impl parse_u16
let parse_u16_impl : parser_impl parse_u16 = make_total_constant_size_parser_impl 2 2ul parse_u16_aux () (fun x -> let lo = B.index x 0ul in let hi = B.index x 1ul in Aux.decode_u16 (lo, hi) )
{ "file_name": "examples/miniparse/MiniParse.Impl.Int.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 1, "end_line": 48, "start_col": 0, "start_line": 44 }
(* 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 MiniParse.Impl.Int include MiniParse.Spec.Int include MiniParse.Impl.Combinators module U16 = FStar.UInt16 module B = LowStar.Buffer module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module Aux = MiniParse.Spec.Int.Aux inline_for_extraction let parse_u8_impl : parser_impl parse_u8 = make_total_constant_size_parser_impl 1 1ul (fun x -> Seq.index x 0) () (fun x -> B.index x 0ul) inline_for_extraction let serialize_u8_impl : serializer_impl serialize_u8 = (fun output (len: U32.t { len == B.len output } ) x -> let h = HST.get () in if len `U32.lt` 1ul then None else begin let output' = B.sub output 0ul 1ul in B.upd output' 0ul x; let h' = HST.get () in assert (B.as_seq h' output' `Seq.equal` Seq.create 1 x); Some 1ul end)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MiniParse.Spec.Int.Aux.fst.checked", "MiniParse.Spec.Int.fst.checked", "MiniParse.Impl.Combinators.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "MiniParse.Impl.Int.fst" }
[ { "abbrev": true, "full_module": "MiniParse.Spec.Int.Aux", "short_module": "Aux" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": false, "full_module": "MiniParse.Impl.Combinators", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Impl", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
MiniParse.Impl.Base.parser_impl MiniParse.Spec.Int.parse_u16
Prims.Tot
[ "total" ]
[]
[ "MiniParse.Impl.Combinators.make_total_constant_size_parser_impl", "FStar.UInt32.__uint_to_t", "FStar.UInt16.t", "MiniParse.Spec.Int.parse_u16_aux", "MiniParse.Impl.Base.buffer8", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "MiniParse.Spec.Int.Aux.decode_u16", "FStar.Pervasives.Native.Mktuple2", "LowStar.Monotonic.Buffer.index" ]
[]
false
false
false
true
false
let parse_u16_impl:parser_impl parse_u16 =
make_total_constant_size_parser_impl 2 2ul parse_u16_aux () (fun x -> let lo = B.index x 0ul in let hi = B.index x 1ul in Aux.decode_u16 (lo, hi))
false
MiniParse.Impl.Int.fst
MiniParse.Impl.Int.parse_u8_impl
val parse_u8_impl:parser_impl parse_u8
val parse_u8_impl:parser_impl parse_u8
let parse_u8_impl : parser_impl parse_u8 = make_total_constant_size_parser_impl 1 1ul (fun x -> Seq.index x 0) () (fun x -> B.index x 0ul)
{ "file_name": "examples/miniparse/MiniParse.Impl.Int.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 138, "end_line": 27, "start_col": 0, "start_line": 27 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module MiniParse.Impl.Int include MiniParse.Spec.Int include MiniParse.Impl.Combinators module U16 = FStar.UInt16 module B = LowStar.Buffer module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module Aux = MiniParse.Spec.Int.Aux
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MiniParse.Spec.Int.Aux.fst.checked", "MiniParse.Spec.Int.fst.checked", "MiniParse.Impl.Combinators.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "MiniParse.Impl.Int.fst" }
[ { "abbrev": true, "full_module": "MiniParse.Spec.Int.Aux", "short_module": "Aux" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": false, "full_module": "MiniParse.Impl.Combinators", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Impl", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
MiniParse.Impl.Base.parser_impl MiniParse.Spec.Int.parse_u8
Prims.Tot
[ "total" ]
[]
[ "MiniParse.Impl.Combinators.make_total_constant_size_parser_impl", "FStar.UInt32.__uint_to_t", "MiniParse.Spec.Base.byte", "MiniParse.Spec.Base.bytes", "Prims.eq2", "Prims.nat", "FStar.Seq.Base.length", "FStar.Seq.Base.index", "MiniParse.Impl.Base.buffer8", "LowStar.Monotonic.Buffer.length", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.index" ]
[]
false
false
false
true
false
let parse_u8_impl:parser_impl parse_u8 =
make_total_constant_size_parser_impl 1 1ul (fun x -> Seq.index x 0) () (fun x -> B.index x 0ul)
false
MiniParse.Impl.Int.fst
MiniParse.Impl.Int.serialize_bounded_u16_impl
val serialize_bounded_u16_impl (b: nat) : Tot (serializer_impl (serialize_bounded_u16 b))
val serialize_bounded_u16_impl (b: nat) : Tot (serializer_impl (serialize_bounded_u16 b))
let serialize_bounded_u16_impl (b: nat) : Tot (serializer_impl (serialize_bounded_u16 b)) = fun output len x -> serialize_u16_impl output len x
{ "file_name": "examples/miniparse/MiniParse.Impl.Int.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 53, "end_line": 87, "start_col": 0, "start_line": 86 }
(* 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 MiniParse.Impl.Int include MiniParse.Spec.Int include MiniParse.Impl.Combinators module U16 = FStar.UInt16 module B = LowStar.Buffer module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module Aux = MiniParse.Spec.Int.Aux inline_for_extraction let parse_u8_impl : parser_impl parse_u8 = make_total_constant_size_parser_impl 1 1ul (fun x -> Seq.index x 0) () (fun x -> B.index x 0ul) inline_for_extraction let serialize_u8_impl : serializer_impl serialize_u8 = (fun output (len: U32.t { len == B.len output } ) x -> let h = HST.get () in if len `U32.lt` 1ul then None else begin let output' = B.sub output 0ul 1ul in B.upd output' 0ul x; let h' = HST.get () in assert (B.as_seq h' output' `Seq.equal` Seq.create 1 x); Some 1ul end) inline_for_extraction let parse_u16_impl : parser_impl parse_u16 = make_total_constant_size_parser_impl 2 2ul parse_u16_aux () (fun x -> let lo = B.index x 0ul in let hi = B.index x 1ul in Aux.decode_u16 (lo, hi) ) inline_for_extraction let serialize_u16_impl : serializer_impl serialize_u16 = fun output (len: U32.t { len == B.len output } ) x -> if len `U32.lt` 2ul then None else begin let (lo, hi) = Aux.encode_u16 x in let output' = B.sub output 0ul 2ul in B.upd output' 0ul lo; B.upd output' 1ul hi; let h' = HST.get () in assert (B.as_seq h' output' `Seq.equal` Seq.append (Seq.create 1 lo) (Seq.create 1 hi)); Some 2ul end #set-options "--z3rlimit 64" inline_for_extraction let parse_bounded_u16_impl (b: nat) : Tot (parser_impl (parse_bounded_u16 b)) = if b >= 65536 then (fun input len -> parse_synth_impl parse_u16_impl (fun x -> x <: bounded_u16 b) (fun x -> x <: bounded_u16 b) (fun x -> x) () input len) else [@@inline_let] let b' = U16.uint_to_t b in parse_synth_impl (parse_filter_impl parse_u16_impl (fun x -> U16.v x < b) (fun x -> x `U16.lt` b')) (fun x -> x <: bounded_u16 b) (fun x -> x <: bounded_u16 b) (fun x -> x) () #reset-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MiniParse.Spec.Int.Aux.fst.checked", "MiniParse.Spec.Int.fst.checked", "MiniParse.Impl.Combinators.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "MiniParse.Impl.Int.fst" }
[ { "abbrev": true, "full_module": "MiniParse.Spec.Int.Aux", "short_module": "Aux" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": false, "full_module": "MiniParse.Impl.Combinators", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Impl", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.nat -> MiniParse.Impl.Base.serializer_impl (MiniParse.Spec.Int.serialize_bounded_u16 b)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "MiniParse.Impl.Base.buffer8", "FStar.UInt32.t", "Prims.eq2", "LowStar.Monotonic.Buffer.len", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "MiniParse.Spec.Int.bounded_u16", "MiniParse.Impl.Int.serialize_u16_impl", "FStar.Pervasives.Native.option", "MiniParse.Impl.Base.serializer_impl", "MiniParse.Spec.Int.parse_bounded_u16", "MiniParse.Spec.Int.serialize_bounded_u16" ]
[]
false
false
false
false
false
let serialize_bounded_u16_impl (b: nat) : Tot (serializer_impl (serialize_bounded_u16 b)) =
fun output len x -> serialize_u16_impl output len x
false
Spec.RSAPSS.fst
Spec.RSAPSS.xor_bytes
val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len)
val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len)
let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 57, "end_line": 29, "start_col": 0, "start_line": 29 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 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
b1: Lib.ByteSequence.lbytes len -> b2: Lib.ByteSequence.lbytes len -> Lib.ByteSequence.lbytes len
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_pos", "Lib.ByteSequence.lbytes", "Lib.Sequence.map2", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Hat_Dot" ]
[]
false
false
false
false
false
let xor_bytes #len b1 b2 =
map2 (fun x y -> x ^. y) b1 b2
false
MiniParse.Impl.Int.fst
MiniParse.Impl.Int.serialize_u8_impl
val serialize_u8_impl:serializer_impl serialize_u8
val serialize_u8_impl:serializer_impl serialize_u8
let serialize_u8_impl : serializer_impl serialize_u8 = (fun output (len: U32.t { len == B.len output } ) x -> let h = HST.get () in if len `U32.lt` 1ul then None else begin let output' = B.sub output 0ul 1ul in B.upd output' 0ul x; let h' = HST.get () in assert (B.as_seq h' output' `Seq.equal` Seq.create 1 x); Some 1ul end)
{ "file_name": "examples/miniparse/MiniParse.Impl.Int.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 8, "end_line": 41, "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 MiniParse.Impl.Int include MiniParse.Spec.Int include MiniParse.Impl.Combinators module U16 = FStar.UInt16 module B = LowStar.Buffer module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module Aux = MiniParse.Spec.Int.Aux inline_for_extraction let parse_u8_impl : parser_impl parse_u8 = make_total_constant_size_parser_impl 1 1ul (fun x -> Seq.index x 0) () (fun x -> B.index x 0ul)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MiniParse.Spec.Int.Aux.fst.checked", "MiniParse.Spec.Int.fst.checked", "MiniParse.Impl.Combinators.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "MiniParse.Impl.Int.fst" }
[ { "abbrev": true, "full_module": "MiniParse.Spec.Int.Aux", "short_module": "Aux" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": false, "full_module": "MiniParse.Impl.Combinators", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Impl", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
MiniParse.Impl.Base.serializer_impl MiniParse.Spec.Int.serialize_u8
Prims.Tot
[ "total" ]
[]
[ "MiniParse.Impl.Base.buffer8", "FStar.UInt32.t", "Prims.eq2", "LowStar.Monotonic.Buffer.len", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.lt", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "Prims.bool", "FStar.Pervasives.Native.Some", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "LowStar.Monotonic.Buffer.as_seq", "FStar.Seq.Base.create", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.upd", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.sub", "FStar.Ghost.hide" ]
[]
false
false
false
true
false
let serialize_u8_impl:serializer_impl serialize_u8 =
(fun output (len: U32.t{len == B.len output}) x -> let h = HST.get () in if len `U32.lt` 1ul then None else let output' = B.sub output 0ul 1ul in B.upd output' 0ul x; let h' = HST.get () in assert ((B.as_seq h' output') `Seq.equal` (Seq.create 1 x)); Some 1ul)
false
Spec.RSAPSS.fst
Spec.RSAPSS.mgf_hash_a
val mgf_hash_a : len: Lib.IntTypes.size_nat{len + 4 <= Lib.IntTypes.max_size_t} -> n: Prims.pos -> i: Prims.nat{i <= n} -> Type0
let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4)
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 95, "end_line": 52, "start_col": 0, "start_line": 52 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_nat{len + 4 <= Lib.IntTypes.max_size_t} -> n: Prims.pos -> i: Prims.nat{i <= n} -> Type0
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Prims.pos", "Prims.nat", "Lib.ByteSequence.lbytes" ]
[]
false
false
false
false
true
let mgf_hash_a (len: size_nat{len + 4 <= max_size_t}) (n: pos) (i: nat{i <= n}) =
lbytes (len + 4)
false
Vale.Transformers.MovbeElim.fst
Vale.Transformers.MovbeElim.movbe_elim_ph
val movbe_elim_ph : Vale.Transformers.PeepHole.pre_peephole
let movbe_elim_ph = { ph = (function | [Instr i oprs (AnnotateMovbe64 proof_of_movbe)] -> let oprs:normal (instr_operands_t [out op64] [op64]) = coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs in let (dst, (src, ())) = oprs in if OReg? dst then ( let mov = make_instr ins_Mov64 dst src in let bswap = make_instr ins_Bswap64 dst in Some [mov; bswap] ) else None | _ -> None); input_hint = 1; }
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.MovbeElim.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 1, "end_line": 27, "start_col": 0, "start_line": 14 }
module Vale.Transformers.MovbeElim open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Transformers.InstructionReorder open Vale.X64.InsLemmas open Vale.Transformers.PeepHole
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.InsLemmas.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.PeepHole.fsti.checked", "Vale.Transformers.InstructionReorder.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.MovbeElim.fst" }
[ { "abbrev": false, "full_module": "Vale.Transformers.PeepHole", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.InstructionReorder", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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.Transformers.PeepHole.pre_peephole
Prims.Tot
[ "total" ]
[]
[ "Vale.Transformers.PeepHole.Mkpre_peephole", "Prims.list", "Vale.X64.Machine_Semantics_s.ins", "Vale.X64.Instruction_s.instr_t_record", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args", "Vale.X64.Machine_Semantics_s.equals_instr", "Vale.X64.Instruction_s.InstrTypeRecord", "Prims.Cons", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.out", "Vale.X64.Instruction_s.op64", "Prims.Nil", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.PreserveFlags", "Vale.X64.Instructions_s.ins_MovBe64", "Vale.X64.Machine_s.operand64", "Vale.X64.Machine_s.uu___is_OReg", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "FStar.Pervasives.Native.Some", "Vale.X64.InsLemmas.make_instr_t", "Vale.X64.InsLemmas.make_instr", "Vale.X64.Instruction_s.inOut", "Vale.X64.Instructions_s.ins_Bswap64", "Vale.X64.InsLemmas.make_instr_t_args", "Vale.X64.Instructions_s.ins_Mov64", "Prims.bool", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "FStar.Pervasives.norm", "FStar.Pervasives.norm_step", "FStar.Pervasives.zeta", "FStar.Pervasives.iota", "FStar.Pervasives.delta_attr", "Prims.string", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.Instruction_s.instr_operand_inout", "Vale.X64.Instruction_s.Out", "Vale.X64.Instruction_s.IOpEx", "Vale.X64.Instruction_s.IOp64", "Vale.Transformers.PeepHole.coerce_to_normal" ]
[]
false
false
false
true
false
let movbe_elim_ph =
{ ph = (function | [Instr i oprs (AnnotateMovbe64 proof_of_movbe)] -> let oprs:normal (instr_operands_t [out op64] [op64]) = coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs in let dst, (src, ()) = oprs in if OReg? dst then (let mov = make_instr ins_Mov64 dst src in let bswap = make_instr ins_Bswap64 dst in Some [mov; bswap]) else None | _ -> None); input_hint = 1 }
false
Spec.RSAPSS.fst
Spec.RSAPSS.blocks
val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r})
val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r})
let blocks x m = (x - 1) / m + 1
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 26, "start_col": 0, "start_line": 26 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions ///
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 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.size_pos -> m: Lib.IntTypes.size_pos -> r: Lib.IntTypes.size_pos{x <= m * r}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_pos", "Prims.op_Addition", "Prims.op_Division", "Prims.op_Subtraction", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star" ]
[]
false
false
false
false
false
let blocks x m =
(x - 1) / m + 1
false
Spec.RSAPSS.fst
Spec.RSAPSS.i2osp
val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len)
val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len)
let i2osp len n = nat_to_intseq_be len n
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 40, "end_line": 76, "start_col": 0, "start_line": 76 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_nat -> n: Prims.nat{n < Prims.pow2 (8 * len)} -> Lib.ByteSequence.lbytes len
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_nat", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "FStar.Mul.op_Star", "Lib.ByteSequence.nat_to_intseq_be", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.ByteSequence.lbytes" ]
[]
false
false
false
false
false
let i2osp len n =
nat_to_intseq_be len n
false
MiniParse.Impl.Int.fst
MiniParse.Impl.Int.serialize_u16_impl
val serialize_u16_impl:serializer_impl serialize_u16
val serialize_u16_impl:serializer_impl serialize_u16
let serialize_u16_impl : serializer_impl serialize_u16 = fun output (len: U32.t { len == B.len output } ) x -> if len `U32.lt` 2ul then None else begin let (lo, hi) = Aux.encode_u16 x in let output' = B.sub output 0ul 2ul in B.upd output' 0ul lo; B.upd output' 1ul hi; let h' = HST.get () in assert (B.as_seq h' output' `Seq.equal` Seq.append (Seq.create 1 lo) (Seq.create 1 hi)); Some 2ul end
{ "file_name": "examples/miniparse/MiniParse.Impl.Int.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 63, "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 MiniParse.Impl.Int include MiniParse.Spec.Int include MiniParse.Impl.Combinators module U16 = FStar.UInt16 module B = LowStar.Buffer module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module Aux = MiniParse.Spec.Int.Aux inline_for_extraction let parse_u8_impl : parser_impl parse_u8 = make_total_constant_size_parser_impl 1 1ul (fun x -> Seq.index x 0) () (fun x -> B.index x 0ul) inline_for_extraction let serialize_u8_impl : serializer_impl serialize_u8 = (fun output (len: U32.t { len == B.len output } ) x -> let h = HST.get () in if len `U32.lt` 1ul then None else begin let output' = B.sub output 0ul 1ul in B.upd output' 0ul x; let h' = HST.get () in assert (B.as_seq h' output' `Seq.equal` Seq.create 1 x); Some 1ul end) inline_for_extraction let parse_u16_impl : parser_impl parse_u16 = make_total_constant_size_parser_impl 2 2ul parse_u16_aux () (fun x -> let lo = B.index x 0ul in let hi = B.index x 1ul in Aux.decode_u16 (lo, hi) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MiniParse.Spec.Int.Aux.fst.checked", "MiniParse.Spec.Int.fst.checked", "MiniParse.Impl.Combinators.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "MiniParse.Impl.Int.fst" }
[ { "abbrev": true, "full_module": "MiniParse.Spec.Int.Aux", "short_module": "Aux" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": false, "full_module": "MiniParse.Impl.Combinators", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Impl", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
MiniParse.Impl.Base.serializer_impl MiniParse.Spec.Int.serialize_u16
Prims.Tot
[ "total" ]
[]
[ "MiniParse.Impl.Base.buffer8", "FStar.UInt32.t", "Prims.eq2", "LowStar.Monotonic.Buffer.len", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "FStar.UInt16.t", "FStar.UInt32.lt", "FStar.UInt32.__uint_to_t", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "Prims.bool", "FStar.Pervasives.Native.Some", "Prims.unit", "Prims._assert", "FStar.Seq.Base.equal", "LowStar.Monotonic.Buffer.as_seq", "FStar.Seq.Base.append", "FStar.Seq.Base.create", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.upd", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.sub", "FStar.Ghost.hide", "FStar.Pervasives.Native.tuple2", "MiniParse.Spec.Int.Aux.encode_u16" ]
[]
false
false
false
true
false
let serialize_u16_impl:serializer_impl serialize_u16 =
fun output (len: U32.t{len == B.len output}) x -> if len `U32.lt` 2ul then None else let lo, hi = Aux.encode_u16 x in let output' = B.sub output 0ul 2ul in B.upd output' 0ul lo; B.upd output' 1ul hi; let h' = HST.get () in assert ((B.as_seq h' output') `Seq.equal` (Seq.append (Seq.create 1 lo) (Seq.create 1 hi))); Some 2ul
false
Spec.RSAPSS.fst
Spec.RSAPSS.os2ip
val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)})
val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)})
let os2ip #len b = nat_from_bytes_be b
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 73, "start_col": 0, "start_line": 73 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *)
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Lib.ByteSequence.lbytes len -> res: Prims.nat{res < Prims.pow2 (8 * len)}
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_nat", "Lib.ByteSequence.lbytes", "Lib.ByteSequence.nat_from_bytes_be", "Lib.IntTypes.SEC", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "FStar.Mul.op_Star" ]
[]
false
false
false
false
false
let os2ip #len b =
nat_from_bytes_be b
false
Spec.RSAPSS.fst
Spec.RSAPSS.rsapss_verify
val rsapss_verify: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat -> k:size_nat -> sgnt:lbytes k -> msgLen:nat -> msg:bytes{length msg == msgLen} -> Tot bool
val rsapss_verify: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat -> k:size_nat -> sgnt:lbytes k -> msgLen:nat -> msg:bytes{length msg == msgLen} -> Tot bool
let rsapss_verify a modBits pkey sLen k sgnt msgLen msg = let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && k = blocks modBits 8 in if b then rsapss_verify_ a modBits pkey sLen sgnt msgLen msg else false
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 9, "end_line": 359, "start_col": 0, "start_line": 349 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len) let i2osp len n = nat_to_intseq_be len n /// /// RSA /// type modBits_t = modBits:size_nat{1 < modBits} noeq type rsapss_pkey (modBits:modBits_t) = | Mk_rsapss_pkey: n:pos{pow2 (modBits - 1) < n /\ n < pow2 modBits} -> e:pos -> rsapss_pkey modBits noeq type rsapss_skey (modBits:modBits_t) = | Mk_rsapss_skey: pkey:rsapss_pkey modBits -> d:pos -> rsapss_skey modBits val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0]))) let db_zero #len db emBits = let msBits = emBits % 8 in if msBits > 0 then begin let r = db.[0] <- db.[0] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[0] (u8 0xff >>. size (8 - msBits)) msBits; r end else db val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8) let pss_encode a sLen salt msgLen msg emBits = let mHash = Hash.hash a msg in let hLen = Hash.hash_length a in //m1 = [8 * 0x00; mHash; salt] let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash = Hash.hash a m1 in //db = [0x00;..; 0x00; 0x01; salt] let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let db = create dbLen (u8 0) in let last_before_salt = dbLen - sLen - 1 in let db = db.[last_before_salt] <- u8 1 in let db = update_sub db (last_before_salt + 1) sLen salt in let dbMask = mgf_hash a hLen m1Hash dbLen in let maskedDB = xor_bytes db dbMask in let maskedDB = db_zero maskedDB emBits in //em = [maskedDB; m1Hash; 0xbc] let em = create emLen (u8 0) in let em = update_sub em 0 dbLen maskedDB in let em = update_sub em dbLen hLen m1Hash in assert (v em.[0] == v maskedDB.[0]); em.[emLen - 1] <- u8 0xbc val pss_verify_: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{sLen + Hash.hash_length a + 2 <= blocks emBits 8} -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify_ a sLen msgLen msg emBits em = let hLen = Hash.hash_length a in let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let maskedDB = sub em 0 dbLen in let m1Hash = sub em dbLen hLen in let dbMask = mgf_hash a hLen m1Hash dbLen in let db = xor_bytes dbMask maskedDB in let db = db_zero db emBits in let padLen = emLen - sLen - hLen - 1 in let pad2 = create padLen (u8 0) in let pad2 = pad2.[padLen - 1] <- u8 0x01 in let pad = sub db 0 padLen in let salt = sub db padLen sLen in if not (lbytes_eq pad pad2) then false else begin let mHash = Hash.hash a msg in let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash0 = Hash.hash a m1 in lbytes_eq m1Hash0 m1Hash end val pss_verify: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify a sLen msgLen msg emBits em = let emLen = blocks emBits 8 in let msBits = emBits % 8 in let em_0 = if msBits > 0 then em.[0] &. (u8 0xff <<. size msBits) else u8 0 in let em_last = em.[emLen - 1] in if (emLen < sLen + Hash.hash_length a + 2) then false else begin if not (FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_last =^ 0xbcuy) && FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_0 =^ 0uy)) then false else pss_verify_ a sLen msgLen msg emBits em end val os2ip_lemma: emBits:size_pos -> em:lbytes (blocks emBits 8) -> Lemma (requires (if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8)) (ensures os2ip #(blocks emBits 8) em < pow2 emBits) let os2ip_lemma emBits em = let emLen = blocks emBits 8 in let aux (emBits:size_pos{emBits % 8 > 0}) : Lemma (8 * ((emBits - 1) / 8) + emBits % 8 <= emBits) = assert ((emBits - 1) / 8 <= emBits / 8) in if emBits % 8 > 0 then begin nat_from_intseq_be_slice_lemma em 1; nat_from_intseq_be_lemma0 (slice em 0 1); assert (nat_from_bytes_be em == nat_from_bytes_be (slice em 1 emLen) + pow2 ((emLen - 1) * 8) * v em.[0]); assert (nat_from_bytes_be em < pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]); calc (<=) { pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]; (==) { Math.Lemmas.distributivity_add_right (pow2 (8 * (emLen - 1))) 1 (v em.[0]) } pow2 (8 * (emLen - 1)) * (1 + v em.[0]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (8 * emLen - 1)) (v em.[0] + 1) (pow2 (emBits % 8)) } pow2 (8 * (emLen - 1)) * pow2 (emBits % 8); (==) { Math.Lemmas.pow2_plus (8 * (emLen - 1)) (emBits % 8) } pow2 (8 * ((emBits - 1) / 8) + emBits % 8); (<=) { aux emBits; Math.Lemmas.pow2_le_compat emBits ((emBits - 1) - (emBits - 1) % 8 + emBits % 8) } pow2 emBits; }; assert (nat_from_bytes_be em < pow2 emBits) end else begin assert (nat_from_bytes_be em < pow2 (emLen * 8)); assert (emBits == 8 * emLen) end val rsapss_sign_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a /\ sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> tuple2 bool (lbytes (blocks modBits 8)) let rsapss_sign_ a modBits skey sLen salt msgLen msg = let pkey = Mk_rsapss_skey?.pkey skey in let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let d = Mk_rsapss_skey?.d skey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let em = pss_encode a sLen salt msgLen msg emBits in let m = os2ip #emLen em in os2ip_lemma emBits em; let s = pow_mod #n m d in let m' = pow_mod #n s e in let eq_m = m = m' in let s = if eq_m then s else 0 in (eq_m, i2osp k s) val rsapss_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8)) let rsapss_sign a modBits skey sLen salt msgLen msg = let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8 in if b then begin let (eq_m, sgnt) = rsapss_sign_ a modBits skey sLen salt msgLen msg in if eq_m then Some sgnt else None end else None val rsapss_verify_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> sgnt:lbytes (blocks modBits 8) -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> Tot bool let rsapss_verify_ a modBits pkey sLen sgnt msgLen msg = let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let s = os2ip #k sgnt in if s < n then begin let m = pow_mod #n s e in if m < pow2 (emLen * 8) then let em = i2osp emLen m in pss_verify a sLen msgLen msg emBits em else false end else false val rsapss_verify: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat -> k:size_nat -> sgnt:lbytes k -> msgLen:nat -> msg:bytes{length msg == msgLen} -> Tot bool
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} -> modBits: Spec.RSAPSS.modBits_t -> pkey: Spec.RSAPSS.rsapss_pkey modBits -> sLen: Lib.IntTypes.size_nat -> k: Lib.IntTypes.size_nat -> sgnt: Lib.ByteSequence.lbytes k -> msgLen: Prims.nat -> msg: Lib.ByteSequence.bytes{Lib.Sequence.length msg == msgLen} -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.RSAPSS.hash_is_supported", "Spec.RSAPSS.modBits_t", "Spec.RSAPSS.rsapss_pkey", "Lib.IntTypes.size_nat", "Lib.ByteSequence.lbytes", "Prims.nat", "Lib.ByteSequence.bytes", "Prims.eq2", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Spec.RSAPSS.rsapss_verify_", "Prims.bool", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Spec.Hash.Definitions.hash_length", "Lib.IntTypes.max_size_t", "Spec.Hash.Definitions.less_than_max_input_length", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.l_and", "Prims.op_GreaterThanOrEqual", "Prims.op_GreaterThan", "FStar.Mul.op_Star", "Spec.RSAPSS.blocks" ]
[]
false
false
false
false
false
let rsapss_verify a modBits pkey sLen k sgnt msgLen msg =
let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && k = blocks modBits 8 in if b then rsapss_verify_ a modBits pkey sLen sgnt msgLen msg else false
false
Vale.Transformers.MovbeElim.fst
Vale.Transformers.MovbeElim.lemma_movbe_is_mov_bswap
val lemma_movbe_is_mov_bswap (dst src: operand64) (s: machine_state) : Lemma (requires (OReg? dst)) (ensures (let movbe = make_instr_annotate ins_MovBe64 (AnnotateMovbe64 ()) dst src in let mov = make_instr ins_Mov64 dst src in let bswap = make_instr ins_Bswap64 dst in let s1 = machine_eval_ins movbe s in let s2 = machine_eval_ins bswap (machine_eval_ins mov s) in s1.ms_ok ==> equiv_states s1 s2))
val lemma_movbe_is_mov_bswap (dst src: operand64) (s: machine_state) : Lemma (requires (OReg? dst)) (ensures (let movbe = make_instr_annotate ins_MovBe64 (AnnotateMovbe64 ()) dst src in let mov = make_instr ins_Mov64 dst src in let bswap = make_instr ins_Bswap64 dst in let s1 = machine_eval_ins movbe s in let s2 = machine_eval_ins bswap (machine_eval_ins mov s) in s1.ms_ok ==> equiv_states s1 s2))
let lemma_movbe_is_mov_bswap (dst src:operand64) (s:machine_state) : Lemma (requires (OReg? dst)) (ensures ( let movbe = make_instr_annotate ins_MovBe64 (AnnotateMovbe64 ()) dst src in let mov = make_instr ins_Mov64 dst src in let bswap = make_instr ins_Bswap64 dst in let s1 = machine_eval_ins movbe s in let s2 = machine_eval_ins bswap (machine_eval_ins mov s) in s1.ms_ok ==> equiv_states s1 s2)) = let movbe = make_instr_annotate ins_MovBe64 (AnnotateMovbe64 ()) dst src in let mov = make_instr ins_Mov64 dst src in let bswap = make_instr ins_Bswap64 dst in let s_movbe = machine_eval_ins movbe s in let s_mov = machine_eval_ins mov s in let s_bswap = machine_eval_ins bswap s_mov in if valid_src_operand64_and_taint src s && valid_dst_operand64 dst s then ( let src_v = eval_operand src s in let dst_movbe_v = T.reverse_bytes_nat64 src_v in let dst_mov_v = eval_operand dst s_mov in let dst_bswap_v = T.reverse_bytes_nat64 dst_mov_v in if s_movbe.ms_ok then ( assert (Vale.X64.CPU_Features_s.movbe_enabled); assert (s_movbe == update_operand64_preserve_flags'' dst dst_movbe_v s s); assert (s_mov == update_operand64_preserve_flags'' dst src_v s s); lemma_update_to_valid_destination_keeps_it_as_valid_src dst s src_v; assert (eval_operand dst s_mov == src_v); assert (valid_src_operand64_and_taint dst s_mov); assert (s_bswap == update_operand64_preserve_flags'' dst dst_bswap_v s_mov s_mov); assert (src_v == dst_mov_v); assert (dst_movbe_v == dst_bswap_v); lemma_double_update_reg dst s s_mov s_bswap s_movbe src_v dst_bswap_v ) else () ) else ( assert (s_movbe == {s with ms_ok = false}); assert (s_mov == {s with ms_ok = false}); assert (s_bswap.ms_ok == false) )
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.MovbeElim.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 70, "start_col": 0, "start_line": 33 }
module Vale.Transformers.MovbeElim open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Transformers.InstructionReorder open Vale.X64.InsLemmas open Vale.Transformers.PeepHole let movbe_elim_ph = { ph = (function | [Instr i oprs (AnnotateMovbe64 proof_of_movbe)] -> let oprs:normal (instr_operands_t [out op64] [op64]) = coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs in let (dst, (src, ())) = oprs in if OReg? dst then ( let mov = make_instr ins_Mov64 dst src in let bswap = make_instr ins_Bswap64 dst in Some [mov; bswap] ) else None | _ -> None); input_hint = 1; } module T = Vale.Def.Types_s module H = Vale.Arch.Heap
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.InsLemmas.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.PeepHole.fsti.checked", "Vale.Transformers.InstructionReorder.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.MovbeElim.fst" }
[ { "abbrev": true, "full_module": "Vale.Arch.Heap", "short_module": "H" }, { "abbrev": true, "full_module": "Vale.Def.Types_s", "short_module": "T" }, { "abbrev": false, "full_module": "Vale.Transformers.PeepHole", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.InstructionReorder", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 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": 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
dst: Vale.X64.Machine_s.operand64 -> src: Vale.X64.Machine_s.operand64 -> s: Vale.X64.Machine_Semantics_s.machine_state -> FStar.Pervasives.Lemma (requires OReg? dst) (ensures (let movbe = Vale.X64.InsLemmas.make_instr_annotate Vale.X64.Instructions_s.ins_MovBe64 (Vale.X64.Machine_Semantics_s.AnnotateMovbe64 ()) dst src in let mov = Vale.X64.InsLemmas.make_instr Vale.X64.Instructions_s.ins_Mov64 dst src in let bswap = Vale.X64.InsLemmas.make_instr Vale.X64.Instructions_s.ins_Bswap64 dst in let s1 = Vale.X64.Machine_Semantics_s.machine_eval_ins movbe s in let s2 = Vale.X64.Machine_Semantics_s.machine_eval_ins bswap (Vale.X64.Machine_Semantics_s.machine_eval_ins mov s) in Mkmachine_state?.ms_ok s1 ==> Vale.Transformers.InstructionReorder.equiv_states s1 s2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.X64.Machine_s.operand64", "Vale.X64.Machine_Semantics_s.machine_state", "Prims.op_AmpAmp", "Vale.X64.Machine_Semantics_s.valid_src_operand64_and_taint", "Vale.X64.Machine_Semantics_s.valid_dst_operand64", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok", "Vale.Transformers.PeepHole.lemma_double_update_reg", "Prims.unit", "Prims._assert", "Prims.eq2", "Vale.Def.Types_s.nat64", "Vale.X64.Machine_Semantics_s.update_operand64_preserve_flags''", "Prims.b2t", "Vale.X64.Machine_Semantics_s.eval_operand", "Vale.Transformers.PeepHole.lemma_update_to_valid_destination_keeps_it_as_valid_src", "Vale.X64.CPU_Features_s.movbe_enabled", "Prims.bool", "Vale.Def.Words_s.nat64", "Vale.Def.Types_s.reverse_bytes_nat64", "Vale.X64.Machine_Semantics_s.Mkmachine_state", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_regs", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_flags", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_heap", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stack", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_stackTaint", "Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace", "Vale.X64.Machine_Semantics_s.machine_eval_ins", "Vale.X64.InsLemmas.make_instr_t", "Prims.Nil", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.InsLemmas.make_instr", "Prims.Cons", "Vale.X64.Instruction_s.inOut", "Vale.X64.Instruction_s.op64", "Vale.X64.Instruction_s.PreserveFlags", "Vale.X64.Instructions_s.ins_Bswap64", "Vale.X64.InsLemmas.make_instr_t_args", "Vale.X64.Instruction_s.out", "Vale.X64.Instructions_s.ins_Mov64", "Vale.X64.InsLemmas.make_instr_annotate", "Vale.X64.Instructions_s.ins_MovBe64", "Vale.X64.Machine_Semantics_s.AnnotateMovbe64", "Vale.X64.Instruction_s.InstrTypeRecord", "Vale.X64.Machine_s.uu___is_OReg", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Prims.squash", "Prims.l_imp", "Vale.Transformers.InstructionReorder.equiv_states", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_movbe_is_mov_bswap (dst src: operand64) (s: machine_state) : Lemma (requires (OReg? dst)) (ensures (let movbe = make_instr_annotate ins_MovBe64 (AnnotateMovbe64 ()) dst src in let mov = make_instr ins_Mov64 dst src in let bswap = make_instr ins_Bswap64 dst in let s1 = machine_eval_ins movbe s in let s2 = machine_eval_ins bswap (machine_eval_ins mov s) in s1.ms_ok ==> equiv_states s1 s2)) =
let movbe = make_instr_annotate ins_MovBe64 (AnnotateMovbe64 ()) dst src in let mov = make_instr ins_Mov64 dst src in let bswap = make_instr ins_Bswap64 dst in let s_movbe = machine_eval_ins movbe s in let s_mov = machine_eval_ins mov s in let s_bswap = machine_eval_ins bswap s_mov in if valid_src_operand64_and_taint src s && valid_dst_operand64 dst s then (let src_v = eval_operand src s in let dst_movbe_v = T.reverse_bytes_nat64 src_v in let dst_mov_v = eval_operand dst s_mov in let dst_bswap_v = T.reverse_bytes_nat64 dst_mov_v in if s_movbe.ms_ok then (assert (Vale.X64.CPU_Features_s.movbe_enabled); assert (s_movbe == update_operand64_preserve_flags'' dst dst_movbe_v s s); assert (s_mov == update_operand64_preserve_flags'' dst src_v s s); lemma_update_to_valid_destination_keeps_it_as_valid_src dst s src_v; assert (eval_operand dst s_mov == src_v); assert (valid_src_operand64_and_taint dst s_mov); assert (s_bswap == update_operand64_preserve_flags'' dst dst_bswap_v s_mov s_mov); assert (src_v == dst_mov_v); assert (dst_movbe_v == dst_bswap_v); lemma_double_update_reg dst s s_mov s_bswap s_movbe src_v dst_bswap_v)) else (assert (s_movbe == { s with ms_ok = false }); assert (s_mov == { s with ms_ok = false }); assert (s_bswap.ms_ok == false))
false
Spec.RSAPSS.fst
Spec.RSAPSS.db_zero
val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0])))
val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0])))
let db_zero #len db emBits = let msBits = emBits % 8 in if msBits > 0 then begin let r = db.[0] <- db.[0] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[0] (u8 0xff >>. size (8 - msBits)) msBits; r end else db
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 9, "end_line": 104, "start_col": 0, "start_line": 97 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len) let i2osp len n = nat_to_intseq_be len n /// /// RSA /// type modBits_t = modBits:size_nat{1 < modBits} noeq type rsapss_pkey (modBits:modBits_t) = | Mk_rsapss_pkey: n:pos{pow2 (modBits - 1) < n /\ n < pow2 modBits} -> e:pos -> rsapss_pkey modBits noeq type rsapss_skey (modBits:modBits_t) = | Mk_rsapss_skey: pkey:rsapss_pkey modBits -> d:pos -> rsapss_skey modBits val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0])))
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 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
db: Lib.ByteSequence.lbytes len -> emBits: Lib.IntTypes.size_nat -> Prims.Pure (Lib.ByteSequence.lbytes len)
Prims.Pure
[]
[]
[ "Lib.IntTypes.size_pos", "Lib.ByteSequence.lbytes", "Lib.IntTypes.size_nat", "Prims.op_GreaterThan", "Prims.unit", "Lib.IntTypes.logand_mask", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Lib.IntTypes.uint_t", "Lib.IntTypes.op_Greater_Greater_Dot", "Lib.IntTypes.u8", "Lib.IntTypes.size", "Prims.op_Subtraction", "FStar.Math.Lemmas.pow2_plus", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Prims.l_and", "Prims.eq2", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.upd", "Lib.IntTypes.logand", "Lib.Sequence.index", "Lib.IntTypes.shift_right", "Lib.IntTypes.mk_int", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.l_Forall", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.pow2", "Prims.l_imp", "Prims.op_LessThan", "Prims.op_disEquality", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.op_String_Assignment", "Lib.IntTypes.op_Amp_Dot", "Prims.bool", "Prims.int", "Prims.op_Modulus" ]
[]
false
false
false
false
false
let db_zero #len db emBits =
let msBits = emBits % 8 in if msBits > 0 then let r = db.[ 0 ] <- db.[ 0 ] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[ 0 ] (u8 0xff >>. size (8 - msBits)) msBits; r else db
false
Spec.RSAPSS.fst
Spec.RSAPSS.mgf_hash_f
val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a)
val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a)
let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 50, "start_col": 0, "start_line": 46 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a)
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} -> len: Lib.IntTypes.size_nat { len + 4 <= Lib.IntTypes.max_size_t /\ Spec.Hash.Definitions.less_than_max_input_length (len + 4) a } -> i: Lib.IntTypes.size_nat -> mgfseed_counter: Lib.ByteSequence.lbytes (len + 4) -> Lib.ByteSequence.lbytes (len + 4) * Lib.ByteSequence.lbytes (Spec.Hash.Definitions.hash_length a)
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.RSAPSS.hash_is_supported", "Lib.IntTypes.size_nat", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Spec.Hash.Definitions.less_than_max_input_length", "Lib.ByteSequence.lbytes", "FStar.Pervasives.Native.Mktuple2", "Spec.Hash.Definitions.hash_length", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Spec.Hash.Definitions.hash_length'", "Spec.Agile.Hash.hash", "Prims.eq2", "Lib.Sequence.sub", "Prims.l_Forall", "Prims.nat", "Prims.l_or", "Prims.op_LessThan", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.Sequence.update_sub", "Lib.IntTypes.uint_t", "Lib.Sequence.seq", "Lib.Sequence.length", "Prims.pow2", "Prims.op_Multiply", "Lib.ByteSequence.nat_from_intseq_be", "Lib.ByteSequence.nat_to_intseq_be", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let mgf_hash_f a len i mgfseed_counter =
let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block
false
Spec.RSAPSS.fst
Spec.RSAPSS.rsapss_sign
val rsapss_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8))
val rsapss_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8))
let rsapss_sign a modBits skey sLen salt msgLen msg = let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8 in if b then begin let (eq_m, sgnt) = rsapss_sign_ a modBits skey sLen salt msgLen msg in if eq_m then Some sgnt else None end else None
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 8, "end_line": 304, "start_col": 0, "start_line": 293 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len) let i2osp len n = nat_to_intseq_be len n /// /// RSA /// type modBits_t = modBits:size_nat{1 < modBits} noeq type rsapss_pkey (modBits:modBits_t) = | Mk_rsapss_pkey: n:pos{pow2 (modBits - 1) < n /\ n < pow2 modBits} -> e:pos -> rsapss_pkey modBits noeq type rsapss_skey (modBits:modBits_t) = | Mk_rsapss_skey: pkey:rsapss_pkey modBits -> d:pos -> rsapss_skey modBits val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0]))) let db_zero #len db emBits = let msBits = emBits % 8 in if msBits > 0 then begin let r = db.[0] <- db.[0] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[0] (u8 0xff >>. size (8 - msBits)) msBits; r end else db val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8) let pss_encode a sLen salt msgLen msg emBits = let mHash = Hash.hash a msg in let hLen = Hash.hash_length a in //m1 = [8 * 0x00; mHash; salt] let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash = Hash.hash a m1 in //db = [0x00;..; 0x00; 0x01; salt] let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let db = create dbLen (u8 0) in let last_before_salt = dbLen - sLen - 1 in let db = db.[last_before_salt] <- u8 1 in let db = update_sub db (last_before_salt + 1) sLen salt in let dbMask = mgf_hash a hLen m1Hash dbLen in let maskedDB = xor_bytes db dbMask in let maskedDB = db_zero maskedDB emBits in //em = [maskedDB; m1Hash; 0xbc] let em = create emLen (u8 0) in let em = update_sub em 0 dbLen maskedDB in let em = update_sub em dbLen hLen m1Hash in assert (v em.[0] == v maskedDB.[0]); em.[emLen - 1] <- u8 0xbc val pss_verify_: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{sLen + Hash.hash_length a + 2 <= blocks emBits 8} -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify_ a sLen msgLen msg emBits em = let hLen = Hash.hash_length a in let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let maskedDB = sub em 0 dbLen in let m1Hash = sub em dbLen hLen in let dbMask = mgf_hash a hLen m1Hash dbLen in let db = xor_bytes dbMask maskedDB in let db = db_zero db emBits in let padLen = emLen - sLen - hLen - 1 in let pad2 = create padLen (u8 0) in let pad2 = pad2.[padLen - 1] <- u8 0x01 in let pad = sub db 0 padLen in let salt = sub db padLen sLen in if not (lbytes_eq pad pad2) then false else begin let mHash = Hash.hash a msg in let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash0 = Hash.hash a m1 in lbytes_eq m1Hash0 m1Hash end val pss_verify: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify a sLen msgLen msg emBits em = let emLen = blocks emBits 8 in let msBits = emBits % 8 in let em_0 = if msBits > 0 then em.[0] &. (u8 0xff <<. size msBits) else u8 0 in let em_last = em.[emLen - 1] in if (emLen < sLen + Hash.hash_length a + 2) then false else begin if not (FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_last =^ 0xbcuy) && FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_0 =^ 0uy)) then false else pss_verify_ a sLen msgLen msg emBits em end val os2ip_lemma: emBits:size_pos -> em:lbytes (blocks emBits 8) -> Lemma (requires (if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8)) (ensures os2ip #(blocks emBits 8) em < pow2 emBits) let os2ip_lemma emBits em = let emLen = blocks emBits 8 in let aux (emBits:size_pos{emBits % 8 > 0}) : Lemma (8 * ((emBits - 1) / 8) + emBits % 8 <= emBits) = assert ((emBits - 1) / 8 <= emBits / 8) in if emBits % 8 > 0 then begin nat_from_intseq_be_slice_lemma em 1; nat_from_intseq_be_lemma0 (slice em 0 1); assert (nat_from_bytes_be em == nat_from_bytes_be (slice em 1 emLen) + pow2 ((emLen - 1) * 8) * v em.[0]); assert (nat_from_bytes_be em < pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]); calc (<=) { pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]; (==) { Math.Lemmas.distributivity_add_right (pow2 (8 * (emLen - 1))) 1 (v em.[0]) } pow2 (8 * (emLen - 1)) * (1 + v em.[0]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (8 * emLen - 1)) (v em.[0] + 1) (pow2 (emBits % 8)) } pow2 (8 * (emLen - 1)) * pow2 (emBits % 8); (==) { Math.Lemmas.pow2_plus (8 * (emLen - 1)) (emBits % 8) } pow2 (8 * ((emBits - 1) / 8) + emBits % 8); (<=) { aux emBits; Math.Lemmas.pow2_le_compat emBits ((emBits - 1) - (emBits - 1) % 8 + emBits % 8) } pow2 emBits; }; assert (nat_from_bytes_be em < pow2 emBits) end else begin assert (nat_from_bytes_be em < pow2 (emLen * 8)); assert (emBits == 8 * emLen) end val rsapss_sign_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a /\ sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> tuple2 bool (lbytes (blocks modBits 8)) let rsapss_sign_ a modBits skey sLen salt msgLen msg = let pkey = Mk_rsapss_skey?.pkey skey in let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let d = Mk_rsapss_skey?.d skey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let em = pss_encode a sLen salt msgLen msg emBits in let m = os2ip #emLen em in os2ip_lemma emBits em; let s = pow_mod #n m d in let m' = pow_mod #n s e in let eq_m = m = m' in let s = if eq_m then s else 0 in (eq_m, i2osp k s) val rsapss_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8))
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} -> modBits: Spec.RSAPSS.modBits_t -> skey: Spec.RSAPSS.rsapss_skey modBits -> sLen: Lib.IntTypes.size_nat -> salt: Lib.ByteSequence.lbytes sLen -> msgLen: Prims.nat -> msg: Lib.ByteSequence.bytes{Lib.Sequence.length msg == msgLen} -> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes (Spec.RSAPSS.blocks modBits 8))
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.RSAPSS.hash_is_supported", "Spec.RSAPSS.modBits_t", "Spec.RSAPSS.rsapss_skey", "Lib.IntTypes.size_nat", "Lib.ByteSequence.lbytes", "Prims.nat", "Lib.ByteSequence.bytes", "Prims.eq2", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Prims.bool", "Spec.RSAPSS.blocks", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Spec.RSAPSS.rsapss_sign_", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Spec.Hash.Definitions.hash_length", "Lib.IntTypes.max_size_t", "Spec.Hash.Definitions.less_than_max_input_length", "Prims.op_Subtraction" ]
[]
false
false
false
false
false
let rsapss_sign a modBits skey sLen salt msgLen msg =
let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8 in if b then let eq_m, sgnt = rsapss_sign_ a modBits skey sLen salt msgLen msg in if eq_m then Some sgnt else None else None
false
Vale.Transformers.MovbeElim.fst
Vale.Transformers.MovbeElim.movbe_elim_correct
val movbe_elim_correct (is: list ins) (s: machine_state) : Lemma (peephole_correct movbe_elim_ph is s) [SMTPat (peephole_correct movbe_elim_ph is s)]
val movbe_elim_correct (is: list ins) (s: machine_state) : Lemma (peephole_correct movbe_elim_ph is s) [SMTPat (peephole_correct movbe_elim_ph is s)]
let movbe_elim_correct (is:list ins) (s:machine_state) : Lemma (peephole_correct movbe_elim_ph is s) [SMTPat (peephole_correct movbe_elim_ph is s)] = match is with | [Instr i oprs (AnnotateMovbe64 proof_of_movbe)] -> let oprs:normal (instr_operands_t [out op64] [op64]) = coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs in let (dst, (src, ())) = oprs in if OReg? dst then ( let Some is' = movbe_elim_ph.ph is in lemma_movbe_is_mov_bswap dst src s ) else () | _ -> ()
{ "file_name": "vale/code/lib/transformers/Vale.Transformers.MovbeElim.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 11, "end_line": 86, "start_col": 0, "start_line": 74 }
module Vale.Transformers.MovbeElim open Vale.X64.Bytes_Code_s open Vale.X64.Instruction_s open Vale.X64.Instructions_s open Vale.X64.Machine_Semantics_s open Vale.X64.Machine_s open Vale.X64.Print_s open Vale.Transformers.InstructionReorder open Vale.X64.InsLemmas open Vale.Transformers.PeepHole let movbe_elim_ph = { ph = (function | [Instr i oprs (AnnotateMovbe64 proof_of_movbe)] -> let oprs:normal (instr_operands_t [out op64] [op64]) = coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs in let (dst, (src, ())) = oprs in if OReg? dst then ( let mov = make_instr ins_Mov64 dst src in let bswap = make_instr ins_Bswap64 dst in Some [mov; bswap] ) else None | _ -> None); input_hint = 1; } module T = Vale.Def.Types_s module H = Vale.Arch.Heap #push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 0 --max_ifuel 0" let lemma_movbe_is_mov_bswap (dst src:operand64) (s:machine_state) : Lemma (requires (OReg? dst)) (ensures ( let movbe = make_instr_annotate ins_MovBe64 (AnnotateMovbe64 ()) dst src in let mov = make_instr ins_Mov64 dst src in let bswap = make_instr ins_Bswap64 dst in let s1 = machine_eval_ins movbe s in let s2 = machine_eval_ins bswap (machine_eval_ins mov s) in s1.ms_ok ==> equiv_states s1 s2)) = let movbe = make_instr_annotate ins_MovBe64 (AnnotateMovbe64 ()) dst src in let mov = make_instr ins_Mov64 dst src in let bswap = make_instr ins_Bswap64 dst in let s_movbe = machine_eval_ins movbe s in let s_mov = machine_eval_ins mov s in let s_bswap = machine_eval_ins bswap s_mov in if valid_src_operand64_and_taint src s && valid_dst_operand64 dst s then ( let src_v = eval_operand src s in let dst_movbe_v = T.reverse_bytes_nat64 src_v in let dst_mov_v = eval_operand dst s_mov in let dst_bswap_v = T.reverse_bytes_nat64 dst_mov_v in if s_movbe.ms_ok then ( assert (Vale.X64.CPU_Features_s.movbe_enabled); assert (s_movbe == update_operand64_preserve_flags'' dst dst_movbe_v s s); assert (s_mov == update_operand64_preserve_flags'' dst src_v s s); lemma_update_to_valid_destination_keeps_it_as_valid_src dst s src_v; assert (eval_operand dst s_mov == src_v); assert (valid_src_operand64_and_taint dst s_mov); assert (s_bswap == update_operand64_preserve_flags'' dst dst_bswap_v s_mov s_mov); assert (src_v == dst_mov_v); assert (dst_movbe_v == dst_bswap_v); lemma_double_update_reg dst s s_mov s_bswap s_movbe src_v dst_bswap_v ) else () ) else ( assert (s_movbe == {s with ms_ok = false}); assert (s_mov == {s with ms_ok = false}); assert (s_bswap.ms_ok == false) ) #pop-options
{ "checked_file": "/", "dependencies": [ "Vale.X64.Print_s.fst.checked", "Vale.X64.Machine_Semantics_s.fst.checked", "Vale.X64.Machine_s.fst.checked", "Vale.X64.Instructions_s.fsti.checked", "Vale.X64.Instruction_s.fsti.checked", "Vale.X64.InsLemmas.fsti.checked", "Vale.X64.CPU_Features_s.fst.checked", "Vale.X64.Bytes_Code_s.fst.checked", "Vale.Transformers.PeepHole.fsti.checked", "Vale.Transformers.InstructionReorder.fst.checked", "Vale.Def.Types_s.fst.checked", "Vale.Arch.Heap.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Vale.Transformers.MovbeElim.fst" }
[ { "abbrev": true, "full_module": "Vale.Arch.Heap", "short_module": "H" }, { "abbrev": true, "full_module": "Vale.Def.Types_s", "short_module": "T" }, { "abbrev": false, "full_module": "Vale.Transformers.PeepHole", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.InsLemmas", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers.InstructionReorder", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Print_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Machine_Semantics_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instructions_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Instruction_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.X64.Bytes_Code_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "Vale.Transformers", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 3, "initial_ifuel": 0, "max_fuel": 3, "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": 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
is: Prims.list Vale.X64.Machine_Semantics_s.ins -> s: Vale.X64.Machine_Semantics_s.machine_state -> FStar.Pervasives.Lemma (ensures Vale.Transformers.PeepHole.peephole_correct Vale.Transformers.MovbeElim.movbe_elim_ph is s) [ SMTPat (Vale.Transformers.PeepHole.peephole_correct Vale.Transformers.MovbeElim.movbe_elim_ph is s) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Vale.X64.Machine_Semantics_s.ins", "Vale.X64.Machine_Semantics_s.machine_state", "Vale.X64.Instruction_s.instr_t_record", "Vale.X64.Instruction_s.instr_operands_t", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__outs", "Vale.X64.Instruction_s.__proj__InstrTypeRecord__item__args", "Vale.X64.Machine_Semantics_s.equals_instr", "Vale.X64.Instruction_s.InstrTypeRecord", "Prims.Cons", "Vale.X64.Instruction_s.instr_out", "Vale.X64.Instruction_s.out", "Vale.X64.Instruction_s.op64", "Prims.Nil", "Vale.X64.Instruction_s.instr_operand", "Vale.X64.Instruction_s.PreserveFlags", "Vale.X64.Instructions_s.ins_MovBe64", "Vale.X64.Machine_s.operand64", "Vale.X64.Machine_s.uu___is_OReg", "Vale.X64.Machine_s.nat64", "Vale.X64.Machine_s.reg_64", "Vale.Transformers.MovbeElim.lemma_movbe_is_mov_bswap", "Prims.unit", "FStar.Pervasives.Native.option", "Vale.Transformers.PeepHole.__proj__Mkpre_peephole__item__ph", "Vale.Transformers.MovbeElim.movbe_elim_ph", "Prims.bool", "FStar.Pervasives.norm", "FStar.Pervasives.norm_step", "FStar.Pervasives.zeta", "FStar.Pervasives.iota", "FStar.Pervasives.delta_attr", "Prims.string", "FStar.Pervasives.Native.Mktuple2", "Vale.X64.Instruction_s.instr_operand_inout", "Vale.X64.Instruction_s.Out", "Vale.X64.Instruction_s.IOpEx", "Vale.X64.Instruction_s.IOp64", "Vale.Transformers.PeepHole.coerce_to_normal", "Prims.l_True", "Prims.squash", "Vale.Transformers.PeepHole.peephole_correct", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat" ]
[]
false
false
true
false
false
let movbe_elim_correct (is: list ins) (s: machine_state) : Lemma (peephole_correct movbe_elim_ph is s) [SMTPat (peephole_correct movbe_elim_ph is s)] =
match is with | [Instr i oprs (AnnotateMovbe64 proof_of_movbe)] -> let oprs:normal (instr_operands_t [out op64] [op64]) = coerce_to_normal #(instr_operands_t [out op64] [op64]) oprs in let dst, (src, ()) = oprs in if OReg? dst then (let Some is' = movbe_elim_ph.ph is in lemma_movbe_is_mov_bswap dst src s) | _ -> ()
false
Spec.RSAPSS.fst
Spec.RSAPSS.mgf_hash
val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen)
val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen)
let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 68, "start_col": 0, "start_line": 61 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen)
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} -> len: Lib.IntTypes.size_nat { len + 4 <= Lib.IntTypes.max_size_t /\ Spec.Hash.Definitions.less_than_max_input_length (len + 4) a } -> mgfseed: Lib.ByteSequence.lbytes len -> maskLen: Lib.IntTypes.size_pos { Spec.RSAPSS.blocks maskLen (Spec.Hash.Definitions.hash_length a) * Spec.Hash.Definitions.hash_length a < Prims.pow2 32 } -> Lib.ByteSequence.lbytes maskLen
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.RSAPSS.hash_is_supported", "Lib.IntTypes.size_nat", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Spec.Hash.Definitions.less_than_max_input_length", "Lib.ByteSequence.lbytes", "Lib.IntTypes.size_pos", "Prims.op_LessThan", "FStar.Mul.op_Star", "Spec.RSAPSS.blocks", "Spec.Hash.Definitions.hash_length", "Prims.pow2", "Spec.RSAPSS.mgf_hash_a", "Lib.Sequence.seq", "Lib.IntTypes.uint8", "Prims.eq2", "Prims.int", "Lib.Sequence.length", "Lib.Sequence.sub", "FStar.Pervasives.Native.tuple2", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Prims.op_Multiply", "Lib.Sequence.generate_blocks", "Spec.RSAPSS.mgf_hash_f", "Prims.pos", "Prims.op_Subtraction", "Prims.nat", "Prims.op_GreaterThan", "Lib.Sequence.lseq", "Prims.l_Forall", "Prims.l_or", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.Sequence.update_sub", "Lib.IntTypes.uint_t", "FStar.Seq.Base.seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Prims.l_imp", "Lib.Sequence.create", "Lib.IntTypes.u8" ]
[]
false
false
false
false
false
let mgf_hash a len mgfseed maskLen =
let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen
false
Spec.RSAPSS.fst
Spec.RSAPSS.pss_verify
val pss_verify: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos -> em:lbytes (blocks emBits 8) -> Tot bool
val pss_verify: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos -> em:lbytes (blocks emBits 8) -> Tot bool
let pss_verify a sLen msgLen msg emBits em = let emLen = blocks emBits 8 in let msBits = emBits % 8 in let em_0 = if msBits > 0 then em.[0] &. (u8 0xff <<. size msBits) else u8 0 in let em_last = em.[emLen - 1] in if (emLen < sLen + Hash.hash_length a + 2) then false else begin if not (FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_last =^ 0xbcuy) && FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_0 =^ 0uy)) then false else pss_verify_ a sLen msgLen msg emBits em end
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 52, "end_line": 212, "start_col": 0, "start_line": 200 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len) let i2osp len n = nat_to_intseq_be len n /// /// RSA /// type modBits_t = modBits:size_nat{1 < modBits} noeq type rsapss_pkey (modBits:modBits_t) = | Mk_rsapss_pkey: n:pos{pow2 (modBits - 1) < n /\ n < pow2 modBits} -> e:pos -> rsapss_pkey modBits noeq type rsapss_skey (modBits:modBits_t) = | Mk_rsapss_skey: pkey:rsapss_pkey modBits -> d:pos -> rsapss_skey modBits val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0]))) let db_zero #len db emBits = let msBits = emBits % 8 in if msBits > 0 then begin let r = db.[0] <- db.[0] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[0] (u8 0xff >>. size (8 - msBits)) msBits; r end else db val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8) let pss_encode a sLen salt msgLen msg emBits = let mHash = Hash.hash a msg in let hLen = Hash.hash_length a in //m1 = [8 * 0x00; mHash; salt] let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash = Hash.hash a m1 in //db = [0x00;..; 0x00; 0x01; salt] let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let db = create dbLen (u8 0) in let last_before_salt = dbLen - sLen - 1 in let db = db.[last_before_salt] <- u8 1 in let db = update_sub db (last_before_salt + 1) sLen salt in let dbMask = mgf_hash a hLen m1Hash dbLen in let maskedDB = xor_bytes db dbMask in let maskedDB = db_zero maskedDB emBits in //em = [maskedDB; m1Hash; 0xbc] let em = create emLen (u8 0) in let em = update_sub em 0 dbLen maskedDB in let em = update_sub em dbLen hLen m1Hash in assert (v em.[0] == v maskedDB.[0]); em.[emLen - 1] <- u8 0xbc val pss_verify_: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{sLen + Hash.hash_length a + 2 <= blocks emBits 8} -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify_ a sLen msgLen msg emBits em = let hLen = Hash.hash_length a in let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let maskedDB = sub em 0 dbLen in let m1Hash = sub em dbLen hLen in let dbMask = mgf_hash a hLen m1Hash dbLen in let db = xor_bytes dbMask maskedDB in let db = db_zero db emBits in let padLen = emLen - sLen - hLen - 1 in let pad2 = create padLen (u8 0) in let pad2 = pad2.[padLen - 1] <- u8 0x01 in let pad = sub db 0 padLen in let salt = sub db padLen sLen in if not (lbytes_eq pad pad2) then false else begin let mHash = Hash.hash a msg in let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash0 = Hash.hash a m1 in lbytes_eq m1Hash0 m1Hash end val pss_verify: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos -> em:lbytes (blocks emBits 8) -> Tot bool
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} -> sLen: Lib.IntTypes.size_nat { sLen + Spec.Hash.Definitions.hash_length a + 8 <= Lib.IntTypes.max_size_t /\ Spec.Hash.Definitions.less_than_max_input_length (sLen + Spec.Hash.Definitions.hash_length a + 8) a } -> msgLen: Prims.nat{Spec.Hash.Definitions.less_than_max_input_length msgLen a} -> msg: Lib.ByteSequence.bytes{Lib.Sequence.length msg == msgLen} -> emBits: Lib.IntTypes.size_pos -> em: Lib.ByteSequence.lbytes (Spec.RSAPSS.blocks emBits 8) -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.RSAPSS.hash_is_supported", "Lib.IntTypes.size_nat", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Spec.Hash.Definitions.hash_length", "Lib.IntTypes.max_size_t", "Spec.Hash.Definitions.less_than_max_input_length", "Prims.nat", "Lib.ByteSequence.bytes", "Prims.eq2", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.IntTypes.size_pos", "Lib.ByteSequence.lbytes", "Spec.RSAPSS.blocks", "Prims.op_LessThan", "Prims.bool", "Prims.op_Negation", "Prims.op_AmpAmp", "FStar.UInt8.op_Equals_Hat", "Lib.RawIntTypes.u8_to_UInt8", "FStar.UInt8.__uint_to_t", "Spec.RSAPSS.pss_verify_", "Lib.IntTypes.int_t", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Prims.op_Subtraction", "Lib.Sequence.op_String_Access", "Prims.op_GreaterThan", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.op_Less_Less_Dot", "Lib.IntTypes.u8", "Lib.IntTypes.size", "Lib.IntTypes.uint8", "Prims.int", "Prims.op_Modulus", "Prims.pos", "Prims.pow2", "Prims.op_Multiply" ]
[]
false
false
false
false
false
let pss_verify a sLen msgLen msg emBits em =
let emLen = blocks emBits 8 in let msBits = emBits % 8 in let em_0 = if msBits > 0 then em.[ 0 ] &. (u8 0xff <<. size msBits) else u8 0 in let em_last = em.[ emLen - 1 ] in if (emLen < sLen + Hash.hash_length a + 2) then false else if not (FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_last =^ 0xbcuy) && FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_0 =^ 0uy)) then false else pss_verify_ a sLen msgLen msg emBits em
false
Spec.RSAPSS.fst
Spec.RSAPSS.rsapss_load_pkey
val rsapss_load_pkey: modBits:modBits_t -> eBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> option (rsapss_pkey modBits)
val rsapss_load_pkey: modBits:modBits_t -> eBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> option (rsapss_pkey modBits)
let rsapss_load_pkey modBits eBits nb eb = let n = os2ip #(blocks modBits 8) nb in let e = os2ip #(blocks eBits 8) eb in //`n % 2 = 1` is needed to store `r2 = r * r % n` as a part of pkey if (n % 2 = 1 && pow2 (modBits - 1) < n && n < pow2 modBits && 0 < e && e < pow2 eBits) then Some (Mk_rsapss_pkey n e) else None
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 8, "end_line": 378, "start_col": 0, "start_line": 369 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len) let i2osp len n = nat_to_intseq_be len n /// /// RSA /// type modBits_t = modBits:size_nat{1 < modBits} noeq type rsapss_pkey (modBits:modBits_t) = | Mk_rsapss_pkey: n:pos{pow2 (modBits - 1) < n /\ n < pow2 modBits} -> e:pos -> rsapss_pkey modBits noeq type rsapss_skey (modBits:modBits_t) = | Mk_rsapss_skey: pkey:rsapss_pkey modBits -> d:pos -> rsapss_skey modBits val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0]))) let db_zero #len db emBits = let msBits = emBits % 8 in if msBits > 0 then begin let r = db.[0] <- db.[0] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[0] (u8 0xff >>. size (8 - msBits)) msBits; r end else db val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8) let pss_encode a sLen salt msgLen msg emBits = let mHash = Hash.hash a msg in let hLen = Hash.hash_length a in //m1 = [8 * 0x00; mHash; salt] let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash = Hash.hash a m1 in //db = [0x00;..; 0x00; 0x01; salt] let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let db = create dbLen (u8 0) in let last_before_salt = dbLen - sLen - 1 in let db = db.[last_before_salt] <- u8 1 in let db = update_sub db (last_before_salt + 1) sLen salt in let dbMask = mgf_hash a hLen m1Hash dbLen in let maskedDB = xor_bytes db dbMask in let maskedDB = db_zero maskedDB emBits in //em = [maskedDB; m1Hash; 0xbc] let em = create emLen (u8 0) in let em = update_sub em 0 dbLen maskedDB in let em = update_sub em dbLen hLen m1Hash in assert (v em.[0] == v maskedDB.[0]); em.[emLen - 1] <- u8 0xbc val pss_verify_: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{sLen + Hash.hash_length a + 2 <= blocks emBits 8} -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify_ a sLen msgLen msg emBits em = let hLen = Hash.hash_length a in let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let maskedDB = sub em 0 dbLen in let m1Hash = sub em dbLen hLen in let dbMask = mgf_hash a hLen m1Hash dbLen in let db = xor_bytes dbMask maskedDB in let db = db_zero db emBits in let padLen = emLen - sLen - hLen - 1 in let pad2 = create padLen (u8 0) in let pad2 = pad2.[padLen - 1] <- u8 0x01 in let pad = sub db 0 padLen in let salt = sub db padLen sLen in if not (lbytes_eq pad pad2) then false else begin let mHash = Hash.hash a msg in let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash0 = Hash.hash a m1 in lbytes_eq m1Hash0 m1Hash end val pss_verify: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify a sLen msgLen msg emBits em = let emLen = blocks emBits 8 in let msBits = emBits % 8 in let em_0 = if msBits > 0 then em.[0] &. (u8 0xff <<. size msBits) else u8 0 in let em_last = em.[emLen - 1] in if (emLen < sLen + Hash.hash_length a + 2) then false else begin if not (FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_last =^ 0xbcuy) && FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_0 =^ 0uy)) then false else pss_verify_ a sLen msgLen msg emBits em end val os2ip_lemma: emBits:size_pos -> em:lbytes (blocks emBits 8) -> Lemma (requires (if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8)) (ensures os2ip #(blocks emBits 8) em < pow2 emBits) let os2ip_lemma emBits em = let emLen = blocks emBits 8 in let aux (emBits:size_pos{emBits % 8 > 0}) : Lemma (8 * ((emBits - 1) / 8) + emBits % 8 <= emBits) = assert ((emBits - 1) / 8 <= emBits / 8) in if emBits % 8 > 0 then begin nat_from_intseq_be_slice_lemma em 1; nat_from_intseq_be_lemma0 (slice em 0 1); assert (nat_from_bytes_be em == nat_from_bytes_be (slice em 1 emLen) + pow2 ((emLen - 1) * 8) * v em.[0]); assert (nat_from_bytes_be em < pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]); calc (<=) { pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]; (==) { Math.Lemmas.distributivity_add_right (pow2 (8 * (emLen - 1))) 1 (v em.[0]) } pow2 (8 * (emLen - 1)) * (1 + v em.[0]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (8 * emLen - 1)) (v em.[0] + 1) (pow2 (emBits % 8)) } pow2 (8 * (emLen - 1)) * pow2 (emBits % 8); (==) { Math.Lemmas.pow2_plus (8 * (emLen - 1)) (emBits % 8) } pow2 (8 * ((emBits - 1) / 8) + emBits % 8); (<=) { aux emBits; Math.Lemmas.pow2_le_compat emBits ((emBits - 1) - (emBits - 1) % 8 + emBits % 8) } pow2 emBits; }; assert (nat_from_bytes_be em < pow2 emBits) end else begin assert (nat_from_bytes_be em < pow2 (emLen * 8)); assert (emBits == 8 * emLen) end val rsapss_sign_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a /\ sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> tuple2 bool (lbytes (blocks modBits 8)) let rsapss_sign_ a modBits skey sLen salt msgLen msg = let pkey = Mk_rsapss_skey?.pkey skey in let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let d = Mk_rsapss_skey?.d skey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let em = pss_encode a sLen salt msgLen msg emBits in let m = os2ip #emLen em in os2ip_lemma emBits em; let s = pow_mod #n m d in let m' = pow_mod #n s e in let eq_m = m = m' in let s = if eq_m then s else 0 in (eq_m, i2osp k s) val rsapss_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8)) let rsapss_sign a modBits skey sLen salt msgLen msg = let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8 in if b then begin let (eq_m, sgnt) = rsapss_sign_ a modBits skey sLen salt msgLen msg in if eq_m then Some sgnt else None end else None val rsapss_verify_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> sgnt:lbytes (blocks modBits 8) -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> Tot bool let rsapss_verify_ a modBits pkey sLen sgnt msgLen msg = let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let s = os2ip #k sgnt in if s < n then begin let m = pow_mod #n s e in if m < pow2 (emLen * 8) then let em = i2osp emLen m in pss_verify a sLen msgLen msg emBits em else false end else false val rsapss_verify: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat -> k:size_nat -> sgnt:lbytes k -> msgLen:nat -> msg:bytes{length msg == msgLen} -> Tot bool let rsapss_verify a modBits pkey sLen k sgnt msgLen msg = let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && k = blocks modBits 8 in if b then rsapss_verify_ a modBits pkey sLen sgnt msgLen msg else false val rsapss_load_pkey: modBits:modBits_t -> eBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> option (rsapss_pkey modBits)
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 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
modBits: Spec.RSAPSS.modBits_t -> eBits: Lib.IntTypes.size_pos -> nb: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.RSAPSS.blocks modBits 8) -> eb: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.RSAPSS.blocks eBits 8) -> FStar.Pervasives.Native.option (Spec.RSAPSS.rsapss_pkey modBits)
Prims.Tot
[ "total" ]
[]
[ "Spec.RSAPSS.modBits_t", "Lib.IntTypes.size_pos", "Lib.Sequence.lseq", "Lib.IntTypes.uint8", "Spec.RSAPSS.blocks", "Prims.op_AmpAmp", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "FStar.Pervasives.Native.Some", "Spec.RSAPSS.rsapss_pkey", "Spec.RSAPSS.Mk_rsapss_pkey", "Prims.bool", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "Prims.nat", "Prims.b2t", "Prims.op_Multiply", "Spec.RSAPSS.os2ip" ]
[]
false
false
false
false
false
let rsapss_load_pkey modBits eBits nb eb =
let n = os2ip #(blocks modBits 8) nb in let e = os2ip #(blocks eBits 8) eb in if (n % 2 = 1 && pow2 (modBits - 1) < n && n < pow2 modBits && 0 < e && e < pow2 eBits) then Some (Mk_rsapss_pkey n e) else None
false
Spec.RSAPSS.fst
Spec.RSAPSS.rsapss_sign_
val rsapss_sign_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a /\ sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> tuple2 bool (lbytes (blocks modBits 8))
val rsapss_sign_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a /\ sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> tuple2 bool (lbytes (blocks modBits 8))
let rsapss_sign_ a modBits skey sLen salt msgLen msg = let pkey = Mk_rsapss_skey?.pkey skey in let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let d = Mk_rsapss_skey?.d skey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let em = pss_encode a sLen salt msgLen msg emBits in let m = os2ip #emLen em in os2ip_lemma emBits em; let s = pow_mod #n m d in let m' = pow_mod #n s e in let eq_m = m = m' in let s = if eq_m then s else 0 in (eq_m, i2osp k s)
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 280, "start_col": 0, "start_line": 261 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len) let i2osp len n = nat_to_intseq_be len n /// /// RSA /// type modBits_t = modBits:size_nat{1 < modBits} noeq type rsapss_pkey (modBits:modBits_t) = | Mk_rsapss_pkey: n:pos{pow2 (modBits - 1) < n /\ n < pow2 modBits} -> e:pos -> rsapss_pkey modBits noeq type rsapss_skey (modBits:modBits_t) = | Mk_rsapss_skey: pkey:rsapss_pkey modBits -> d:pos -> rsapss_skey modBits val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0]))) let db_zero #len db emBits = let msBits = emBits % 8 in if msBits > 0 then begin let r = db.[0] <- db.[0] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[0] (u8 0xff >>. size (8 - msBits)) msBits; r end else db val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8) let pss_encode a sLen salt msgLen msg emBits = let mHash = Hash.hash a msg in let hLen = Hash.hash_length a in //m1 = [8 * 0x00; mHash; salt] let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash = Hash.hash a m1 in //db = [0x00;..; 0x00; 0x01; salt] let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let db = create dbLen (u8 0) in let last_before_salt = dbLen - sLen - 1 in let db = db.[last_before_salt] <- u8 1 in let db = update_sub db (last_before_salt + 1) sLen salt in let dbMask = mgf_hash a hLen m1Hash dbLen in let maskedDB = xor_bytes db dbMask in let maskedDB = db_zero maskedDB emBits in //em = [maskedDB; m1Hash; 0xbc] let em = create emLen (u8 0) in let em = update_sub em 0 dbLen maskedDB in let em = update_sub em dbLen hLen m1Hash in assert (v em.[0] == v maskedDB.[0]); em.[emLen - 1] <- u8 0xbc val pss_verify_: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{sLen + Hash.hash_length a + 2 <= blocks emBits 8} -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify_ a sLen msgLen msg emBits em = let hLen = Hash.hash_length a in let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let maskedDB = sub em 0 dbLen in let m1Hash = sub em dbLen hLen in let dbMask = mgf_hash a hLen m1Hash dbLen in let db = xor_bytes dbMask maskedDB in let db = db_zero db emBits in let padLen = emLen - sLen - hLen - 1 in let pad2 = create padLen (u8 0) in let pad2 = pad2.[padLen - 1] <- u8 0x01 in let pad = sub db 0 padLen in let salt = sub db padLen sLen in if not (lbytes_eq pad pad2) then false else begin let mHash = Hash.hash a msg in let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash0 = Hash.hash a m1 in lbytes_eq m1Hash0 m1Hash end val pss_verify: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify a sLen msgLen msg emBits em = let emLen = blocks emBits 8 in let msBits = emBits % 8 in let em_0 = if msBits > 0 then em.[0] &. (u8 0xff <<. size msBits) else u8 0 in let em_last = em.[emLen - 1] in if (emLen < sLen + Hash.hash_length a + 2) then false else begin if not (FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_last =^ 0xbcuy) && FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_0 =^ 0uy)) then false else pss_verify_ a sLen msgLen msg emBits em end val os2ip_lemma: emBits:size_pos -> em:lbytes (blocks emBits 8) -> Lemma (requires (if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8)) (ensures os2ip #(blocks emBits 8) em < pow2 emBits) let os2ip_lemma emBits em = let emLen = blocks emBits 8 in let aux (emBits:size_pos{emBits % 8 > 0}) : Lemma (8 * ((emBits - 1) / 8) + emBits % 8 <= emBits) = assert ((emBits - 1) / 8 <= emBits / 8) in if emBits % 8 > 0 then begin nat_from_intseq_be_slice_lemma em 1; nat_from_intseq_be_lemma0 (slice em 0 1); assert (nat_from_bytes_be em == nat_from_bytes_be (slice em 1 emLen) + pow2 ((emLen - 1) * 8) * v em.[0]); assert (nat_from_bytes_be em < pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]); calc (<=) { pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]; (==) { Math.Lemmas.distributivity_add_right (pow2 (8 * (emLen - 1))) 1 (v em.[0]) } pow2 (8 * (emLen - 1)) * (1 + v em.[0]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (8 * emLen - 1)) (v em.[0] + 1) (pow2 (emBits % 8)) } pow2 (8 * (emLen - 1)) * pow2 (emBits % 8); (==) { Math.Lemmas.pow2_plus (8 * (emLen - 1)) (emBits % 8) } pow2 (8 * ((emBits - 1) / 8) + emBits % 8); (<=) { aux emBits; Math.Lemmas.pow2_le_compat emBits ((emBits - 1) - (emBits - 1) % 8 + emBits % 8) } pow2 emBits; }; assert (nat_from_bytes_be em < pow2 emBits) end else begin assert (nat_from_bytes_be em < pow2 (emLen * 8)); assert (emBits == 8 * emLen) end val rsapss_sign_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a /\ sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> tuple2 bool (lbytes (blocks modBits 8))
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} -> modBits: Spec.RSAPSS.modBits_t -> skey: Spec.RSAPSS.rsapss_skey modBits -> sLen: Lib.IntTypes.size_nat { sLen + Spec.Hash.Definitions.hash_length a + 8 <= Lib.IntTypes.max_size_t /\ Spec.Hash.Definitions.less_than_max_input_length (sLen + Spec.Hash.Definitions.hash_length a + 8) a /\ sLen + Spec.Hash.Definitions.hash_length a + 2 <= Spec.RSAPSS.blocks (modBits - 1) 8 } -> salt: Lib.ByteSequence.lbytes sLen -> msgLen: Prims.nat{Spec.Hash.Definitions.less_than_max_input_length msgLen a} -> msg: Lib.ByteSequence.bytes{Lib.Sequence.length msg == msgLen} -> Prims.bool * Lib.ByteSequence.lbytes (Spec.RSAPSS.blocks modBits 8)
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.RSAPSS.hash_is_supported", "Spec.RSAPSS.modBits_t", "Spec.RSAPSS.rsapss_skey", "Lib.IntTypes.size_nat", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Spec.Hash.Definitions.hash_length", "Lib.IntTypes.max_size_t", "Spec.Hash.Definitions.less_than_max_input_length", "Spec.RSAPSS.blocks", "Prims.op_Subtraction", "Lib.ByteSequence.lbytes", "Prims.nat", "Lib.ByteSequence.bytes", "Prims.eq2", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.Pervasives.Native.Mktuple2", "Prims.bool", "Spec.RSAPSS.i2osp", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Multiply", "FStar.Mul.op_Star", "Prims.op_Equality", "Prims.l_or", "Lib.NatMod.nat_mod", "Lib.NatMod.pow_mod", "Prims.unit", "Spec.RSAPSS.os2ip_lemma", "Spec.RSAPSS.os2ip", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Spec.RSAPSS.pss_encode", "Prims.pos", "Prims.int", "FStar.Math.Lemmas.pow2_le_compat", "Spec.RSAPSS.__proj__Mk_rsapss_skey__item__d", "Spec.RSAPSS.__proj__Mk_rsapss_pkey__item__e", "Spec.RSAPSS.__proj__Mk_rsapss_pkey__item__n", "Spec.RSAPSS.rsapss_pkey", "Spec.RSAPSS.__proj__Mk_rsapss_skey__item__pkey", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let rsapss_sign_ a modBits skey sLen salt msgLen msg =
let pkey = Mk_rsapss_skey?.pkey skey in let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let d = Mk_rsapss_skey?.d skey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let em = pss_encode a sLen salt msgLen msg emBits in let m = os2ip #emLen em in os2ip_lemma emBits em; let s = pow_mod #n m d in let m' = pow_mod #n s e in let eq_m = m = m' in let s = if eq_m then s else 0 in (eq_m, i2osp k s)
false
Hacl.P256.PrecompTable.fst
Hacl.P256.PrecompTable.precomp_g_pow2_64_table_lemma_w4
val precomp_g_pow2_64_table_lemma_w4: unit -> Lemma (forall (i:nat{i < 16}). precomp_table_acc_inv g_pow2_64 16 precomp_g_pow2_64_table_lseq_w4 i)
val precomp_g_pow2_64_table_lemma_w4: unit -> Lemma (forall (i:nat{i < 16}). precomp_table_acc_inv g_pow2_64 16 precomp_g_pow2_64_table_lseq_w4 i)
let precomp_g_pow2_64_table_lemma_w4 () = normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_64 15); SPT.precomp_base_table_lemma mk_p256_precomp_base_table proj_g_pow2_64 16 precomp_g_pow2_64_table_lseq_w4; proj_g_pow2_64_lemma ()
{ "file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 230, "start_col": 0, "start_line": 226 }
module Hacl.P256.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.P256.PrecompTable module S = Spec.P256 module SL = Spec.P256.Lemmas open Hacl.Impl.P256.Point include Hacl.Impl.P256.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 = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in [@inline_let] let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in [@inline_let] let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in (rX, rY, rZ) val lemma_proj_g_pow2_64_eval : unit -> Lemma (SE.exp_pow2 S.mk_p256_concrete_ops S.base_point 64 == proj_g_pow2_64) let lemma_proj_g_pow2_64_eval () = SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops S.base_point 64; let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64) in normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64); let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b 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 = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in [@inline_let] let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in [@inline_let] let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in (rX, rY, rZ) val lemma_proj_g_pow2_128_eval : unit -> Lemma (SE.exp_pow2 S.mk_p256_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_p256_concrete_ops proj_g_pow2_64 64; let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64); let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 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 = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in [@inline_let] let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in [@inline_let] let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in (rX, rY, rZ) val lemma_proj_g_pow2_192_eval : unit -> Lemma (SE.exp_pow2 S.mk_p256_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_p256_concrete_ops proj_g_pow2_128 64; let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64) in normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64); let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 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_p256_concrete_ops S.base_point 64) // let proj_g_pow2_128 : S.proj_point = // normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) // let proj_g_pow2_192 : S.proj_point = // normalize_term (SPT256.exp_pow2_rec S.mk_p256_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 12 = 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 12 = 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 12 = 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_p256_concrete_ops S.base_point 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_p256_concrete_ops S.base_point 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_p256_concrete_ops S.base_point 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 = 192} = normalize_term (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 15) let precomp_basepoint_table_lseq_w4 : LSeq.lseq uint64 192 = normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 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_p256_precomp_base_table S.base_point 15); SPT.precomp_base_table_lemma mk_p256_precomp_base_table S.base_point 16 precomp_basepoint_table_lseq_w4 let precomp_basepoint_table_w4: x:glbuffer uint64 192ul{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 = 192} = normalize_term (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_64 15) let precomp_g_pow2_64_table_lseq_w4 : LSeq.lseq uint64 192 = normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_64 15); Seq.seq_of_list precomp_g_pow2_64_table_list_w4
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.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.P256.PrecompTable.fsti.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.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.P256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Spec.P256.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.P256.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Point", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "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.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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
_: Prims.unit -> FStar.Pervasives.Lemma (ensures forall (i: Prims.nat{i < 16}). Hacl.P256.PrecompTable.precomp_table_acc_inv Hacl.P256.PrecompTable.g_pow2_64 16 Hacl.P256.PrecompTable.precomp_g_pow2_64_table_lseq_w4 i)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "Hacl.P256.PrecompTable.proj_g_pow2_64_lemma", "Hacl.Spec.PrecompBaseTable.precomp_base_table_lemma", "Spec.P256.PointOps.proj_point", "Lib.IntTypes.U64", "FStar.UInt32.uint_to_t", "Hacl.P256.PrecompTable.mk_p256_precomp_base_table", "Hacl.P256.PrecompTable.proj_g_pow2_64", "Hacl.P256.PrecompTable.precomp_g_pow2_64_table_lseq_w4", "FStar.Pervasives.normalize_term_spec", "Prims.list", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.List.Tot.Base.length", "FStar.Mul.op_Star", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Spec.PrecompBaseTable.precomp_base_table_list" ]
[]
true
false
true
false
false
let precomp_g_pow2_64_table_lemma_w4 () =
normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table proj_g_pow2_64 15); SPT.precomp_base_table_lemma mk_p256_precomp_base_table proj_g_pow2_64 16 precomp_g_pow2_64_table_lseq_w4; proj_g_pow2_64_lemma ()
false
Spec.RSAPSS.fst
Spec.RSAPSS.rsapss_verify_
val rsapss_verify_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> sgnt:lbytes (blocks modBits 8) -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> Tot bool
val rsapss_verify_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> sgnt:lbytes (blocks modBits 8) -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> Tot bool
let rsapss_verify_ a modBits pkey sLen sgnt msgLen msg = let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let s = os2ip #k sgnt in if s < n then begin let m = pow_mod #n s e in if m < pow2 (emLen * 8) then let em = i2osp emLen m in pss_verify a sLen msgLen msg emBits em else false end else false
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 12, "end_line": 335, "start_col": 0, "start_line": 319 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len) let i2osp len n = nat_to_intseq_be len n /// /// RSA /// type modBits_t = modBits:size_nat{1 < modBits} noeq type rsapss_pkey (modBits:modBits_t) = | Mk_rsapss_pkey: n:pos{pow2 (modBits - 1) < n /\ n < pow2 modBits} -> e:pos -> rsapss_pkey modBits noeq type rsapss_skey (modBits:modBits_t) = | Mk_rsapss_skey: pkey:rsapss_pkey modBits -> d:pos -> rsapss_skey modBits val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0]))) let db_zero #len db emBits = let msBits = emBits % 8 in if msBits > 0 then begin let r = db.[0] <- db.[0] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[0] (u8 0xff >>. size (8 - msBits)) msBits; r end else db val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8) let pss_encode a sLen salt msgLen msg emBits = let mHash = Hash.hash a msg in let hLen = Hash.hash_length a in //m1 = [8 * 0x00; mHash; salt] let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash = Hash.hash a m1 in //db = [0x00;..; 0x00; 0x01; salt] let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let db = create dbLen (u8 0) in let last_before_salt = dbLen - sLen - 1 in let db = db.[last_before_salt] <- u8 1 in let db = update_sub db (last_before_salt + 1) sLen salt in let dbMask = mgf_hash a hLen m1Hash dbLen in let maskedDB = xor_bytes db dbMask in let maskedDB = db_zero maskedDB emBits in //em = [maskedDB; m1Hash; 0xbc] let em = create emLen (u8 0) in let em = update_sub em 0 dbLen maskedDB in let em = update_sub em dbLen hLen m1Hash in assert (v em.[0] == v maskedDB.[0]); em.[emLen - 1] <- u8 0xbc val pss_verify_: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{sLen + Hash.hash_length a + 2 <= blocks emBits 8} -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify_ a sLen msgLen msg emBits em = let hLen = Hash.hash_length a in let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let maskedDB = sub em 0 dbLen in let m1Hash = sub em dbLen hLen in let dbMask = mgf_hash a hLen m1Hash dbLen in let db = xor_bytes dbMask maskedDB in let db = db_zero db emBits in let padLen = emLen - sLen - hLen - 1 in let pad2 = create padLen (u8 0) in let pad2 = pad2.[padLen - 1] <- u8 0x01 in let pad = sub db 0 padLen in let salt = sub db padLen sLen in if not (lbytes_eq pad pad2) then false else begin let mHash = Hash.hash a msg in let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash0 = Hash.hash a m1 in lbytes_eq m1Hash0 m1Hash end val pss_verify: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify a sLen msgLen msg emBits em = let emLen = blocks emBits 8 in let msBits = emBits % 8 in let em_0 = if msBits > 0 then em.[0] &. (u8 0xff <<. size msBits) else u8 0 in let em_last = em.[emLen - 1] in if (emLen < sLen + Hash.hash_length a + 2) then false else begin if not (FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_last =^ 0xbcuy) && FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_0 =^ 0uy)) then false else pss_verify_ a sLen msgLen msg emBits em end val os2ip_lemma: emBits:size_pos -> em:lbytes (blocks emBits 8) -> Lemma (requires (if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8)) (ensures os2ip #(blocks emBits 8) em < pow2 emBits) let os2ip_lemma emBits em = let emLen = blocks emBits 8 in let aux (emBits:size_pos{emBits % 8 > 0}) : Lemma (8 * ((emBits - 1) / 8) + emBits % 8 <= emBits) = assert ((emBits - 1) / 8 <= emBits / 8) in if emBits % 8 > 0 then begin nat_from_intseq_be_slice_lemma em 1; nat_from_intseq_be_lemma0 (slice em 0 1); assert (nat_from_bytes_be em == nat_from_bytes_be (slice em 1 emLen) + pow2 ((emLen - 1) * 8) * v em.[0]); assert (nat_from_bytes_be em < pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]); calc (<=) { pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]; (==) { Math.Lemmas.distributivity_add_right (pow2 (8 * (emLen - 1))) 1 (v em.[0]) } pow2 (8 * (emLen - 1)) * (1 + v em.[0]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (8 * emLen - 1)) (v em.[0] + 1) (pow2 (emBits % 8)) } pow2 (8 * (emLen - 1)) * pow2 (emBits % 8); (==) { Math.Lemmas.pow2_plus (8 * (emLen - 1)) (emBits % 8) } pow2 (8 * ((emBits - 1) / 8) + emBits % 8); (<=) { aux emBits; Math.Lemmas.pow2_le_compat emBits ((emBits - 1) - (emBits - 1) % 8 + emBits % 8) } pow2 emBits; }; assert (nat_from_bytes_be em < pow2 emBits) end else begin assert (nat_from_bytes_be em < pow2 (emLen * 8)); assert (emBits == 8 * emLen) end val rsapss_sign_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a /\ sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> tuple2 bool (lbytes (blocks modBits 8)) let rsapss_sign_ a modBits skey sLen salt msgLen msg = let pkey = Mk_rsapss_skey?.pkey skey in let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let d = Mk_rsapss_skey?.d skey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let em = pss_encode a sLen salt msgLen msg emBits in let m = os2ip #emLen em in os2ip_lemma emBits em; let s = pow_mod #n m d in let m' = pow_mod #n s e in let eq_m = m = m' in let s = if eq_m then s else 0 in (eq_m, i2osp k s) val rsapss_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8)) let rsapss_sign a modBits skey sLen salt msgLen msg = let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8 in if b then begin let (eq_m, sgnt) = rsapss_sign_ a modBits skey sLen salt msgLen msg in if eq_m then Some sgnt else None end else None val rsapss_verify_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> sgnt:lbytes (blocks modBits 8) -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> Tot bool
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} -> modBits: Spec.RSAPSS.modBits_t -> pkey: Spec.RSAPSS.rsapss_pkey modBits -> sLen: Lib.IntTypes.size_nat { sLen + Spec.Hash.Definitions.hash_length a + 8 <= Lib.IntTypes.max_size_t /\ Spec.Hash.Definitions.less_than_max_input_length (sLen + Spec.Hash.Definitions.hash_length a + 8) a } -> sgnt: Lib.ByteSequence.lbytes (Spec.RSAPSS.blocks modBits 8) -> msgLen: Prims.nat{Spec.Hash.Definitions.less_than_max_input_length msgLen a} -> msg: Lib.ByteSequence.bytes{Lib.Sequence.length msg == msgLen} -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.RSAPSS.hash_is_supported", "Spec.RSAPSS.modBits_t", "Spec.RSAPSS.rsapss_pkey", "Lib.IntTypes.size_nat", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Spec.Hash.Definitions.hash_length", "Lib.IntTypes.max_size_t", "Spec.Hash.Definitions.less_than_max_input_length", "Lib.ByteSequence.lbytes", "Spec.RSAPSS.blocks", "Prims.nat", "Lib.ByteSequence.bytes", "Prims.eq2", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Prims.op_LessThan", "Prims.pow2", "FStar.Mul.op_Star", "Spec.RSAPSS.pss_verify", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Spec.RSAPSS.i2osp", "Prims.bool", "Lib.NatMod.nat_mod", "Lib.NatMod.pow_mod", "Prims.op_Multiply", "Spec.RSAPSS.os2ip", "Prims.pos", "Prims.op_Subtraction", "Prims.int", "Prims.unit", "FStar.Math.Lemmas.pow2_le_compat", "Spec.RSAPSS.__proj__Mk_rsapss_pkey__item__e", "Spec.RSAPSS.__proj__Mk_rsapss_pkey__item__n" ]
[]
false
false
false
false
false
let rsapss_verify_ a modBits pkey sLen sgnt msgLen msg =
let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let s = os2ip #k sgnt in if s < n then let m = pow_mod #n s e in if m < pow2 (emLen * 8) then let em = i2osp emLen m in pss_verify a sLen msgLen msg emBits em else false else false
false
Bug2605.fst
Bug2605.g3
val g3 (#a: Type) (i: int) : Steel unit emp (fun _ -> emp) (requires fun _ -> phi i) (ensures fun _ _ _ -> True)
val g3 (#a: Type) (i: int) : Steel unit emp (fun _ -> emp) (requires fun _ -> phi i) (ensures fun _ _ _ -> True)
let g3 (#a:Type) (i:int) : Steel unit emp (λ _ → emp) (requires λ _ → phi i) (ensures λ _ _ _ → ⊤) = f3 i
{ "file_name": "share/steel/tests/Bug2605.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 8, "end_line": 19, "start_col": 0, "start_line": 15 }
module Bug2605 open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.ST.Util open Steel.ST.Coercions assume val phi : int -> Type0 assume val f3 (i:int{phi i}) : STT unit emp (fun _ -> emp)
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Coercions.fsti.checked", "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Bug2605.fst" }
[ { "abbrev": false, "full_module": "Steel.ST.Coercions", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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
i: Prims.int -> Steel.Effect.Steel Prims.unit
Steel.Effect.Steel
[]
[]
[ "Prims.int", "Bug2605.f3", "Prims.unit", "Steel.Effect.Common.emp", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Bug2605.phi", "Prims.l_True" ]
[]
false
true
false
false
false
let g3 (#a: Type) (i: int) : Steel unit emp (fun _ -> emp) (requires fun _ -> phi i) (ensures fun _ _ _ -> True) =
f3 i
false
Spec.RSAPSS.fst
Spec.RSAPSS.rsapss_load_skey
val rsapss_load_skey: modBits:modBits_t -> eBits:size_pos -> dBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> db:lseq uint8 (blocks dBits 8) -> option (rsapss_skey modBits)
val rsapss_load_skey: modBits:modBits_t -> eBits:size_pos -> dBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> db:lseq uint8 (blocks dBits 8) -> option (rsapss_skey modBits)
let rsapss_load_skey modBits eBits dBits nb eb db = let pkey = rsapss_load_pkey modBits eBits nb eb in let d = os2ip #(blocks dBits 8) db in if (Some? pkey && 0 < d && d < pow2 dBits) then Some (Mk_rsapss_skey (Some?.v pkey) d) else None
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 8, "end_line": 397, "start_col": 0, "start_line": 390 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len) let i2osp len n = nat_to_intseq_be len n /// /// RSA /// type modBits_t = modBits:size_nat{1 < modBits} noeq type rsapss_pkey (modBits:modBits_t) = | Mk_rsapss_pkey: n:pos{pow2 (modBits - 1) < n /\ n < pow2 modBits} -> e:pos -> rsapss_pkey modBits noeq type rsapss_skey (modBits:modBits_t) = | Mk_rsapss_skey: pkey:rsapss_pkey modBits -> d:pos -> rsapss_skey modBits val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0]))) let db_zero #len db emBits = let msBits = emBits % 8 in if msBits > 0 then begin let r = db.[0] <- db.[0] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[0] (u8 0xff >>. size (8 - msBits)) msBits; r end else db val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8) let pss_encode a sLen salt msgLen msg emBits = let mHash = Hash.hash a msg in let hLen = Hash.hash_length a in //m1 = [8 * 0x00; mHash; salt] let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash = Hash.hash a m1 in //db = [0x00;..; 0x00; 0x01; salt] let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let db = create dbLen (u8 0) in let last_before_salt = dbLen - sLen - 1 in let db = db.[last_before_salt] <- u8 1 in let db = update_sub db (last_before_salt + 1) sLen salt in let dbMask = mgf_hash a hLen m1Hash dbLen in let maskedDB = xor_bytes db dbMask in let maskedDB = db_zero maskedDB emBits in //em = [maskedDB; m1Hash; 0xbc] let em = create emLen (u8 0) in let em = update_sub em 0 dbLen maskedDB in let em = update_sub em dbLen hLen m1Hash in assert (v em.[0] == v maskedDB.[0]); em.[emLen - 1] <- u8 0xbc val pss_verify_: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{sLen + Hash.hash_length a + 2 <= blocks emBits 8} -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify_ a sLen msgLen msg emBits em = let hLen = Hash.hash_length a in let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let maskedDB = sub em 0 dbLen in let m1Hash = sub em dbLen hLen in let dbMask = mgf_hash a hLen m1Hash dbLen in let db = xor_bytes dbMask maskedDB in let db = db_zero db emBits in let padLen = emLen - sLen - hLen - 1 in let pad2 = create padLen (u8 0) in let pad2 = pad2.[padLen - 1] <- u8 0x01 in let pad = sub db 0 padLen in let salt = sub db padLen sLen in if not (lbytes_eq pad pad2) then false else begin let mHash = Hash.hash a msg in let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash0 = Hash.hash a m1 in lbytes_eq m1Hash0 m1Hash end val pss_verify: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify a sLen msgLen msg emBits em = let emLen = blocks emBits 8 in let msBits = emBits % 8 in let em_0 = if msBits > 0 then em.[0] &. (u8 0xff <<. size msBits) else u8 0 in let em_last = em.[emLen - 1] in if (emLen < sLen + Hash.hash_length a + 2) then false else begin if not (FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_last =^ 0xbcuy) && FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_0 =^ 0uy)) then false else pss_verify_ a sLen msgLen msg emBits em end val os2ip_lemma: emBits:size_pos -> em:lbytes (blocks emBits 8) -> Lemma (requires (if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8)) (ensures os2ip #(blocks emBits 8) em < pow2 emBits) let os2ip_lemma emBits em = let emLen = blocks emBits 8 in let aux (emBits:size_pos{emBits % 8 > 0}) : Lemma (8 * ((emBits - 1) / 8) + emBits % 8 <= emBits) = assert ((emBits - 1) / 8 <= emBits / 8) in if emBits % 8 > 0 then begin nat_from_intseq_be_slice_lemma em 1; nat_from_intseq_be_lemma0 (slice em 0 1); assert (nat_from_bytes_be em == nat_from_bytes_be (slice em 1 emLen) + pow2 ((emLen - 1) * 8) * v em.[0]); assert (nat_from_bytes_be em < pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]); calc (<=) { pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]; (==) { Math.Lemmas.distributivity_add_right (pow2 (8 * (emLen - 1))) 1 (v em.[0]) } pow2 (8 * (emLen - 1)) * (1 + v em.[0]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (8 * emLen - 1)) (v em.[0] + 1) (pow2 (emBits % 8)) } pow2 (8 * (emLen - 1)) * pow2 (emBits % 8); (==) { Math.Lemmas.pow2_plus (8 * (emLen - 1)) (emBits % 8) } pow2 (8 * ((emBits - 1) / 8) + emBits % 8); (<=) { aux emBits; Math.Lemmas.pow2_le_compat emBits ((emBits - 1) - (emBits - 1) % 8 + emBits % 8) } pow2 emBits; }; assert (nat_from_bytes_be em < pow2 emBits) end else begin assert (nat_from_bytes_be em < pow2 (emLen * 8)); assert (emBits == 8 * emLen) end val rsapss_sign_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a /\ sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> tuple2 bool (lbytes (blocks modBits 8)) let rsapss_sign_ a modBits skey sLen salt msgLen msg = let pkey = Mk_rsapss_skey?.pkey skey in let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let d = Mk_rsapss_skey?.d skey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let em = pss_encode a sLen salt msgLen msg emBits in let m = os2ip #emLen em in os2ip_lemma emBits em; let s = pow_mod #n m d in let m' = pow_mod #n s e in let eq_m = m = m' in let s = if eq_m then s else 0 in (eq_m, i2osp k s) val rsapss_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8)) let rsapss_sign a modBits skey sLen salt msgLen msg = let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8 in if b then begin let (eq_m, sgnt) = rsapss_sign_ a modBits skey sLen salt msgLen msg in if eq_m then Some sgnt else None end else None val rsapss_verify_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> sgnt:lbytes (blocks modBits 8) -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> Tot bool let rsapss_verify_ a modBits pkey sLen sgnt msgLen msg = let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let s = os2ip #k sgnt in if s < n then begin let m = pow_mod #n s e in if m < pow2 (emLen * 8) then let em = i2osp emLen m in pss_verify a sLen msgLen msg emBits em else false end else false val rsapss_verify: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat -> k:size_nat -> sgnt:lbytes k -> msgLen:nat -> msg:bytes{length msg == msgLen} -> Tot bool let rsapss_verify a modBits pkey sLen k sgnt msgLen msg = let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && k = blocks modBits 8 in if b then rsapss_verify_ a modBits pkey sLen sgnt msgLen msg else false val rsapss_load_pkey: modBits:modBits_t -> eBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> option (rsapss_pkey modBits) let rsapss_load_pkey modBits eBits nb eb = let n = os2ip #(blocks modBits 8) nb in let e = os2ip #(blocks eBits 8) eb in //`n % 2 = 1` is needed to store `r2 = r * r % n` as a part of pkey if (n % 2 = 1 && pow2 (modBits - 1) < n && n < pow2 modBits && 0 < e && e < pow2 eBits) then Some (Mk_rsapss_pkey n e) else None val rsapss_load_skey: modBits:modBits_t -> eBits:size_pos -> dBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> db:lseq uint8 (blocks dBits 8) -> option (rsapss_skey modBits)
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 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
modBits: Spec.RSAPSS.modBits_t -> eBits: Lib.IntTypes.size_pos -> dBits: Lib.IntTypes.size_pos -> nb: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.RSAPSS.blocks modBits 8) -> eb: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.RSAPSS.blocks eBits 8) -> db: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.RSAPSS.blocks dBits 8) -> FStar.Pervasives.Native.option (Spec.RSAPSS.rsapss_skey modBits)
Prims.Tot
[ "total" ]
[]
[ "Spec.RSAPSS.modBits_t", "Lib.IntTypes.size_pos", "Lib.Sequence.lseq", "Lib.IntTypes.uint8", "Spec.RSAPSS.blocks", "Prims.op_AmpAmp", "FStar.Pervasives.Native.uu___is_Some", "Spec.RSAPSS.rsapss_pkey", "Prims.op_LessThan", "Prims.pow2", "FStar.Pervasives.Native.Some", "Spec.RSAPSS.rsapss_skey", "Spec.RSAPSS.Mk_rsapss_skey", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.bool", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "Prims.nat", "Prims.b2t", "Prims.op_Multiply", "Spec.RSAPSS.os2ip", "Spec.RSAPSS.rsapss_load_pkey" ]
[]
false
false
false
false
false
let rsapss_load_skey modBits eBits dBits nb eb db =
let pkey = rsapss_load_pkey modBits eBits nb eb in let d = os2ip #(blocks dBits 8) db in if (Some? pkey && 0 < d && d < pow2 dBits) then Some (Mk_rsapss_skey (Some?.v pkey) d) else None
false
Spec.RSAPSS.fst
Spec.RSAPSS.rsapss_skey_sign
val rsapss_skey_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> eBits:size_pos -> dBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> db:lseq uint8 (blocks dBits 8) -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8))
val rsapss_skey_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> eBits:size_pos -> dBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> db:lseq uint8 (blocks dBits 8) -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8))
let rsapss_skey_sign a modBits eBits dBits nb eb db sLen salt msgLen msg = let skey = rsapss_load_skey modBits eBits dBits nb eb db in match skey with | Some vskey -> rsapss_sign a modBits vskey sLen salt msgLen msg | None -> None
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 418, "start_col": 0, "start_line": 414 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len) let i2osp len n = nat_to_intseq_be len n /// /// RSA /// type modBits_t = modBits:size_nat{1 < modBits} noeq type rsapss_pkey (modBits:modBits_t) = | Mk_rsapss_pkey: n:pos{pow2 (modBits - 1) < n /\ n < pow2 modBits} -> e:pos -> rsapss_pkey modBits noeq type rsapss_skey (modBits:modBits_t) = | Mk_rsapss_skey: pkey:rsapss_pkey modBits -> d:pos -> rsapss_skey modBits val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0]))) let db_zero #len db emBits = let msBits = emBits % 8 in if msBits > 0 then begin let r = db.[0] <- db.[0] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[0] (u8 0xff >>. size (8 - msBits)) msBits; r end else db val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8) let pss_encode a sLen salt msgLen msg emBits = let mHash = Hash.hash a msg in let hLen = Hash.hash_length a in //m1 = [8 * 0x00; mHash; salt] let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash = Hash.hash a m1 in //db = [0x00;..; 0x00; 0x01; salt] let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let db = create dbLen (u8 0) in let last_before_salt = dbLen - sLen - 1 in let db = db.[last_before_salt] <- u8 1 in let db = update_sub db (last_before_salt + 1) sLen salt in let dbMask = mgf_hash a hLen m1Hash dbLen in let maskedDB = xor_bytes db dbMask in let maskedDB = db_zero maskedDB emBits in //em = [maskedDB; m1Hash; 0xbc] let em = create emLen (u8 0) in let em = update_sub em 0 dbLen maskedDB in let em = update_sub em dbLen hLen m1Hash in assert (v em.[0] == v maskedDB.[0]); em.[emLen - 1] <- u8 0xbc val pss_verify_: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{sLen + Hash.hash_length a + 2 <= blocks emBits 8} -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify_ a sLen msgLen msg emBits em = let hLen = Hash.hash_length a in let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let maskedDB = sub em 0 dbLen in let m1Hash = sub em dbLen hLen in let dbMask = mgf_hash a hLen m1Hash dbLen in let db = xor_bytes dbMask maskedDB in let db = db_zero db emBits in let padLen = emLen - sLen - hLen - 1 in let pad2 = create padLen (u8 0) in let pad2 = pad2.[padLen - 1] <- u8 0x01 in let pad = sub db 0 padLen in let salt = sub db padLen sLen in if not (lbytes_eq pad pad2) then false else begin let mHash = Hash.hash a msg in let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash0 = Hash.hash a m1 in lbytes_eq m1Hash0 m1Hash end val pss_verify: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify a sLen msgLen msg emBits em = let emLen = blocks emBits 8 in let msBits = emBits % 8 in let em_0 = if msBits > 0 then em.[0] &. (u8 0xff <<. size msBits) else u8 0 in let em_last = em.[emLen - 1] in if (emLen < sLen + Hash.hash_length a + 2) then false else begin if not (FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_last =^ 0xbcuy) && FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_0 =^ 0uy)) then false else pss_verify_ a sLen msgLen msg emBits em end val os2ip_lemma: emBits:size_pos -> em:lbytes (blocks emBits 8) -> Lemma (requires (if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8)) (ensures os2ip #(blocks emBits 8) em < pow2 emBits) let os2ip_lemma emBits em = let emLen = blocks emBits 8 in let aux (emBits:size_pos{emBits % 8 > 0}) : Lemma (8 * ((emBits - 1) / 8) + emBits % 8 <= emBits) = assert ((emBits - 1) / 8 <= emBits / 8) in if emBits % 8 > 0 then begin nat_from_intseq_be_slice_lemma em 1; nat_from_intseq_be_lemma0 (slice em 0 1); assert (nat_from_bytes_be em == nat_from_bytes_be (slice em 1 emLen) + pow2 ((emLen - 1) * 8) * v em.[0]); assert (nat_from_bytes_be em < pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]); calc (<=) { pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]; (==) { Math.Lemmas.distributivity_add_right (pow2 (8 * (emLen - 1))) 1 (v em.[0]) } pow2 (8 * (emLen - 1)) * (1 + v em.[0]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (8 * emLen - 1)) (v em.[0] + 1) (pow2 (emBits % 8)) } pow2 (8 * (emLen - 1)) * pow2 (emBits % 8); (==) { Math.Lemmas.pow2_plus (8 * (emLen - 1)) (emBits % 8) } pow2 (8 * ((emBits - 1) / 8) + emBits % 8); (<=) { aux emBits; Math.Lemmas.pow2_le_compat emBits ((emBits - 1) - (emBits - 1) % 8 + emBits % 8) } pow2 emBits; }; assert (nat_from_bytes_be em < pow2 emBits) end else begin assert (nat_from_bytes_be em < pow2 (emLen * 8)); assert (emBits == 8 * emLen) end val rsapss_sign_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a /\ sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> tuple2 bool (lbytes (blocks modBits 8)) let rsapss_sign_ a modBits skey sLen salt msgLen msg = let pkey = Mk_rsapss_skey?.pkey skey in let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let d = Mk_rsapss_skey?.d skey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let em = pss_encode a sLen salt msgLen msg emBits in let m = os2ip #emLen em in os2ip_lemma emBits em; let s = pow_mod #n m d in let m' = pow_mod #n s e in let eq_m = m = m' in let s = if eq_m then s else 0 in (eq_m, i2osp k s) val rsapss_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8)) let rsapss_sign a modBits skey sLen salt msgLen msg = let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8 in if b then begin let (eq_m, sgnt) = rsapss_sign_ a modBits skey sLen salt msgLen msg in if eq_m then Some sgnt else None end else None val rsapss_verify_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> sgnt:lbytes (blocks modBits 8) -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> Tot bool let rsapss_verify_ a modBits pkey sLen sgnt msgLen msg = let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let s = os2ip #k sgnt in if s < n then begin let m = pow_mod #n s e in if m < pow2 (emLen * 8) then let em = i2osp emLen m in pss_verify a sLen msgLen msg emBits em else false end else false val rsapss_verify: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat -> k:size_nat -> sgnt:lbytes k -> msgLen:nat -> msg:bytes{length msg == msgLen} -> Tot bool let rsapss_verify a modBits pkey sLen k sgnt msgLen msg = let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && k = blocks modBits 8 in if b then rsapss_verify_ a modBits pkey sLen sgnt msgLen msg else false val rsapss_load_pkey: modBits:modBits_t -> eBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> option (rsapss_pkey modBits) let rsapss_load_pkey modBits eBits nb eb = let n = os2ip #(blocks modBits 8) nb in let e = os2ip #(blocks eBits 8) eb in //`n % 2 = 1` is needed to store `r2 = r * r % n` as a part of pkey if (n % 2 = 1 && pow2 (modBits - 1) < n && n < pow2 modBits && 0 < e && e < pow2 eBits) then Some (Mk_rsapss_pkey n e) else None val rsapss_load_skey: modBits:modBits_t -> eBits:size_pos -> dBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> db:lseq uint8 (blocks dBits 8) -> option (rsapss_skey modBits) let rsapss_load_skey modBits eBits dBits nb eb db = let pkey = rsapss_load_pkey modBits eBits nb eb in let d = os2ip #(blocks dBits 8) db in if (Some? pkey && 0 < d && d < pow2 dBits) then Some (Mk_rsapss_skey (Some?.v pkey) d) else None val rsapss_skey_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> eBits:size_pos -> dBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> db:lseq uint8 (blocks dBits 8) -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8))
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} -> modBits: Spec.RSAPSS.modBits_t -> eBits: Lib.IntTypes.size_pos -> dBits: Lib.IntTypes.size_pos -> nb: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.RSAPSS.blocks modBits 8) -> eb: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.RSAPSS.blocks eBits 8) -> db: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.RSAPSS.blocks dBits 8) -> sLen: Lib.IntTypes.size_nat -> salt: Lib.ByteSequence.lbytes sLen -> msgLen: Prims.nat -> msg: Lib.ByteSequence.bytes{Lib.Sequence.length msg == msgLen} -> FStar.Pervasives.Native.option (Lib.ByteSequence.lbytes (Spec.RSAPSS.blocks modBits 8))
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.RSAPSS.hash_is_supported", "Spec.RSAPSS.modBits_t", "Lib.IntTypes.size_pos", "Lib.Sequence.lseq", "Lib.IntTypes.uint8", "Spec.RSAPSS.blocks", "Lib.IntTypes.size_nat", "Lib.ByteSequence.lbytes", "Prims.nat", "Lib.ByteSequence.bytes", "Prims.eq2", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Spec.RSAPSS.rsapss_skey", "Spec.RSAPSS.rsapss_sign", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "Spec.RSAPSS.rsapss_load_skey" ]
[]
false
false
false
false
false
let rsapss_skey_sign a modBits eBits dBits nb eb db sLen salt msgLen msg =
let skey = rsapss_load_skey modBits eBits dBits nb eb db in match skey with | Some vskey -> rsapss_sign a modBits vskey sLen salt msgLen msg | None -> None
false
Spec.RSAPSS.fst
Spec.RSAPSS.rsapss_pkey_verify
val rsapss_pkey_verify: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> eBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> sLen:size_nat -> k:size_nat -> sgnt:lbytes k -> msgLen:nat -> msg:bytes{length msg == msgLen} -> Tot bool
val rsapss_pkey_verify: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> eBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> sLen:size_nat -> k:size_nat -> sgnt:lbytes k -> msgLen:nat -> msg:bytes{length msg == msgLen} -> Tot bool
let rsapss_pkey_verify a modBits eBits nb eb sLen k sgnt msgLen msg = let pkey = rsapss_load_pkey modBits eBits nb eb in match pkey with | Some vpkey -> rsapss_verify a modBits vpkey sLen k sgnt msgLen msg | None -> false
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 17, "end_line": 438, "start_col": 0, "start_line": 434 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len) let i2osp len n = nat_to_intseq_be len n /// /// RSA /// type modBits_t = modBits:size_nat{1 < modBits} noeq type rsapss_pkey (modBits:modBits_t) = | Mk_rsapss_pkey: n:pos{pow2 (modBits - 1) < n /\ n < pow2 modBits} -> e:pos -> rsapss_pkey modBits noeq type rsapss_skey (modBits:modBits_t) = | Mk_rsapss_skey: pkey:rsapss_pkey modBits -> d:pos -> rsapss_skey modBits val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0]))) let db_zero #len db emBits = let msBits = emBits % 8 in if msBits > 0 then begin let r = db.[0] <- db.[0] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[0] (u8 0xff >>. size (8 - msBits)) msBits; r end else db val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8) let pss_encode a sLen salt msgLen msg emBits = let mHash = Hash.hash a msg in let hLen = Hash.hash_length a in //m1 = [8 * 0x00; mHash; salt] let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash = Hash.hash a m1 in //db = [0x00;..; 0x00; 0x01; salt] let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let db = create dbLen (u8 0) in let last_before_salt = dbLen - sLen - 1 in let db = db.[last_before_salt] <- u8 1 in let db = update_sub db (last_before_salt + 1) sLen salt in let dbMask = mgf_hash a hLen m1Hash dbLen in let maskedDB = xor_bytes db dbMask in let maskedDB = db_zero maskedDB emBits in //em = [maskedDB; m1Hash; 0xbc] let em = create emLen (u8 0) in let em = update_sub em 0 dbLen maskedDB in let em = update_sub em dbLen hLen m1Hash in assert (v em.[0] == v maskedDB.[0]); em.[emLen - 1] <- u8 0xbc val pss_verify_: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{sLen + Hash.hash_length a + 2 <= blocks emBits 8} -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify_ a sLen msgLen msg emBits em = let hLen = Hash.hash_length a in let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let maskedDB = sub em 0 dbLen in let m1Hash = sub em dbLen hLen in let dbMask = mgf_hash a hLen m1Hash dbLen in let db = xor_bytes dbMask maskedDB in let db = db_zero db emBits in let padLen = emLen - sLen - hLen - 1 in let pad2 = create padLen (u8 0) in let pad2 = pad2.[padLen - 1] <- u8 0x01 in let pad = sub db 0 padLen in let salt = sub db padLen sLen in if not (lbytes_eq pad pad2) then false else begin let mHash = Hash.hash a msg in let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash0 = Hash.hash a m1 in lbytes_eq m1Hash0 m1Hash end val pss_verify: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos -> em:lbytes (blocks emBits 8) -> Tot bool let pss_verify a sLen msgLen msg emBits em = let emLen = blocks emBits 8 in let msBits = emBits % 8 in let em_0 = if msBits > 0 then em.[0] &. (u8 0xff <<. size msBits) else u8 0 in let em_last = em.[emLen - 1] in if (emLen < sLen + Hash.hash_length a + 2) then false else begin if not (FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_last =^ 0xbcuy) && FStar.UInt8.(Lib.RawIntTypes.u8_to_UInt8 em_0 =^ 0uy)) then false else pss_verify_ a sLen msgLen msg emBits em end val os2ip_lemma: emBits:size_pos -> em:lbytes (blocks emBits 8) -> Lemma (requires (if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8)) (ensures os2ip #(blocks emBits 8) em < pow2 emBits) let os2ip_lemma emBits em = let emLen = blocks emBits 8 in let aux (emBits:size_pos{emBits % 8 > 0}) : Lemma (8 * ((emBits - 1) / 8) + emBits % 8 <= emBits) = assert ((emBits - 1) / 8 <= emBits / 8) in if emBits % 8 > 0 then begin nat_from_intseq_be_slice_lemma em 1; nat_from_intseq_be_lemma0 (slice em 0 1); assert (nat_from_bytes_be em == nat_from_bytes_be (slice em 1 emLen) + pow2 ((emLen - 1) * 8) * v em.[0]); assert (nat_from_bytes_be em < pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]); calc (<=) { pow2 ((emLen - 1) * 8) + pow2 ((emLen - 1) * 8) * v em.[0]; (==) { Math.Lemmas.distributivity_add_right (pow2 (8 * (emLen - 1))) 1 (v em.[0]) } pow2 (8 * (emLen - 1)) * (1 + v em.[0]); (<=) { Math.Lemmas.lemma_mult_le_left (pow2 (8 * emLen - 1)) (v em.[0] + 1) (pow2 (emBits % 8)) } pow2 (8 * (emLen - 1)) * pow2 (emBits % 8); (==) { Math.Lemmas.pow2_plus (8 * (emLen - 1)) (emBits % 8) } pow2 (8 * ((emBits - 1) / 8) + emBits % 8); (<=) { aux emBits; Math.Lemmas.pow2_le_compat emBits ((emBits - 1) - (emBits - 1) % 8 + emBits % 8) } pow2 emBits; }; assert (nat_from_bytes_be em < pow2 emBits) end else begin assert (nat_from_bytes_be em < pow2 (emLen * 8)); assert (emBits == 8 * emLen) end val rsapss_sign_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a /\ sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> tuple2 bool (lbytes (blocks modBits 8)) let rsapss_sign_ a modBits skey sLen salt msgLen msg = let pkey = Mk_rsapss_skey?.pkey skey in let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let d = Mk_rsapss_skey?.d skey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let em = pss_encode a sLen salt msgLen msg emBits in let m = os2ip #emLen em in os2ip_lemma emBits em; let s = pow_mod #n m d in let m' = pow_mod #n s e in let eq_m = m = m' in let s = if eq_m then s else 0 in (eq_m, i2osp k s) val rsapss_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> skey:rsapss_skey modBits -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8)) let rsapss_sign a modBits skey sLen salt msgLen msg = let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && sLen + Hash.hash_length a + 2 <= blocks (modBits - 1) 8 in if b then begin let (eq_m, sgnt) = rsapss_sign_ a modBits skey sLen salt msgLen msg in if eq_m then Some sgnt else None end else None val rsapss_verify_: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat{ sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> sgnt:lbytes (blocks modBits 8) -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> Tot bool let rsapss_verify_ a modBits pkey sLen sgnt msgLen msg = let n = Mk_rsapss_pkey?.n pkey in let e = Mk_rsapss_pkey?.e pkey in let k = blocks modBits 8 in FStar.Math.Lemmas.pow2_le_compat (8 * k) modBits; let emBits = modBits - 1 in let emLen = blocks emBits 8 in let s = os2ip #k sgnt in if s < n then begin let m = pow_mod #n s e in if m < pow2 (emLen * 8) then let em = i2osp emLen m in pss_verify a sLen msgLen msg emBits em else false end else false val rsapss_verify: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> pkey:rsapss_pkey modBits -> sLen:size_nat -> k:size_nat -> sgnt:lbytes k -> msgLen:nat -> msg:bytes{length msg == msgLen} -> Tot bool let rsapss_verify a modBits pkey sLen k sgnt msgLen msg = let b = sLen + Hash.hash_length a + 8 <= max_size_t && (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a && msgLen `Hash.less_than_max_input_length` a && k = blocks modBits 8 in if b then rsapss_verify_ a modBits pkey sLen sgnt msgLen msg else false val rsapss_load_pkey: modBits:modBits_t -> eBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> option (rsapss_pkey modBits) let rsapss_load_pkey modBits eBits nb eb = let n = os2ip #(blocks modBits 8) nb in let e = os2ip #(blocks eBits 8) eb in //`n % 2 = 1` is needed to store `r2 = r * r % n` as a part of pkey if (n % 2 = 1 && pow2 (modBits - 1) < n && n < pow2 modBits && 0 < e && e < pow2 eBits) then Some (Mk_rsapss_pkey n e) else None val rsapss_load_skey: modBits:modBits_t -> eBits:size_pos -> dBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> db:lseq uint8 (blocks dBits 8) -> option (rsapss_skey modBits) let rsapss_load_skey modBits eBits dBits nb eb db = let pkey = rsapss_load_pkey modBits eBits nb eb in let d = os2ip #(blocks dBits 8) db in if (Some? pkey && 0 < d && d < pow2 dBits) then Some (Mk_rsapss_skey (Some?.v pkey) d) else None val rsapss_skey_sign: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> eBits:size_pos -> dBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> db:lseq uint8 (blocks dBits 8) -> sLen:size_nat -> salt:lbytes sLen -> msgLen:nat -> msg:bytes{length msg == msgLen} -> option (lbytes (blocks modBits 8)) let rsapss_skey_sign a modBits eBits dBits nb eb db sLen salt msgLen msg = let skey = rsapss_load_skey modBits eBits dBits nb eb db in match skey with | Some vskey -> rsapss_sign a modBits vskey sLen salt msgLen msg | None -> None val rsapss_pkey_verify: a:Hash.hash_alg{hash_is_supported a} -> modBits:modBits_t -> eBits:size_pos -> nb:lseq uint8 (blocks modBits 8) -> eb:lseq uint8 (blocks eBits 8) -> sLen:size_nat -> k:size_nat -> sgnt:lbytes k -> msgLen:nat -> msg:bytes{length msg == msgLen} -> Tot bool
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} -> modBits: Spec.RSAPSS.modBits_t -> eBits: Lib.IntTypes.size_pos -> nb: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.RSAPSS.blocks modBits 8) -> eb: Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.RSAPSS.blocks eBits 8) -> sLen: Lib.IntTypes.size_nat -> k: Lib.IntTypes.size_nat -> sgnt: Lib.ByteSequence.lbytes k -> msgLen: Prims.nat -> msg: Lib.ByteSequence.bytes{Lib.Sequence.length msg == msgLen} -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.RSAPSS.hash_is_supported", "Spec.RSAPSS.modBits_t", "Lib.IntTypes.size_pos", "Lib.Sequence.lseq", "Lib.IntTypes.uint8", "Spec.RSAPSS.blocks", "Lib.IntTypes.size_nat", "Lib.ByteSequence.lbytes", "Prims.nat", "Lib.ByteSequence.bytes", "Prims.eq2", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Spec.RSAPSS.rsapss_pkey", "Spec.RSAPSS.rsapss_verify", "Prims.bool", "FStar.Pervasives.Native.option", "Spec.RSAPSS.rsapss_load_pkey" ]
[]
false
false
false
false
false
let rsapss_pkey_verify a modBits eBits nb eb sLen k sgnt msgLen msg =
let pkey = rsapss_load_pkey modBits eBits nb eb in match pkey with | Some vpkey -> rsapss_verify a modBits vpkey sLen k sgnt msgLen msg | None -> false
false
MiniParse.Impl.Int.fst
MiniParse.Impl.Int.parse_bounded_u16_impl
val parse_bounded_u16_impl (b: nat) : Tot (parser_impl (parse_bounded_u16 b))
val parse_bounded_u16_impl (b: nat) : Tot (parser_impl (parse_bounded_u16 b))
let parse_bounded_u16_impl (b: nat) : Tot (parser_impl (parse_bounded_u16 b)) = if b >= 65536 then (fun input len -> parse_synth_impl parse_u16_impl (fun x -> x <: bounded_u16 b) (fun x -> x <: bounded_u16 b) (fun x -> x) () input len) else [@@inline_let] let b' = U16.uint_to_t b in parse_synth_impl (parse_filter_impl parse_u16_impl (fun x -> U16.v x < b) (fun x -> x `U16.lt` b')) (fun x -> x <: bounded_u16 b) (fun x -> x <: bounded_u16 b) (fun x -> x) ()
{ "file_name": "examples/miniparse/MiniParse.Impl.Int.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 8, "end_line": 81, "start_col": 0, "start_line": 68 }
(* 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 MiniParse.Impl.Int include MiniParse.Spec.Int include MiniParse.Impl.Combinators module U16 = FStar.UInt16 module B = LowStar.Buffer module U32 = FStar.UInt32 module HST = FStar.HyperStack.ST module Aux = MiniParse.Spec.Int.Aux inline_for_extraction let parse_u8_impl : parser_impl parse_u8 = make_total_constant_size_parser_impl 1 1ul (fun x -> Seq.index x 0) () (fun x -> B.index x 0ul) inline_for_extraction let serialize_u8_impl : serializer_impl serialize_u8 = (fun output (len: U32.t { len == B.len output } ) x -> let h = HST.get () in if len `U32.lt` 1ul then None else begin let output' = B.sub output 0ul 1ul in B.upd output' 0ul x; let h' = HST.get () in assert (B.as_seq h' output' `Seq.equal` Seq.create 1 x); Some 1ul end) inline_for_extraction let parse_u16_impl : parser_impl parse_u16 = make_total_constant_size_parser_impl 2 2ul parse_u16_aux () (fun x -> let lo = B.index x 0ul in let hi = B.index x 1ul in Aux.decode_u16 (lo, hi) ) inline_for_extraction let serialize_u16_impl : serializer_impl serialize_u16 = fun output (len: U32.t { len == B.len output } ) x -> if len `U32.lt` 2ul then None else begin let (lo, hi) = Aux.encode_u16 x in let output' = B.sub output 0ul 2ul in B.upd output' 0ul lo; B.upd output' 1ul hi; let h' = HST.get () in assert (B.as_seq h' output' `Seq.equal` Seq.append (Seq.create 1 lo) (Seq.create 1 hi)); Some 2ul end #set-options "--z3rlimit 64"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "MiniParse.Spec.Int.Aux.fst.checked", "MiniParse.Spec.Int.fst.checked", "MiniParse.Impl.Combinators.fst.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked" ], "interface_file": false, "source_file": "MiniParse.Impl.Int.fst" }
[ { "abbrev": true, "full_module": "MiniParse.Spec.Int.Aux", "short_module": "Aux" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.UInt16", "short_module": "U16" }, { "abbrev": false, "full_module": "MiniParse.Impl.Combinators", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Spec.Int", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Impl", "short_module": null }, { "abbrev": false, "full_module": "MiniParse.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.nat -> MiniParse.Impl.Base.parser_impl (MiniParse.Spec.Int.parse_bounded_u16 b)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.op_GreaterThanOrEqual", "MiniParse.Impl.Base.buffer8", "FStar.UInt32.t", "Prims.eq2", "LowStar.Monotonic.Buffer.len", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "MiniParse.Impl.Combinators.parse_synth_impl", "FStar.UInt16.t", "MiniParse.Spec.Int.bounded_u16", "MiniParse.Spec.Int.parse_u16", "MiniParse.Impl.Int.parse_u16_impl", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "Prims.bool", "Prims.op_LessThan", "FStar.UInt16.v", "MiniParse.Spec.Combinators.parse_filter", "MiniParse.Impl.Combinators.parse_filter_impl", "FStar.UInt16.lt", "FStar.UInt16.uint_to_t", "MiniParse.Impl.Base.parser_impl", "MiniParse.Spec.Int.parse_bounded_u16" ]
[]
false
false
false
false
false
let parse_bounded_u16_impl (b: nat) : Tot (parser_impl (parse_bounded_u16 b)) =
if b >= 65536 then (fun input len -> parse_synth_impl parse_u16_impl (fun x -> x <: bounded_u16 b) (fun x -> x <: bounded_u16 b) (fun x -> x) () input len) else [@@ inline_let ]let b' = U16.uint_to_t b in parse_synth_impl (parse_filter_impl parse_u16_impl (fun x -> U16.v x < b) (fun x -> x `U16.lt` b') ) (fun x -> x <: bounded_u16 b) (fun x -> x <: bounded_u16 b) (fun x -> x) ()
false
Spec.RSAPSS.fst
Spec.RSAPSS.pss_verify_
val pss_verify_: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{sLen + Hash.hash_length a + 2 <= blocks emBits 8} -> em:lbytes (blocks emBits 8) -> Tot bool
val pss_verify_: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{sLen + Hash.hash_length a + 2 <= blocks emBits 8} -> em:lbytes (blocks emBits 8) -> Tot bool
let pss_verify_ a sLen msgLen msg emBits em = let hLen = Hash.hash_length a in let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let maskedDB = sub em 0 dbLen in let m1Hash = sub em dbLen hLen in let dbMask = mgf_hash a hLen m1Hash dbLen in let db = xor_bytes dbMask maskedDB in let db = db_zero db emBits in let padLen = emLen - sLen - hLen - 1 in let pad2 = create padLen (u8 0) in let pad2 = pad2.[padLen - 1] <- u8 0x01 in let pad = sub db 0 padLen in let salt = sub db padLen sLen in if not (lbytes_eq pad pad2) then false else begin let mHash = Hash.hash a msg in let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash0 = Hash.hash a m1 in lbytes_eq m1Hash0 m1Hash end
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 187, "start_col": 0, "start_line": 160 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len) let i2osp len n = nat_to_intseq_be len n /// /// RSA /// type modBits_t = modBits:size_nat{1 < modBits} noeq type rsapss_pkey (modBits:modBits_t) = | Mk_rsapss_pkey: n:pos{pow2 (modBits - 1) < n /\ n < pow2 modBits} -> e:pos -> rsapss_pkey modBits noeq type rsapss_skey (modBits:modBits_t) = | Mk_rsapss_skey: pkey:rsapss_pkey modBits -> d:pos -> rsapss_skey modBits val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0]))) let db_zero #len db emBits = let msBits = emBits % 8 in if msBits > 0 then begin let r = db.[0] <- db.[0] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[0] (u8 0xff >>. size (8 - msBits)) msBits; r end else db val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8) let pss_encode a sLen salt msgLen msg emBits = let mHash = Hash.hash a msg in let hLen = Hash.hash_length a in //m1 = [8 * 0x00; mHash; salt] let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash = Hash.hash a m1 in //db = [0x00;..; 0x00; 0x01; salt] let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let db = create dbLen (u8 0) in let last_before_salt = dbLen - sLen - 1 in let db = db.[last_before_salt] <- u8 1 in let db = update_sub db (last_before_salt + 1) sLen salt in let dbMask = mgf_hash a hLen m1Hash dbLen in let maskedDB = xor_bytes db dbMask in let maskedDB = db_zero maskedDB emBits in //em = [maskedDB; m1Hash; 0xbc] let em = create emLen (u8 0) in let em = update_sub em 0 dbLen maskedDB in let em = update_sub em dbLen hLen m1Hash in assert (v em.[0] == v maskedDB.[0]); em.[emLen - 1] <- u8 0xbc val pss_verify_: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{sLen + Hash.hash_length a + 2 <= blocks emBits 8} -> em:lbytes (blocks emBits 8) -> Tot bool
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} -> sLen: Lib.IntTypes.size_nat { sLen + Spec.Hash.Definitions.hash_length a + 8 <= Lib.IntTypes.max_size_t /\ Spec.Hash.Definitions.less_than_max_input_length (sLen + Spec.Hash.Definitions.hash_length a + 8) a } -> msgLen: Prims.nat{Spec.Hash.Definitions.less_than_max_input_length msgLen a} -> msg: Lib.ByteSequence.bytes{Lib.Sequence.length msg == msgLen} -> emBits: Lib.IntTypes.size_pos {sLen + Spec.Hash.Definitions.hash_length a + 2 <= Spec.RSAPSS.blocks emBits 8} -> em: Lib.ByteSequence.lbytes (Spec.RSAPSS.blocks emBits 8) -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.RSAPSS.hash_is_supported", "Lib.IntTypes.size_nat", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Spec.Hash.Definitions.hash_length", "Lib.IntTypes.max_size_t", "Spec.Hash.Definitions.less_than_max_input_length", "Prims.nat", "Lib.ByteSequence.bytes", "Prims.eq2", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.IntTypes.size_pos", "Spec.RSAPSS.blocks", "Lib.ByteSequence.lbytes", "Prims.op_Negation", "Lib.ByteSequence.lbytes_eq", "Prims.bool", "Spec.Hash.Definitions.hash_length'", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Spec.Agile.Hash.hash", "Lib.Sequence.sub", "Prims.l_Forall", "Prims.l_or", "Prims.op_LessThan", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.Sequence.update_sub", "FStar.Seq.Base.seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Prims.l_imp", "Lib.Sequence.create", "Lib.IntTypes.u8", "Prims.int", "FStar.Seq.Base.slice", "FStar.Seq.Base.upd", "Prims.op_Subtraction", "Prims.pow2", "Prims.op_disEquality", "Lib.Sequence.op_String_Assignment", "Spec.RSAPSS.db_zero", "Spec.RSAPSS.xor_bytes", "Spec.RSAPSS.mgf_hash", "Prims.pos", "Prims.op_Multiply", "Prims.op_GreaterThan" ]
[]
false
false
false
false
false
let pss_verify_ a sLen msgLen msg emBits em =
let hLen = Hash.hash_length a in let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let maskedDB = sub em 0 dbLen in let m1Hash = sub em dbLen hLen in let dbMask = mgf_hash a hLen m1Hash dbLen in let db = xor_bytes dbMask maskedDB in let db = db_zero db emBits in let padLen = emLen - sLen - hLen - 1 in let pad2 = create padLen (u8 0) in let pad2 = pad2.[ padLen - 1 ] <- u8 0x01 in let pad = sub db 0 padLen in let salt = sub db padLen sLen in if not (lbytes_eq pad pad2) then false else let mHash = Hash.hash a msg in let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash0 = Hash.hash a m1 in lbytes_eq m1Hash0 m1Hash
false
Hacl.Spec.Curve25519.Field51.Lemmas.fst
Hacl.Spec.Curve25519.Field51.Lemmas.lemma_prime
val lemma_prime: unit -> Lemma (pow2 255 % prime = 19)
val lemma_prime: unit -> Lemma (pow2 255 % prime = 19)
let lemma_prime () = assert_norm (pow2 255 % prime = 19 % prime); assert_norm (19 < prime); FStar.Math.Lemmas.modulo_lemma 19 prime
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 41, "end_line": 73, "start_col": 0, "start_line": 70 }
module Hacl.Spec.Curve25519.Field51.Lemmas open FStar.Mul open Lib.Sequence open Lib.IntTypes open FStar.Tactics open FStar.Tactics.Canon open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition module BSeq = Lib.ByteSequence module LSeq = Lib.Sequence #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq -FStar.Tactics'" val lemma_mod_sub_distr: a:int -> b:int -> n:pos -> Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr a b n = FStar.Math.Lemmas.lemma_div_mod b n; FStar.Math.Lemmas.distributivity_sub_left 0 (b / n) n; // (a - b) % n == (a - (b % n) - (b / n) * n) % n FStar.Math.Lemmas.lemma_mod_plus (a - (b % n)) (-(b / n)) n val lemma_mul5_distr_r: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma ((a + b + c + d + e) * f == a * f + b * f + c * f + d * f + e * f) let lemma_mul5_distr_r a b c d e f = () val lemma_mul5_distr_l: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * (b + c + d + e + f) == a * b + a * c + a * d + a * e + a * f) let lemma_mul5_distr_l a b c d e f = () val lemma_mul_assos_3: a:nat -> b:nat -> c:nat -> Lemma (a * b * c == a * (b * c)) let lemma_mul_assos_3 a b c = () val lemma_mul_assos_4: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (a * b * c * d == a * (b * c * d)) let lemma_mul_assos_4 a b c d = () val lemma_mul_assos_5: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> Lemma (a * b * c * d * e == a * (b * c * d * e)) let lemma_mul_assos_5 a b c d e = () val lemma_mul_assos_6: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * b * c * d * e * f == a * (b * c * d * e * f)) let lemma_mul_assos_6 a b c d e f = () val lemma_add_le:a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a + c <= b + d) let lemma_add_le a b c d = () val lemma_mul_le:a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a * c <= b * d) let lemma_mul_le a b c d = () val lemma_prime: unit ->
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Canon.fst.checked", "FStar.Tactics.fst.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.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "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.Tactics.Canon", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "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": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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
_: Prims.unit -> FStar.Pervasives.Lemma (ensures Prims.pow2 255 % Spec.Curve25519.prime = 19)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Math.Lemmas.modulo_lemma", "Spec.Curve25519.prime", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Equality", "Prims.int", "Prims.op_Modulus", "Prims.pow2" ]
[]
true
false
true
false
false
let lemma_prime () =
assert_norm (pow2 255 % prime = 19 % prime); assert_norm (19 < prime); FStar.Math.Lemmas.modulo_lemma 19 prime
false
Hacl.Spec.Curve25519.Field51.Lemmas.fst
Hacl.Spec.Curve25519.Field51.Lemmas.lemma_mod_sub_distr
val lemma_mod_sub_distr: a:int -> b:int -> n:pos -> Lemma ((a - b % n) % n = (a - b) % n)
val lemma_mod_sub_distr: a:int -> b:int -> n:pos -> Lemma ((a - b % n) % n = (a - b) % n)
let lemma_mod_sub_distr a b n = FStar.Math.Lemmas.lemma_div_mod b n; FStar.Math.Lemmas.distributivity_sub_left 0 (b / n) n; // (a - b) % n == (a - (b % n) - (b / n) * n) % n FStar.Math.Lemmas.lemma_mod_plus (a - (b % n)) (-(b / n)) n
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 61, "end_line": 24, "start_col": 0, "start_line": 20 }
module Hacl.Spec.Curve25519.Field51.Lemmas open FStar.Mul open Lib.Sequence open Lib.IntTypes open FStar.Tactics open FStar.Tactics.Canon open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition module BSeq = Lib.ByteSequence module LSeq = Lib.Sequence #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq -FStar.Tactics'" val lemma_mod_sub_distr: a:int -> b:int -> n:pos ->
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Canon.fst.checked", "FStar.Tactics.fst.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.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "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.Tactics.Canon", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "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": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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: Prims.int -> b: Prims.int -> n: Prims.pos -> FStar.Pervasives.Lemma (ensures (a - b % n) % n = (a - b) % n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.pos", "FStar.Math.Lemmas.lemma_mod_plus", "Prims.op_Subtraction", "Prims.op_Modulus", "Prims.op_Minus", "Prims.op_Division", "Prims.unit", "FStar.Math.Lemmas.distributivity_sub_left", "FStar.Math.Lemmas.lemma_div_mod" ]
[]
true
false
true
false
false
let lemma_mod_sub_distr a b n =
FStar.Math.Lemmas.lemma_div_mod b n; FStar.Math.Lemmas.distributivity_sub_left 0 (b / n) n; FStar.Math.Lemmas.lemma_mod_plus (a - (b % n)) (- (b / n)) n
false
Spec.RSAPSS.fst
Spec.RSAPSS.pss_encode
val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8)
val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8)
let pss_encode a sLen salt msgLen msg emBits = let mHash = Hash.hash a msg in let hLen = Hash.hash_length a in //m1 = [8 * 0x00; mHash; salt] let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash = Hash.hash a m1 in //db = [0x00;..; 0x00; 0x01; salt] let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let db = create dbLen (u8 0) in let last_before_salt = dbLen - sLen - 1 in let db = db.[last_before_salt] <- u8 1 in let db = update_sub db (last_before_salt + 1) sLen salt in let dbMask = mgf_hash a hLen m1Hash dbLen in let maskedDB = xor_bytes db dbMask in let maskedDB = db_zero maskedDB emBits in //em = [maskedDB; m1Hash; 0xbc] let em = create emLen (u8 0) in let em = update_sub em 0 dbLen maskedDB in let em = update_sub em dbLen hLen m1Hash in assert (v em.[0] == v maskedDB.[0]); em.[emLen - 1] <- u8 0xbc
{ "file_name": "specs/Spec.RSAPSS.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 147, "start_col": 0, "start_line": 119 }
module Spec.RSAPSS open FStar.Mul open Lib.IntTypes open Lib.NatMod open Lib.Sequence open Lib.ByteSequence open Lib.LoopCombinators module Hash = Spec.Agile.Hash #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" (** RFC spec of RSA-PSS: https://tools.ietf.org/html/rfc8017#section-8.1 List of supported hash functions: https://tools.ietf.org/html/rfc8446#appendix-B.3.1.3 Mask generation function: https://tools.ietf.org/html/rfc8017#page-67 *) /// /// Auxillary functions /// val blocks: x:size_pos -> m:size_pos -> Tot (r:size_pos{x <= m * r}) let blocks x m = (x - 1) / m + 1 val xor_bytes: #len:size_pos -> b1:lbytes len -> b2:lbytes len -> Tot (lbytes len) let xor_bytes #len b1 b2 = map2 (fun x y -> x ^. y) b1 b2 let hash_is_supported (a:Hash.hash_alg) : Tot bool = match a with | Hash.SHA2_256 -> true | Hash.SHA2_384 -> true | Hash.SHA2_512 -> true | _ -> false (* Mask Generation Function *) val mgf_hash_f: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> i:size_nat -> mgfseed_counter:lbytes (len + 4) -> lbytes (len + 4) & lbytes (Hash.hash_length a) let mgf_hash_f a len i mgfseed_counter = let counter = nat_to_intseq_be 4 i in let mgfseed_counter = update_sub mgfseed_counter len 4 counter in let block = Hash.hash a mgfseed_counter in mgfseed_counter, block let mgf_hash_a (len:size_nat{len + 4 <= max_size_t}) (n:pos) (i:nat{i <= n}) = lbytes (len + 4) val mgf_hash: a:Hash.hash_alg{hash_is_supported a} -> len:size_nat{len + 4 <= max_size_t /\ (len + 4) `Hash.less_than_max_input_length` a} -> mgfseed:lbytes len -> maskLen:size_pos{(blocks maskLen (Hash.hash_length a)) * Hash.hash_length a < pow2 32} -> Tot (lbytes maskLen) let mgf_hash a len mgfseed maskLen = let mgfseed_counter = create (len + 4) (u8 0) in let mgfseed_counter = update_sub mgfseed_counter 0 len mgfseed in let hLen = Hash.hash_length a in let n = blocks maskLen hLen in let _, acc = generate_blocks #uint8 hLen n n (mgf_hash_a len n) (mgf_hash_f a len) mgfseed_counter in sub #uint8 #(n * hLen) acc 0 maskLen (* Bignum convert functions *) val os2ip: #len:size_nat -> b:lbytes len -> Tot (res:nat{res < pow2 (8 * len)}) let os2ip #len b = nat_from_bytes_be b val i2osp: len:size_nat -> n:nat{n < pow2 (8 * len)} -> Tot (lbytes len) let i2osp len n = nat_to_intseq_be len n /// /// RSA /// type modBits_t = modBits:size_nat{1 < modBits} noeq type rsapss_pkey (modBits:modBits_t) = | Mk_rsapss_pkey: n:pos{pow2 (modBits - 1) < n /\ n < pow2 modBits} -> e:pos -> rsapss_pkey modBits noeq type rsapss_skey (modBits:modBits_t) = | Mk_rsapss_skey: pkey:rsapss_pkey modBits -> d:pos -> rsapss_skey modBits val db_zero: #len:size_pos -> db:lbytes len -> emBits:size_nat -> Pure (lbytes len) (requires True) (ensures fun res -> (v res.[0] == (if emBits % 8 > 0 then v db.[0] % pow2 (emBits % 8) else v db.[0]))) let db_zero #len db emBits = let msBits = emBits % 8 in if msBits > 0 then begin let r = db.[0] <- db.[0] &. (u8 0xff >>. size (8 - msBits)) in Math.Lemmas.pow2_plus msBits (8 - msBits); logand_mask db.[0] (u8 0xff >>. size (8 - msBits)) msBits; r end else db val pss_encode: a:Hash.hash_alg{hash_is_supported a} -> sLen:size_nat{sLen + Hash.hash_length a + 8 <= max_size_t /\ (sLen + Hash.hash_length a + 8) `Hash.less_than_max_input_length` a} -> salt:lbytes sLen -> msgLen:nat{msgLen `Hash.less_than_max_input_length` a} -> msg:bytes{length msg == msgLen} -> emBits:size_pos{Hash.hash_length a + sLen + 2 <= blocks emBits 8} -> Pure (lbytes (blocks emBits 8)) (requires True) (ensures fun em -> if emBits % 8 > 0 then v em.[0] < pow2 (emBits % 8) else v em.[0] < pow2 8)
{ "checked_file": "/", "dependencies": [ "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.NatMod.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.UInt8.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Spec.RSAPSS.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NatMod", "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", "short_module": null }, { "abbrev": false, "full_module": "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Hash.Definitions.hash_alg{Spec.RSAPSS.hash_is_supported a} -> sLen: Lib.IntTypes.size_nat { sLen + Spec.Hash.Definitions.hash_length a + 8 <= Lib.IntTypes.max_size_t /\ Spec.Hash.Definitions.less_than_max_input_length (sLen + Spec.Hash.Definitions.hash_length a + 8) a } -> salt: Lib.ByteSequence.lbytes sLen -> msgLen: Prims.nat{Spec.Hash.Definitions.less_than_max_input_length msgLen a} -> msg: Lib.ByteSequence.bytes{Lib.Sequence.length msg == msgLen} -> emBits: Lib.IntTypes.size_pos {Spec.Hash.Definitions.hash_length a + sLen + 2 <= Spec.RSAPSS.blocks emBits 8} -> Prims.Pure (Lib.ByteSequence.lbytes (Spec.RSAPSS.blocks emBits 8))
Prims.Pure
[]
[]
[ "Spec.Hash.Definitions.hash_alg", "Prims.b2t", "Spec.RSAPSS.hash_is_supported", "Lib.IntTypes.size_nat", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Spec.Hash.Definitions.hash_length", "Lib.IntTypes.max_size_t", "Spec.Hash.Definitions.less_than_max_input_length", "Lib.ByteSequence.lbytes", "Prims.nat", "Lib.ByteSequence.bytes", "Prims.eq2", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.IntTypes.size_pos", "Spec.RSAPSS.blocks", "Lib.Sequence.op_String_Assignment", "Prims.op_Subtraction", "Lib.IntTypes.u8", "Prims.unit", "Prims._assert", "Lib.IntTypes.range_t", "Lib.IntTypes.v", "Lib.Sequence.op_String_Access", "Lib.Sequence.lseq", "Lib.IntTypes.int_t", "Lib.Sequence.sub", "Prims.l_Forall", "Prims.l_or", "Prims.op_LessThan", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.Sequence.index", "Lib.Sequence.update_sub", "FStar.Seq.Base.seq", "FStar.Seq.Base.create", "Lib.IntTypes.mk_int", "Prims.l_imp", "Lib.Sequence.create", "Spec.RSAPSS.db_zero", "Spec.RSAPSS.xor_bytes", "Spec.RSAPSS.mgf_hash", "FStar.Seq.Base.upd", "Prims.pow2", "Prims.op_disEquality", "Prims.int", "Prims.pos", "Prims.op_Multiply", "Spec.Hash.Definitions.hash_length'", "Spec.Agile.Hash.hash", "Prims.op_GreaterThan" ]
[]
false
false
false
false
false
let pss_encode a sLen salt msgLen msg emBits =
let mHash = Hash.hash a msg in let hLen = Hash.hash_length a in let m1Len = 8 + hLen + sLen in let m1 = create m1Len (u8 0) in let m1 = update_sub m1 8 hLen mHash in let m1 = update_sub m1 (8 + hLen) sLen salt in let m1Hash = Hash.hash a m1 in let emLen = blocks emBits 8 in let dbLen = emLen - hLen - 1 in let db = create dbLen (u8 0) in let last_before_salt = dbLen - sLen - 1 in let db = db.[ last_before_salt ] <- u8 1 in let db = update_sub db (last_before_salt + 1) sLen salt in let dbMask = mgf_hash a hLen m1Hash dbLen in let maskedDB = xor_bytes db dbMask in let maskedDB = db_zero maskedDB emBits in let em = create emLen (u8 0) in let em = update_sub em 0 dbLen maskedDB in let em = update_sub em dbLen hLen m1Hash in assert (v em.[ 0 ] == v maskedDB.[ 0 ]); em.[ emLen - 1 ] <- u8 0xbc
false
Hacl.Spec.Curve25519.Field51.Lemmas.fst
Hacl.Spec.Curve25519.Field51.Lemmas.lemma_add_zero
val lemma_add_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> Lemma ( let (f10, f11, f12, f13, f14) = f1 in 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 let out = (o0, o1, o2, o3, o4) in feval out == feval f1)
val lemma_add_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> Lemma ( let (f10, f11, f12, f13, f14) = f1 in 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 let out = (o0, o1, o2, o3, o4) in feval out == feval f1)
let lemma_add_zero f1 = let (f10, f11, f12, f13, f14) = f1 in 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 let out = (o0, o1, o2, o3, o4) in assert (feval out == (v f10 + 0x3fffffffffff68 + (v f11 + 0x3ffffffffffff8) * pow51 + (v f12 + 0x3ffffffffffff8) * pow51 * pow51 + (v f13 + 0x3ffffffffffff8) * pow51 * pow51 * pow51 + (v f14 + 0x3ffffffffffff8) * pow51 * pow51 * pow51 * pow51) % prime); FStar.Math.Lemmas.distributivity_add_left (v f11) 0x3ffffffffffff8 pow51; FStar.Math.Lemmas.distributivity_add_left (v f12) 0x3ffffffffffff8 (pow51 * pow51); FStar.Math.Lemmas.distributivity_add_left (v f13) 0x3ffffffffffff8 (pow51 * pow51 * pow51); FStar.Math.Lemmas.distributivity_add_left (v f14) 0x3ffffffffffff8 (pow51 * pow51 * pow51 * pow51); assert_norm ( 0x3fffffffffff68 + 0x3ffffffffffff8 * pow51 + 0x3ffffffffffff8 * pow51 * pow51 + 0x3ffffffffffff8 * pow51 * pow51 * pow51 + 0x3ffffffffffff8 * pow51 * pow51 * pow51 * pow51 = 8 * prime); assert (feval out == (v f10 + v f11 * pow51 + v f12 * pow51 * pow51 + v f13 * pow51 * pow51 * pow51 + v f14 * pow51 * pow51 * pow51 * pow51 + 8 * prime) % prime); FStar.Math.Lemmas.lemma_mod_plus (as_nat5 f1) 8 prime; assert (feval out == (v f10 + v f11 * pow51 + v f12 * pow51 * pow51 + v f13 * pow51 * pow51 * pow51 + v f14 * pow51 * pow51 * pow51 * pow51) % prime)
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 51, "end_line": 116, "start_col": 0, "start_line": 86 }
module Hacl.Spec.Curve25519.Field51.Lemmas open FStar.Mul open Lib.Sequence open Lib.IntTypes open FStar.Tactics open FStar.Tactics.Canon open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition module BSeq = Lib.ByteSequence module LSeq = Lib.Sequence #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq -FStar.Tactics'" val lemma_mod_sub_distr: a:int -> b:int -> n:pos -> Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr a b n = FStar.Math.Lemmas.lemma_div_mod b n; FStar.Math.Lemmas.distributivity_sub_left 0 (b / n) n; // (a - b) % n == (a - (b % n) - (b / n) * n) % n FStar.Math.Lemmas.lemma_mod_plus (a - (b % n)) (-(b / n)) n val lemma_mul5_distr_r: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma ((a + b + c + d + e) * f == a * f + b * f + c * f + d * f + e * f) let lemma_mul5_distr_r a b c d e f = () val lemma_mul5_distr_l: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * (b + c + d + e + f) == a * b + a * c + a * d + a * e + a * f) let lemma_mul5_distr_l a b c d e f = () val lemma_mul_assos_3: a:nat -> b:nat -> c:nat -> Lemma (a * b * c == a * (b * c)) let lemma_mul_assos_3 a b c = () val lemma_mul_assos_4: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (a * b * c * d == a * (b * c * d)) let lemma_mul_assos_4 a b c d = () val lemma_mul_assos_5: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> Lemma (a * b * c * d * e == a * (b * c * d * e)) let lemma_mul_assos_5 a b c d e = () val lemma_mul_assos_6: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * b * c * d * e * f == a * (b * c * d * e * f)) let lemma_mul_assos_6 a b c d e f = () val lemma_add_le:a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a + c <= b + d) let lemma_add_le a b c d = () val lemma_mul_le:a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a * c <= b * d) let lemma_mul_le a b c d = () val lemma_prime: unit -> Lemma (pow2 255 % prime = 19) let lemma_prime () = assert_norm (pow2 255 % prime = 19 % prime); assert_norm (19 < prime); FStar.Math.Lemmas.modulo_lemma 19 prime val lemma_add_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> Lemma ( let (f10, f11, f12, f13, f14) = f1 in 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 let out = (o0, o1, o2, o3, o4) in
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Canon.fst.checked", "FStar.Tactics.fst.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.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "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.Tactics.Canon", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "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": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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
f1: Hacl.Spec.Curve25519.Field51.Definition.felem5 {Hacl.Spec.Curve25519.Field51.Definition.felem_fits5 f1 (1, 2, 1, 1, 1)} -> FStar.Pervasives.Lemma (ensures (let _ = f1 in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ f10 f11 f12 f13 f14 = _ in let o0 = f10 +! Lib.IntTypes.u64 0x3fffffffffff68 in let o1 = f11 +! Lib.IntTypes.u64 0x3ffffffffffff8 in let o2 = f12 +! Lib.IntTypes.u64 0x3ffffffffffff8 in let o3 = f13 +! Lib.IntTypes.u64 0x3ffffffffffff8 in let o4 = f14 +! Lib.IntTypes.u64 0x3ffffffffffff8 in let out = o0, o1, o2, o3, o4 in Hacl.Spec.Curve25519.Field51.Definition.feval out == Hacl.Spec.Curve25519.Field51.Definition.feval f1) <: 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._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.Curve25519.Field51.Definition.feval", "Prims.op_Modulus", "Prims.op_Addition", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.Mul.op_Star", "Hacl.Spec.Curve25519.Field51.Definition.pow51", "Spec.Curve25519.prime", "Prims.unit", "FStar.Math.Lemmas.lemma_mod_plus", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality", "FStar.Math.Lemmas.distributivity_add_left", "FStar.Pervasives.Native.tuple5", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Plus_Bang", "Lib.IntTypes.u64" ]
[]
false
false
true
false
false
let lemma_add_zero f1 =
let f10, f11, f12, f13, f14 = f1 in 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 let out = (o0, o1, o2, o3, o4) in assert (feval out == (v f10 + 0x3fffffffffff68 + (v f11 + 0x3ffffffffffff8) * pow51 + ((v f12 + 0x3ffffffffffff8) * pow51) * pow51 + (((v f13 + 0x3ffffffffffff8) * pow51) * pow51) * pow51 + ((((v f14 + 0x3ffffffffffff8) * pow51) * pow51) * pow51) * pow51) % prime); FStar.Math.Lemmas.distributivity_add_left (v f11) 0x3ffffffffffff8 pow51; FStar.Math.Lemmas.distributivity_add_left (v f12) 0x3ffffffffffff8 (pow51 * pow51); FStar.Math.Lemmas.distributivity_add_left (v f13) 0x3ffffffffffff8 ((pow51 * pow51) * pow51); FStar.Math.Lemmas.distributivity_add_left (v f14) 0x3ffffffffffff8 (((pow51 * pow51) * pow51) * pow51); assert_norm (0x3fffffffffff68 + 0x3ffffffffffff8 * pow51 + (0x3ffffffffffff8 * pow51) * pow51 + ((0x3ffffffffffff8 * pow51) * pow51) * pow51 + (((0x3ffffffffffff8 * pow51) * pow51) * pow51) * pow51 = 8 * prime); assert (feval out == (v f10 + v f11 * pow51 + (v f12 * pow51) * pow51 + ((v f13 * pow51) * pow51) * pow51 + (((v f14 * pow51) * pow51) * pow51) * pow51 + 8 * prime) % prime); FStar.Math.Lemmas.lemma_mod_plus (as_nat5 f1) 8 prime; assert (feval out == (v f10 + v f11 * pow51 + (v f12 * pow51) * pow51 + ((v f13 * pow51) * pow51) * pow51 + (((v f14 * pow51) * pow51) * pow51) * pow51) % prime)
false
Hacl.Spec.Curve25519.Field51.Lemmas.fst
Hacl.Spec.Curve25519.Field51.Lemmas.lemma_fmul5_pow51_pow51_pow51_pow51
val lemma_fmul5_pow51_pow51_pow51_pow51: r:felem5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 19 <= 190 * pow51 /\ v r3 * 19 <= 190 * pow51 /\ v r2 * 19 <= 190 * pow51 /\ v r1 * 19 <= 190 * pow51)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow51 * pow51 * pow51 * pow51 * as_nat5 r) % prime == as_nat5 (r1 *! u64 19, r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0) % prime))
val lemma_fmul5_pow51_pow51_pow51_pow51: r:felem5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 19 <= 190 * pow51 /\ v r3 * 19 <= 190 * pow51 /\ v r2 * 19 <= 190 * pow51 /\ v r1 * 19 <= 190 * pow51)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow51 * pow51 * pow51 * pow51 * as_nat5 r) % prime == as_nat5 (r1 *! u64 19, r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0) % prime))
let lemma_fmul5_pow51_pow51_pow51_pow51 r = let (r0, r1, r2, r3, r4) = r in lemma_mul_assos_5 pow51 pow51 pow51 pow51 (as_nat5 r); let p51p51p51r = pow51 * pow51 * pow51 * as_nat5 r in FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 p51p51p51r prime; assert ((pow51 * pow51 * pow51 * pow51 * as_nat5 r) % prime == (pow51 * (p51p51p51r % prime)) % prime); lemma_fmul5_pow51_pow51_pow51 r; assert ((pow51 * pow51 * pow51 * pow51 * as_nat5 r) % prime == (pow51 * (as_nat5 (r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0, r1) % prime)) % prime); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0, r1)) prime; lemma_fmul5_pow51 (r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0, r1); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r1 *! u64 19, r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0)) prime
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 124, "end_line": 203, "start_col": 0, "start_line": 192 }
module Hacl.Spec.Curve25519.Field51.Lemmas open FStar.Mul open Lib.Sequence open Lib.IntTypes open FStar.Tactics open FStar.Tactics.Canon open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition module BSeq = Lib.ByteSequence module LSeq = Lib.Sequence #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq -FStar.Tactics'" val lemma_mod_sub_distr: a:int -> b:int -> n:pos -> Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr a b n = FStar.Math.Lemmas.lemma_div_mod b n; FStar.Math.Lemmas.distributivity_sub_left 0 (b / n) n; // (a - b) % n == (a - (b % n) - (b / n) * n) % n FStar.Math.Lemmas.lemma_mod_plus (a - (b % n)) (-(b / n)) n val lemma_mul5_distr_r: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma ((a + b + c + d + e) * f == a * f + b * f + c * f + d * f + e * f) let lemma_mul5_distr_r a b c d e f = () val lemma_mul5_distr_l: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * (b + c + d + e + f) == a * b + a * c + a * d + a * e + a * f) let lemma_mul5_distr_l a b c d e f = () val lemma_mul_assos_3: a:nat -> b:nat -> c:nat -> Lemma (a * b * c == a * (b * c)) let lemma_mul_assos_3 a b c = () val lemma_mul_assos_4: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (a * b * c * d == a * (b * c * d)) let lemma_mul_assos_4 a b c d = () val lemma_mul_assos_5: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> Lemma (a * b * c * d * e == a * (b * c * d * e)) let lemma_mul_assos_5 a b c d e = () val lemma_mul_assos_6: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * b * c * d * e * f == a * (b * c * d * e * f)) let lemma_mul_assos_6 a b c d e f = () val lemma_add_le:a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a + c <= b + d) let lemma_add_le a b c d = () val lemma_mul_le:a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a * c <= b * d) let lemma_mul_le a b c d = () val lemma_prime: unit -> Lemma (pow2 255 % prime = 19) let lemma_prime () = assert_norm (pow2 255 % prime = 19 % prime); assert_norm (19 < prime); FStar.Math.Lemmas.modulo_lemma 19 prime val lemma_add_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> Lemma ( let (f10, f11, f12, f13, f14) = f1 in 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 let out = (o0, o1, o2, o3, o4) in feval out == feval f1) let lemma_add_zero f1 = let (f10, f11, f12, f13, f14) = f1 in 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 let out = (o0, o1, o2, o3, o4) in assert (feval out == (v f10 + 0x3fffffffffff68 + (v f11 + 0x3ffffffffffff8) * pow51 + (v f12 + 0x3ffffffffffff8) * pow51 * pow51 + (v f13 + 0x3ffffffffffff8) * pow51 * pow51 * pow51 + (v f14 + 0x3ffffffffffff8) * pow51 * pow51 * pow51 * pow51) % prime); FStar.Math.Lemmas.distributivity_add_left (v f11) 0x3ffffffffffff8 pow51; FStar.Math.Lemmas.distributivity_add_left (v f12) 0x3ffffffffffff8 (pow51 * pow51); FStar.Math.Lemmas.distributivity_add_left (v f13) 0x3ffffffffffff8 (pow51 * pow51 * pow51); FStar.Math.Lemmas.distributivity_add_left (v f14) 0x3ffffffffffff8 (pow51 * pow51 * pow51 * pow51); assert_norm ( 0x3fffffffffff68 + 0x3ffffffffffff8 * pow51 + 0x3ffffffffffff8 * pow51 * pow51 + 0x3ffffffffffff8 * pow51 * pow51 * pow51 + 0x3ffffffffffff8 * pow51 * pow51 * pow51 * pow51 = 8 * prime); assert (feval out == (v f10 + v f11 * pow51 + v f12 * pow51 * pow51 + v f13 * pow51 * pow51 * pow51 + v f14 * pow51 * pow51 * pow51 * pow51 + 8 * prime) % prime); FStar.Math.Lemmas.lemma_mod_plus (as_nat5 f1) 8 prime; assert (feval out == (v f10 + v f11 * pow51 + v f12 * pow51 * pow51 + v f13 * pow51 * pow51 * pow51 + v f14 * pow51 * pow51 * pow51 * pow51) % prime) val lemma_fmul5_pow51: r:felem5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 19 <= 190 * pow51)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow51 * as_nat5 r) % prime == as_nat5 (r4 *! u64 19, r0, r1, r2, r3) % prime)) let lemma_fmul5_pow51 r = let (r0, r1, r2, r3, r4) = r in assert (pow51 * as_nat5 r == pow51 * (v r0 + v r1 * pow51 + v r2 * pow51 * pow51 + v r3 * pow51 * pow51 * pow51 + v r4 * pow51 * pow51 * pow51 * pow51)); lemma_mul5_distr_l pow51 (v r0) (v r1 * pow51) (v r2 * pow51 * pow51) (v r3 * pow51 * pow51 * pow51) (v r4 * pow51 * pow51 * pow51 * pow51); let p51r0123 = pow51 * v r0 + pow51 * v r1 * pow51 + pow51 * v r2 * pow51 * pow51 + pow51 * v r3 * pow51 * pow51 * pow51 in let p51r4 = pow51 * v r4 * pow51 * pow51 * pow51 * pow51 in assert ((pow51 * as_nat5 r) % prime == (p51r0123 + p51r4) % prime); FStar.Math.Lemmas.lemma_mod_plus_distr_r p51r0123 p51r4 prime; assert_norm (p51r4 % prime == (v r4 * pow2 255) % prime); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v r4) (pow2 255) prime; lemma_prime (); assert_norm ((v r4 * pow2 255) % prime == (v r4 * 19) % prime); FStar.Math.Lemmas.lemma_mod_plus_distr_r p51r0123 (v r4 * 19) prime val lemma_fmul5_pow51_pow51:r:felem5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 19 <= 190 * pow51 /\ v r3 * 19 <= 190 * pow51)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow51 * pow51 * as_nat5 r) % prime == as_nat5 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2) % prime)) let lemma_fmul5_pow51_pow51 r = let (r0, r1, r2, r3, r4) = r in lemma_mul_assos_3 pow51 pow51 (as_nat5 r); let p51r = pow51 * as_nat5 r in FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 p51r prime; assert ((pow51 * pow51 * as_nat5 r) % prime == (pow51 * (p51r % prime)) % prime); lemma_fmul5_pow51 r; assert ((pow51 * pow51 * as_nat5 r) % prime == (pow51 * (as_nat5 (r4 *! u64 19, r0, r1, r2, r3) % prime)) % prime); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r4 *! u64 19, r0, r1, r2, r3)) prime; lemma_fmul5_pow51 (r4 *! u64 19, r0, r1, r2, r3); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2)) prime val lemma_fmul5_pow51_pow51_pow51: r:felem5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 19 <= 190 * pow51 /\ v r3 * 19 <= 190 * pow51 /\ v r2 * 19 <= 190 * pow51)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow51 * pow51 * pow51 * as_nat5 r) % prime == as_nat5 (r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0, r1) % prime)) let lemma_fmul5_pow51_pow51_pow51 r = let (r0, r1, r2, r3, r4) = r in lemma_mul_assos_4 pow51 pow51 pow51 (as_nat5 r); let p51p51r = pow51 * pow51 * as_nat5 r in FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 p51p51r prime; assert ((pow51 * pow51 * pow51 * as_nat5 r) % prime == (pow51 * (p51p51r % prime)) % prime); lemma_fmul5_pow51_pow51 r; assert ((pow51 * pow51 * pow51 * as_nat5 r) % prime == (pow51 * (as_nat5 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2) % prime)) % prime); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2)) prime; lemma_fmul5_pow51 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0, r1)) prime val lemma_fmul5_pow51_pow51_pow51_pow51: r:felem5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 19 <= 190 * pow51 /\ v r3 * 19 <= 190 * pow51 /\ v r2 * 19 <= 190 * pow51 /\ v r1 * 19 <= 190 * pow51)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow51 * pow51 * pow51 * pow51 * as_nat5 r) % prime ==
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Canon.fst.checked", "FStar.Tactics.fst.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.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "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.Tactics.Canon", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "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": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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
r: Hacl.Spec.Curve25519.Field51.Definition.felem5 -> FStar.Pervasives.Lemma (requires (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ r1 r2 r3 r4 = _ in Lib.IntTypes.v r4 * 19 <= 190 * Hacl.Spec.Curve25519.Field51.Definition.pow51 /\ Lib.IntTypes.v r3 * 19 <= 190 * Hacl.Spec.Curve25519.Field51.Definition.pow51 /\ Lib.IntTypes.v r2 * 19 <= 190 * Hacl.Spec.Curve25519.Field51.Definition.pow51 /\ Lib.IntTypes.v r1 * 19 <= 190 * Hacl.Spec.Curve25519.Field51.Definition.pow51) <: Type0)) (ensures (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ r0 r1 r2 r3 r4 = _ in (((Hacl.Spec.Curve25519.Field51.Definition.pow51 * Hacl.Spec.Curve25519.Field51.Definition.pow51) * Hacl.Spec.Curve25519.Field51.Definition.pow51) * Hacl.Spec.Curve25519.Field51.Definition.pow51) * Hacl.Spec.Curve25519.Field51.Definition.as_nat5 r % Spec.Curve25519.prime == Hacl.Spec.Curve25519.Field51.Definition.as_nat5 (r1 *! Lib.IntTypes.u64 19, r2 *! Lib.IntTypes.u64 19, r3 *! Lib.IntTypes.u64 19, r4 *! Lib.IntTypes.u64 19, r0) % Spec.Curve25519.prime) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Lib.IntTypes.uint64", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "Hacl.Spec.Curve25519.Field51.Definition.pow51", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.u64", "Spec.Curve25519.prime", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_fmul5_pow51", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.Mul.op_Star", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_fmul5_pow51_pow51_pow51", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_mul_assos_5" ]
[]
false
false
true
false
false
let lemma_fmul5_pow51_pow51_pow51_pow51 r =
let r0, r1, r2, r3, r4 = r in lemma_mul_assos_5 pow51 pow51 pow51 pow51 (as_nat5 r); let p51p51p51r = ((pow51 * pow51) * pow51) * as_nat5 r in FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 p51p51p51r prime; assert (((((pow51 * pow51) * pow51) * pow51) * as_nat5 r) % prime == (pow51 * (p51p51p51r % prime)) % prime); lemma_fmul5_pow51_pow51_pow51 r; assert (((((pow51 * pow51) * pow51) * pow51) * as_nat5 r) % prime == (pow51 * (as_nat5 (r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0, r1) % prime)) % prime); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0, r1)) prime; lemma_fmul5_pow51 (r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0, r1); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r1 *! u64 19, r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0)) prime
false
Hacl.Spec.Curve25519.Field51.Lemmas.fst
Hacl.Spec.Curve25519.Field51.Lemmas.lemma_fmul5_pow51_pow51_pow51
val lemma_fmul5_pow51_pow51_pow51: r:felem5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 19 <= 190 * pow51 /\ v r3 * 19 <= 190 * pow51 /\ v r2 * 19 <= 190 * pow51)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow51 * pow51 * pow51 * as_nat5 r) % prime == as_nat5 (r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0, r1) % prime))
val lemma_fmul5_pow51_pow51_pow51: r:felem5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 19 <= 190 * pow51 /\ v r3 * 19 <= 190 * pow51 /\ v r2 * 19 <= 190 * pow51)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow51 * pow51 * pow51 * as_nat5 r) % prime == as_nat5 (r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0, r1) % prime))
let lemma_fmul5_pow51_pow51_pow51 r = let (r0, r1, r2, r3, r4) = r in lemma_mul_assos_4 pow51 pow51 pow51 (as_nat5 r); let p51p51r = pow51 * pow51 * as_nat5 r in FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 p51p51r prime; assert ((pow51 * pow51 * pow51 * as_nat5 r) % prime == (pow51 * (p51p51r % prime)) % prime); lemma_fmul5_pow51_pow51 r; assert ((pow51 * pow51 * pow51 * as_nat5 r) % prime == (pow51 * (as_nat5 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2) % prime)) % prime); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2)) prime; lemma_fmul5_pow51 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0, r1)) prime
{ "file_name": "code/curve25519/Hacl.Spec.Curve25519.Field51.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 114, "end_line": 182, "start_col": 0, "start_line": 171 }
module Hacl.Spec.Curve25519.Field51.Lemmas open FStar.Mul open Lib.Sequence open Lib.IntTypes open FStar.Tactics open FStar.Tactics.Canon open Spec.Curve25519 open Hacl.Spec.Curve25519.Field51.Definition module BSeq = Lib.ByteSequence module LSeq = Lib.Sequence #reset-options "--z3rlimit 50 --using_facts_from '* -FStar.Seq -FStar.Tactics'" val lemma_mod_sub_distr: a:int -> b:int -> n:pos -> Lemma ((a - b % n) % n = (a - b) % n) let lemma_mod_sub_distr a b n = FStar.Math.Lemmas.lemma_div_mod b n; FStar.Math.Lemmas.distributivity_sub_left 0 (b / n) n; // (a - b) % n == (a - (b % n) - (b / n) * n) % n FStar.Math.Lemmas.lemma_mod_plus (a - (b % n)) (-(b / n)) n val lemma_mul5_distr_r: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma ((a + b + c + d + e) * f == a * f + b * f + c * f + d * f + e * f) let lemma_mul5_distr_r a b c d e f = () val lemma_mul5_distr_l: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * (b + c + d + e + f) == a * b + a * c + a * d + a * e + a * f) let lemma_mul5_distr_l a b c d e f = () val lemma_mul_assos_3: a:nat -> b:nat -> c:nat -> Lemma (a * b * c == a * (b * c)) let lemma_mul_assos_3 a b c = () val lemma_mul_assos_4: a:nat -> b:nat -> c:nat -> d:nat -> Lemma (a * b * c * d == a * (b * c * d)) let lemma_mul_assos_4 a b c d = () val lemma_mul_assos_5: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> Lemma (a * b * c * d * e == a * (b * c * d * e)) let lemma_mul_assos_5 a b c d e = () val lemma_mul_assos_6: a:nat -> b:nat -> c:nat -> d:nat -> e:nat -> f:nat -> Lemma (a * b * c * d * e * f == a * (b * c * d * e * f)) let lemma_mul_assos_6 a b c d e f = () val lemma_add_le:a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a + c <= b + d) let lemma_add_le a b c d = () val lemma_mul_le:a:nat -> b:nat -> c:nat -> d:nat -> Lemma (requires a <= b /\ c <= d) (ensures a * c <= b * d) let lemma_mul_le a b c d = () val lemma_prime: unit -> Lemma (pow2 255 % prime = 19) let lemma_prime () = assert_norm (pow2 255 % prime = 19 % prime); assert_norm (19 < prime); FStar.Math.Lemmas.modulo_lemma 19 prime val lemma_add_zero: f1:felem5{felem_fits5 f1 (1, 2, 1, 1, 1)} -> Lemma ( let (f10, f11, f12, f13, f14) = f1 in 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 let out = (o0, o1, o2, o3, o4) in feval out == feval f1) let lemma_add_zero f1 = let (f10, f11, f12, f13, f14) = f1 in 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 let out = (o0, o1, o2, o3, o4) in assert (feval out == (v f10 + 0x3fffffffffff68 + (v f11 + 0x3ffffffffffff8) * pow51 + (v f12 + 0x3ffffffffffff8) * pow51 * pow51 + (v f13 + 0x3ffffffffffff8) * pow51 * pow51 * pow51 + (v f14 + 0x3ffffffffffff8) * pow51 * pow51 * pow51 * pow51) % prime); FStar.Math.Lemmas.distributivity_add_left (v f11) 0x3ffffffffffff8 pow51; FStar.Math.Lemmas.distributivity_add_left (v f12) 0x3ffffffffffff8 (pow51 * pow51); FStar.Math.Lemmas.distributivity_add_left (v f13) 0x3ffffffffffff8 (pow51 * pow51 * pow51); FStar.Math.Lemmas.distributivity_add_left (v f14) 0x3ffffffffffff8 (pow51 * pow51 * pow51 * pow51); assert_norm ( 0x3fffffffffff68 + 0x3ffffffffffff8 * pow51 + 0x3ffffffffffff8 * pow51 * pow51 + 0x3ffffffffffff8 * pow51 * pow51 * pow51 + 0x3ffffffffffff8 * pow51 * pow51 * pow51 * pow51 = 8 * prime); assert (feval out == (v f10 + v f11 * pow51 + v f12 * pow51 * pow51 + v f13 * pow51 * pow51 * pow51 + v f14 * pow51 * pow51 * pow51 * pow51 + 8 * prime) % prime); FStar.Math.Lemmas.lemma_mod_plus (as_nat5 f1) 8 prime; assert (feval out == (v f10 + v f11 * pow51 + v f12 * pow51 * pow51 + v f13 * pow51 * pow51 * pow51 + v f14 * pow51 * pow51 * pow51 * pow51) % prime) val lemma_fmul5_pow51: r:felem5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 19 <= 190 * pow51)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow51 * as_nat5 r) % prime == as_nat5 (r4 *! u64 19, r0, r1, r2, r3) % prime)) let lemma_fmul5_pow51 r = let (r0, r1, r2, r3, r4) = r in assert (pow51 * as_nat5 r == pow51 * (v r0 + v r1 * pow51 + v r2 * pow51 * pow51 + v r3 * pow51 * pow51 * pow51 + v r4 * pow51 * pow51 * pow51 * pow51)); lemma_mul5_distr_l pow51 (v r0) (v r1 * pow51) (v r2 * pow51 * pow51) (v r3 * pow51 * pow51 * pow51) (v r4 * pow51 * pow51 * pow51 * pow51); let p51r0123 = pow51 * v r0 + pow51 * v r1 * pow51 + pow51 * v r2 * pow51 * pow51 + pow51 * v r3 * pow51 * pow51 * pow51 in let p51r4 = pow51 * v r4 * pow51 * pow51 * pow51 * pow51 in assert ((pow51 * as_nat5 r) % prime == (p51r0123 + p51r4) % prime); FStar.Math.Lemmas.lemma_mod_plus_distr_r p51r0123 p51r4 prime; assert_norm (p51r4 % prime == (v r4 * pow2 255) % prime); FStar.Math.Lemmas.lemma_mod_mul_distr_r (v r4) (pow2 255) prime; lemma_prime (); assert_norm ((v r4 * pow2 255) % prime == (v r4 * 19) % prime); FStar.Math.Lemmas.lemma_mod_plus_distr_r p51r0123 (v r4 * 19) prime val lemma_fmul5_pow51_pow51:r:felem5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 19 <= 190 * pow51 /\ v r3 * 19 <= 190 * pow51)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow51 * pow51 * as_nat5 r) % prime == as_nat5 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2) % prime)) let lemma_fmul5_pow51_pow51 r = let (r0, r1, r2, r3, r4) = r in lemma_mul_assos_3 pow51 pow51 (as_nat5 r); let p51r = pow51 * as_nat5 r in FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 p51r prime; assert ((pow51 * pow51 * as_nat5 r) % prime == (pow51 * (p51r % prime)) % prime); lemma_fmul5_pow51 r; assert ((pow51 * pow51 * as_nat5 r) % prime == (pow51 * (as_nat5 (r4 *! u64 19, r0, r1, r2, r3) % prime)) % prime); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r4 *! u64 19, r0, r1, r2, r3)) prime; lemma_fmul5_pow51 (r4 *! u64 19, r0, r1, r2, r3); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2)) prime val lemma_fmul5_pow51_pow51_pow51: r:felem5 -> Lemma (requires (let (r0, r1, r2, r3, r4) = r in v r4 * 19 <= 190 * pow51 /\ v r3 * 19 <= 190 * pow51 /\ v r2 * 19 <= 190 * pow51)) (ensures (let (r0, r1, r2, r3, r4) = r in (pow51 * pow51 * pow51 * as_nat5 r) % prime ==
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Canon.fst.checked", "FStar.Tactics.fst.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.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "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.Tactics.Canon", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "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": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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
r: Hacl.Spec.Curve25519.Field51.Definition.felem5 -> FStar.Pervasives.Lemma (requires (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ _ _ r2 r3 r4 = _ in Lib.IntTypes.v r4 * 19 <= 190 * Hacl.Spec.Curve25519.Field51.Definition.pow51 /\ Lib.IntTypes.v r3 * 19 <= 190 * Hacl.Spec.Curve25519.Field51.Definition.pow51 /\ Lib.IntTypes.v r2 * 19 <= 190 * Hacl.Spec.Curve25519.Field51.Definition.pow51) <: Type0)) (ensures (let _ = r in (let FStar.Pervasives.Native.Mktuple5 #_ #_ #_ #_ #_ r0 r1 r2 r3 r4 = _ in ((Hacl.Spec.Curve25519.Field51.Definition.pow51 * Hacl.Spec.Curve25519.Field51.Definition.pow51) * Hacl.Spec.Curve25519.Field51.Definition.pow51) * Hacl.Spec.Curve25519.Field51.Definition.as_nat5 r % Spec.Curve25519.prime == Hacl.Spec.Curve25519.Field51.Definition.as_nat5 (r2 *! Lib.IntTypes.u64 19, r3 *! Lib.IntTypes.u64 19, r4 *! Lib.IntTypes.u64 19, r0, r1) % Spec.Curve25519.prime) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Lib.IntTypes.uint64", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "Hacl.Spec.Curve25519.Field51.Definition.pow51", "Hacl.Spec.Curve25519.Field51.Definition.as_nat5", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.IntTypes.u64", "Spec.Curve25519.prime", "Prims.unit", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_fmul5_pow51", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.Mul.op_Star", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_fmul5_pow51_pow51", "Hacl.Spec.Curve25519.Field51.Lemmas.lemma_mul_assos_4" ]
[]
false
false
true
false
false
let lemma_fmul5_pow51_pow51_pow51 r =
let r0, r1, r2, r3, r4 = r in lemma_mul_assos_4 pow51 pow51 pow51 (as_nat5 r); let p51p51r = (pow51 * pow51) * as_nat5 r in FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 p51p51r prime; assert ((((pow51 * pow51) * pow51) * as_nat5 r) % prime == (pow51 * (p51p51r % prime)) % prime); lemma_fmul5_pow51_pow51 r; assert ((((pow51 * pow51) * pow51) * as_nat5 r) % prime == (pow51 * (as_nat5 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2) % prime)) % prime); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2)) prime; lemma_fmul5_pow51 (r3 *! u64 19, r4 *! u64 19, r0, r1, r2); FStar.Math.Lemmas.lemma_mod_mul_distr_r pow51 (as_nat5 (r2 *! u64 19, r3 *! u64 19, r4 *! u64 19, r0, r1)) prime
false
InterpreterTarget.fst
InterpreterTarget.index
val index : a: Type -> Type
let index a = option a
{ "file_name": "src/3d/InterpreterTarget.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 22, "end_line": 43, "start_col": 0, "start_line": 43 }
(* Copyright 2021 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 InterpreterTarget (* The abstract syntax for the code produced by 3d, targeting prelude/Interpreter.fst *) open FStar.All open FStar.List.Tot module A = Ast module T = Target module H = Hashtable noeq type inv = | Inv_conj : inv -> inv -> inv | Inv_ptr : expr -> inv | Inv_copy_buf: expr -> inv noeq type eloc = | Eloc_output : eloc | Eloc_union : eloc -> eloc -> eloc | Eloc_ptr : expr -> eloc | Eloc_copy_buf: e:expr { T.Identifier? (fst e) } -> eloc noeq type disj = | Disj_pair : l:eloc{ Eloc_copy_buf? l } -> eloc -> disj | Disj_conj : disj -> disj -> disj
{ "checked_file": "/", "dependencies": [ "Target.fsti.checked", "prims.fst.checked", "Hashtable.fsti.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.All.fst.checked", "Ast.fst.checked" ], "interface_file": true, "source_file": "InterpreterTarget.fst" }
[ { "abbrev": true, "full_module": "Hashtable", "short_module": "H" }, { "abbrev": true, "full_module": "Target", "short_module": "T" }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "Binding", "short_module": null }, { "abbrev": true, "full_module": "Target", "short_module": "T" }, { "abbrev": true, "full_module": "Ast", "short_module": "A" }, { "abbrev": false, "full_module": "FStar.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": 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 -> Type
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.option" ]
[]
false
false
false
true
true
let index a =
option a
false