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

Subversion Repositories ecg

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /ecg/trunk
    from Rev 10 to Rev 11
    Reverse comparison

Rev 10 → Rev 11

/testbench/test_point_scalar_mult.v
48,7 → 48,7
zero1 = 0;
c = 0;
go;
if (zero3 !== 1) begin $display("E"); $finish; end
if (zero3 !== 1) begin $display("E"); $finish; end else $display(":D");
 
// if scalar value is one, then the result is the input point, test case 1
x1 = 194'h2a4290286121261a82446a41200622024988295015114486;
59,7 → 59,8
if (zero3 !== 0 ||
x3 !== 194'h2a4290286121261a82446a41200622024988295015114486 ||
y3 !== 194'h16595a61040a8611209820112a1582a081a1a182264601252
) begin $display("E"); $finish; end
) begin $display("E"); $finish; end
else $display(":D");
 
// if scalar value is one, then the result is the input point, test case 2
x1 = 194'h2a4290286121261a82446a41200622024988295015114486;
68,6 → 69,7
c = 1;
go;
if (zero3 !== 1) begin $display("E"); $finish; end
else $display(":D");
 
// if scalar value is one thousand. test case 1
x1 = 194'h126569286a9860859046680265109015266416aa984082610;
79,6 → 81,7
x3 !== 194'h221495405a9425682104a6a005a42a562564469158a962019 ||
y3 !== 194'h1048569408a2846964811161095218005098aa06582419a46
) begin $display("E"); $finish; end
else $display(":D");
// if scalar value is one thousand. test case 2
x1 = 194'h126569286a9860859046680265109015266416aa984082610;
87,14 → 90,16
c = 1000;
go;
if (zero3 !== 1) begin $display("E"); $finish; end
else $display(":D");
 
// if scalar value is the order of the generator point, then the result is the inf point
/* // if scalar value is the order of the generator point, then the result is the inf point
x1 = 194'h288162298554054820552a05426081a1842886a58916a6249;
y1 = 194'h2895955069089214054596a189a4420556589054140941695;
zero1 = 0;
c = 152'd2726865189058261010774960798134976187171462721;
go;
if (zero3 !== 1) begin $display("E"); $finish; end
if (zero3 !== 1) begin $display("E"); $finish; end
else $display(":D"); */
// good work, buddy
$display("nice!");
/testbench/test_point_add.v
111,6 → 111,18
y3 !== 194'h2502568a5aa504152460984aa699616901895100a595862a8
) begin $display("E"); $finish; end
// If P1==P2. test case 3
x1 = 194'h126569286a9860859046680265109015266416aa984082610;
y1 = 194'h2a41880890628944a6844a269258216041061196854181160;
zero1 = 0;
x2 = x1; y2 = y1; zero2 = 0;
go;
#5 if(zero3 !== 0 ||
x3 !== 194'h68060682a5016661a990165691662666126691485920a940 ||
y3 !== 194'h1a428568aa082410a482244a642905a015582a945860a8898
) begin $display("E"); $finish; end
 
// If P1 != +- P2, test case 1
x1 = p1x; y1 = p1y; zero1 = 0;
x2 = p2x; y2 = p2y; zero2 = 0;
/rtl/ecg.v
32,38 → 32,34
output reg [`WIDTH:0] x3, y3;
output reg zero3;
reg [`WIDTH:0] x2, y2; reg zero2; // the result
reg [`WIDTH:0] x4, y4; wire zero4;
wire [`WIDTH:0] x5, y5; wire zero5;
reg [`SCALAR_WIDTH : 0] k; // the scalar value
reg [`SCALAR_WIDTH+1 : 0] i; // the counter
reg [`WIDTH:0] x2, y2; reg zero2; // accumulator
reg [`WIDTH:0] x4, y4; reg zero4; // doubler
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
wire fin; // asserted if job done
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 ;
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
ins2 (clk, reset, done1, p),
ins3 (clk, reset, p, p2);
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;
else if (op & p) k <= k << 1;
else if (op & p) k <= k >> 1;
 
always @ (posedge clk)
if (reset) op <= 0;
71,12 → 67,16
always @ (posedge clk)
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)
if (reset) begin x3 <= 0; y3 <= 0; zero3 <= 1; done <= 0; end
else if (i[`SCALAR_WIDTH+1])
begin x3 <= x2; y3 <= y2; zero3 <= zero2; done <= 1; end
else if (fin)
begin {x3,y3,zero3} <= {x2,y2,zero2}; done <= 1; end
endmodule
 
/* add two points on the elliptic curve $y^2=x^3-x+1$ over a Galois field GF(3^M)
95,22 → 95,15
y3a, y3b, y3c,
ny2;
wire zero3a,
use1, // asserted if $ins9$ did the work
done10, // asserted if $ins10$ finished
done11,
done11;
reg use1, // asserted if $ins9$ did the work
cond1,
cond2,
cond3,
cond4,
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
ins1 (y2, ny2); // ny2 == -y2
func9
122,6 → 115,26
always @ (posedge clk)
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;
else
zero3 <= (use1 & zero3a) | cond1; // if both of $P1$ and $P2$ are inf point, or $P1 == -P2$, then $P3$ is inf point

powered by: WebSVN 2.1.0

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