54
54
#include <stdint.h>
55
55
#include <stddef.h>
56
56
57
- #define NUM_OF_NIST_KEYS 16
58
57
#define NUM_OF_FIXED_KEYS 128
59
58
60
59
61
60
struct kat_table {
62
- uint8_t in [NUM_OF_NIST_KEYS ];
63
- uint8_t out [NUM_OF_NIST_KEYS ];
61
+ uint8_t in [TC_AES_BLOCK_SIZE ];
62
+ uint8_t out [TC_AES_BLOCK_SIZE ];
64
63
};
65
64
66
65
/*
@@ -69,7 +68,7 @@ struct kat_table {
69
68
int test_1 (void )
70
69
{
71
70
int result = TC_PASS ;
72
- const uint8_t nist_key [NUM_OF_NIST_KEYS ] = {
71
+ const uint8_t nist_key [TC_AES_KEY_SIZE ] = {
73
72
0x2b , 0x7e , 0x15 , 0x16 , 0x28 , 0xae , 0xd2 , 0xa6 ,
74
73
0xab , 0xf7 , 0x15 , 0x88 , 0x09 , 0xcf , 0x4f , 0x3c
75
74
};
@@ -112,20 +111,20 @@ int test_1(void)
112
111
int test_2 (void )
113
112
{
114
113
int result = TC_PASS ;
115
- const uint8_t nist_key [NUM_OF_NIST_KEYS ] = {
114
+ const uint8_t nist_key [TC_AES_KEY_SIZE ] = {
116
115
0x2b , 0x7e , 0x15 , 0x16 , 0x28 , 0xae , 0xd2 , 0xa6 ,
117
116
0xab , 0xf7 , 0x15 , 0x88 , 0x09 , 0xcf , 0x4f , 0x3c
118
117
};
119
- const uint8_t nist_input [NUM_OF_NIST_KEYS ] = {
118
+ const uint8_t nist_input [TC_AES_BLOCK_SIZE ] = {
120
119
0x32 , 0x43 , 0xf6 , 0xa8 , 0x88 , 0x5a , 0x30 , 0x8d ,
121
120
0x31 , 0x31 , 0x98 , 0xa2 , 0xe0 , 0x37 , 0x07 , 0x34
122
121
};
123
- const uint8_t expected [NUM_OF_NIST_KEYS ] = {
122
+ const uint8_t expected [TC_AES_BLOCK_SIZE ] = {
124
123
0x39 , 0x25 , 0x84 , 0x1d , 0x02 , 0xdc , 0x09 , 0xfb ,
125
124
0xdc , 0x11 , 0x85 , 0x97 , 0x19 , 0x6a , 0x0b , 0x32
126
125
};
127
126
struct tc_aes_key_sched_struct s ;
128
- uint8_t ciphertext [NUM_OF_NIST_KEYS ];
127
+ uint8_t ciphertext [TC_AES_BLOCK_SIZE ];
129
128
130
129
TC_PRINT ("AES128 %s (NIST encryption test):\n" , __func__ );
131
130
@@ -149,19 +148,19 @@ int test_2(void)
149
148
int var_text_test (uint32_t r , const uint8_t * in , const uint8_t * out ,
150
149
TCAesKeySched_t s )
151
150
{
152
- uint8_t ciphertext [NUM_OF_NIST_KEYS ];
153
- uint8_t decrypted [NUM_OF_NIST_KEYS ];
151
+ uint8_t ciphertext [TC_AES_BLOCK_SIZE ];
152
+ uint8_t decrypted [TC_AES_BLOCK_SIZE ];
154
153
int result = TC_PASS ;
155
154
156
155
(void )tc_aes_encrypt (ciphertext , in , s );
157
- result = check_result (r , out , NUM_OF_NIST_KEYS ,
156
+ result = check_result (r , out , TC_AES_BLOCK_SIZE ,
158
157
ciphertext , sizeof (ciphertext ));
159
158
if (result != TC_FAIL ) {
160
159
if (tc_aes_decrypt (decrypted , ciphertext , s ) == 0 ) {
161
160
TC_ERROR ("aes_decrypt failed\n" );
162
161
result = TC_FAIL ;
163
162
} else {
164
- result = check_result (r , in , NUM_OF_NIST_KEYS ,
163
+ result = check_result (r , in , TC_AES_BLOCK_SIZE ,
165
164
decrypted , sizeof (decrypted ));
166
165
}
167
166
}
@@ -1100,17 +1099,17 @@ int var_key_test(uint32_t r, const uint8_t *in, const uint8_t *out)
1100
1099
{
1101
1100
int result = TC_PASS ;
1102
1101
1103
- const uint8_t plaintext [NUM_OF_NIST_KEYS ] = {
1102
+ const uint8_t plaintext [TC_AES_BLOCK_SIZE ] = {
1104
1103
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
1105
1104
0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
1106
1105
};
1107
- uint8_t ciphertext [NUM_OF_NIST_KEYS ];
1106
+ uint8_t ciphertext [TC_AES_BLOCK_SIZE ];
1108
1107
struct tc_aes_key_sched_struct s ;
1109
1108
1110
1109
(void )tc_aes128_set_encrypt_key (& s , in );
1111
1110
1112
1111
(void )tc_aes_encrypt (ciphertext , plaintext , & s );
1113
- result = check_result (r , out , NUM_OF_NIST_KEYS ,
1112
+ result = check_result (r , out , TC_AES_BLOCK_SIZE ,
1114
1113
ciphertext , sizeof (ciphertext ));
1115
1114
1116
1115
return result ;
0 commit comments