@@ -913,8 +913,10 @@ static int we_rsa_priv_dec_int(size_t fromLen, const unsigned char *from,
913913 }
914914 else {
915915 /* PKCS#1 v1.5 padding using block type 2. */
916+ PRIVATE_KEY_UNLOCK ();
916917 ret = wc_RsaPrivateDecrypt (from , (word32 )fromLen , to ,
917918 (word32 )toLen , & rsa -> key );
919+ PRIVATE_KEY_LOCK ();
918920 if (ret < 0 ) {
919921 WOLFENGINE_ERROR_FUNC (WE_LOG_PK , "wc_RsaPrivateDecrypt" ,
920922 ret );
@@ -934,10 +936,12 @@ static int we_rsa_priv_dec_int(size_t fromLen, const unsigned char *from,
934936 }
935937 else {
936938 mdMGF1 = rsa -> mdMGF1 != NULL ? rsa -> mdMGF1 : rsa -> md ;
939+ PRIVATE_KEY_UNLOCK ();
937940 ret = wc_RsaPrivateDecrypt_ex (from , (word32 )fromLen , to ,
938941 (word32 )toLen , & rsa -> key , WC_RSA_OAEP_PAD ,
939942 we_nid_to_wc_hash_type (EVP_MD_type (rsa -> md )),
940943 we_mgf_from_hash (EVP_MD_type (mdMGF1 )), NULL , 0 );
944+ PRIVATE_KEY_LOCK ();
941945 if (ret < 0 ) {
942946 WOLFENGINE_ERROR_FUNC (WE_LOG_PK ,
943947 "wc_RsaPrivateDecrypt_ex" , ret );
@@ -948,10 +952,12 @@ static int we_rsa_priv_dec_int(size_t fromLen, const unsigned char *from,
948952 case RSA_NO_PADDING :
949953 WOLFENGINE_MSG (WE_LOG_PK , "padMode: RSA_NO_PADDING" );
950954 /* Raw private decrypt - no padding. */
955+ PRIVATE_KEY_UNLOCK ();
951956 ret = wc_RsaPrivateDecrypt_ex (from , (word32 )fromLen , to ,
952957 (word32 )toLen , & rsa -> key , WC_RSA_NO_PAD ,
953958 WC_HASH_TYPE_NONE ,
954959 0 , NULL , 0 );
960+ PRIVATE_KEY_LOCK ();
955961 if (ret < 0 ) {
956962 WOLFENGINE_ERROR_FUNC (WE_LOG_PK , "wc_RsaPrivateDecrypt_ex" ,
957963 ret );
@@ -1097,8 +1103,10 @@ static int we_rsa_priv_enc_int(size_t fromLen, const unsigned char *from,
10971103 case RSA_PKCS1_PADDING :
10981104 WOLFENGINE_MSG (WE_LOG_PK , "padMode: RSA_PKCS1_PADDING" );
10991105 /* PKCS#1 v1.5 padding using block type 1. */
1106+ PRIVATE_KEY_UNLOCK ();
11001107 ret = wc_RsaSSL_Sign (from , (word32 )fromLen , to , (word32 )toLen ,
11011108 & rsa -> key , rng );
1109+ PRIVATE_KEY_LOCK ();
11021110 if (ret < 0 ) {
11031111 WOLFENGINE_ERROR_FUNC (WE_LOG_PK , "wc_RsaSSL_Sign" , ret );
11041112 ret = -1 ;
@@ -1107,8 +1115,10 @@ static int we_rsa_priv_enc_int(size_t fromLen, const unsigned char *from,
11071115 case RSA_NO_PADDING :
11081116 WOLFENGINE_MSG (WE_LOG_PK , "padMode: RSA_NO_PADDING" );
11091117 /* Raw private encrypt - no padding. */
1118+ PRIVATE_KEY_UNLOCK ();
11101119 ret = wc_RsaDirect ((byte * )from , (unsigned int )fromLen , to , & tLen ,
11111120 & rsa -> key , RSA_PRIVATE_ENCRYPT , rng );
1121+ PRIVATE_KEY_LOCK ();
11121122 if (ret < 0 ) {
11131123 WOLFENGINE_ERROR_FUNC (WE_LOG_PK , "wc_RsaDirect" , ret );
11141124 ret = -1 ;
@@ -1130,10 +1140,12 @@ static int we_rsa_priv_enc_int(size_t fromLen, const unsigned char *from,
11301140 }
11311141 /* When MGF1 digest is not specified, use signing digest. */
11321142 mdMGF1 = rsa -> mdMGF1 != NULL ? rsa -> mdMGF1 : rsa -> md ;
1143+ PRIVATE_KEY_UNLOCK ();
11331144 ret = wc_RsaPSS_Sign_ex (from , (word32 )fromLen , to ,
11341145 (word32 )toLen , we_nid_to_wc_hash_type (EVP_MD_type (rsa -> md )),
11351146 we_mgf_from_hash (EVP_MD_type (mdMGF1 )), wc_saltLen ,
11361147 & rsa -> key , rng );
1148+ PRIVATE_KEY_LOCK ();
11371149 if (ret < 0 ) {
11381150 WOLFENGINE_ERROR_FUNC (WE_LOG_PK , "wc_RsaPSS_Sign_ex" , ret );
11391151 ret = -1 ;
@@ -1162,8 +1174,10 @@ static int we_rsa_priv_enc_int(size_t fromLen, const unsigned char *from,
11621174 ret = -1 ;
11631175 }
11641176 else {
1177+ PRIVATE_KEY_UNLOCK ();
11651178 ret = wc_RsaDirect (padded , paddedSz , to , & tLen ,
11661179 & rsa -> key , RSA_PRIVATE_ENCRYPT , rng );
1180+ PRIVATE_KEY_UNLOCK ();
11671181 if (ret < 0 ) {
11681182 WOLFENGINE_ERROR_FUNC (WE_LOG_PK , "wc_RsaDirect" ,
11691183 ret );
@@ -1379,8 +1393,10 @@ static int we_rsa_pub_dec_int(size_t fromLen, const unsigned char *from,
13791393 else
13801394 #endif
13811395 {
1396+ PRIVATE_KEY_UNLOCK ();
13821397 ret = wc_RsaDirect ((byte * )from , (unsigned int )fromLen , to ,
13831398 & tLen , & rsa -> key , RSA_PUBLIC_DECRYPT , rng );
1399+ PRIVATE_KEY_LOCK ();
13841400 if (ret < 0 ) {
13851401 WOLFENGINE_ERROR_FUNC (WE_LOG_PK , "wc_RsaDirect" , ret );
13861402 ret = -1 ;
@@ -1422,8 +1438,10 @@ static int we_rsa_pub_dec_int(size_t fromLen, const unsigned char *from,
14221438 #ifdef WE_HAVE_RSA_X931
14231439 case RSA_X931_PADDING :
14241440 WOLFENGINE_MSG (WE_LOG_PK , "padMode: RSA_X931_PADDING" );
1441+ PRIVATE_KEY_UNLOCK ();
14251442 ret = wc_RsaDirect ((byte * )from , (unsigned int )fromLen , to ,
14261443 & tLen , & rsa -> key , RSA_PUBLIC_DECRYPT , rng );
1444+ PRIVATE_KEY_LOCK ();
14271445 if (ret < 0 ) {
14281446 WOLFENGINE_ERROR_FUNC (WE_LOG_PK , "wc_RsaDirect" , ret );
14291447 ret = -1 ;
0 commit comments