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

Subversion Repositories ecg

[/] [ecg/] [trunk/] [rtl/] [ecg.v] - Diff between revs 7 and 11

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 7 Rev 11
Line 30... Line 30...
    input [`SCALAR_WIDTH:0] c;
    input [`SCALAR_WIDTH:0] c;
    output reg done;
    output reg done;
    output reg [`WIDTH:0] x3, y3;
    output reg [`WIDTH:0] x3, y3;
    output reg zero3;
    output reg zero3;
 
 
    reg [`WIDTH:0] x2, y2; reg zero2; // the result
    reg [`WIDTH:0] x2, y2; reg zero2; // accumulator
    reg [`WIDTH:0] x4, y4; wire zero4;
    reg [`WIDTH:0] x4, y4; reg zero4; // doubler
    wire [`WIDTH:0] x5, y5; wire zero5;
    wire [`WIDTH:0] x5, y5; wire zero5; // the first input of the adder
 
    wire [`WIDTH:0] x6, y6; wire zero6; // the second input of the adder
 
    wire [`WIDTH:0] x7, y7; wire zero7; // the output of the adder
    reg [`SCALAR_WIDTH   : 0] k; // the scalar value
    reg [`SCALAR_WIDTH   : 0] k; // the scalar value
    reg [`SCALAR_WIDTH+1 : 0] i; // the counter
    wire fin; // asserted if job done
    reg op;
    reg op;
    wire p, p2, rst, done1;
    wire p, p2, rst, done1, lastbit;
 
 
    assign zero4 = (~op) ? zero2 : (k[`SCALAR_WIDTH]?zero1:1);
    assign lastbit = k[0];
 
    assign fin = (k == 0);
 
    assign x5 = op ? x4 : x2;
 
    assign y5 = op ? y4 : y2;
 
    assign zero5 = op ? zero4 : zero2;
 
    assign {x6,y6} = {x4,y4};
 
    assign zero6 = ((~op)&(~lastbit)) ? 1 : zero4;
    assign rst   = reset | p2 ;
    assign rst   = reset | p2 ;
 
 
    point_add
    point_add
        ins1 (clk, rst, x2, y2, zero2, x4, y4, zero4, done1, x5, y5, zero5);
        ins1 (clk, rst, x5, y5, zero5, x6, y6, zero6, done1, x7, y7, zero7);
    func6
    func6
        ins2 (clk, reset, done1, p),
        ins2 (clk, reset, done1, p),
        ins3 (clk, reset, p, p2);
        ins3 (clk, reset, p, p2);
 
 
    always @ (posedge clk)
    always @ (posedge clk)
        if (reset) begin x4 <= 0; y4 <= 0; end
 
        else
 
          begin
 
            x4 <= (~op) ? x2 : (k[`SCALAR_WIDTH]?x1:0);
 
            y4 <= (~op) ? y2 : (k[`SCALAR_WIDTH]?y1:0);
 
          end
 
 
 
    always @ (posedge clk)
 
        if (reset) i <= 1;
 
        else if ((op & p) | i[`SCALAR_WIDTH+1]) i <= i << 1;
 
 
 
    always @ (posedge clk)
 
        if (reset) k <= c;
        if (reset) k <= c;
        else if (op & p) k <= k << 1;
        else if (op & p) k <= k >> 1;
 
 
    always @ (posedge clk)
    always @ (posedge clk)
        if (reset) op <= 0;
        if (reset) op <= 0;
        else if (p) op <= ~op;
        else if (p) op <= ~op;
 
 
    always @ (posedge clk)
    always @ (posedge clk)
        if (reset)  begin x2 <= 0; y2 <= 0; zero2 <= 1; end
        if (reset)  begin x2 <= 0; y2 <= 0; zero2 <= 1; end
        else if (p) begin x2 <= x5; y2 <= y5; zero2 <= zero5; end
        else if ((~op) & p) begin {x2,y2,zero2} <= {x7,y7,zero7}; end
 
 
 
    always @ (posedge clk)
 
        if (reset)  begin {x4,y4,zero4} <= {x1,y1,zero1}; end
 
        else if (op & p) begin {x4,y4,zero4} <= {x7,y7,zero7}; end
 
 
    always @ (posedge clk)
    always @ (posedge clk)
        if (reset)  begin x3 <= 0; y3 <= 0; zero3 <= 1; done <= 0; end
        if (reset)  begin x3 <= 0; y3 <= 0; zero3 <= 1; done <= 0; end
        else if (i[`SCALAR_WIDTH+1])
        else if (fin)
          begin x3 <= x2; y3 <= y2; zero3 <= zero2; done <= 1; end
          begin {x3,y3,zero3} <= {x2,y2,zero2}; done <= 1; end
endmodule
endmodule
 
 
/* add two points on the elliptic curve $y^2=x^3-x+1$ over a Galois field GF(3^M)
/* add two points on the elliptic curve $y^2=x^3-x+1$ over a Galois field GF(3^M)
 * whose irreducible polynomial is $x^97 + x^12 + 2$. */
 * whose irreducible polynomial is $x^97 + x^12 + 2$. */
/* $P3(x3,y3) == P1 + P2$ for any points $P1(x1,y1),P2(x2,y2)$ */
/* $P3(x3,y3) == P1 + P2$ for any points $P1(x1,y1),P2(x2,y2)$ */
Line 93... Line 93...
    output reg zero3; // asserted if P3 == 0
    output reg zero3; // asserted if P3 == 0
    wire [`WIDTH:0] x3a, x3b, x3c,
    wire [`WIDTH:0] x3a, x3b, x3c,
                    y3a, y3b, y3c,
                    y3a, y3b, y3c,
                    ny2;
                    ny2;
    wire zero3a,
    wire zero3a,
         use1,  // asserted if $ins9$ did the work
 
         done10, // asserted if $ins10$ finished
         done10, // asserted if $ins10$ finished
         done11,
         done11;
 
    reg  use1,  // asserted if $ins9$ did the work
         cond1,
         cond1,
         cond2,
         cond2,
         cond3,
         cond3,
         cond4,
         cond4,
         cond5;
         cond5;
 
 
    assign use1 = zero1 | zero2;
 
    assign cond1 = (~use1) && cond2 && cond4; // asserted if $P1 == -P2$
 
    assign cond2 = (x1 == x2);
 
    assign cond3 = (y1 == y2);
 
    assign cond4 = (y1 == ny2);
 
    assign cond5 = (~use1) && cond2 && cond3; // asserted if $P1 == P2$
 
 
 
    f3m_neg
    f3m_neg
        ins1 (y2, ny2); // ny2 == -y2
        ins1 (y2, ny2); // ny2 == -y2
    func9
    func9
        ins9 (x1, y1, zero1, x2, y2, zero2, x3a, y3a, zero3a);
        ins9 (x1, y1, zero1, x2, y2, zero2, x3a, y3a, zero3a);
    func10
    func10
Line 120... Line 113...
    func11
    func11
        ins11 (clk, reset, x1, y1, x2, y2, done11, x3c, y3c);
        ins11 (clk, reset, x1, y1, x2, y2, done11, x3c, y3c);
 
 
    always @ (posedge clk)
    always @ (posedge clk)
        if (reset)
        if (reset)
 
          begin
 
            use1 <= 0;
 
            cond1 <= 0;
 
            cond2 <= 0;
 
            cond3 <= 0;
 
            cond4 <= 0;
 
            cond5 <= 0;
 
          end
 
        else
 
          begin
 
            use1 <= zero1 | zero2;
 
            cond1 <= (~use1) && cond2 && cond4; // asserted if $P1 == -P2$
 
            cond2 <= (x1 == x2);
 
            cond3 <= (y1 == y2);
 
            cond4 <= (y1 == ny2);
 
            cond5 <= (~use1) && cond2 && cond3; // asserted if $P1 == P2$
 
          end
 
 
 
    always @ (posedge clk)
 
        if (reset)
            zero3 <= 0;
            zero3 <= 0;
        else
        else
            zero3 <= (use1 & zero3a) | cond1; // if both of $P1$ and $P2$ are inf point, or $P1 == -P2$, then $P3$ is inf point
            zero3 <= (use1 & zero3a) | cond1; // if both of $P1$ and $P2$ are inf point, or $P1 == -P2$, then $P3$ is inf point
 
 
    always @ (posedge clk)
    always @ (posedge clk)

powered by: WebSVN 2.1.0

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