This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dh_test.v
60 lines (56 loc) · 1.92 KB
/
dh_test.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
`default_nettype none
`define assert(condition) if(!((|{condition})===1)) begin $display("FAIL"); $finish(1); end
module curve25519_test;
reg [254:0] a_seed, b_seed, a, b, A, B, shared_a, shared_b, base=9;
initial begin
// a_seed={$random, $random, $random, $random, $random, $random, $random, $random};
// b_seed={$random, $random, $random, $random, $random, $random, $random, $random};
// a={1'b1, a_seed[3 +: 251], 3'b000};
// b={1'b1, b_seed[3 +: 251], 3'b000};
a=255'h49375212b2c2846546df998d06b97b0db1f056638484d609c0895e8112153520;
b=255'h633724c67cfde9f9462df78c76d457ed1e8dcd3d3b23f17606d7cd0d00f3e300;
$display("a = 0x%x", a);
$display("b = 0x%x", b);
end
reg clock = 0, start = 0;
reg [254:0] scalar, point;
wire [254:0] out;
wire done;
curve25519 c(clock, start, scalar, point, done, out);
always #1 clock <= !clock;
reg [7:0] pc = 0;
always @(posedge clock) begin
if (start) start <= 0;
if (pc == 0) begin
start <= 1; scalar <= a; point <= base;
pc <= pc+1;
end
if (pc == 1 && done) begin
A <= out;
$display("A = 0x%x", out);
start <= 1; scalar <= b; point <= base;
pc <= pc+1;
end
if (pc == 2 && done) begin
B <= out;
$display("B = 0x%x", out);
start <= 1; scalar <= b; point <= A;
pc <= pc+1;
end
if (pc == 3 && done) begin
$display("shared_b = 0x%x", out);
shared_b <= out;
start <= 1; scalar <= a; point <= B;
pc <= pc+1;
end
if (pc == 3 && done) begin
$display("shared_a = 0x%x", out);
shared_a <= out;
pc <= pc+1;
end
if (pc == 4 && done) begin
`assert(shared_a === shared_b)
$finish;
end
end
endmodule