@@ -669,6 +669,215 @@ static int test_aes_tag_dec_ossh_multi(const EVP_CIPHER *cipher,
669669 return err ;
670670}
671671
672+ static int test_aes_tag_enc_ossh_iv_params (const EVP_CIPHER * cipher ,
673+ unsigned char * key , unsigned char * iv , int ivFixedSetArg ,
674+ unsigned char * aad , unsigned char * msg , int len , unsigned char * enc ,
675+ unsigned char * tag , unsigned char * ivInv , size_t ivInvLen )
676+ {
677+ int err ;
678+ EVP_CIPHER_CTX * encCtx ;
679+ unsigned int tagLen = 16 ;
680+
681+ err = (encCtx = EVP_CIPHER_CTX_new ()) == NULL ;
682+ if (err == 0 ) {
683+ err = EVP_CipherInit (encCtx , cipher , NULL , iv , 1 ) != 1 ;
684+ }
685+ if (err == 0 ) {
686+ err = EVP_CIPHER_CTX_ctrl (encCtx , EVP_CTRL_GCM_SET_IV_FIXED ,
687+ ivFixedSetArg , iv ) != 1 ;
688+ }
689+ if (err == 0 ) {
690+ err = EVP_CipherInit (encCtx , NULL , key , NULL , -1 ) != 1 ;
691+ }
692+ if (err == 0 ) {
693+ err = EVP_CIPHER_CTX_ctrl (encCtx , EVP_CTRL_GCM_IV_GEN , (int )ivInvLen ,
694+ ivInv ) != 1 ;
695+ }
696+ if (err == 0 ) {
697+ err = EVP_Cipher (encCtx , NULL , aad , (int )strlen ((char * )aad )) <= 0 ;
698+ }
699+ if (err == 0 ) {
700+ err = EVP_Cipher (encCtx , enc , msg , len ) != len ;
701+ }
702+ if (err == 0 ) {
703+ err = EVP_Cipher (encCtx , NULL , NULL , 0 ) < 0 ;
704+ }
705+ if (err == 0 ) {
706+ err = EVP_CIPHER_CTX_ctrl (encCtx , EVP_CTRL_GCM_GET_TAG , tagLen ,
707+ tag ) != 1 ;
708+ }
709+
710+ EVP_CIPHER_CTX_free (encCtx );
711+ return err ;
712+ }
713+
714+ static int test_aes_tag_dec_ossh_set_iv_inv (const EVP_CIPHER * cipher ,
715+ unsigned char * key , unsigned char * iv , int ivFixedSetArg ,
716+ unsigned char * aad , unsigned char * msg , int len , unsigned char * enc ,
717+ unsigned char * tag , unsigned char * dec , unsigned char * ivInv ,
718+ size_t ivInvLen )
719+ {
720+ int err ;
721+ EVP_CIPHER_CTX * decCtx ;
722+ unsigned int tagLen = 16 ;
723+
724+ err = (decCtx = EVP_CIPHER_CTX_new ()) == NULL ;
725+ if (err == 0 ) {
726+ err = EVP_CipherInit (decCtx , cipher , NULL , iv , 0 ) != 1 ;
727+ }
728+ if (err == 0 ) {
729+ err = EVP_CIPHER_CTX_ctrl (decCtx , EVP_CTRL_GCM_SET_IV_FIXED ,
730+ ivFixedSetArg , iv ) != 1 ;
731+ }
732+ if (err == 0 ) {
733+ err = EVP_CipherInit (decCtx , NULL , key , NULL , -1 ) != 1 ;
734+ }
735+ if (err == 0 ) {
736+ err = EVP_CIPHER_CTX_ctrl (decCtx , EVP_CTRL_GCM_SET_IV_INV ,
737+ (int )ivInvLen , ivInv ) != 1 ;
738+ }
739+ if (err == 0 ) {
740+ err = EVP_CIPHER_CTX_ctrl (decCtx , EVP_CTRL_GCM_SET_TAG , tagLen ,
741+ tag ) != 1 ;
742+ }
743+ if (err == 0 ) {
744+ err = EVP_Cipher (decCtx , NULL , aad , (int )strlen ((char * )aad )) <= 0 ;
745+ }
746+ if (err == 0 ) {
747+ err = EVP_Cipher (decCtx , dec , enc , len ) != len ;
748+ }
749+ if (err == 0 ) {
750+ err = EVP_Cipher (decCtx , NULL , NULL , 0 ) < 0 ;
751+ }
752+ if ((err == 0 ) && (dec != NULL ) && (msg != NULL ) && (memcmp (dec , msg ,
753+ len ) != 0 )) {
754+ err = 1 ;
755+ }
756+
757+ EVP_CIPHER_CTX_free (decCtx );
758+ return err ;
759+ }
760+
761+ static int test_aes_tag_set_iv_inv (void * data , const char * cipher ,
762+ int keyLen )
763+ {
764+ int err = 0 ;
765+ unsigned char msg [] = "Test pattern" ;
766+ unsigned char key [32 ];
767+ unsigned char iv [12 ];
768+ unsigned char aad [] = "AAD" ;
769+ unsigned char enc [sizeof (msg )];
770+ unsigned char tag [AES_BLOCK_SIZE ];
771+ unsigned char dec [sizeof (msg )];
772+ unsigned char ivInv [EVP_GCM_TLS_EXPLICIT_IV_LEN ];
773+ EVP_CIPHER * ocipher ;
774+ EVP_CIPHER * wcipher ;
775+
776+ (void )data ;
777+
778+ ocipher = EVP_CIPHER_fetch (osslLibCtx , cipher , "" );
779+ wcipher = EVP_CIPHER_fetch (wpLibCtx , cipher , "" );
780+
781+ if (RAND_bytes (key , keyLen ) == 0 ) {
782+ err = 1 ;
783+ }
784+ if ((err == 0 ) && (RAND_bytes (iv , sizeof (iv )) == 0 )) {
785+ err = 1 ;
786+ }
787+
788+ if (err == 0 ) {
789+ PRINT_MSG ("Encrypt with OpenSSL (SET_IV_INV)" );
790+ err = test_aes_tag_enc_ossh_iv_params (ocipher , key , iv , -1 , aad , msg ,
791+ sizeof (msg ), enc , tag , ivInv ,
792+ sizeof (ivInv ));
793+ }
794+ if (err == 0 ) {
795+ PRINT_MSG ("Decrypt with wolfprovider (SET_IV_INV)" );
796+ err = test_aes_tag_dec_ossh_set_iv_inv (wcipher , key , iv , -1 , aad , msg ,
797+ sizeof (msg ), enc , tag , dec ,
798+ ivInv , sizeof (ivInv ));
799+ }
800+ if (err == 0 ) {
801+ PRINT_MSG ("Encrypt with wolfprovider (SET_IV_INV)" );
802+ err = test_aes_tag_enc_ossh_iv_params (wcipher , key , iv , -1 , aad , msg ,
803+ sizeof (msg ), enc , tag , ivInv ,
804+ sizeof (ivInv ));
805+ }
806+ if (err == 0 ) {
807+ PRINT_MSG ("Decrypt with OpenSSL (SET_IV_INV)" );
808+ err = test_aes_tag_dec_ossh_set_iv_inv (ocipher , key , iv , -1 , aad , msg ,
809+ sizeof (msg ), enc , tag , dec ,
810+ ivInv , sizeof (ivInv ));
811+ }
812+
813+ EVP_CIPHER_free (wcipher );
814+ EVP_CIPHER_free (ocipher );
815+
816+ return err ;
817+ }
818+
819+ static int test_aes_tag_set_iv_fixed (void * data , const char * cipher ,
820+ int keyLen )
821+ {
822+ int err = 0 ;
823+ unsigned char msg [] = "Test pattern" ;
824+ unsigned char key [32 ];
825+ unsigned char iv [12 ];
826+ unsigned char aad [] = "AAD" ;
827+ unsigned char enc [sizeof (msg )];
828+ unsigned char tag [AES_BLOCK_SIZE ];
829+ unsigned char dec [sizeof (msg )];
830+ unsigned char ivInv [EVP_GCM_TLS_EXPLICIT_IV_LEN ];
831+ EVP_CIPHER * ocipher ;
832+ EVP_CIPHER * wcipher ;
833+
834+ (void )data ;
835+
836+ ocipher = EVP_CIPHER_fetch (osslLibCtx , cipher , "" );
837+ wcipher = EVP_CIPHER_fetch (wpLibCtx , cipher , "" );
838+
839+ if (RAND_bytes (key , keyLen ) == 0 ) {
840+ err = 1 ;
841+ }
842+ if ((err == 0 ) && (RAND_bytes (iv , sizeof (iv )) == 0 )) {
843+ err = 1 ;
844+ }
845+
846+ if (err == 0 ) {
847+ PRINT_MSG ("Encrypt with OpenSSL (TLS1_IV_FIXED)" );
848+ err = test_aes_tag_enc_ossh_iv_params (ocipher , key , iv ,
849+ EVP_GCM_TLS_FIXED_IV_LEN , aad ,
850+ msg , sizeof (msg ), enc , tag ,
851+ ivInv , sizeof (ivInv ));
852+ }
853+ if (err == 0 ) {
854+ PRINT_MSG ("Decrypt with wolfprovider (TLS1_IV_FIXED)" );
855+ err = test_aes_tag_dec_ossh_set_iv_inv (wcipher , key , iv ,
856+ EVP_GCM_TLS_FIXED_IV_LEN , aad ,
857+ msg , sizeof (msg ), enc , tag , dec ,
858+ ivInv , sizeof (ivInv ));
859+ }
860+ if (err == 0 ) {
861+ PRINT_MSG ("Encrypt with wolfprovider (TLS1_IV_FIXED)" );
862+ err = test_aes_tag_enc_ossh_iv_params (wcipher , key , iv ,
863+ EVP_GCM_TLS_FIXED_IV_LEN , aad ,
864+ msg , sizeof (msg ), enc , tag ,
865+ ivInv , sizeof (ivInv ));
866+ }
867+ if (err == 0 ) {
868+ PRINT_MSG ("Decrypt with OpenSSL (TLS1_IV_FIXED)" );
869+ err = test_aes_tag_dec_ossh_set_iv_inv (ocipher , key , iv ,
870+ EVP_GCM_TLS_FIXED_IV_LEN , aad ,
871+ msg , sizeof (msg ), enc , tag , dec ,
872+ ivInv , sizeof (ivInv ));
873+ }
874+
875+ EVP_CIPHER_free (wcipher );
876+ EVP_CIPHER_free (ocipher );
877+
878+ return err ;
879+ }
880+
672881static int test_aes_tag_fixed (void * data , const char * cipher ,
673882 int keyLen , int ivFixedLen , int ivLen )
674883{
@@ -1042,6 +1251,20 @@ int test_aes128_gcm_tls(void *data)
10421251 EVP_GCM_TLS_FIXED_IV_LEN , 0 );
10431252}
10441253
1254+ /******************************************************************************/
1255+
1256+ int test_aes128_gcm_set_iv_inv (void * data )
1257+ {
1258+ return test_aes_tag_set_iv_inv (data , "AES-128-GCM" , 16 );
1259+ }
1260+
1261+ /******************************************************************************/
1262+
1263+ int test_aes128_gcm_set_iv_fixed (void * data )
1264+ {
1265+ return test_aes_tag_set_iv_fixed (data , "AES-128-GCM" , 16 );
1266+ }
1267+
10451268#endif /* WP_HAVE_AESGCM */
10461269
10471270/******************************************************************************/
@@ -1092,4 +1315,3 @@ int test_aes128_ccm_tls(void *data)
10921315}
10931316
10941317#endif /* WP_HAVE_AESCCM */
1095-
0 commit comments