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

Subversion Repositories pairing

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

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

Line No. Rev Author Line
1 24 homer.xing
/*
2
    Copyright 2011, City University of Hong Kong
3
    Author is Homer (Dongsheng) Xing.
4
 
5
    This file is part of Tate Bilinear Pairing Core.
6
 
7
    Tate Bilinear Pairing Core is free software: you can redistribute it and/or modify
8
    it under the terms of the GNU Lesser General Public License as published by
9
    the Free Software Foundation, either version 3 of the License, or
10
    (at your option) any later version.
11
 
12
    Tate Bilinear Pairing Core is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU Lesser General Public License for more details.
16
 
17
    You should have received a copy of the GNU General Public License
18
    along with Foobar.  If not, see http://www.gnu.org/licenses/lgpl.txt
19
*/
20
 
21 8 homer.xing
`include "inc.v"
22
`define ZERO {(2*`M){1'b0}}
23
`define TWO {(2*`M-2){1'b0}},2'b10
24
 
25
// The Modified Duursma-Lee Algorithm
26
// out == e_({xp,yp}, {xr,yr})
27
module duursma_lee_algo(clk, reset, xp, yp, xr, yr, done, out);
28
    input clk, reset;
29
    input [`WIDTH:0] xp, yp, xr, yr;
30
    output reg done;
31
    output reg [`W6:0] out;
32
 
33
    reg [`W6:0] t;
34
    reg [`WIDTH:0] a, b, y;
35
    reg [1:0] d;
36
    reg [`M:0] i;
37
    reg f3m_reset, delay1, delay2;
38
    wire [`W6:0] g,v7,v8;
39
    wire [`WIDTH:0] mu /* my name is "mew" */,nmu,ny,
40
                    x,v2,v3,v4,v5,v6;
41
    wire [1:0] v9;
42 27 homer.xing
    wire f36m_reset, dummy, f3m_done, f36m_done, finish, change;
43 8 homer.xing
 
44
    assign g = {`ZERO,`TWO,`ZERO,nmu,v6,v5};
45
    assign finish = i[0];
46
 
47
    f3m_cubic
48
        ins1 (xr, x), // x == {x_r}^3
49
        ins2 (yr, v2); // v2 == {y_r}^3
50
    f3m_nine
51
        ins3 (clk, a, v3), // v3 == a^9
52
        ins4 (clk, b, v4); // v4 == b^9
53
    f3m_add3
54
        ins5 (v3, x, {{(2*`M-2){1'b0}},d}, mu); // mu == a^9+x+d
55
    f3m_neg
56
        ins6 (mu, nmu), // nmu == -mu
57
        ins7 (y,  ny);  // ny  == -y
58
    f3m_mult
59
        ins8 (clk, delay2, mu, nmu, v5, f3m_done), // v5 == - mu^2
60
        ins9 (clk, delay2, v4, ny,  v6, dummy); // v6 == - (b^9)*y
61
    f36m_cubic
62
        ins10 (clk, t, v7); // v7 == t^3
63
    f36m_mult
64
        ins11 (clk, f36m_reset, v7, g, v8, f36m_done); // v8 == v7*g = (t^3)*g
65
    func6
66
        ins12 (clk, reset, f36m_done, change),
67
        ins13 (clk, reset, f3m_done, f36m_reset);
68
    f3_sub1
69
        ins14 (d, v9); // v9 == d-1
70
 
71
    always @ (posedge clk)
72
        if (reset)
73
            i <= {1'b1, {`M{1'b0}}};
74
        else if (change | i[0])
75
            i <= i >> 1;
76
 
77
    always @ (posedge clk)
78
      begin
79
        if (reset)
80
          begin
81
            a <= xp; b <= yp; t <= 1;
82
            y <= v2; d <= 1;
83
          end
84
        else if (change)
85
          begin
86
            a <= v3; b <= v4; t <= v8;
87
            y <= ny; d <= v9;
88
          end
89
      end
90
 
91
    always @ (posedge clk)
92
        if (reset)
93
          begin done <= 0; end
94
        else if (finish)
95
          begin done <= 1; out <= v8; end
96
 
97
    always @ (posedge clk)
98
        if (reset)
99
          begin delay1 <= 1; delay2 <= 1; end
100
        else
101
          begin delay2 <= delay1; delay1 <= f3m_reset; end
102
 
103
    always @ (posedge clk)
104
        if (reset) f3m_reset <= 1;
105
        else if (change) f3m_reset <= 1;
106
        else f3m_reset <= 0;
107
endmodule
108
 
109
// do Tate pairing, hahahaha
110 12 homer.xing
module tate_pairing(clk, reset, x1, y1, x2, y2, done, out);
111 8 homer.xing
    input clk, reset;
112
    input [`WIDTH:0] x1, y1, x2, y2;
113
    output reg done;
114 12 homer.xing
    output reg [`W6:0] out;
115 8 homer.xing
 
116
    reg delay1, rst1;
117 27 homer.xing
    wire done1, rst2, done2;
118 8 homer.xing
    wire [`W6:0] out1, out2;
119
    reg [2:0] K;
120
 
121
    duursma_lee_algo
122
        ins1 (clk, rst1, x1, y1, x2, y2, done1, out1);
123
    second_part
124
        ins2 (clk, rst2, out1, out2, done2);
125
    func6
126
        ins3 (clk, reset, done1, rst2);
127
 
128
    always @ (posedge clk)
129
        if (reset)
130
          begin
131
            rst1 <= 1; delay1 <= 1;
132
          end
133
        else
134
          begin
135
            rst1 <= delay1; delay1 <= reset;
136
          end
137
 
138
    always @ (posedge clk)
139
        if (reset) K <= 3'b100;
140
        else if ((K[2]&rst2)|(K[1]&done2)|K[0])
141
            K <= K >> 1;
142
 
143
    always @ (posedge clk)
144
        if (reset) done <= 0;
145 12 homer.xing
        else if (K[0]) begin done <= 1; out <= out2; end
146
endmodule
147 8 homer.xing
 

powered by: WebSVN 2.1.0

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