aboutsummaryrefslogtreecommitdiff
path: root/src/tb/tb_aes.v
diff options
context:
space:
mode:
Diffstat (limited to 'src/tb/tb_aes.v')
-rw-r--r--src/tb/tb_aes.v100
1 files changed, 66 insertions, 34 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();