diff options
author | Joachim StroĢmbergson <joachim@secworks.se> | 2018-07-06 12:53:37 +0200 |
---|---|---|
committer | Joachim StroĢmbergson <joachim@secworks.se> | 2018-07-06 12:53:37 +0200 |
commit | 44caddc20134935cc53d9507ac29f4ed29d4ad3c (patch) | |
tree | 15bc53fab177ec91c17281a0adca4f485b184dbc /src | |
parent | 697456be8bf1eb4585dd0d88b185659b4bc17fe9 (diff) |
Adding test case for 4096 bit unwrap. Testcase passed! We have unwrap.
Diffstat (limited to 'src')
-rw-r--r-- | src/tb/tb_keywrap.v | 210 | ||||
-rwxr-xr-x | src/tools/gen_cmds.py | 4 |
2 files changed, 210 insertions, 4 deletions
diff --git a/src/tb/tb_keywrap.v b/src/tb/tb_keywrap.v index edbbbcf..c8fb927 100644 --- a/src/tb/tb_keywrap.v +++ b/src/tb/tb_keywrap.v @@ -40,8 +40,8 @@ module tb_keywrap(); parameter DEBUG = 1; - parameter DUMP_TOP = 1; - parameter DUMP_CORE = 1; + parameter DUMP_TOP = 0; + parameter DUMP_CORE = 0; parameter CLK_HALF_PERIOD = 1; parameter CLK_PERIOD = 2 * CLK_HALF_PERIOD; @@ -732,6 +732,209 @@ module tb_keywrap(); //---------------------------------------------------------------- + // test_kwp_ad_128_2 + // Implements wrap test based on NIST KWP_AD 128 bit key with + // 4096 bit plaintext. + //---------------------------------------------------------------- + task test_kwp_ad_128_2; + begin : kwp_ad_128_2 + integer i; + tc_ctr = tc_ctr + 1; + + $display("** TC kwp_ad_128_2 START."); + + // Write key and keylength, we also want to unwrap/decrypt. + write_word(ADDR_KEY0, 32'h6b8ba9cc); + write_word(ADDR_KEY1, 32'h9b31068b); + write_word(ADDR_KEY2, 32'ha175abfc); + write_word(ADDR_KEY3, 32'hc60c1338); + write_word(ADDR_CONFIG, 32'h00000000); + + + // Initialize the AES engine (to expand the key). + // Wait for init to complete. + $display("* Trying to initialize."); + write_word(ADDR_CTRL, 32'h00000001); + #(2 * CLK_PERIOD); + wait_ready(); + $display("* Init should be done."); + + + // Set the length or R in blocks. + // Write the R bank to be written to. + // Write the R blocks to be processed. + write_word(ADDR_RLEN, 32'h00000040); + write_word(ADDR_R_BANK, 32'h0); + + write_word(ADDR_R_DATA0 + 0, 32'h4501c1ec); + write_word(ADDR_R_DATA0 + 1, 32'hadc6b5e3); + write_word(ADDR_R_DATA0 + 2, 32'hf1c23c29); + write_word(ADDR_R_DATA0 + 3, 32'heca60890); + write_word(ADDR_R_DATA0 + 4, 32'h5f9cabdd); + write_word(ADDR_R_DATA0 + 5, 32'h46e34a55); + write_word(ADDR_R_DATA0 + 6, 32'he1f7ac83); + write_word(ADDR_R_DATA0 + 7, 32'h08e75c90); + write_word(ADDR_R_DATA0 + 8, 32'h3675982b); + write_word(ADDR_R_DATA0 + 9, 32'hda99173a); + write_word(ADDR_R_DATA0 + 10, 32'h2ba57d2c); + write_word(ADDR_R_DATA0 + 11, 32'hcf2e01a0); + write_word(ADDR_R_DATA0 + 12, 32'h2589f89d); + write_word(ADDR_R_DATA0 + 13, 32'hfd4b3c7f); + write_word(ADDR_R_DATA0 + 14, 32'hd229ec91); + write_word(ADDR_R_DATA0 + 15, 32'hc9d0c46e); + write_word(ADDR_R_DATA0 + 16, 32'ha5dee3c0); + write_word(ADDR_R_DATA0 + 17, 32'h48cd4611); + write_word(ADDR_R_DATA0 + 18, 32'hbfeadc9b); + write_word(ADDR_R_DATA0 + 19, 32'hf26daa1e); + write_word(ADDR_R_DATA0 + 20, 32'h02cb72e2); + write_word(ADDR_R_DATA0 + 21, 32'h22cf3dab); + write_word(ADDR_R_DATA0 + 22, 32'h120dd1e8); + write_word(ADDR_R_DATA0 + 23, 32'hc2dd9bd5); + write_word(ADDR_R_DATA0 + 24, 32'h8bbefa5d); + write_word(ADDR_R_DATA0 + 25, 32'h14526abd); + write_word(ADDR_R_DATA0 + 26, 32'h1e8d2170); + write_word(ADDR_R_DATA0 + 27, 32'ha6ba8283); + write_word(ADDR_R_DATA0 + 28, 32'hc243ec2f); + write_word(ADDR_R_DATA0 + 29, 32'hd5ef0703); + write_word(ADDR_R_DATA0 + 30, 32'h0b1ef5f6); + write_word(ADDR_R_DATA0 + 31, 32'h9f9620e4); + write_word(ADDR_R_DATA0 + 32, 32'hb17a3639); + write_word(ADDR_R_DATA0 + 33, 32'h34100588); + write_word(ADDR_R_DATA0 + 34, 32'h7b9ffc79); + write_word(ADDR_R_DATA0 + 35, 32'h35335947); + write_word(ADDR_R_DATA0 + 36, 32'h03e5dcae); + write_word(ADDR_R_DATA0 + 37, 32'h67bd0ce7); + write_word(ADDR_R_DATA0 + 38, 32'ha3c98ca6); + write_word(ADDR_R_DATA0 + 39, 32'h5815a4d0); + write_word(ADDR_R_DATA0 + 40, 32'h67f27e6e); + write_word(ADDR_R_DATA0 + 41, 32'h66d6636c); + write_word(ADDR_R_DATA0 + 42, 32'hebb78973); + write_word(ADDR_R_DATA0 + 43, 32'h2566a52a); + write_word(ADDR_R_DATA0 + 44, 32'hc3970e14); + write_word(ADDR_R_DATA0 + 45, 32'hc37310dc); + write_word(ADDR_R_DATA0 + 46, 32'h2fcee0e7); + write_word(ADDR_R_DATA0 + 47, 32'h39a16291); + write_word(ADDR_R_DATA0 + 48, 32'h029fd2b4); + write_word(ADDR_R_DATA0 + 49, 32'hd534e304); + write_word(ADDR_R_DATA0 + 50, 32'h45474b26); + write_word(ADDR_R_DATA0 + 51, 32'h711a8b3e); + write_word(ADDR_R_DATA0 + 52, 32'h1ee3cc88); + write_word(ADDR_R_DATA0 + 53, 32'hb09e8b17); + write_word(ADDR_R_DATA0 + 54, 32'h45b6cc0f); + write_word(ADDR_R_DATA0 + 55, 32'h067624ec); + write_word(ADDR_R_DATA0 + 56, 32'hb232db75); + write_word(ADDR_R_DATA0 + 57, 32'h0b01fe54); + write_word(ADDR_R_DATA0 + 58, 32'h57fdea77); + write_word(ADDR_R_DATA0 + 59, 32'hb251b10f); + write_word(ADDR_R_DATA0 + 60, 32'he95d3eee); + write_word(ADDR_R_DATA0 + 61, 32'hdb083bdf); + write_word(ADDR_R_DATA0 + 62, 32'h109c41db); + write_word(ADDR_R_DATA0 + 63, 32'ha26cc965); + write_word(ADDR_R_DATA0 + 64, 32'h4f787bf9); + write_word(ADDR_R_DATA0 + 65, 32'h5735ff07); + write_word(ADDR_R_DATA0 + 66, 32'h070b175c); + write_word(ADDR_R_DATA0 + 67, 32'hea8b6230); + write_word(ADDR_R_DATA0 + 68, 32'h2e6087b9); + write_word(ADDR_R_DATA0 + 69, 32'h1a041547); + write_word(ADDR_R_DATA0 + 70, 32'h46056910); + write_word(ADDR_R_DATA0 + 71, 32'h99f1a9e2); + write_word(ADDR_R_DATA0 + 72, 32'hb626c4b3); + write_word(ADDR_R_DATA0 + 73, 32'hbb7aeb8e); + write_word(ADDR_R_DATA0 + 74, 32'had9922bc); + write_word(ADDR_R_DATA0 + 75, 32'h3617cb42); + write_word(ADDR_R_DATA0 + 76, 32'h7c669b88); + write_word(ADDR_R_DATA0 + 77, 32'hbe5f98ae); + write_word(ADDR_R_DATA0 + 78, 32'ha7edb8b0); + write_word(ADDR_R_DATA0 + 79, 32'h063bec80); + write_word(ADDR_R_DATA0 + 80, 32'haf4c081f); + write_word(ADDR_R_DATA0 + 81, 32'h89778d7c); + write_word(ADDR_R_DATA0 + 82, 32'h7242ddae); + write_word(ADDR_R_DATA0 + 83, 32'h88e8d3af); + write_word(ADDR_R_DATA0 + 84, 32'hf1f80e57); + write_word(ADDR_R_DATA0 + 85, 32'h5e1aab4a); + write_word(ADDR_R_DATA0 + 86, 32'h5d115bc2); + write_word(ADDR_R_DATA0 + 87, 32'h7636fd14); + write_word(ADDR_R_DATA0 + 88, 32'hd19bc594); + write_word(ADDR_R_DATA0 + 89, 32'h33f69763); + write_word(ADDR_R_DATA0 + 90, 32'h5ecd870d); + write_word(ADDR_R_DATA0 + 91, 32'h17e7f5b0); + write_word(ADDR_R_DATA0 + 92, 32'h04dee400); + write_word(ADDR_R_DATA0 + 93, 32'h1cddc34a); + write_word(ADDR_R_DATA0 + 94, 32'hb6e377ee); + write_word(ADDR_R_DATA0 + 95, 32'hb3fb08e9); + write_word(ADDR_R_DATA0 + 96, 32'h47697076); + write_word(ADDR_R_DATA0 + 97, 32'h5105d93e); + write_word(ADDR_R_DATA0 + 98, 32'h4558fe3d); + write_word(ADDR_R_DATA0 + 99, 32'h4fc6fe05); + write_word(ADDR_R_DATA0 + 100, 32'h3aab9c6c); + write_word(ADDR_R_DATA0 + 101, 32'hf032f111); + write_word(ADDR_R_DATA0 + 102, 32'h6e70c2d6); + write_word(ADDR_R_DATA0 + 103, 32'h5f7c8cde); + write_word(ADDR_R_DATA0 + 104, 32'hb6ad63ac); + write_word(ADDR_R_DATA0 + 105, 32'h4291f93d); + write_word(ADDR_R_DATA0 + 106, 32'h467ebbb2); + write_word(ADDR_R_DATA0 + 107, 32'h9ead265c); + write_word(ADDR_R_DATA0 + 108, 32'h05ac684d); + write_word(ADDR_R_DATA0 + 109, 32'h20a6bef0); + write_word(ADDR_R_DATA0 + 110, 32'h9b71830f); + write_word(ADDR_R_DATA0 + 111, 32'h717e08bc); + write_word(ADDR_R_DATA0 + 112, 32'hb4f9d377); + write_word(ADDR_R_DATA0 + 113, 32'h3bec928f); + write_word(ADDR_R_DATA0 + 114, 32'h66eeb64d); + write_word(ADDR_R_DATA0 + 115, 32'hc451e958); + write_word(ADDR_R_DATA0 + 116, 32'he357ebbf); + write_word(ADDR_R_DATA0 + 117, 32'hef5a342d); + write_word(ADDR_R_DATA0 + 118, 32'hf28707ac); + write_word(ADDR_R_DATA0 + 119, 32'h4b8e3e8c); + write_word(ADDR_R_DATA0 + 120, 32'h854e8d69); + write_word(ADDR_R_DATA0 + 121, 32'h1cb92e87); + write_word(ADDR_R_DATA0 + 122, 32'hc0d57558); + write_word(ADDR_R_DATA0 + 123, 32'he44cd754); + write_word(ADDR_R_DATA0 + 124, 32'h424865c2); + write_word(ADDR_R_DATA0 + 125, 32'h29c9e1ab); + write_word(ADDR_R_DATA0 + 126, 32'hb28e003b); + write_word(ADDR_R_DATA0 + 127, 32'h6819400b); + + // Write magic words to A. + write_word(ADDR_A0, 32'haea19443); + write_word(ADDR_A1, 32'hd7f8ad7d); + + + $display("* Contents of memory and dut before wrap processing:"); + dump_mem(65); + + // Start wrapping and wait for wrap to complete. + $display("* Trying to start processing."); + write_word(ADDR_CTRL, 32'h00000002); + #(2 * CLK_PERIOD); + wait_ready(); + $display("* Processing should be done."); + + + $display("Contents of memory and dut after wrap processing:"); + dump_mem(65); + dump_dut_state(); + + + // Read and display the A registers. + read_word(ADDR_A0); + $display("A0 after wrap: 0x%08x", read_data); + read_word(ADDR_A1); + $display("A1 after wrap: 0x%08x", read_data); + + // Read and display the R blocks that has been processed. + for (i = 0 ; i < 128 ; i = i + 1) + begin + read_word(ADDR_R_DATA0 + i); + $display("mem[0x%07x] = 0x%08x", i, read_data); + end + + $display("** TC kwp_ad_128_2 END.\n"); + end + endtask // test_kwp_ad_128_2 + + + //---------------------------------------------------------------- // main //---------------------------------------------------------------- initial @@ -747,8 +950,9 @@ module tb_keywrap(); dump_dut_state(); // test_kwp_ae_128_1(); - test_kwp_ad_128_1(); +// test_kwp_ad_128_1(); // test_kwp_ae_128_2(); + test_kwp_ad_128_2(); display_test_results(); diff --git a/src/tools/gen_cmds.py b/src/tools/gen_cmds.py index 653afeb..8a15be7 100755 --- a/src/tools/gen_cmds.py +++ b/src/tools/gen_cmds.py @@ -8,10 +8,12 @@ cleartext = "8af887c58dfbc38e e0423eefcc0e032d cc79dd116638ca65 ad75dca2a2459f13 934dbe61a62cb26d 8bbddbabf9bf52bb e137ef1d3e30eacf 0fe456ec808d6798 dc29fe54fa1f784a a3c11cf394050095 81d3f1d596843813 a6685e503fac8535 e0c06ecca8561b6a 1f22c578eefb6919 12be2e1667946101 ae8c3501e6c66eb1 7e14f2608c9ce6fb ab4a1597ed49ccb3 930b1060f98c97d8 dc4ce81e35279c4d 30d1bf86c9b919a3 ce4f0109e77929e5 8c4c3aeb5de1ec5e 0afa38ae896df912 1c72c255141f2f5c 9a51be5072547cf8 a3b067404e62f961 5a02479cf8c202e7 feb2e258314e0ebe 62878a5c4ecd4e9d f7dab2e1fa9a7b53 2c2169acedb7998d 5cd8a7118848ce7e e9fb2f68e28c2b27 9ddc064db70ad73c 6dbe10c5e1c56a70 9c1407f93a727cce 1075103a4009ae2f 7731b7d71756eee1 19b828ef4ed61eff 164935532a94fa8f e62dc2e22cf20f16 8ae65f4b6785286c 253f365f29453a47 9dc2824b8bdabd96 2da3b76ae9c8a720 155e158fe389c8cc 7fa6ad522c951b5c 236bf964b5b1bfb0 98a39835759b9540 4b72b17f7dbcda93 6177ae059269f41e cdac81a49f5bbfd2 e801392a043ef068 73550a67fcbc039f 0b5d30ce490baa97 9dbbaf9e53d45d7e 2dff26b2f7e6628d ed694217a39f454b 288e7906b79faf4a 407a7d207646f930 96a157f0d1dca05a 7f92e318fc1ff62c e2de7f129b187053" +ciphertext = "4501c1ecadc6b5e3 f1c23c29eca60890 5f9cabdd46e34a55 e1f7ac8308e75c90 3675982bda99173a 2ba57d2ccf2e01a0 2589f89dfd4b3c7f d229ec91c9d0c46e a5dee3c048cd4611 bfeadc9bf26daa1e 02cb72e222cf3dab 120dd1e8c2dd9bd5 8bbefa5d14526abd 1e8d2170a6ba8283 c243ec2fd5ef0703 0b1ef5f69f9620e4 b17a363934100588 7b9ffc7935335947 03e5dcae67bd0ce7 a3c98ca65815a4d0 67f27e6e66d6636c ebb789732566a52a c3970e14c37310dc 2fcee0e739a16291 029fd2b4d534e304 45474b26711a8b3e 1ee3cc88b09e8b17 45b6cc0f067624ec b232db750b01fe54 57fdea77b251b10f e95d3eeedb083bdf 109c41dba26cc965 4f787bf95735ff07 070b175cea8b6230 2e6087b91a041547 4605691099f1a9e2 b626c4b3bb7aeb8e ad9922bc3617cb42 7c669b88be5f98ae a7edb8b0063bec80 af4c081f89778d7c 7242ddae88e8d3af f1f80e575e1aab4a 5d115bc27636fd14 d19bc59433f69763 5ecd870d17e7f5b0 04dee4001cddc34a b6e377eeb3fb08e9 476970765105d93e 4558fe3d4fc6fe05 3aab9c6cf032f111 6e70c2d65f7c8cde b6ad63ac4291f93d 467ebbb29ead265c 05ac684d20a6bef0 9b71830f717e08bc b4f9d3773bec928f 66eeb64dc451e958 e357ebbfef5a342d f28707ac4b8e3e8c 854e8d691cb92e87 c0d57558e44cd754 424865c229c9e1ab b28e003b6819400b" if __name__ == "__main__": - bigwords = cleartext.split(" ") +# bigwords = cleartext.split(" ") + bigwords = ciphertext.split(" ") i = 0 for word in bigwords: first = word[0 : 8] |