aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_cmac_mode.c
diff options
context:
space:
mode:
authorFlavio Santes <[email protected]>2016-11-21 00:08:11 -0600
committerFlavio Santes <[email protected]>2016-11-21 00:08:11 -0600
commitfa4b82caa6f9af831bda1565542322cc0b2a3902 (patch)
treeb1c63f23fe24ea2fd36de4bfacb8b44ea6844f31 /tests/test_cmac_mode.c
parentdc96970a573efa20b178673efae80fd196650d27 (diff)
test_cmac_mode: Update test case
This commit solve some style issues found at the CMAC mode test application. Return codes are homogenized to 'int' and lines over 80 chars are refactored. Change-Id: I931d2f06233e3f714e18f03fefe46ebaaade2ab6 Signed-off-by: Flavio Santes <[email protected]>
Diffstat (limited to 'tests/test_cmac_mode.c')
-rw-r--r--tests/test_cmac_mode.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/tests/test_cmac_mode.c b/tests/test_cmac_mode.c
index 3435b5b..759c330 100644
--- a/tests/test_cmac_mode.c
+++ b/tests/test_cmac_mode.c
@@ -64,9 +64,10 @@ static void show(const char *label, const uint8_t *s, size_t slen)
extern void gf_double(uint8_t *out, uint8_t *in);
-static uint32_t verify_gf_2_128_double(uint8_t *K1, uint8_t *K2, struct tc_cmac_struct s)
+static int verify_gf_2_128_double(uint8_t *K1, uint8_t *K2,
+ struct tc_cmac_struct s)
{
- uint32_t result = TC_PASS;
+ int result = TC_PASS;
TC_PRINT("Performing CMAC test #1 (GF(2^128) double):\n");
@@ -88,7 +89,7 @@ static uint32_t verify_gf_2_128_double(uint8_t *K1, uint8_t *K2, struct tc_cmac_
(void) memset(zero, '\0', sizeof(zero));
tc_aes_encrypt(L, zero, s.sched);
if (memcmp(L, l, BUF_LEN) != 0) {
- TC_ERROR("AES encryption failed in %s.\n", __func__);
+ TC_ERROR("%s: AES encryption failed\n", __func__);
show("expected L =", l, sizeof(l));
show("computed L =", L, sizeof(L));
return TC_FAIL;
@@ -96,7 +97,7 @@ static uint32_t verify_gf_2_128_double(uint8_t *K1, uint8_t *K2, struct tc_cmac_
gf_double(K1, L);
if (memcmp(K1, k1, BUF_LEN) != 0) {
- TC_ERROR("gf_2_128_double failed when msb = 0\n");
+ TC_ERROR("%s: gf_2_128_double failed when msb = 0\n", __func__);
show("expected K1 =", k1, sizeof(k1));
show("computed K1 =", K1, sizeof(k1));
return TC_FAIL;
@@ -104,7 +105,7 @@ static uint32_t verify_gf_2_128_double(uint8_t *K1, uint8_t *K2, struct tc_cmac_
gf_double(K2, K1);
if (memcmp(K2, k2, BUF_LEN) != 0) {
- TC_ERROR("gf_2_128_double failed when msb = 1\n");
+ TC_ERROR("%s: gf_2_128_double failed when msb = 1\n", __func__);
show("expected K2 =", k2, sizeof(k2));
show("computed K2 =", K2, sizeof(k2));
return TC_FAIL;
@@ -114,9 +115,9 @@ static uint32_t verify_gf_2_128_double(uint8_t *K1, uint8_t *K2, struct tc_cmac_
return result;
}
-static uint32_t verify_cmac_null_msg(TCCmacState_t s)
+static int verify_cmac_null_msg(TCCmacState_t s)
{
- uint32_t result = TC_PASS;
+ int result = TC_PASS;
TC_PRINT("Performing CMAC test #2 (SP 800-38B test vector #1):\n");
@@ -131,7 +132,7 @@ static uint32_t verify_cmac_null_msg(TCCmacState_t s)
(void) tc_cmac_final(Tag, s);
if (memcmp(Tag, tag, BUF_LEN) != 0) {
- TC_ERROR("aes_cmac failed with null msg = 1\n");
+ TC_ERROR("%s: aes_cmac failed with null msg = 1\n", __func__);
show("expected Tag =", tag, sizeof(tag));
show("computed Tag =", Tag, sizeof(Tag));
return TC_FAIL;
@@ -141,9 +142,9 @@ static uint32_t verify_cmac_null_msg(TCCmacState_t s)
return result;
}
-static uint32_t verify_cmac_1_block_msg(TCCmacState_t s)
+static int verify_cmac_1_block_msg(TCCmacState_t s)
{
- uint32_t result = TC_PASS;
+ int result = TC_PASS;
TC_PRINT("Performing CMAC test #3 (SP 800-38B test vector #2):\n");
@@ -162,7 +163,7 @@ static uint32_t verify_cmac_1_block_msg(TCCmacState_t s)
(void) tc_cmac_final(Tag, s);
if (memcmp(Tag, tag, BUF_LEN) != 0) {
- TC_ERROR("aes_cmac failed with 1 block msg\n");
+ TC_ERROR("%s: aes_cmac failed with 1 block msg\n", __func__);
show("aes_cmac failed with 1 block msg =", msg, sizeof(msg));
show("expected Tag =", tag, sizeof(tag));
show("computed Tag =", Tag, sizeof(Tag));
@@ -173,9 +174,9 @@ static uint32_t verify_cmac_1_block_msg(TCCmacState_t s)
return result;
}
-static uint32_t verify_cmac_320_bit_msg(TCCmacState_t s)
+static int verify_cmac_320_bit_msg(TCCmacState_t s)
{
- uint32_t result = TC_PASS;
+ int result = TC_PASS;
TC_PRINT("Performing CMAC test #4 (SP 800-38B test vector #3):\n");
@@ -197,7 +198,7 @@ static uint32_t verify_cmac_320_bit_msg(TCCmacState_t s)
(void) tc_cmac_final(Tag, s);
if (memcmp(Tag, tag, BUF_LEN) != 0) {
- TC_ERROR("aes_cmac failed with 320 bit msg\n");
+ TC_ERROR("%s: aes_cmac failed with 320 bit msg\n", __func__);
show("aes_cmac failed with 320 bit msg =", msg, sizeof(msg));
show("expected Tag =", tag, sizeof(tag));
show("computed Tag =", Tag, sizeof(Tag));
@@ -208,9 +209,9 @@ static uint32_t verify_cmac_320_bit_msg(TCCmacState_t s)
return result;
}
-static uint32_t verify_cmac_512_bit_msg(TCCmacState_t s)
+static int verify_cmac_512_bit_msg(TCCmacState_t s)
{
- uint32_t result = TC_PASS;
+ int result = TC_PASS;
TC_PRINT("Performing CMAC test #5 (SP 800-38B test vector #4)\n");
@@ -235,7 +236,7 @@ static uint32_t verify_cmac_512_bit_msg(TCCmacState_t s)
(void)tc_cmac_final(Tag, s);
if (memcmp(Tag, tag, BUF_LEN) != 0) {
- TC_ERROR("aes_cmac failed with 512 bit msg\n");
+ TC_ERROR("%s: aes_cmac failed with 512 bit msg\n", __func__);
show("aes_cmac failed with 512 bit msg =", msg, sizeof(msg));
show("expected Tag =", tag, sizeof(tag));
show("computed Tag =", Tag, sizeof(Tag));
@@ -249,11 +250,10 @@ static uint32_t verify_cmac_512_bit_msg(TCCmacState_t s)
/*
* Main task to test CMAC
*/
-
int main(void)
{
- uint32_t result = TC_PASS;
+ int result = TC_PASS;
struct tc_cmac_struct state;
struct tc_aes_key_sched_struct sched;
@@ -302,4 +302,6 @@ int main(void)
exitTest:
TC_END_RESULT(result);
TC_END_REPORT(result);
+
+ return result;
}