aboutsummaryrefslogtreecommitdiff
path: root/src/tb
diff options
context:
space:
mode:
Diffstat (limited to 'src/tb')
-rw-r--r--src/tb/tb_aes.v100
-rw-r--r--src/tb/tb_aes_core.v89
-rw-r--r--src/tb/tb_aes_decipher_block.v10
-rw-r--r--src/tb/tb_aes_encipher_block.v27
-rw-r--r--src/tb/tb_aes_key_mem.v11
5 files changed, 105 insertions, 132 deletions
diff --git a/src/tb/tb_aes.v b/src/tb/tb_aes.v
index 6561b4d..84be6a8 100644
--- a/src/tb/tb_aes.v
+++ b/src/tb/tb_aes.v
@@ -429,11 +429,64 @@ module tb_aes();
//----------------------------------------------------------------
- // nist_fips_tests()
+ // single_block_mangle_test()
//
- // Perform tests based on NIST FIPS-197 test vectors.
+ // Perform single block test, but try to mangle the operation
+ // by changing from encryption to decryption mid-processing.
+ // This should cause errors unless changes to config during
+ // processing.
+ //----------------------------------------------------------------
+ task single_block_mangle_test(input [7 : 0] tc_number,
+ input [255 : 0] key,
+ input [127 : 0] block,
+ input [127 : 0] expected);
+ begin
+ $display("*** TC %0d mangle test started.", tc_number);
+ tc_ctr = tc_ctr + 1;
+
+ init_key(key, AES_128_BIT_KEY);
+ write_block(block);
+ dump_dut_state();
+
+ // Set that we want to encipher and start processing.
+ $display("*** Staring encipher operation");
+ write_word(ADDR_CONFIG, (8'h00 + (AES_128_BIT_KEY << 1) + AES_ENCIPHER));
+ write_word(ADDR_CTRL, 8'h02);
+
+ // Wait a number of cycles and then switch from encipher to decipher.
+ #(10 * CLK_PERIOD);
+ $display("*** Switching to decipher operation");
+ write_word(ADDR_CONFIG, (8'h00 + (AES_128_BIT_KEY << 1) + AES_DECIPHER));
+
+ wait_ready();
+ $display("*** Ready has been set!");
+ dump_dut_state();
+ read_result();
+
+ if (result_data == expected)
+ begin
+ $display("*** TC %0d successful.", tc_number);
+ $display("");
+ end
+ else
+ begin
+ $display("*** ERROR: TC %0d NOT successful.", tc_number);
+ $display("Expected: 0x%032x", expected);
+ $display("Got: 0x%032x", result_data);
+ $display("");
+
+ error_ctr = error_ctr + 1;
+ end
+ end
+ endtask // ecb_mode_single_block_test
+
+
//----------------------------------------------------------------
- task nist_fips_tests;
+ // aes_test()
+ //
+ // Main test task will perform complete NIST test of AES.
+ //----------------------------------------------------------------
+ task aes_test;
reg [255 : 0] nist_aes128_key;
reg [255 : 0] nist_aes256_key;
@@ -472,8 +525,8 @@ module tb_aes();
nist_ecb_256_enc_expected3 = 128'h23304b7a39f9f3ff067d8d8f9e24ecc7;
- $display("NIST FIPS ECB 128 bit key tests");
- $display("-------------------------------");
+ $display("ECB 128 bit key tests");
+ $display("---------------------");
ecb_mode_single_block_test(8'h01, AES_ENCIPHER, nist_aes128_key, AES_128_BIT_KEY,
nist_plaintext0, nist_ecb_128_enc_expected0);
@@ -501,8 +554,8 @@ module tb_aes();
$display("");
- $display("NIST FIPS ECB 256 bit key tests");
- $display("-------------------------------");
+ $display("ECB 256 bit key tests");
+ $display("---------------------");
ecb_mode_single_block_test(8'h10, AES_ENCIPHER, nist_aes256_key, AES_256_BIT_KEY,
nist_plaintext0, nist_ecb_256_enc_expected0);
@@ -527,34 +580,14 @@ module tb_aes();
ecb_mode_single_block_test(8'h17, AES_DECIPHER, nist_aes256_key, AES_256_BIT_KEY,
nist_ecb_256_enc_expected3, nist_plaintext3);
- end
- endtask // aes_test
-
- //----------------------------------------------------------------
- // nist_kwp_test()
- //
- // Test that we can perform operations based on NIST KWP
- // AE 128 test vectors.
- //----------------------------------------------------------------
- task nist_kwp_test;
- reg [255 : 0] kwp_key;
- reg [127 : 0] kwp_plaintext;
- reg [127 : 0] kwp_expected;
- begin
- kwp_key = 256'hc03db3cc1416dcd1c069a195a8d77e3d00000000000000000000000000000000;
- kwp_plaintext = 128'ha65959a60000001f46f87f58cdda4200;
- kwp_expected = 128'hd1bac797ff82fa4bde9f7490729fd0a7;
-
- $display("");
- $display("NIST KWP AE 128 bit test");
-
- ecb_mode_single_block_test(8'h18, AES_ENCIPHER, kwp_key, AES_128_BIT_KEY,
- kwp_plaintext, kwp_expected);
+ $display("Block processing mangling test");
+ $display("------------------------------");
+ single_block_mangle_test(8'h18, nist_aes128_key, nist_plaintext0,
+ nist_ecb_128_enc_expected0);
end
- endtask // nist_kwp_test
-
+ endtask // aes_test
//----------------------------------------------------------------
@@ -573,8 +606,7 @@ module tb_aes();
reset_dut();
dump_dut_state();
- nist_fips_tests();
- nist_kwp_test();
+ aes_test();
display_test_results();
diff --git a/src/tb/tb_aes_core.v b/src/tb/tb_aes_core.v
index d7c424c..d36d0bc 100644
--- a/src/tb/tb_aes_core.v
+++ b/src/tb/tb_aes_core.v
@@ -339,8 +339,15 @@ module tb_aes_core();
endtask // ecb_mode_single_block_test
- task nist_fips_tests;
- begin : fips_tests
+ //----------------------------------------------------------------
+ // aes_core_test
+ // The main test functionality.
+ //
+ // Test cases taken from NIST SP 800-38A:
+ // http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
+ //----------------------------------------------------------------
+ initial
+ begin : aes_core_test
reg [255 : 0] nist_aes128_key;
reg [255 : 0] nist_aes256_key;
@@ -378,19 +385,29 @@ module tb_aes_core();
nist_ecb_256_enc_expected3 = 128'h23304b7a39f9f3ff067d8d8f9e24ecc7;
- $display("NIST FIPS ECB 128 bit key tests");
- $display("-------------------------------");
+ $display(" -= Testbench for aes core started =-");
+ $display(" ================================");
+ $display("");
+
+ init_sim();
+ dump_dut_state();
+ reset_dut();
+ dump_dut_state();
+
+
+ $display("ECB 128 bit key tests");
+ $display("---------------------");
ecb_mode_single_block_test(8'h01, AES_ENCIPHER, nist_aes128_key, AES_128_BIT_KEY,
nist_plaintext0, nist_ecb_128_enc_expected0);
- ecb_mode_single_block_test(8'h02, AES_ENCIPHER, nist_aes128_key, AES_128_BIT_KEY,
- nist_plaintext1, nist_ecb_128_enc_expected1);
+ ecb_mode_single_block_test(8'h02, AES_ENCIPHER, nist_aes128_key, AES_128_BIT_KEY,
+ nist_plaintext1, nist_ecb_128_enc_expected1);
- ecb_mode_single_block_test(8'h03, AES_ENCIPHER, nist_aes128_key, AES_128_BIT_KEY,
- nist_plaintext2, nist_ecb_128_enc_expected2);
+ ecb_mode_single_block_test(8'h03, AES_ENCIPHER, nist_aes128_key, AES_128_BIT_KEY,
+ nist_plaintext2, nist_ecb_128_enc_expected2);
- ecb_mode_single_block_test(8'h04, AES_ENCIPHER, nist_aes128_key, AES_128_BIT_KEY,
- nist_plaintext3, nist_ecb_128_enc_expected3);
+ ecb_mode_single_block_test(8'h04, AES_ENCIPHER, nist_aes128_key, AES_128_BIT_KEY,
+ nist_plaintext3, nist_ecb_128_enc_expected3);
ecb_mode_single_block_test(8'h05, AES_DECIPHER, nist_aes128_key, AES_128_BIT_KEY,
@@ -407,8 +424,8 @@ module tb_aes_core();
$display("");
- $display("NIST FIPS ECB 256 bit key tests");
- $display("-------------------------------");
+ $display("ECB 256 bit key tests");
+ $display("---------------------");
ecb_mode_single_block_test(8'h10, AES_ENCIPHER, nist_aes256_key, AES_256_BIT_KEY,
nist_plaintext0, nist_ecb_256_enc_expected0);
@@ -433,55 +450,7 @@ module tb_aes_core();
ecb_mode_single_block_test(8'h17, AES_DECIPHER, nist_aes256_key, AES_256_BIT_KEY,
nist_ecb_256_enc_expected3, nist_plaintext3);
- end
- endtask // nist_fips_tests
-
-
- //----------------------------------------------------------------
- // nist_kwp_test()
- //
- // Test that we can perform operations based on NIST KWP
- // AE 128 test vectors.
- //----------------------------------------------------------------
- task nist_kwp_test;
- reg [255 : 0] kwp_key;
- reg [127 : 0] kwp_plaintext;
- reg [127 : 0] kwp_expected;
-
- begin
- kwp_key = 256'hc03db3cc1416dcd1c069a195a8d77e3d00000000000000000000000000000000;
- kwp_plaintext = 128'ha65959a60000001f46f87f58cdda4200;
- kwp_expected = 128'hd1bac797ff82fa4bde9f7490729fd0a7;
-
- $display("");
- $display("NIST KWP AE 128 bit test");
-
- ecb_mode_single_block_test(8'h18, AES_ENCIPHER, kwp_key, AES_128_BIT_KEY,
- kwp_plaintext, kwp_expected);
- end
- endtask // nist_kwp_test
-
-
- //----------------------------------------------------------------
- // aes_core_test
- // The main test functionality.
- //
- // Test cases taken from NIST SP 800-38A:
- // http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
- //----------------------------------------------------------------
- initial
- begin : aes_core_test
- $display(" -= Testbench for aes core started =-");
- $display(" ================================");
- $display("");
-
- init_sim();
- dump_dut_state();
- reset_dut();
- dump_dut_state();
- nist_fips_tests();
- nist_kwp_test();
display_test_result();
$display("");
diff --git a/src/tb/tb_aes_decipher_block.v b/src/tb/tb_aes_decipher_block.v
index ec228c0..13b9949 100644
--- a/src/tb/tb_aes_decipher_block.v
+++ b/src/tb/tb_aes_decipher_block.v
@@ -152,17 +152,15 @@ module tb_aes_decipher_block();
$display("Control states");
$display("round = 0x%01x", dut.round);
- $display("dec_ctrl = 0x%01x, update_type = 0x%01x, sword_ctr = 0x%01x, round_ctr = 0x%01x",
- dut.dec_ctrl_reg, dut.update_type, dut.sword_ctr_reg, dut.round_ctr_reg);
+ $display("dec_ctrl = 0x%01x, update_type = 0x%01x, round_ctr = 0x%01x",
+ dut.dec_ctrl_reg, dut.update_type, dut.round_ctr_reg);
$display("");
$display("Internal data values");
$display("round_key = 0x%016x", dut.round_key);
- $display("sboxw = 0x%08x, new_sboxw = 0x%08x", dut.tmp_sboxw, dut.new_sboxw);
- $display("block_w0_reg = 0x%08x, block_w1_reg = 0x%08x, block_w2_reg = 0x%08x, block_w3_reg = 0x%08x",
- dut.block_w0_reg, dut.block_w1_reg, dut.block_w2_reg, dut.block_w3_reg);
+ $display("block_reg = 0x%016x", dut.block_reg);
$display("");
- $display("old_block = 0x%08x", dut.round_logic.old_block);
+ $display("subbytes_block = 0x%08x", dut.round_logic.subbytes_block);
$display("inv_shiftrows_block = 0x%08x", dut.round_logic.inv_shiftrows_block);
$display("inv_mixcolumns_block = 0x%08x", dut.round_logic.inv_mixcolumns_block);
$display("addkey_block = 0x%08x", dut.round_logic.addkey_block);
diff --git a/src/tb/tb_aes_encipher_block.v b/src/tb/tb_aes_encipher_block.v
index 68e88dd..0606d95 100644
--- a/src/tb/tb_aes_encipher_block.v
+++ b/src/tb/tb_aes_encipher_block.v
@@ -74,9 +74,6 @@ module tb_aes_encipher_block();
wire [3 : 0] tb_round;
wire [127 : 0] tb_round_key;
- wire [31 : 0] tb_sboxw;
- wire [31 : 0] tb_new_sboxw;
-
reg [127 : 0] tb_block;
wire [127 : 0] tb_new_block;
@@ -92,13 +89,6 @@ module tb_aes_encipher_block();
//----------------------------------------------------------------
// Device Under Test.
//----------------------------------------------------------------
- // We need an sbox for the tests.
- aes_sbox sbox(
- .sboxw(tb_sboxw),
- .new_sboxw(tb_new_sboxw)
- );
-
-
// The device under test.
aes_encipher_block dut(
.clk(tb_clk),
@@ -110,9 +100,6 @@ module tb_aes_encipher_block();
.round(tb_round),
.round_key(tb_round_key),
- .sboxw(tb_sboxw),
- .new_sboxw(tb_new_sboxw),
-
.block(tb_block),
.new_block(tb_new_block),
.ready(tb_ready)
@@ -166,25 +153,21 @@ module tb_aes_encipher_block();
$display("Control states");
$display("round = 0x%01x", dut.round);
- $display("enc_ctrl = 0x%01x, update_type = 0x%01x, sword_ctr = 0x%01x, round_ctr = 0x%01x",
- dut.enc_ctrl_reg, dut.update_type, dut.sword_ctr_reg, dut.round_ctr_reg);
+ $display("enc_ctrl = 0x%01x, update_type = 0x%01x, round_ctr = 0x%01x",
+ dut.enc_ctrl_reg, dut.update_type, dut.round_ctr_reg);
$display("");
$display("Internal data values");
$display("round_key = 0x%016x", dut.round_key);
- $display("sboxw = 0x%08x, new_sboxw = 0x%08x", dut.sboxw, dut.new_sboxw);
- $display("block_w0_reg = 0x%08x, block_w1_reg = 0x%08x, block_w2_reg = 0x%08x, block_w3_reg = 0x%08x",
- dut.block_w0_reg, dut.block_w1_reg, dut.block_w2_reg, dut.block_w3_reg);
+ $display("block_reg = 0x%016x", dut.block_reg);
$display("");
- $display("old_block = 0x%08x", dut.round_logic.old_block);
+ $display("subbytes_block = 0x%08x", dut.round_logic.subbytes_block);
$display("shiftrows_block = 0x%08x", dut.round_logic.shiftrows_block);
$display("mixcolumns_block = 0x%08x", dut.round_logic.mixcolumns_block);
$display("addkey_init_block = 0x%08x", dut.round_logic.addkey_init_block);
$display("addkey_main_block = 0x%08x", dut.round_logic.addkey_main_block);
$display("addkey_final_block = 0x%08x", dut.round_logic.addkey_final_block);
- $display("block_w0_new = 0x%08x, block_w1_new = 0x%08x, block_w2_new = 0x%08x, block_w3_new = 0x%08x",
- dut.block_new[127 : 096], dut.block_new[095 : 064],
- dut.block_new[063 : 032], dut.block_new[031 : 000]);
+ $display("block_new = 0x%08x", dut.block_new);
$display("");
end
endtask // dump_dut_state
diff --git a/src/tb/tb_aes_key_mem.v b/src/tb/tb_aes_key_mem.v
index cac216a..b76fb64 100644
--- a/src/tb/tb_aes_key_mem.v
+++ b/src/tb/tb_aes_key_mem.v
@@ -78,9 +78,6 @@ module tb_aes_key_mem();
wire [127 : 0] tb_round_key;
wire tb_ready;
- wire [31 : 0] tb_sboxw;
- wire [31 : 0] tb_new_sboxw;
-
//----------------------------------------------------------------
// Device Under Test.
@@ -95,15 +92,9 @@ module tb_aes_key_mem();
.round(tb_round),
.round_key(tb_round_key),
- .ready(tb_ready),
-
- .sboxw(tb_sboxw),
- .new_sboxw(tb_new_sboxw)
+ .ready(tb_ready)
);
- // The DUT requirees Sboxes.
- aes_sbox sbox(.sboxw(tb_sboxw), .new_sboxw(tb_new_sboxw));
-
//----------------------------------------------------------------
// clk_gen