OpenCores
URL https://opencores.org/ocsvn/pairing/pairing/trunk

Subversion Repositories pairing

[/] [pairing/] [trunk/] [rtl/] [tate_pairing.v] - Blame information for rev 23

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 homer.xing
`include "inc.v"
2
`define ZERO {(2*`M){1'b0}}
3
`define TWO {(2*`M-2){1'b0}},2'b10
4
 
5
// The Modified Duursma-Lee Algorithm
6
// out == e_({xp,yp}, {xr,yr})
7
module duursma_lee_algo(clk, reset, xp, yp, xr, yr, done, out);
8
    input clk, reset;
9
    input [`WIDTH:0] xp, yp, xr, yr;
10
    output reg done;
11
    output reg [`W6:0] out;
12
 
13
    reg [`W6:0] t;
14
    reg [`WIDTH:0] a, b, y;
15
    reg [1:0] d;
16
    reg [`M:0] i;
17
    reg f3m_reset, delay1, delay2;
18
    wire [`W6:0] g,v7,v8;
19
    wire [`WIDTH:0] mu /* my name is "mew" */,nmu,ny,
20
                    x,v2,v3,v4,v5,v6;
21
    wire [1:0] v9;
22
    wire f36m_reset, dummy, f3m_done, f36m_done, finish;
23
 
24
    assign g = {`ZERO,`TWO,`ZERO,nmu,v6,v5};
25
    assign finish = i[0];
26
 
27
    f3m_cubic
28
        ins1 (xr, x), // x == {x_r}^3
29
        ins2 (yr, v2); // v2 == {y_r}^3
30
    f3m_nine
31
        ins3 (clk, a, v3), // v3 == a^9
32
        ins4 (clk, b, v4); // v4 == b^9
33
    f3m_add3
34
        ins5 (v3, x, {{(2*`M-2){1'b0}},d}, mu); // mu == a^9+x+d
35
    f3m_neg
36
        ins6 (mu, nmu), // nmu == -mu
37
        ins7 (y,  ny);  // ny  == -y
38
    f3m_mult
39
        ins8 (clk, delay2, mu, nmu, v5, f3m_done), // v5 == - mu^2
40
        ins9 (clk, delay2, v4, ny,  v6, dummy); // v6 == - (b^9)*y
41
    f36m_cubic
42
        ins10 (clk, t, v7); // v7 == t^3
43
    f36m_mult
44
        ins11 (clk, f36m_reset, v7, g, v8, f36m_done); // v8 == v7*g = (t^3)*g
45
    func6
46
        ins12 (clk, reset, f36m_done, change),
47
        ins13 (clk, reset, f3m_done, f36m_reset);
48
    f3_sub1
49
        ins14 (d, v9); // v9 == d-1
50
 
51
    always @ (posedge clk)
52
        if (reset)
53
            i <= {1'b1, {`M{1'b0}}};
54
        else if (change | i[0])
55
            i <= i >> 1;
56
 
57
    always @ (posedge clk)
58
      begin
59
        if (reset)
60
          begin
61
            a <= xp; b <= yp; t <= 1;
62
            y <= v2; d <= 1;
63
          end
64
        else if (change)
65
          begin
66
            a <= v3; b <= v4; t <= v8;
67
            y <= ny; d <= v9;
68
          end
69
      end
70
 
71
    always @ (posedge clk)
72
        if (reset)
73
          begin done <= 0; end
74
        else if (finish)
75
          begin done <= 1; out <= v8; end
76
 
77
    always @ (posedge clk)
78
        if (reset)
79
          begin delay1 <= 1; delay2 <= 1; end
80
        else
81
          begin delay2 <= delay1; delay1 <= f3m_reset; end
82
 
83
    always @ (posedge clk)
84
        if (reset) f3m_reset <= 1;
85
        else if (change) f3m_reset <= 1;
86
        else f3m_reset <= 0;
87
endmodule
88
 
89
// do Tate pairing, hahahaha
90 12 homer.xing
module tate_pairing(clk, reset, x1, y1, x2, y2, done, out);
91 8 homer.xing
    input clk, reset;
92
    input [`WIDTH:0] x1, y1, x2, y2;
93
    output reg done;
94 12 homer.xing
    output reg [`W6:0] out;
95 8 homer.xing
 
96
    reg delay1, rst1;
97
    wire done1, rst2;
98
    wire [`W6:0] out1, out2;
99
    reg [2:0] K;
100
 
101
    duursma_lee_algo
102
        ins1 (clk, rst1, x1, y1, x2, y2, done1, out1);
103
    second_part
104
        ins2 (clk, rst2, out1, out2, done2);
105
    func6
106
        ins3 (clk, reset, done1, rst2);
107
 
108
    always @ (posedge clk)
109
        if (reset)
110
          begin
111
            rst1 <= 1; delay1 <= 1;
112
          end
113
        else
114
          begin
115
            rst1 <= delay1; delay1 <= reset;
116
          end
117
 
118
    always @ (posedge clk)
119
        if (reset) K <= 3'b100;
120
        else if ((K[2]&rst2)|(K[1]&done2)|K[0])
121
            K <= K >> 1;
122
 
123
    always @ (posedge clk)
124
        if (reset) done <= 0;
125 12 homer.xing
        else if (K[0]) begin done <= 1; out <= out2; end
126
endmodule
127 8 homer.xing
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.