@@ -494,127 +494,127 @@ mod tests {
494494 let test_set = wycheproof:: aead:: TestSet :: load ( test_name) . unwrap ( ) ;
495495 let mut counter = 0 ;
496496
497- for group in test_set. test_groups . into_iter ( )
497+ for group in test_set
498+ . test_groups
499+ . into_iter ( )
498500 . filter ( |group| group. key_size == 128 )
499- . filter ( |group| group. nonce_size == 96 )
500- {
501- for test in group. tests {
502- counter += 1 ;
503-
504- let mut aes_c_type: Aes = unsafe { mem:: zeroed ( ) } ;
505- let aes_object = unsafe { AesObject :: from_ptr ( & mut aes_c_type) } ;
506-
507- unsafe {
508- let ret = wc_AesInit ( aes_object. as_ptr ( ) , ptr:: null_mut ( ) , INVALID_DEVID ) ;
509- check_if_zero ( ret) . unwrap ( ) ;
510-
511- let ret = wc_AesGcmSetKey (
512- aes_object. as_ptr ( ) ,
513- test. key . as_ptr ( ) ,
514- test. key . len ( ) as word32
515- ) ;
516- check_if_zero ( ret) . unwrap ( ) ;
517- }
501+ . filter ( |group| group. nonce_size == 96 )
502+ {
503+ for test in group. tests {
504+ counter += 1 ;
505+
506+ let mut aes_c_type: Aes = unsafe { mem:: zeroed ( ) } ;
507+ let aes_object = unsafe { AesObject :: from_ptr ( & mut aes_c_type) } ;
508+
509+ unsafe {
510+ let ret = wc_AesInit ( aes_object. as_ptr ( ) , ptr:: null_mut ( ) , INVALID_DEVID ) ;
511+ check_if_zero ( ret) . unwrap ( ) ;
512+
513+ let ret = wc_AesGcmSetKey (
514+ aes_object. as_ptr ( ) ,
515+ test. key . as_ptr ( ) ,
516+ test. key . len ( ) as word32 ,
517+ ) ;
518+ check_if_zero ( ret) . unwrap ( ) ;
519+ }
518520
519- let mut actual_ciphertext = test. pt . to_vec ( ) ;
520- let mut actual_tag = [ 0u8 ; GCM_TAG_LENGTH ] ;
521-
522- let encrypt_result = unsafe {
523- wc_AesGcmEncrypt (
524- aes_object. as_ptr ( ) ,
525- actual_ciphertext. as_mut_ptr ( ) ,
526- test. pt . as_ptr ( ) ,
527- test. pt . len ( ) as word32 ,
528- test. nonce . as_ptr ( ) ,
529- test. nonce . len ( ) as word32 ,
530- actual_tag. as_mut_ptr ( ) ,
531- actual_tag. len ( ) as word32 ,
532- test. aad . as_ptr ( ) ,
533- test. aad . len ( ) as word32 ,
534- )
535- } ;
536-
537- match & test. result {
538- TestResult :: Invalid => {
539- if test. flags . iter ( ) . any ( |flag| * flag == TestFlag :: ModifiedTag ) {
540- assert_ne ! (
541- actual_tag[ ..] ,
542- test. tag[ ..] ,
543- "Expected incorrect tag. Id {}: {}" ,
544- test. tc_id,
545- test. comment
546- ) ;
547- }
548- }
549- TestResult :: Valid | TestResult :: Acceptable => {
550- assert_eq ! (
551- encrypt_result, 0 ,
552- "Encryption failed for test case {}: {}" ,
553- test. tc_id,
554- test. comment
555- ) ;
556-
557- assert_eq ! (
558- actual_ciphertext[ ..] ,
559- test. ct[ ..] ,
560- "Encryption failed for test case {}: {}" ,
561- test. tc_id,
562- test. comment
563- ) ;
564-
565- assert_eq ! (
566- actual_tag[ ..] ,
567- test. tag[ ..] ,
568- "Tag mismatch in test case {}: {}" ,
569- test. tc_id,
570- test. comment
571- ) ;
572- }
521+ let mut actual_ciphertext = test. pt . to_vec ( ) ;
522+ let mut actual_tag = [ 0u8 ; GCM_TAG_LENGTH ] ;
523+
524+ let encrypt_result = unsafe {
525+ wc_AesGcmEncrypt (
526+ aes_object. as_ptr ( ) ,
527+ actual_ciphertext. as_mut_ptr ( ) ,
528+ test. pt . as_ptr ( ) ,
529+ test. pt . len ( ) as word32 ,
530+ test. nonce . as_ptr ( ) ,
531+ test. nonce . len ( ) as word32 ,
532+ actual_tag. as_mut_ptr ( ) ,
533+ actual_tag. len ( ) as word32 ,
534+ test. aad . as_ptr ( ) ,
535+ test. aad . len ( ) as word32 ,
536+ )
537+ } ;
538+
539+ match & test. result {
540+ TestResult :: Invalid => {
541+ if test. flags . iter ( ) . any ( |flag| * flag == TestFlag :: ModifiedTag ) {
542+ assert_ne ! (
543+ actual_tag[ ..] ,
544+ test. tag[ ..] ,
545+ "Expected incorrect tag. Id {}: {}" ,
546+ test. tc_id,
547+ test. comment
548+ ) ;
573549 }
550+ }
551+ TestResult :: Valid | TestResult :: Acceptable => {
552+ assert_eq ! (
553+ encrypt_result, 0 ,
554+ "Encryption failed for test case {}: {}" ,
555+ test. tc_id, test. comment
556+ ) ;
557+
558+ assert_eq ! (
559+ actual_ciphertext[ ..] ,
560+ test. ct[ ..] ,
561+ "Encryption failed for test case {}: {}" ,
562+ test. tc_id,
563+ test. comment
564+ ) ;
565+
566+ assert_eq ! (
567+ actual_tag[ ..] ,
568+ test. tag[ ..] ,
569+ "Tag mismatch in test case {}: {}" ,
570+ test. tc_id,
571+ test. comment
572+ ) ;
573+ }
574+ }
574575
575- let mut decrypted_data = test. ct . to_vec ( ) ;
576- let decrypt_result = unsafe {
577- wc_AesGcmDecrypt (
578- aes_object. as_ptr ( ) ,
579- decrypted_data. as_mut_ptr ( ) ,
580- test. ct . as_ptr ( ) ,
581- test. ct . len ( ) as word32 ,
582- test. nonce . as_ptr ( ) ,
583- test. nonce . len ( ) as word32 ,
584- test. tag . as_ptr ( ) ,
585- test. tag . len ( ) as word32 ,
586- test. aad . as_ptr ( ) ,
587- test. aad . len ( ) as word32 ,
588- )
589- } ;
590-
591- match & test. result {
592- TestResult :: Invalid => {
593- assert ! (
594- decrypt_result != 0 ,
595- "Decryption should have failed for invalid test case {}: {}" ,
596- test. tc_id,
597- test. comment
598- ) ;
599- }
600- TestResult :: Valid | TestResult :: Acceptable => {
601- assert_eq ! (
602- decrypt_result, 0 ,
603- "Decryption failed for test case {}: {}" ,
604- test. tc_id,
605- test. comment
606- ) ;
607- assert_eq ! (
608- decrypted_data[ ..] ,
609- test. pt[ ..] ,
610- "Decryption failed for test case {}: {}" ,
611- test. tc_id,
612- test. comment
613- ) ;
614- }
615- }
576+ let mut decrypted_data = test. ct . to_vec ( ) ;
577+ let decrypt_result = unsafe {
578+ wc_AesGcmDecrypt (
579+ aes_object. as_ptr ( ) ,
580+ decrypted_data. as_mut_ptr ( ) ,
581+ test. ct . as_ptr ( ) ,
582+ test. ct . len ( ) as word32 ,
583+ test. nonce . as_ptr ( ) ,
584+ test. nonce . len ( ) as word32 ,
585+ test. tag . as_ptr ( ) ,
586+ test. tag . len ( ) as word32 ,
587+ test. aad . as_ptr ( ) ,
588+ test. aad . len ( ) as word32 ,
589+ )
590+ } ;
591+
592+ match & test. result {
593+ TestResult :: Invalid => {
594+ assert ! (
595+ decrypt_result != 0 ,
596+ "Decryption should have failed for invalid test case {}: {}" ,
597+ test. tc_id,
598+ test. comment
599+ ) ;
600+ }
601+ TestResult :: Valid | TestResult :: Acceptable => {
602+ assert_eq ! (
603+ decrypt_result, 0 ,
604+ "Decryption failed for test case {}: {}" ,
605+ test. tc_id, test. comment
606+ ) ;
607+ assert_eq ! (
608+ decrypted_data[ ..] ,
609+ test. pt[ ..] ,
610+ "Decryption failed for test case {}: {}" ,
611+ test. tc_id,
612+ test. comment
613+ ) ;
616614 }
617615 }
616+ }
617+ }
618618
619619 assert ! (
620620 counter > 50 ,
0 commit comments