|
@ -21,14 +21,17 @@ |
|
|
`timescale 1ns/1ps |
|
|
`timescale 1ns/1ps |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module tb_des; |
|
|
module tb_des; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set dumpfile |
|
|
// set dumpfile |
|
|
initial begin |
|
|
initial begin |
|
|
$dumpfile ("tb_des.vcd"); |
|
|
|
|
|
$dumpvars (0, tb_des); |
|
|
|
|
|
|
|
|
`ifdef ITER |
|
|
|
|
|
$dumpfile ("tb_des_iter.vcd"); |
|
|
|
|
|
`else |
|
|
|
|
|
$dumpfile ("tb_des_pipe.vcd"); |
|
|
|
|
|
`endif |
|
|
|
|
|
$dumpvars (0, tb_des); |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -38,18 +41,19 @@ module tb_des; |
|
|
reg [0:63] key; |
|
|
reg [0:63] key; |
|
|
reg [0:63] datain; |
|
|
reg [0:63] datain; |
|
|
reg validin; |
|
|
reg validin; |
|
|
|
|
|
reg acceptin; |
|
|
integer index; |
|
|
integer index; |
|
|
integer outdex; |
|
|
integer outdex; |
|
|
integer enc_errors; |
|
|
integer enc_errors; |
|
|
integer dec_errors; |
|
|
integer dec_errors; |
|
|
wire [0:63] dataout; |
|
|
wire [0:63] dataout; |
|
|
wire validout; |
|
|
wire validout; |
|
|
|
|
|
wire acceptout; |
|
|
|
|
|
|
|
|
reg [0:63] data_input [0:469]; |
|
|
reg [0:63] data_input [0:469]; |
|
|
reg [0:63] key_input [0:469]; |
|
|
reg [0:63] key_input [0:469]; |
|
|
reg [0:63] data_output [0:469]; |
|
|
reg [0:63] data_output [0:469]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// read in test data files |
|
|
// read in test data files |
|
|
initial begin |
|
|
initial begin |
|
|
$readmemh("data_input.txt", data_input); |
|
|
$readmemh("data_input.txt", data_input); |
|
@ -86,15 +90,23 @@ module tb_des; |
|
|
|
|
|
|
|
|
// stimuli generator process |
|
|
// stimuli generator process |
|
|
initial |
|
|
initial |
|
|
forever @(negedge reset) begin |
|
|
|
|
|
|
|
|
forever @(posedge reset) begin |
|
|
@(posedge clk) |
|
|
@(posedge clk) |
|
|
for (index = 0; index < 235; index = index + 1) |
|
|
for (index = 0; index < 235; index = index + 1) |
|
|
begin |
|
|
begin |
|
|
|
|
|
`ifdef ITER |
|
|
|
|
|
@(posedge acceptout) |
|
|
|
|
|
`else |
|
|
@(posedge clk) |
|
|
@(posedge clk) |
|
|
|
|
|
`endif |
|
|
mode <= 0; |
|
|
mode <= 0; |
|
|
validin <= 1; |
|
|
validin <= 1; |
|
|
datain <= data_input[index]; |
|
|
datain <= data_input[index]; |
|
|
key <= key_input[index]; |
|
|
key <= key_input[index]; |
|
|
|
|
|
`ifdef ITER |
|
|
|
|
|
@(negedge acceptout) |
|
|
|
|
|
validin <= 0; |
|
|
|
|
|
`endif |
|
|
end |
|
|
end |
|
|
for (index = 0; index < 10; index = index + 1) |
|
|
for (index = 0; index < 10; index = index + 1) |
|
|
begin |
|
|
begin |
|
@ -103,11 +115,19 @@ module tb_des; |
|
|
end |
|
|
end |
|
|
for (index = 235; index < 470; index = index + 1) |
|
|
for (index = 235; index < 470; index = index + 1) |
|
|
begin |
|
|
begin |
|
|
|
|
|
`ifdef ITER |
|
|
|
|
|
@(posedge acceptout) |
|
|
|
|
|
`else |
|
|
@(posedge clk) |
|
|
@(posedge clk) |
|
|
|
|
|
`endif |
|
|
mode <= 1; |
|
|
mode <= 1; |
|
|
validin <= 1; |
|
|
validin <= 1; |
|
|
datain <= data_input[index]; |
|
|
datain <= data_input[index]; |
|
|
key <= key_input[index]; |
|
|
key <= key_input[index]; |
|
|
|
|
|
`ifdef ITER |
|
|
|
|
|
@(negedge acceptout) |
|
|
|
|
|
validin <= 0; |
|
|
|
|
|
`endif |
|
|
end |
|
|
end |
|
|
@(posedge clk) |
|
|
@(posedge clk) |
|
|
validin <= 0; |
|
|
validin <= 0; |
|
@ -120,11 +140,21 @@ module tb_des; |
|
|
|
|
|
|
|
|
wait (reset) |
|
|
wait (reset) |
|
|
|
|
|
|
|
|
|
|
|
acceptin <= 1; |
|
|
|
|
|
|
|
|
// encryption tests |
|
|
// encryption tests |
|
|
|
|
|
`ifdef ITER |
|
|
|
|
|
@(posedge clk) |
|
|
|
|
|
`else |
|
|
@(posedge validout) |
|
|
@(posedge validout) |
|
|
|
|
|
`endif |
|
|
for(outdex = 0; outdex < 235; outdex = outdex + 1) |
|
|
for(outdex = 0; outdex < 235; outdex = outdex + 1) |
|
|
begin |
|
|
begin |
|
|
|
|
|
`ifdef ITER |
|
|
|
|
|
@(posedge validout) |
|
|
|
|
|
`else |
|
|
@(posedge clk) |
|
|
@(posedge clk) |
|
|
|
|
|
`endif |
|
|
// detected an error -> print error message |
|
|
// detected an error -> print error message |
|
|
// increment error counter |
|
|
// increment error counter |
|
|
if (dataout != data_output[outdex]) begin |
|
|
if (dataout != data_output[outdex]) begin |
|
@ -142,10 +172,18 @@ module tb_des; |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
// decryption tests |
|
|
// decryption tests |
|
|
|
|
|
`ifdef ITER |
|
|
|
|
|
@(posedge clk) |
|
|
|
|
|
`else |
|
|
@(posedge validout) |
|
|
@(posedge validout) |
|
|
|
|
|
`endif |
|
|
for(outdex = 235; outdex < 470; outdex = outdex + 1) |
|
|
for(outdex = 235; outdex < 470; outdex = outdex + 1) |
|
|
begin |
|
|
begin |
|
|
|
|
|
`ifdef ITER |
|
|
|
|
|
@(posedge validout) |
|
|
|
|
|
`else |
|
|
@(posedge clk) |
|
|
@(posedge clk) |
|
|
|
|
|
`endif |
|
|
// detected an error -> print error message |
|
|
// detected an error -> print error message |
|
|
// increment error counter |
|
|
// increment error counter |
|
|
if (dataout != data_output[outdex]) begin |
|
|
if (dataout != data_output[outdex]) begin |
|
@ -183,8 +221,10 @@ module tb_des; |
|
|
.key_i(key), |
|
|
.key_i(key), |
|
|
.data_i(datain), |
|
|
.data_i(datain), |
|
|
.valid_i(validin), |
|
|
.valid_i(validin), |
|
|
|
|
|
.accept_o(acceptout), |
|
|
.data_o(dataout), |
|
|
.data_o(dataout), |
|
|
.valid_o(validout) |
|
|
|
|
|
|
|
|
.valid_o(validout), |
|
|
|
|
|
.accept_i(acceptin) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|