@@ -912,6 +912,7 @@ int qat_rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to,
912912 const BIGNUM * n = NULL ;
913913 const BIGNUM * e = NULL ;
914914 const BIGNUM * d = NULL ;
915+ int lenstra_ret = 0 ;
915916#endif
916917
917918 DEBUG ("- Started.\n" );
@@ -978,19 +979,27 @@ int qat_rsa_priv_enc(int flen, const unsigned char *from, unsigned char *to,
978979
979980 /* Note: not checking 'd' as it is not used */
980981 if (e != NULL ) { /* then a public key exists and we can effect Lenstra attack protection*/
981- ver_msg = OPENSSL_zalloc (flen );
982- if (ver_msg == NULL ) {
983- WARN ("ver_msg zalloc failed.\n" );
984- QATerr (QAT_F_QAT_RSA_PRIV_ENC , ERR_R_MALLOC_FAILURE );
985- sts = 0 ;
986- goto exit_lenstra ;
987- }
988- if ((RSA_meth_get_pub_dec (RSA_PKCS1_OpenSSL ())
989- (rsa_len , (const unsigned char * )to , ver_msg , rsa , padding ) <= 0 )
990- || (CRYPTO_memcmp (from , ver_msg , flen ) != 0 )) {
991- WARN ("- Verify failed - redoing sign operation in s/w\n" );
982+ ver_msg = OPENSSL_zalloc (flen );
983+ if (ver_msg == NULL ) {
984+ WARN ("ver_msg zalloc failed.\n" );
985+ QATerr (QAT_F_QAT_RSA_PRIV_ENC , ERR_R_MALLOC_FAILURE );
986+ sts = 0 ;
987+ goto exit_lenstra ;
988+ }
989+ # ifdef ENABLE_QAT_HW_LENSTRA_VERIFY_HW
990+ lenstra_ret = qat_rsa_pub_dec (rsa_len , (const unsigned char * )to ,
991+ ver_msg , rsa , padding );
992+ # else
993+ lenstra_ret = RSA_meth_get_pub_dec (RSA_PKCS1_OpenSSL ())
994+ (rsa_len ,
995+ (const unsigned char * )to ,
996+ ver_msg , rsa , padding );
997+ # endif
998+ if ((lenstra_ret <= 0 ) || (CRYPTO_memcmp (from , ver_msg , flen ) != 0 )) {
999+ WARN ("QAT RSA Verify failed - redoing sign operation in s/w\n" );
9921000 OPENSSL_free (ver_msg );
993- return RSA_meth_get_priv_enc (RSA_PKCS1_OpenSSL ())(flen , from , to , rsa , padding );
1001+ return RSA_meth_get_priv_enc (RSA_PKCS1_OpenSSL ())
1002+ (flen , from , to , rsa , padding );
9941003 }
9951004 OPENSSL_free (ver_msg );
9961005 }
@@ -1050,6 +1059,7 @@ int qat_rsa_priv_dec(int flen, const unsigned char *from,
10501059 const BIGNUM * n = NULL ;
10511060 const BIGNUM * e = NULL ;
10521061 const BIGNUM * d = NULL ;
1062+ int lenstra_ret = 0 ;
10531063#endif
10541064
10551065 DEBUG ("- Started.\n" );
@@ -1110,10 +1120,18 @@ int qat_rsa_priv_dec(int flen, const unsigned char *from,
11101120 sts = 0 ;
11111121 goto exit ;
11121122 }
1113- if ((RSA_meth_get_pub_enc (RSA_PKCS1_OpenSSL ())
1114- (rsa_len , (const unsigned char * )output_buffer -> pData , ver_msg , rsa , RSA_NO_PADDING ) <= 0 )
1115- || (CRYPTO_memcmp (from , ver_msg , flen ) != 0 )) {
1116- WARN ("- Verify of offloaded decrypt operation failed - redoing decrypt operation in s/w\n" );
1123+ # ifdef ENABLE_QAT_HW_LENSTRA_VERIFY_HW
1124+ lenstra_ret = qat_rsa_pub_enc (rsa_len ,
1125+ (const unsigned char * )output_buffer -> pData ,
1126+ ver_msg , rsa , RSA_NO_PADDING );
1127+ # else
1128+ lenstra_ret = RSA_meth_get_pub_enc (RSA_PKCS1_OpenSSL ())
1129+ (rsa_len ,
1130+ (const unsigned char * )output_buffer -> pData ,
1131+ ver_msg , rsa , RSA_NO_PADDING );
1132+ # endif
1133+ if ((lenstra_ret <= 0 ) || (CRYPTO_memcmp (from , ver_msg , flen ) != 0 )) {
1134+ WARN ("- QAT RSA sign failed - redoing decrypt operation in s/w\n" );
11171135 OPENSSL_free (ver_msg );
11181136 rsa_decrypt_op_buf_free (dec_op_data , output_buffer );
11191137 return RSA_meth_get_priv_dec (RSA_PKCS1_OpenSSL ())(flen , from , to , rsa , padding );
0 commit comments