5454#include <stdint.h>
5555#include <stddef.h>
5656
57- #define NUM_OF_NIST_KEYS 16
5857#define NUM_OF_FIXED_KEYS 128
5958
6059
6160struct 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 ];
6463};
6564
6665/*
@@ -69,7 +68,7 @@ struct kat_table {
6968int test_1 (void )
7069{
7170 int result = TC_PASS ;
72- const uint8_t nist_key [NUM_OF_NIST_KEYS ] = {
71+ const uint8_t nist_key [TC_AES_KEY_SIZE ] = {
7372 0x2b , 0x7e , 0x15 , 0x16 , 0x28 , 0xae , 0xd2 , 0xa6 ,
7473 0xab , 0xf7 , 0x15 , 0x88 , 0x09 , 0xcf , 0x4f , 0x3c
7574 };
@@ -112,20 +111,20 @@ int test_1(void)
112111int test_2 (void )
113112{
114113 int result = TC_PASS ;
115- const uint8_t nist_key [NUM_OF_NIST_KEYS ] = {
114+ const uint8_t nist_key [TC_AES_KEY_SIZE ] = {
116115 0x2b , 0x7e , 0x15 , 0x16 , 0x28 , 0xae , 0xd2 , 0xa6 ,
117116 0xab , 0xf7 , 0x15 , 0x88 , 0x09 , 0xcf , 0x4f , 0x3c
118117 };
119- const uint8_t nist_input [NUM_OF_NIST_KEYS ] = {
118+ const uint8_t nist_input [TC_AES_BLOCK_SIZE ] = {
120119 0x32 , 0x43 , 0xf6 , 0xa8 , 0x88 , 0x5a , 0x30 , 0x8d ,
121120 0x31 , 0x31 , 0x98 , 0xa2 , 0xe0 , 0x37 , 0x07 , 0x34
122121 };
123- const uint8_t expected [NUM_OF_NIST_KEYS ] = {
122+ const uint8_t expected [TC_AES_BLOCK_SIZE ] = {
124123 0x39 , 0x25 , 0x84 , 0x1d , 0x02 , 0xdc , 0x09 , 0xfb ,
125124 0xdc , 0x11 , 0x85 , 0x97 , 0x19 , 0x6a , 0x0b , 0x32
126125 };
127126 struct tc_aes_key_sched_struct s ;
128- uint8_t ciphertext [NUM_OF_NIST_KEYS ];
127+ uint8_t ciphertext [TC_AES_BLOCK_SIZE ];
129128
130129 TC_PRINT ("AES128 %s (NIST encryption test):\n" , __func__ );
131130
@@ -149,19 +148,19 @@ int test_2(void)
149148int var_text_test (uint32_t r , const uint8_t * in , const uint8_t * out ,
150149 TCAesKeySched_t s )
151150{
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 ];
154153 int result = TC_PASS ;
155154
156155 (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 ,
158157 ciphertext , sizeof (ciphertext ));
159158 if (result != TC_FAIL ) {
160159 if (tc_aes_decrypt (decrypted , ciphertext , s ) == 0 ) {
161160 TC_ERROR ("aes_decrypt failed\n" );
162161 result = TC_FAIL ;
163162 } else {
164- result = check_result (r , in , NUM_OF_NIST_KEYS ,
163+ result = check_result (r , in , TC_AES_BLOCK_SIZE ,
165164 decrypted , sizeof (decrypted ));
166165 }
167166 }
@@ -1100,17 +1099,17 @@ int var_key_test(uint32_t r, const uint8_t *in, const uint8_t *out)
11001099{
11011100 int result = TC_PASS ;
11021101
1103- const uint8_t plaintext [NUM_OF_NIST_KEYS ] = {
1102+ const uint8_t plaintext [TC_AES_BLOCK_SIZE ] = {
11041103 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
11051104 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00
11061105 };
1107- uint8_t ciphertext [NUM_OF_NIST_KEYS ];
1106+ uint8_t ciphertext [TC_AES_BLOCK_SIZE ];
11081107 struct tc_aes_key_sched_struct s ;
11091108
11101109 (void )tc_aes128_set_encrypt_key (& s , in );
11111110
11121111 (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 ,
11141113 ciphertext , sizeof (ciphertext ));
11151114
11161115 return result ;
0 commit comments