@@ -208,6 +208,7 @@ UTEST(AES_GCM, HAPPY_PATH_TC_APPLY_WYCHEPROOF)
208
208
const char * filename = "/home/jstar/Dev/cryptolib/test/include/wycheproof/aes_gcm.json" ;
209
209
char * json_data = read_json_file (filename );
210
210
void * ctx ;
211
+ int num_tests_ran = 0 ;
211
212
212
213
printf ("Read File: %s \n" , filename );
213
214
if (!json_data ) {
@@ -236,67 +237,73 @@ UTEST(AES_GCM, HAPPY_PATH_TC_APPLY_WYCHEPROOF)
236
237
// Print Parsed Test Cases
237
238
printf ("Parsed %d AES-GCM Test Cases:\n" , test_count );
238
239
240
+ remove ("sa_save_file.bin" );
241
+ // Setup & Initialize CryptoLib
242
+ Crypto_Config_CryptoLib (KEY_TYPE_INTERNAL , MC_TYPE_INTERNAL , SA_TYPE_INMEMORY , CRYPTOGRAPHY_TYPE_LIBGCRYPT ,
243
+ IV_INTERNAL , CRYPTO_TC_CREATE_FECF_TRUE , TC_PROCESS_SDLS_PDUS_TRUE , TC_HAS_PUS_HDR ,
244
+ TC_IGNORE_SA_STATE_FALSE , TC_IGNORE_ANTI_REPLAY_FALSE , TC_UNIQUE_SA_PER_MAP_ID_TRUE ,
245
+ TC_CHECK_FECF_TRUE , 0x3F , SA_INCREMENT_NONTRANSMITTED_IV_TRUE );
246
+ // Crypto_Config_Add_Gvcid_Managed_Parameter(0, 0x0003, 0, TC_HAS_FECF, TC_NO_SEGMENT_HDRS, TC_OCF_NA, 1024,
247
+ // AOS_FHEC_NA, AOS_IZ_NA, 0);
248
+ GvcidManagedParameters_t TC_UT_Managed_Parameters = {
249
+ 0 , 0x0003 , 0 , TC_HAS_FECF , AOS_FHEC_NA , AOS_IZ_NA , 0 , TC_NO_SEGMENT_HDRS , 1024 , TC_OCF_NA , 1 };
250
+ Crypto_Config_Add_Gvcid_Managed_Parameters (TC_UT_Managed_Parameters );
251
+ Crypto_Init ();
252
+
253
+ SecurityAssociation_t * test_association ;
254
+ crypto_key_t * key = key_if -> get_key (250 );
255
+ key -> key_state = KEY_ACTIVE ;
256
+ key = key_if -> get_key (250 );
257
+ key -> key_state = KEY_ACTIVE ;
258
+
259
+ printf ("Setting up SA...\n" );
260
+ sa_if -> sa_get_from_spi (1 , & test_association );
261
+ test_association -> sa_state = SA_NONE ;
262
+ sa_if -> sa_get_from_spi (4 , & test_association );
263
+ test_association -> sa_state = SA_OPERATIONAL ;
264
+ test_association -> ekid = 250 ;
265
+
266
+ printf ("Setting up ARSN...\n" );
267
+ test_association -> shsnf_len = 1 ;
268
+ test_association -> arsn_len = 1 ;
269
+ test_association -> arsn [0 ] = 0x00 ;
270
+ test_association -> arsnw_len = 1 ;
271
+ test_association -> arsnw = 5 ;
272
+
273
+ int tcid = 0 ;
239
274
for (int j = 0 ; j < MAX_SUITES ; j ++ )
240
275
{
241
276
printf ("j = %d\n" , j );
277
+ key -> key_len = suites [j ].keySize / 8 ;
278
+ printf ("KeyLen: %d\n" , key -> key_len );
279
+ if (key -> key_len != 32 )
280
+ {
281
+ tcid += suites [j ].numTests ;
282
+ printf ("TCID: %d\n" , tcid + 1 );
283
+ continue ;
284
+ }
242
285
for (int i = 0 ; i < suites [j ].numTests ; i ++ )
243
286
{
244
- printf ("i = %d\n" , i );
245
- if (strlen (tests [i ].aad ) > 0 ) continue ;
246
- printf ("\nTest Case ID: %d\n" , tests [i ].tcId );
247
- printf ("comment: %s\n" , tests [i ].comment );
248
- printf ("key: %s\n" , tests [i ].key );
249
- printf ("iv: %s\n" , tests [i ].iv );
250
- printf ("aad: %s\n" , tests [i ].aad );
251
- printf ("msg: %s\n" , tests [i ].msg );
252
- printf ("ct: %s\n" , tests [i ].ct );
253
- printf ("tag: %s\n" , tests [i ].tag );
254
- printf ("result: %s\n" , tests [i ].result );
255
- printf ("~~~~~~~~~~~~~~~~~~~~~~~~\n" );
256
-
257
- remove ("sa_save_file.bin" );
258
- // Setup & Initialize CryptoLib
259
- Crypto_Config_CryptoLib (KEY_TYPE_INTERNAL , MC_TYPE_INTERNAL , SA_TYPE_INMEMORY , CRYPTOGRAPHY_TYPE_LIBGCRYPT ,
260
- IV_INTERNAL , CRYPTO_TC_CREATE_FECF_TRUE , TC_PROCESS_SDLS_PDUS_TRUE , TC_HAS_PUS_HDR ,
261
- TC_IGNORE_SA_STATE_FALSE , TC_IGNORE_ANTI_REPLAY_FALSE , TC_UNIQUE_SA_PER_MAP_ID_TRUE ,
262
- TC_CHECK_FECF_TRUE , 0x3F , SA_INCREMENT_NONTRANSMITTED_IV_TRUE );
263
- // Crypto_Config_Add_Gvcid_Managed_Parameter(0, 0x0003, 0, TC_HAS_FECF, TC_NO_SEGMENT_HDRS, TC_OCF_NA, 1024,
264
- // AOS_FHEC_NA, AOS_IZ_NA, 0);
265
- GvcidManagedParameters_t TC_UT_Managed_Parameters = {
266
- 0 , 0x0003 , 0 , TC_HAS_FECF , AOS_FHEC_NA , AOS_IZ_NA , 0 , TC_NO_SEGMENT_HDRS , 1024 , TC_OCF_NA , 1 };
267
- Crypto_Config_Add_Gvcid_Managed_Parameters (TC_UT_Managed_Parameters );
268
- Crypto_Init ();
269
-
270
- printf ("Setting up SA...\n" );
271
- SecurityAssociation_t * test_association = NULL ;
272
- test_association = malloc (sizeof (SecurityAssociation_t ) * sizeof (uint8_t ));
273
- sa_if -> sa_get_from_spi (1 , & test_association );
274
- test_association -> sa_state = SA_NONE ;
275
- sa_if -> sa_get_from_spi (4 , & test_association );
276
- test_association -> sa_state = SA_OPERATIONAL ;
287
+ printf ("TCID: %d\n" , tcid + 1 );
277
288
278
289
printf ("Setting up Key...\n" );
279
- test_association -> ekid = 250 ;
280
- crypto_key_t * key = key_if -> get_key (250 );
281
- key -> key_state = KEY_ACTIVE ;
282
290
key -> key_len = suites [j ].keySize / 8 ;
283
- printf ("KeyLen: %d\n" , key -> key_len );
284
- for (int k = 0 ; k < (int )key -> key_len ; k += 2 )
291
+
292
+ convert_hexstring_to_byte_array (tests [tcid ].key , (char * )key -> value );
293
+ for (int k = 0 ; k < (int )key -> key_len ; k ++ )
285
294
{
286
- key -> value [k ] = tests [i ].key [k ] << 4 | tests [i ].key [k + 1 ];
287
295
printf ("KeyVal: %02x\n" , (uint8_t )key -> value [k ]);
288
296
}
289
297
290
298
printf ("Setting up IV...\n" );
291
299
test_association -> shivf_len = suites [j ].ivSize / 8 ;
292
300
test_association -> iv_len = suites [j ].ivSize / 8 ;
293
301
printf ("IVLen: %d\n" , test_association -> iv_len );
294
- //memcpy(&test_association->iv[0], &tests[i].iv[0], test_association->iv_len);
295
- // for (int k = 0; k < test_association->iv_len; k+=2)
296
- // {
297
- // test_association->iv[k] = tests[i].iv[k] << 4 | tests[i].iv[k+1];
298
- // printf("IVVal: %02x\n", (uint8_t)test_association->iv[k]);
299
- // }
302
+ convert_hexstring_to_byte_array (tests [tcid ].iv , (char * )test_association -> iv );
303
+ for (int k = 0 ; k < test_association -> iv_len ; k ++ )
304
+ {
305
+ printf ("IVVal: %02x\n" , test_association -> iv [k ]);
306
+ }
300
307
301
308
printf ("Setting up Mac...\n" );
302
309
test_association -> stmacf_len = suites [j ].tagSize / 8 ;
@@ -311,9 +318,9 @@ UTEST(AES_GCM, HAPPY_PATH_TC_APPLY_WYCHEPROOF)
311
318
312
319
printf ("Setting up Assert Val...\n" );
313
320
int assert_val ;
314
- if (strcmp (tests [i ].result , "invalid" ) == 0 )
321
+ if (strcmp (tests [tcid ].result , "invalid" ) == 0 )
315
322
{
316
- assert_val = -1 ;
323
+ assert_val = 999 ;
317
324
}
318
325
else
319
326
{
@@ -322,14 +329,21 @@ UTEST(AES_GCM, HAPPY_PATH_TC_APPLY_WYCHEPROOF)
322
329
printf ("Assert Val = %d\n" , assert_val );
323
330
324
331
printf ("Setting up Test String...\n" );
325
- // 20030015000004028318ABC1824029138141A2001D0C231287C1182784554CA3A219080A3EA7A5487CB5F7D70FB6C58D038554
332
+
333
+ char * frameLength = "002B00" ;
334
+ char * second = "0004" ;
326
335
// Test string
327
- char raw_tc_sdls_ping_h [1024 ] = "2003003200000400" ;
328
- strncat (raw_tc_sdls_ping_h , & tests [i ].iv [0 ], test_association -> iv_len * 2 );
336
+ char raw_tc_sdls_ping_h [1024 ] = "2003" ;
337
+ strncat (raw_tc_sdls_ping_h , frameLength , 6 );
338
+ printf ("Packet: %s\n" , raw_tc_sdls_ping_h );
339
+ strncat (raw_tc_sdls_ping_h , second , 4 );
329
340
printf ("Packet: %s\n" , raw_tc_sdls_ping_h );
330
- strncat (raw_tc_sdls_ping_h , tests [i ]. msg , 256 );
341
+ strncat (raw_tc_sdls_ping_h , tests [tcid ]. iv , test_association -> iv_len * 2 );
331
342
printf ("Packet: %s\n" , raw_tc_sdls_ping_h );
332
- strncat (raw_tc_sdls_ping_h , tests [i ].tag , test_association -> stmacf_len * 2 );
343
+ // arsn??
344
+ strncat (raw_tc_sdls_ping_h , tests [tcid ].msg , 256 );
345
+ printf ("Packet: %s\n" , raw_tc_sdls_ping_h );
346
+ strncat (raw_tc_sdls_ping_h , tests [tcid ].tag , test_association -> stmacf_len * 2 );
333
347
printf ("Packet: %s\n" , raw_tc_sdls_ping_h );
334
348
335
349
char * raw_tc_sdls_ping_b = NULL ;
@@ -344,14 +358,21 @@ UTEST(AES_GCM, HAPPY_PATH_TC_APPLY_WYCHEPROOF)
344
358
return_val =
345
359
Crypto_TC_ApplySecurity ((uint8_t * )raw_tc_sdls_ping_b , raw_tc_sdls_ping_len , & ptr_enc_frame , & enc_frame_len );
346
360
347
- ASSERT_EQ (assert_val , return_val );
348
- Crypto_Shutdown ();
349
- free (raw_tc_sdls_ping_b );
350
- free (test_association );
361
+ if (assert_val != 0 )
362
+ {
363
+ printf (KRED "Expected to fail, but passed\n" RESET );
364
+ ASSERT_NE (0 , return_val );
365
+ }
366
+ else
367
+ {
368
+ ASSERT_EQ (assert_val , return_val );
369
+ }
370
+ num_tests_ran ++ ;
351
371
}
372
+ tcid ++ ;
352
373
}
353
-
354
- ASSERT_EQ ( CRYPTO_LIB_SUCCESS , 0 );
374
+ printf ( "Number of Tests Ran: %d\n" , num_tests_ran );
375
+ Crypto_Shutdown ( );
355
376
}
356
377
357
378
UTEST_MAIN ()
0 commit comments