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

Subversion Repositories pairing

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

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
module tate_pairing(clk, reset, x1, y1, x2, y2, done, sel, out);
91
    input clk, reset;
92
    input [`WIDTH:0] x1, y1, x2, y2;
93
    input [2:0] sel;
94
    output reg done;
95
    output reg [149:0] out;
96
 
97
    reg delay1, rst1;
98
    wire done1, rst2;
99
    wire [`W6:0] out1, out2;
100
    reg [`W6:0] o;
101
    reg [2:0] K;
102
 
103
    duursma_lee_algo
104
        ins1 (clk, rst1, x1, y1, x2, y2, done1, out1);
105
    second_part
106
        ins2 (clk, rst2, out1, out2, done2);
107
    func6
108
        ins3 (clk, reset, done1, rst2);
109
 
110
    always @ (posedge clk)
111
        if (reset)
112
          begin
113
            rst1 <= 1; delay1 <= 1;
114
          end
115
        else
116
          begin
117
            rst1 <= delay1; delay1 <= reset;
118
          end
119
 
120
    always @ (posedge clk)
121
        if (reset) K <= 3'b100;
122
        else if ((K[2]&rst2)|(K[1]&done2)|K[0])
123
            K <= K >> 1;
124
 
125
    always @ (posedge clk)
126
        if (reset) done <= 0;
127
        else if (K[0]) begin done <= 1; o <= out2; end
128
 
129
    always @ (o, sel)
130
        case (sel)
131
            3'd0: out = o[150-1:0];
132
            3'd1: out = o[300-1:150];
133
            3'd2: out = o[450-1:300];
134
            3'd3: out = o[600-1:450];
135
            3'd4: out = o[750-1:600];
136
            3'd5: out = o[900-1:750];
137
            3'd6: out = o[1050-1:900];
138
            3'd7: out = o[`W6-1:1050];
139
            default: out = 0;
140
        endcase
141
endmodule

powered by: WebSVN 2.1.0

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