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

Subversion Repositories ecg

[/] [ecg/] [trunk/] [rtl/] [ecg.v] - Blame information for rev 2

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

Line No. Rev Author Line
1 2 homer.xing
`include "inc.v"
2
 
3
/* add two points on the elliptic curve $y^2=x^3-x+1$ over a Galois field GF(3^M)
4
 * whose irreducible polynomial is $x^97 + x^12 + 2$. */
5
 
6
/* $P3(x3,y3) == P1 + P2$ for any points $P1(x1,y1),P2(x2,y2)$ */
7
module point_add(clk, reset, x1, y1, zero1, x2, y2, zero2, done, x3, y3, zero3);
8
    input clk, reset;
9
    input [`WIDTH:0] x1, y1, x2, y2;
10
    input zero1; // asserted if P1 == 0
11
    input zero2; // asserted if P2 == 0
12
    output reg done;
13
    output reg [`WIDTH:0] x3, y3;
14
    output reg zero3; // asserted if P3 == 0
15
    wire [`WIDTH:0] x3a, x3b, y3a, y3b;
16
    wire zero3a,
17
         use1,  // asserted if $ins1$ do work
18
         done2; // asserted if $ins2$ finished
19
 
20
    assign use1 = zero1 | zero2;
21
 
22
    func9
23
        ins9 (x1, y1, zero1, x2, y2, zero2, x3a, y3a, zero3a);
24
    func10
25
        ins10 (clk, reset, x1, y1, x2, y2, done2, x3b, y3b);
26
 
27
    always @ (posedge clk)
28
        zero3 <= use1 & zero3a;
29
 
30
    always @ (posedge clk)
31
        if (reset)
32
            done <= 0;
33
        else
34
            done <= use1 ? 1 : done2;
35
 
36
    always @ (posedge clk)
37
        if (reset)
38
          begin
39
            x3 <= 0; y3 <= 0;
40
          end
41
        else
42
          begin
43
            x3 <= use1 ? x3a : x3b;
44
            y3 <= use1 ? y3a : y3b;
45
          end
46
endmodule
47
 
48
/* $P1$ and/or $P2$ is the infinite point */
49
module func9(x1, y1, zero1, x2, y2, zero2, x3, y3, zero3);
50
    input [`WIDTH:0] x1, y1, x2, y2;
51
    input zero1; // asserted if P1 == 0
52
    input zero2; // asserted if P2 == 0
53
    output [`WIDTH:0] x3, y3;
54
    output zero3; // asserted if P3 == 0
55
 
56
    assign zero3 = zero1 & zero2;
57
 
58
    genvar i;
59
    generate
60
        for (i=0; i<=`WIDTH; i=i+1)
61
          begin:label
62
            assign x3[i] = (x1[i] & zero1) | (x2[i] & zero2);
63
            assign y3[i] = (y1[i] & zero1) | (y2[i] & zero2);
64
          end
65
    endgenerate
66
endmodule
67
 
68
/* $P1$ or $P2$ is not the infinite point */
69
module func10(clk, reset, x1, y1, x2, y2, done, x3, y3);
70
    input clk, reset;
71
    input [`WIDTH:0] x1, y1, x2, y2;
72
    output done;
73
    output [`WIDTH:0] x3, y3;
74
 
75
    assign x3 = x1;
76
    assign y3 = y1;
77
    assign done = 1;
78
endmodule

powered by: WebSVN 2.1.0

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