Debian Codegraph @

src/Bedrock/End2End/X25519/MontgomeryLadderRISCV.v

raw
1 From Coq Require Import ZArith.
2 Require Import bedrock2.Map.Separation.
3 Require Import bedrock2.Map.SeparationLogic.
4 Require Import bedrock2.Syntax.
5 Require Import compiler.Pipeline.
6 Require Import compiler.MMIO.
7 Require Import compiler.NaiveRiscvWordProperties.
8 Require Import coqutil.Map.SortedListWord.
9 Require Import coqutil.Map.Z_keyed_SortedListMap.
10 Require Import coqutil.Word.Bitwidth32.
11 Require Import Crypto.Arithmetic.PrimeFieldTheorems.
12 Require Import Crypto.Bedrock.End2End.X25519.Field25519.
13 Require Import Crypto.Bedrock.Field.Synthesis.New.UnsaturatedSolinas.
14 Require Import Crypto.Bedrock.Specs.Field.
15 Require Import Crypto.Bedrock.Group.ScalarMult.MontgomeryLadder.
16 Require Import Crypto.Bedrock.End2End.X25519.MontgomeryLadder.
17
18 Local Arguments map.rep: clear implicits.
19
20 #[export]
21 Instance BWM_RV32IM : FlatToRiscvCommon.bitwidth_iset 32 Decode.RV32IM := eq_refl.
22
23 Derive montladder_compiler_result SuchThat
24 (compile
25 (compile_ext_call (funname_env:=SortedListString.map))
26 funcs = Success montladder_compiler_result)
27 As montladder_compiler_result_ok.
28 Proof.
29 match goal with x := _ |- _ => cbv delta [x]; clear x end.
30 match goal with |- ?a = _ => set a end.
31 vm_compute.
32 match goal with |- @Success ?A ?x = Success ?e => is_evar e;
33 exact (@eq_refl (result A) (@Success A x)) end.
34 Qed.
35
36 Definition montladder_stack_size := snd montladder_compiler_result.
37 Definition montladder_finfo := snd (fst montladder_compiler_result).
38 Definition montladder_insns := fst (fst montladder_compiler_result).
39 Definition montladder_bytes := Pipeline.instrencode montladder_insns.
40 Definition montladder_symbols : list _ := Symbols.symbols montladder_finfo.
41
42 Require riscv.Utility.InstructionNotations.
43 Require riscv.Utility.InstructionCoercions.
44 Module PrintAssembly.
45 Import riscv.Utility.InstructionNotations.
46 Import riscv.Utility.InstructionCoercions.
47 Unset Printing Coercions.
48
49 (* Compute garagedoor_finfo. (* fe25519_mul is more than 10KB in just one function *) *)
50 Goal True. let r := eval cbv in montladder_insns in idtac (* r *). Abort.
51 End PrintAssembly.
52
53 Definition f_rel_pos : Z := ltac:(
54 let y := eval vm_compute in (List.find (fun '(name, pos) => String.eqb name "montladder") montladder_finfo) in
55 match y with Some (_, ?pos) => exact pos end).
56
57 Local Instance mem : map.map (word.rep (width:=32)) Init.Byte.byte := SortedListWord.map _ _.
58 Local Existing Instance BW32.