53
53
54
54
#include <stdint.h>
55
55
#include <stddef.h>
56
- #include <misc/printk.h>
57
56
58
57
#define NUM_OF_NIST_KEYS 16
59
58
#define NUM_OF_FIXED_KEYS 128
@@ -67,9 +66,9 @@ struct kat_table {
67
66
/*
68
67
* NIST test key schedule.
69
68
*/
70
- uint32_t test_1 (void )
69
+ int test_1 (void )
71
70
{
72
- uint32_t result = TC_PASS ;
71
+ int result = TC_PASS ;
73
72
const uint8_t nist_key [NUM_OF_NIST_KEYS ] = {
74
73
0x2b , 0x7e , 0x15 , 0x16 , 0x28 , 0xae , 0xd2 , 0xa6 ,
75
74
0xab , 0xf7 , 0x15 , 0x88 , 0x09 , 0xcf , 0x4f , 0x3c
@@ -100,7 +99,7 @@ uint32_t test_1(void)
100
99
101
100
result = check_result (1 , expected .words ,
102
101
sizeof (expected .words ),
103
- s .words , sizeof (s .words ), 1 );
102
+ s .words , sizeof (s .words ));
104
103
105
104
exitTest1 :
106
105
TC_END_RESULT (result );
@@ -110,7 +109,7 @@ uint32_t test_1(void)
110
109
/*
111
110
* NIST test vectors for encryption.
112
111
*/
113
- int32_t test_2 (void )
112
+ int test_2 (void )
114
113
{
115
114
int result = TC_PASS ;
116
115
const uint8_t nist_key [NUM_OF_NIST_KEYS ] = {
@@ -139,42 +138,43 @@ int32_t test_2(void)
139
138
}
140
139
141
140
result = check_result (2 , expected , sizeof (expected ),
142
- ciphertext , sizeof (ciphertext ), 1 );
141
+ ciphertext , sizeof (ciphertext ));
143
142
144
143
exitTest2 :
145
-
146
144
TC_END_RESULT (result );
145
+
147
146
return result ;
148
147
}
149
148
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 )
152
151
{
153
152
uint8_t ciphertext [NUM_OF_NIST_KEYS ];
154
153
uint8_t decrypted [NUM_OF_NIST_KEYS ];
155
- uint32_t result = TC_PASS ;
154
+ int result = TC_PASS ;
156
155
157
156
(void )tc_aes_encrypt (ciphertext , in , s );
158
157
result = check_result (r , out , NUM_OF_NIST_KEYS ,
159
- ciphertext , sizeof (ciphertext ), 0 );
158
+ ciphertext , sizeof (ciphertext ));
160
159
if (result != TC_FAIL ) {
161
160
if (tc_aes_decrypt (decrypted , ciphertext , s ) == 0 ) {
162
161
TC_ERROR ("aes_decrypt failed\n" );
163
162
result = TC_FAIL ;
164
163
} else {
165
164
result = check_result (r , in , NUM_OF_NIST_KEYS ,
166
- decrypted , sizeof (decrypted ), 0 );
165
+ decrypted , sizeof (decrypted ));
167
166
}
168
167
}
168
+
169
169
return result ;
170
170
}
171
171
172
172
/*
173
173
* All NIST tests with fixed key and variable text.
174
174
*/
175
- uint32_t test_3 (void )
175
+ int test_3 (void )
176
176
{
177
- uint32_t result = TC_PASS ;
177
+ int result = TC_PASS ;
178
178
const uint8_t key [NUM_OF_NIST_KEYS ] = {
179
179
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
180
180
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
@@ -1092,12 +1092,13 @@ uint32_t test_3(void)
1092
1092
}
1093
1093
1094
1094
TC_END_RESULT (result );
1095
+
1095
1096
return result ;
1096
1097
}
1097
1098
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 )
1099
1100
{
1100
- uint32_t result = TC_PASS ;
1101
+ int result = TC_PASS ;
1101
1102
1102
1103
const uint8_t plaintext [NUM_OF_NIST_KEYS ] = {
1103
1104
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)
1110
1111
1111
1112
(void )tc_aes_encrypt (ciphertext , plaintext , & s );
1112
1113
result = check_result (r , out , NUM_OF_NIST_KEYS ,
1113
- ciphertext , sizeof (ciphertext ), 0 );
1114
+ ciphertext , sizeof (ciphertext ));
1115
+
1114
1116
return result ;
1115
1117
}
1116
1118
1117
1119
/*
1118
1120
* All NIST tests with variable key and fixed text.
1119
1121
*/
1120
- uint32_t test_4 (void )
1122
+ int test_4 (void )
1121
1123
{
1122
- uint32_t result = TC_PASS ;
1124
+ int result = TC_PASS ;
1123
1125
const struct kat_table kat_tbl [NUM_OF_FIXED_KEYS ] = {
1124
1126
{{
1125
1127
0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
@@ -2031,16 +2033,16 @@ uint32_t test_4(void)
2031
2033
}
2032
2034
2033
2035
TC_END_RESULT (result );
2036
+
2034
2037
return result ;
2035
2038
}
2036
2039
2037
2040
/*
2038
2041
* Main task to test AES
2039
2042
*/
2040
-
2041
- void main (void )
2043
+ int main (void )
2042
2044
{
2043
- uint32_t result = TC_PASS ;
2045
+ int result = TC_PASS ;
2044
2046
2045
2047
TC_START ("Performing AES128 tests:" );
2046
2048
@@ -2072,4 +2074,6 @@ void main(void)
2072
2074
exitTest :
2073
2075
TC_END_RESULT (result );
2074
2076
TC_END_REPORT (result );
2077
+
2078
+ return result ;
2075
2079
}
0 commit comments