aboutsummaryrefslogtreecommitdiff
path: root/src/tb
diff options
context:
space:
mode:
authorJoachim StroĢˆmbergson <joachim@secworks.se>2017-12-06 14:08:14 +0100
committerJoachim StroĢˆmbergson <joachim@secworks.se>2017-12-06 14:08:14 +0100
commit26a85f83022fc3b3c704f037616a398e28134f8d (patch)
treeedac1830d8986838962fab49690c2f5f654b644a /src/tb
parent3b6f569c3506e82193fd81cfb3e0049a8a61a222 (diff)
Synced AES repo. This commit fixes many nits such as: (1) Silence warnings on size of contants. (2) warning on tasks for empty arguments in tasks. (3) timescale directives not needed. It also implements API in a code-wise more compact way. Info about implementation status updated. No changes affect the functionality of the core.api_error_fix
Diffstat (limited to 'src/tb')
-rw-r--r--src/tb/tb_aes.v120
-rw-r--r--src/tb/tb_aes_core.v20
-rw-r--r--src/tb/tb_aes_decipher_block.v16
-rw-r--r--src/tb/tb_aes_encipher_block.v16
-rw-r--r--src/tb/tb_aes_key_mem.v16
5 files changed, 76 insertions, 112 deletions
diff --git a/src/tb/tb_aes.v b/src/tb/tb_aes.v
index 377ed76..cb42010 100644
--- a/src/tb/tb_aes.v
+++ b/src/tb/tb_aes.v
@@ -37,12 +37,6 @@
//======================================================================
//------------------------------------------------------------------
-// Simulator directives.
-//------------------------------------------------------------------
-`timescale 1ns/100ps
-
-
-//------------------------------------------------------------------
// Test module.
//------------------------------------------------------------------
module tb_aes();
@@ -50,52 +44,52 @@ module tb_aes();
//----------------------------------------------------------------
// Internal constant and parameter definitions.
//----------------------------------------------------------------
- localparam DEBUG = 0;
+ parameter DEBUG = 0;
- localparam CLK_HALF_PERIOD = 1;
- localparam CLK_PERIOD = 2 * CLK_HALF_PERIOD;
+ parameter CLK_HALF_PERIOD = 1;
+ parameter CLK_PERIOD = 2 * CLK_HALF_PERIOD;
// The DUT address map.
- localparam ADDR_NAME0 = 8'h00;
- localparam ADDR_NAME1 = 8'h01;
- localparam ADDR_VERSION = 8'h02;
+ parameter ADDR_NAME0 = 8'h00;
+ parameter ADDR_NAME1 = 8'h01;
+ parameter ADDR_VERSION = 8'h02;
- localparam ADDR_CTRL = 8'h08;
- localparam CTRL_INIT_BIT = 0;
- localparam CTRL_NEXT_BIT = 1;
+ parameter ADDR_CTRL = 8'h08;
+ parameter CTRL_INIT_BIT = 0;
+ parameter CTRL_NEXT_BIT = 1;
+ parameter CTRL_ENCDEC_BIT = 2;
+ parameter CTRL_KEYLEN_BIT = 3;
- localparam ADDR_STATUS = 8'h09;
- localparam STATUS_READY_BIT = 0;
- localparam STATUS_VALID_BIT = 1;
+ parameter ADDR_STATUS = 8'h09;
+ parameter STATUS_READY_BIT = 0;
+ parameter STATUS_VALID_BIT = 1;
- localparam ADDR_CONFIG = 8'h0a;
- localparam CTRL_ENCDEC_BIT = 2;
- localparam CTRL_KEYLEN_BIT = 3;
+ parameter ADDR_CONFIG = 8'h0a;
- localparam ADDR_KEY0 = 8'h10;
- localparam ADDR_KEY1 = 8'h11;
- localparam ADDR_KEY2 = 8'h12;
- localparam ADDR_KEY3 = 8'h13;
- localparam ADDR_KEY4 = 8'h14;
- localparam ADDR_KEY5 = 8'h15;
- localparam ADDR_KEY6 = 8'h16;
- localparam ADDR_KEY7 = 8'h17;
+ parameter ADDR_KEY0 = 8'h10;
+ parameter ADDR_KEY1 = 8'h11;
+ parameter ADDR_KEY2 = 8'h12;
+ parameter ADDR_KEY3 = 8'h13;
+ parameter ADDR_KEY4 = 8'h14;
+ parameter ADDR_KEY5 = 8'h15;
+ parameter ADDR_KEY6 = 8'h16;
+ parameter ADDR_KEY7 = 8'h17;
- localparam ADDR_BLOCK0 = 8'h20;
- localparam ADDR_BLOCK1 = 8'h21;
- localparam ADDR_BLOCK2 = 8'h22;
- localparam ADDR_BLOCK3 = 8'h23;
+ parameter ADDR_BLOCK0 = 8'h20;
+ parameter ADDR_BLOCK1 = 8'h21;
+ parameter ADDR_BLOCK2 = 8'h22;
+ parameter ADDR_BLOCK3 = 8'h23;
- localparam ADDR_RESULT0 = 8'h30;
- localparam ADDR_RESULT1 = 8'h31;
- localparam ADDR_RESULT2 = 8'h32;
- localparam ADDR_RESULT3 = 8'h33;
+ parameter ADDR_RESULT0 = 8'h30;
+ parameter ADDR_RESULT1 = 8'h31;
+ parameter ADDR_RESULT2 = 8'h32;
+ parameter ADDR_RESULT3 = 8'h33;
- localparam AES_128_BIT_KEY = 0;
- localparam AES_256_BIT_KEY = 1;
+ parameter AES_128_BIT_KEY = 0;
+ parameter AES_256_BIT_KEY = 1;
- localparam AES_DECIPHER = 1'b0;
- localparam AES_ENCIPHER = 1'b1;
+ parameter AES_DECIPHER = 1'b0;
+ parameter AES_ENCIPHER = 1'b1;
//----------------------------------------------------------------
@@ -132,11 +126,6 @@ module tb_aes();
//----------------------------------------------------------------
- // Concurrent assignments.
- //----------------------------------------------------------------
-
-
- //----------------------------------------------------------------
// clk_gen
//
// Always running clock generator process.
@@ -172,7 +161,7 @@ module tb_aes();
//
// Dump the state of the dump when needed.
//----------------------------------------------------------------
- task dump_dut_state();
+ task dump_dut_state;
begin
$display("cycle: 0x%016x", cycle_ctr);
$display("State of DUT");
@@ -182,7 +171,7 @@ module tb_aes();
$display("");
$display("block: 0x%08x, 0x%08x, 0x%08x, 0x%08x",
- dut.block0_reg, dut.block1_reg, dut.block2_reg, dut.block3_reg);
+ dut.block_reg[0], dut.block_reg[1], dut.block_reg[2], dut.block_reg[3]);
$display("");
end
@@ -194,7 +183,7 @@ module tb_aes();
//
// Toggle reset to put the DUT into a well known state.
//----------------------------------------------------------------
- task reset_dut();
+ task reset_dut;
begin
$display("*** Toggle reset.");
tb_reset_n = 0;
@@ -211,7 +200,7 @@ module tb_aes();
//
// Display the accumulated test results.
//----------------------------------------------------------------
- task display_test_results();
+ task display_test_results;
begin
if (error_ctr == 0)
begin
@@ -232,19 +221,19 @@ module tb_aes();
// Initialize all counters and testbed functionality as well
// as setting the DUT inputs to defined values.
//----------------------------------------------------------------
- task init_sim();
+ task init_sim;
begin
- cycle_ctr = 0;
- error_ctr = 0;
- tc_ctr = 0;
+ cycle_ctr = 0;
+ error_ctr = 0;
+ tc_ctr = 0;
- tb_clk = 0;
- tb_reset_n = 1;
+ tb_clk = 0;
+ tb_reset_n = 1;
- tb_cs = 0;
- tb_we = 0;
- tb_address = 8'h00;
- tb_write_data = 32'h00000000;
+ tb_cs = 0;
+ tb_we = 0;
+ tb_address = 8'h0;
+ tb_write_data = 32'h0;
end
endtask // init_sim
@@ -254,7 +243,7 @@ module tb_aes();
//
// Write the given word to the DUT using the DUT interface.
//----------------------------------------------------------------
- task write_word(input [11 : 0] address,
+ task write_word(input [11 : 0] address,
input [31 : 0] word);
begin
if (DEBUG)
@@ -319,7 +308,7 @@ module tb_aes();
//
// Read the result block in the dut.
//----------------------------------------------------------------
- task read_result();
+ task read_result;
begin
read_word(ADDR_RESULT0);
result_data[127 : 096] = read_data;
@@ -385,12 +374,13 @@ module tb_aes();
input [127 : 0] expected);
begin
$display("*** TC %0d ECB mode test started.", tc_number);
+ tc_ctr = tc_ctr + 1;
init_key(key, key_length);
write_block(block);
dump_dut_state();
- write_word(ADDR_CONFIG, (8'h00 + (key_length << 1) + encdec));
+ write_word(ADDR_CONFIG, (8'h00 + (key_length << 1)+ encdec));
write_word(ADDR_CTRL, 8'h02);
#(100 * CLK_PERIOD);
@@ -399,7 +389,6 @@ module tb_aes();
if (result_data == expected)
begin
- tc_ctr = tc_ctr + 1;
$display("*** TC %0d successful.", tc_number);
$display("");
end
@@ -421,7 +410,7 @@ module tb_aes();
//
// Main test task will perform complete NIST test of AES.
//----------------------------------------------------------------
- task aes_test();
+ task aes_test;
reg [255 : 0] nist_aes128_key;
reg [255 : 0] nist_aes256_key;
@@ -526,7 +515,6 @@ module tb_aes();
//----------------------------------------------------------------
initial
begin : main
-
$display(" -= Testbench for AES started =-");
$display(" ==============================");
$display("");
diff --git a/src/tb/tb_aes_core.v b/src/tb/tb_aes_core.v
index 426e817..7f6791e 100644
--- a/src/tb/tb_aes_core.v
+++ b/src/tb/tb_aes_core.v
@@ -37,12 +37,6 @@
//======================================================================
//------------------------------------------------------------------
-// Simulator directives.
-//------------------------------------------------------------------
-`timescale 1ns/100ps
-
-
-//------------------------------------------------------------------
// Test module.
//------------------------------------------------------------------
module tb_aes_core();
@@ -137,7 +131,7 @@ module tb_aes_core();
//
// Dump the state of the dump when needed.
//----------------------------------------------------------------
- task dump_dut_state();
+ task dump_dut_state;
begin
$display("State of DUT");
$display("------------");
@@ -164,7 +158,7 @@ module tb_aes_core();
//
// Dump the keys in the key memory of the dut.
//----------------------------------------------------------------
- task dump_keys();
+ task dump_keys;
begin
$display("State of key memory in DUT:");
$display("key[00] = 0x%016x", dut.keymem.key_mem[00]);
@@ -192,7 +186,7 @@ module tb_aes_core();
//
// Toggle reset to put the DUT into a well known state.
//----------------------------------------------------------------
- task reset_dut();
+ task reset_dut;
begin
$display("*** Toggle reset.");
tb_reset_n = 0;
@@ -208,7 +202,7 @@ module tb_aes_core();
// Initialize all counters and testbed functionality as well
// as setting the DUT inputs to defined values.
//----------------------------------------------------------------
- task init_sim();
+ task init_sim;
begin
cycle_ctr = 0;
error_ctr = 0;
@@ -232,7 +226,7 @@ module tb_aes_core();
//
// Display the accumulated test results.
//----------------------------------------------------------------
- task display_test_result();
+ task display_test_result;
begin
if (error_ctr == 0)
begin
@@ -256,7 +250,7 @@ module tb_aes_core();
// when the dut is actively processing and will in fact at some
// point set the flag.
//----------------------------------------------------------------
- task wait_ready();
+ task wait_ready;
begin
while (!tb_ready)
begin
@@ -279,7 +273,7 @@ module tb_aes_core();
// when the dut is actively processing a block and will in fact
// at some point set the flag.
//----------------------------------------------------------------
- task wait_valid();
+ task wait_valid;
begin
while (!tb_result_valid)
begin
diff --git a/src/tb/tb_aes_decipher_block.v b/src/tb/tb_aes_decipher_block.v
index 5a89102..8d125f6 100644
--- a/src/tb/tb_aes_decipher_block.v
+++ b/src/tb/tb_aes_decipher_block.v
@@ -37,12 +37,6 @@
//======================================================================
//------------------------------------------------------------------
-// Simulator directives.
-//------------------------------------------------------------------
-`timescale 1ns/100ps
-
-
-//------------------------------------------------------------------
// Test module.
//------------------------------------------------------------------
module tb_aes_decipher_block();
@@ -144,7 +138,7 @@ module tb_aes_decipher_block();
//
// Dump the state of the dump when needed.
//----------------------------------------------------------------
- task dump_dut_state();
+ task dump_dut_state;
begin
$display("State of DUT");
$display("------------");
@@ -184,7 +178,7 @@ module tb_aes_decipher_block();
//
// Toggle reset to put the DUT into a well known state.
//----------------------------------------------------------------
- task reset_dut();
+ task reset_dut;
begin
$display("*** Toggle reset.");
tb_reset_n = 0;
@@ -200,7 +194,7 @@ module tb_aes_decipher_block();
// Initialize all counters and testbed functionality as well
// as setting the DUT inputs to defined values.
//----------------------------------------------------------------
- task init_sim();
+ task init_sim;
begin
cycle_ctr = 0;
error_ctr = 0;
@@ -222,7 +216,7 @@ module tb_aes_decipher_block();
//
// Display the accumulated test results.
//----------------------------------------------------------------
- task display_test_result();
+ task display_test_result;
begin
if (error_ctr == 0)
begin
@@ -246,7 +240,7 @@ module tb_aes_decipher_block();
// when the dut is actively processing and will in fact at some
// point set the flag.
//----------------------------------------------------------------
- task wait_ready();
+ task wait_ready;
begin
while (!tb_ready)
begin
diff --git a/src/tb/tb_aes_encipher_block.v b/src/tb/tb_aes_encipher_block.v
index 39d7c26..c471bb5 100644
--- a/src/tb/tb_aes_encipher_block.v
+++ b/src/tb/tb_aes_encipher_block.v
@@ -37,12 +37,6 @@
//======================================================================
//------------------------------------------------------------------
-// Simulator directives.
-//------------------------------------------------------------------
-`timescale 1ns/100ps
-
-
-//------------------------------------------------------------------
// Test module.
//------------------------------------------------------------------
module tb_aes_encipher_block();
@@ -158,7 +152,7 @@ module tb_aes_encipher_block();
//
// Dump the state of the dump when needed.
//----------------------------------------------------------------
- task dump_dut_state();
+ task dump_dut_state;
begin
$display("State of DUT");
$display("------------");
@@ -200,7 +194,7 @@ module tb_aes_encipher_block();
//
// Toggle reset to put the DUT into a well known state.
//----------------------------------------------------------------
- task reset_dut();
+ task reset_dut;
begin
$display("*** Toggle reset.");
tb_reset_n = 0;
@@ -216,7 +210,7 @@ module tb_aes_encipher_block();
// Initialize all counters and testbed functionality as well
// as setting the DUT inputs to defined values.
//----------------------------------------------------------------
- task init_sim();
+ task init_sim;
begin
cycle_ctr = 0;
error_ctr = 0;
@@ -238,7 +232,7 @@ module tb_aes_encipher_block();
//
// Display the accumulated test results.
//----------------------------------------------------------------
- task display_test_result();
+ task display_test_result;
begin
if (error_ctr == 0)
begin
@@ -262,7 +256,7 @@ module tb_aes_encipher_block();
// when the dut is actively processing and will in fact at some
// point set the flag.
//----------------------------------------------------------------
- task wait_ready();
+ task wait_ready;
begin
while (!tb_ready)
begin
diff --git a/src/tb/tb_aes_key_mem.v b/src/tb/tb_aes_key_mem.v
index 748ae3f..3e23616 100644
--- a/src/tb/tb_aes_key_mem.v
+++ b/src/tb/tb_aes_key_mem.v
@@ -37,12 +37,6 @@
//======================================================================
//------------------------------------------------------------------
-// Simulator directives.
-//------------------------------------------------------------------
-`timescale 1ns/100ps
-
-
-//------------------------------------------------------------------
// Test module.
//------------------------------------------------------------------
module tb_aes_key_mem();
@@ -144,7 +138,7 @@ module tb_aes_key_mem();
//
// Dump the state of the dump when needed.
//----------------------------------------------------------------
- task dump_dut_state();
+ task dump_dut_state;
begin
$display("State of DUT");
$display("------------");
@@ -196,7 +190,7 @@ module tb_aes_key_mem();
//
// Toggle reset to put the DUT into a well known state.
//----------------------------------------------------------------
- task reset_dut();
+ task reset_dut;
begin
$display("*** Toggle reset.");
tb_reset_n = 0;
@@ -212,7 +206,7 @@ module tb_aes_key_mem();
// Initialize all counters and testbed functionality as well
// as setting the DUT inputs to defined values.
//----------------------------------------------------------------
- task init_sim();
+ task init_sim;
begin
cycle_ctr = 0;
error_ctr = 0;
@@ -237,7 +231,7 @@ module tb_aes_key_mem();
// when the dut is actively processing and will in fact at some
// point set the flag.
//----------------------------------------------------------------
- task wait_ready();
+ task wait_ready;
begin
while (!tb_ready)
begin
@@ -382,7 +376,7 @@ module tb_aes_key_mem();
//
// Display the accumulated test results.
//----------------------------------------------------------------
- task display_test_result();
+ task display_test_result;
begin
if (error_ctr == 0)
begin