diff options
author | Joachim StroĢmbergson <joachim@secworks.se> | 2018-07-04 15:21:27 +0200 |
---|---|---|
committer | Joachim StroĢmbergson <joachim@secworks.se> | 2018-07-04 15:21:27 +0200 |
commit | 98cc06bdeccbd30da21a0439c1cbbf59f9a75f3e (patch) | |
tree | 31c206e82a293f80362a5612408961175e421d96 /src | |
parent | fa155de5469627ae0ff942ea452f2f92f169767c (diff) |
(1) Added NIST KWP test to core. (2) Moved all other tests in core tb to a separate task. (3) Minor cleanup in top tb.
Diffstat (limited to 'src')
-rw-r--r-- | src/tb/tb_aes.v | 27 | ||||
-rw-r--r-- | src/tb/tb_aes_core.v | 89 |
2 files changed, 73 insertions, 43 deletions
diff --git a/src/tb/tb_aes.v b/src/tb/tb_aes.v index 1e229d9..6561b4d 100644 --- a/src/tb/tb_aes.v +++ b/src/tb/tb_aes.v @@ -429,11 +429,11 @@ module tb_aes(); //---------------------------------------------------------------- - // aes_test() + // nist_fips_tests() // - // Main test task will perform complete NIST test of AES. + // Perform tests based on NIST FIPS-197 test vectors. //---------------------------------------------------------------- - task aes_test; + task nist_fips_tests; reg [255 : 0] nist_aes128_key; reg [255 : 0] nist_aes256_key; @@ -472,8 +472,8 @@ module tb_aes(); nist_ecb_256_enc_expected3 = 128'h23304b7a39f9f3ff067d8d8f9e24ecc7; - $display("ECB 128 bit key tests"); - $display("---------------------"); + $display("NIST FIPS 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 +501,8 @@ module tb_aes(); $display(""); - $display("ECB 256 bit key tests"); - $display("---------------------"); + $display("NIST FIPS 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); @@ -531,14 +531,13 @@ module tb_aes(); endtask // aes_test - //---------------------------------------------------------------- - // nist_kwp_ae_128_test() + // nist_kwp_test() // // Test that we can perform operations based on NIST KWP // AE 128 test vectors. //---------------------------------------------------------------- - task nist_kwp_ae_128_test; + task nist_kwp_test; reg [255 : 0] kwp_key; reg [127 : 0] kwp_plaintext; reg [127 : 0] kwp_expected; @@ -551,10 +550,10 @@ module tb_aes(); $display(""); $display("NIST KWP AE 128 bit test"); - ecb_mode_single_block_test(8'h01, AES_ENCIPHER, kwp_key, AES_128_BIT_KEY, + ecb_mode_single_block_test(8'h18, AES_ENCIPHER, kwp_key, AES_128_BIT_KEY, kwp_plaintext, kwp_expected); end - endtask // nist_kwp_ae_128_test + endtask // nist_kwp_test @@ -574,8 +573,8 @@ module tb_aes(); reset_dut(); dump_dut_state(); - aes_test(); - nist_kwp_ae_128_test(); + nist_fips_tests(); + nist_kwp_test(); display_test_results(); diff --git a/src/tb/tb_aes_core.v b/src/tb/tb_aes_core.v index d36d0bc..d7c424c 100644 --- a/src/tb/tb_aes_core.v +++ b/src/tb/tb_aes_core.v @@ -339,15 +339,8 @@ module tb_aes_core(); endtask // ecb_mode_single_block_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 + task nist_fips_tests; + begin : fips_tests reg [255 : 0] nist_aes128_key; reg [255 : 0] nist_aes256_key; @@ -385,29 +378,19 @@ module tb_aes_core(); nist_ecb_256_enc_expected3 = 128'h23304b7a39f9f3ff067d8d8f9e24ecc7; - $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("---------------------"); + $display("NIST FIPS 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, @@ -424,8 +407,8 @@ module tb_aes_core(); $display(""); - $display("ECB 256 bit key tests"); - $display("---------------------"); + $display("NIST FIPS 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); @@ -450,7 +433,55 @@ 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(""); |