Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit ceac249

Browse files
author
hackermnementh
authored
Merge pull request #11 from flavio-santes/test_issues
tests: Update return codes and check_result function call
2 parents 1827aa7 + d92f959 commit ceac249

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

tests/test_aes.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454
#include <stdint.h>
5555
#include <stddef.h>
56-
#include <misc/printk.h>
5756

5857
#define NUM_OF_NIST_KEYS 16
5958
#define NUM_OF_FIXED_KEYS 128
@@ -67,9 +66,9 @@ struct kat_table {
6766
/*
6867
* NIST test key schedule.
6968
*/
70-
uint32_t test_1(void)
69+
int test_1(void)
7170
{
72-
uint32_t result = TC_PASS;
71+
int result = TC_PASS;
7372
const uint8_t nist_key[NUM_OF_NIST_KEYS] = {
7473
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
7574
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
@@ -100,7 +99,7 @@ uint32_t test_1(void)
10099

101100
result = check_result(1, expected.words,
102101
sizeof(expected.words),
103-
s.words, sizeof(s.words), 1);
102+
s.words, sizeof(s.words));
104103

105104
exitTest1:
106105
TC_END_RESULT(result);
@@ -110,7 +109,7 @@ uint32_t test_1(void)
110109
/*
111110
* NIST test vectors for encryption.
112111
*/
113-
int32_t test_2(void)
112+
int test_2(void)
114113
{
115114
int result = TC_PASS;
116115
const uint8_t nist_key[NUM_OF_NIST_KEYS] = {
@@ -139,42 +138,43 @@ int32_t test_2(void)
139138
}
140139

141140
result = check_result(2, expected, sizeof(expected),
142-
ciphertext, sizeof(ciphertext), 1);
141+
ciphertext, sizeof(ciphertext));
143142

144143
exitTest2:
145-
146144
TC_END_RESULT(result);
145+
147146
return result;
148147
}
149148

150-
uint32_t var_text_test(uint32_t r, const uint8_t *in, const uint8_t *out,
151-
TCAesKeySched_t s)
149+
int var_text_test(uint32_t r, const uint8_t *in, const uint8_t *out,
150+
TCAesKeySched_t s)
152151
{
153152
uint8_t ciphertext[NUM_OF_NIST_KEYS];
154153
uint8_t decrypted[NUM_OF_NIST_KEYS];
155-
uint32_t result = TC_PASS;
154+
int result = TC_PASS;
156155

157156
(void)tc_aes_encrypt(ciphertext, in, s);
158157
result = check_result(r, out, NUM_OF_NIST_KEYS,
159-
ciphertext, sizeof(ciphertext), 0);
158+
ciphertext, sizeof(ciphertext));
160159
if (result != TC_FAIL) {
161160
if (tc_aes_decrypt(decrypted, ciphertext, s) == 0) {
162161
TC_ERROR("aes_decrypt failed\n");
163162
result = TC_FAIL;
164163
} else {
165164
result = check_result(r, in, NUM_OF_NIST_KEYS,
166-
decrypted, sizeof(decrypted), 0);
165+
decrypted, sizeof(decrypted));
167166
}
168167
}
168+
169169
return result;
170170
}
171171

172172
/*
173173
* All NIST tests with fixed key and variable text.
174174
*/
175-
uint32_t test_3(void)
175+
int test_3(void)
176176
{
177-
uint32_t result = TC_PASS;
177+
int result = TC_PASS;
178178
const uint8_t key[NUM_OF_NIST_KEYS] = {
179179
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180180
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
@@ -1092,12 +1092,13 @@ uint32_t test_3(void)
10921092
}
10931093

10941094
TC_END_RESULT(result);
1095+
10951096
return result;
10961097
}
10971098

1098-
uint32_t var_key_test(uint32_t r, const uint8_t *in, const uint8_t *out)
1099+
int var_key_test(uint32_t r, const uint8_t *in, const uint8_t *out)
10991100
{
1100-
uint32_t result = TC_PASS;
1101+
int result = TC_PASS;
11011102

11021103
const uint8_t plaintext[NUM_OF_NIST_KEYS] = {
11031104
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -1110,16 +1111,17 @@ uint32_t var_key_test(uint32_t r, const uint8_t *in, const uint8_t *out)
11101111

11111112
(void)tc_aes_encrypt(ciphertext, plaintext, &s);
11121113
result = check_result(r, out, NUM_OF_NIST_KEYS,
1113-
ciphertext, sizeof(ciphertext), 0);
1114+
ciphertext, sizeof(ciphertext));
1115+
11141116
return result;
11151117
}
11161118

11171119
/*
11181120
* All NIST tests with variable key and fixed text.
11191121
*/
1120-
uint32_t test_4(void)
1122+
int test_4(void)
11211123
{
1122-
uint32_t result = TC_PASS;
1124+
int result = TC_PASS;
11231125
const struct kat_table kat_tbl[NUM_OF_FIXED_KEYS] = {
11241126
{{
11251127
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -2031,16 +2033,16 @@ uint32_t test_4(void)
20312033
}
20322034

20332035
TC_END_RESULT(result);
2036+
20342037
return result;
20352038
}
20362039

20372040
/*
20382041
* Main task to test AES
20392042
*/
2040-
2041-
void main(void)
2043+
int main(void)
20422044
{
2043-
uint32_t result = TC_PASS;
2045+
int result = TC_PASS;
20442046

20452047
TC_START("Performing AES128 tests:");
20462048

@@ -2072,4 +2074,6 @@ void main(void)
20722074
exitTest:
20732075
TC_END_RESULT(result);
20742076
TC_END_REPORT(result);
2077+
2078+
return result;
20752079
}

tests/test_cbc_mode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ int test_1_and_2(void)
127127
}
128128

129129
result = check_result(1, ciphertext, sizeof(encrypted),
130-
encrypted, sizeof(encrypted), 1);
130+
encrypted, sizeof(encrypted));
131131
TC_END_RESULT(result);
132132

133133
TC_PRINT("CBC test #2 (decryption SP 800-38a tests):\n");
@@ -145,7 +145,7 @@ int test_1_and_2(void)
145145
}
146146

147147
result = check_result(2, plaintext, sizeof(decrypted),
148-
decrypted, sizeof(decrypted), 1);
148+
decrypted, sizeof(decrypted));
149149

150150
exitTest1:
151151
TC_END_RESULT(result);

0 commit comments

Comments
 (0)