aboutsummaryrefslogtreecommitdiff
path: root/src/tb
diff options
context:
space:
mode:
Diffstat (limited to 'src/tb')
-rw-r--r--src/tb/tb_aes.v59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/tb/tb_aes.v b/src/tb/tb_aes.v
index 35fc1d9..84be6a8 100644
--- a/src/tb/tb_aes.v
+++ b/src/tb/tb_aes.v
@@ -429,6 +429,59 @@ module tb_aes();
//----------------------------------------------------------------
+ // single_block_mangle_test()
+ //
+ // 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
+
+
+ //----------------------------------------------------------------
// aes_test()
//
// Main test task will perform complete NIST test of AES.
@@ -527,6 +580,12 @@ 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);
+
+
+ $display("Block processing mangling test");
+ $display("------------------------------");
+ single_block_mangle_test(8'h18, nist_aes128_key, nist_plaintext0,
+ nist_ecb_128_enc_expected0);
end
endtask // aes_test