aboutsummaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJoachim StroĢˆmbergson <joachim@secworks.se>2015-05-17 11:40:38 +0200
committerJoachim StroĢˆmbergson <joachim@secworks.se>2015-05-17 11:40:38 +0200
commit267edcb85cda77840cc18fce7871f158454dde90 (patch)
treea0b08061ba5e9d56269a4042e16bbb40eef1dd43 /sw
parent644e959a05afa08dfbcfb112ed3609a64a6b84db (diff)
Completed first, simple test of aes core. This test program runs all NIST single block tests with 128 and 256 bit keys in encipher and decipher modes.
Diffstat (limited to 'sw')
-rw-r--r--sw/aes_tester.c68
1 files changed, 64 insertions, 4 deletions
diff --git a/sw/aes_tester.c b/sw/aes_tester.c
index d2f0656..80acc80 100644
--- a/sw/aes_tester.c
+++ b/sw/aes_tester.c
@@ -47,6 +47,14 @@
#include "cryptech.h"
+
+//------------------------------------------------------------------
+// Global defines.
+//------------------------------------------------------------------
+#define VERBOSE 0
+#define CHECK_WRITE 0
+
+
//------------------------------------------------------------------
// Robs macros. Scary scary.
//------------------------------------------------------------------
@@ -112,7 +120,6 @@ void dual_block_test(uint8_t keylength, uint32_t *key, uint32_t *block0,
uint32_t *block1, uint32_t *expected)
{
-
}
@@ -127,6 +134,18 @@ void single_block_test(uint32_t keylength, uint32_t *key, uint32_t *block,
uint32_t enc_result[4];
uint32_t dec_result[4];
+ if (VERBOSE) {
+ if (keylength == 256) {
+ printf("Writing key 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
+ key[0], key[1], key[2], key[3],
+ key[4], key[5], key[6], key[7]);
+ }
+ else {
+ printf("Writing key 0x%08x 0x%08x 0x%08x 0x%08x\n",
+ key[0], key[1], key[2], key[3]);
+ }
+ }
+
tc_w32(AES_ADDR_KEY0, key[0]);
tc_w32(AES_ADDR_KEY1, key[1]);
tc_w32(AES_ADDR_KEY2, key[2]);
@@ -139,21 +158,60 @@ void single_block_test(uint32_t keylength, uint32_t *key, uint32_t *block,
tc_w32(AES_ADDR_KEY3, key[7]);
}
+ if (CHECK_WRITE)
+ {
+ printf("Reading back key: 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
+ tc_r32(AES_ADDR_KEY0), tc_r32(AES_ADDR_KEY1),
+ tc_r32(AES_ADDR_KEY2), tc_r32(AES_ADDR_KEY3),
+ tc_r32(AES_ADDR_KEY4), tc_r32(AES_ADDR_KEY5),
+ tc_r32(AES_ADDR_KEY6), tc_r32(AES_ADDR_KEY7));
+ }
+
+ // Performing init i.e. key expansion,
+ printf("Doing key init\n");
+ if (keylength == 256)
+ tc_w32(AES_ADDR_CONFIG, 0x00000002);
+ else
+ tc_w32(AES_ADDR_CONFIG, 0x00000000);
+
+ tc_w32(AES_ADDR_CTRL, 0x00000001);
+
+
+ if (VERBOSE)
+ printf("Writing block 0x%08x 0x%08x 0x%08x 0x%08x\n",
+ block[0], block[1], block[2], block[3]);
+
tc_w32(AES_ADDR_BLOCK0, block[0]);
tc_w32(AES_ADDR_BLOCK1, block[1]);
tc_w32(AES_ADDR_BLOCK2, block[2]);
tc_w32(AES_ADDR_BLOCK3, block[3]);
- // Single block encipher operation.
+ if (CHECK_WRITE)
+ {
+ printf("Reading back block: 0x%08x 0x%08x 0x%08x 0x%08x\n",
+ tc_r32(AES_ADDR_BLOCK0), tc_r32(AES_ADDR_BLOCK1),
+ tc_r32(AES_ADDR_BLOCK2), tc_r32(AES_ADDR_BLOCK3));
+ }
+
+ if (VERBOSE)
+ printf("Starting single block encipher operation\n");
if (keylength == 256)
tc_w32(AES_ADDR_CONFIG, 0x00000003);
else
tc_w32(AES_ADDR_CONFIG, 0x00000001);
- tc_w32(AES_ADDR_CTRL, 0x00000001);
+ tc_w32(AES_ADDR_CTRL, 0x00000002);
+ if (VERBOSE)
+ printf("Checking ready: 0x%08x\n",
+ tc_r32(AES_ADDR_STATUS));
tc_wait_ready(AES_ADDR_STATUS);
+ if (VERBOSE)
+ printf("Ready seen. Result: 0x%08x 0x%08x 0x%08x 0x%08x\n",
+ tc_r32(AES_ADDR_RESULT0), tc_r32(AES_ADDR_RESULT1),
+ tc_r32(AES_ADDR_RESULT2), tc_r32(AES_ADDR_RESULT3));
+
enc_result[0] = tc_r32(AES_ADDR_RESULT0);
enc_result[1] = tc_r32(AES_ADDR_RESULT1);
enc_result[2] = tc_r32(AES_ADDR_RESULT2);
@@ -169,7 +227,7 @@ void single_block_test(uint32_t keylength, uint32_t *key, uint32_t *block,
tc_w32(AES_ADDR_CONFIG, 0x00000002);
else
tc_w32(AES_ADDR_CONFIG, 0x00000000);
- tc_w32(AES_ADDR_CTRL, 0x00000001);
+ tc_w32(AES_ADDR_CTRL, 0x00000002);
tc_wait_ready(AES_ADDR_STATUS);
@@ -226,6 +284,7 @@ void run_nist_tests()
single_block_test(128, &nist_aes128_key[0], &nist_plaintext0[0], &nist_ecb_128_enc_expected0[0]);
single_block_test(128, &nist_aes128_key[0], &nist_plaintext1[0], &nist_ecb_128_enc_expected1[0]);
+
single_block_test(128, &nist_aes128_key[0], &nist_plaintext2[0], &nist_ecb_128_enc_expected2[0]);
single_block_test(128, &nist_aes128_key[0], &nist_plaintext3[0], &nist_ecb_128_enc_expected3[0]);
@@ -233,6 +292,7 @@ void run_nist_tests()
single_block_test(256, &nist_aes256_key[0], &nist_plaintext1[0], &nist_ecb_256_enc_expected1[0]);
single_block_test(256, &nist_aes256_key[0], &nist_plaintext2[0], &nist_ecb_256_enc_expected2[0]);
single_block_test(256, &nist_aes256_key[0], &nist_plaintext3[0], &nist_ecb_256_enc_expected3[0]);
+
}