@@ -609,13 +609,19 @@ static int wp_rsa_sign_pkcs1(wp_RsaSigCtx* ctx, unsigned char* sig,
609609 }
610610 }
611611 if (ok ) {
612- PRIVATE_KEY_UNLOCK ();
613- rc = wc_RsaSSL_Sign (tbs , (word32 )tbsLen , sig , (word32 )sigSize ,
614- wp_rsa_get_key (ctx -> rsa ), & ctx -> rng );
615- PRIVATE_KEY_LOCK ();
616- if (rc <= 0 ) {
612+ if (wp_lock (wp_rsa_get_mutex (ctx -> rsa )) != 1 ) {
617613 ok = 0 ;
618614 }
615+ if (ok ) {
616+ PRIVATE_KEY_UNLOCK ();
617+ rc = wc_RsaSSL_Sign (tbs , (word32 )tbsLen , sig , (word32 )sigSize ,
618+ wp_rsa_get_key (ctx -> rsa ), & ctx -> rng );
619+ PRIVATE_KEY_LOCK ();
620+ wp_unlock (wp_rsa_get_mutex (ctx -> rsa ));
621+ if (rc <= 0 ) {
622+ ok = 0 ;
623+ }
624+ }
619625 }
620626 if (ok ) {
621627 * sigLen = rc ;
@@ -655,21 +661,29 @@ static int wp_rsa_sign_pss(wp_RsaSigCtx* ctx, unsigned char* sig,
655661#endif
656662 wp_rsa_get_key (ctx -> rsa ), EVP_PKEY_OP_SIGN );
657663
658- PRIVATE_KEY_UNLOCK ();
659- rc = wc_RsaPSS_Sign_ex (tbs , (word32 )tbsLen , sig , (word32 )sigSize ,
660- #if LIBWOLFSSL_VERSION_HEX >= 0x05007004
661- ctx -> hash .type ,
662- #else
663- ctx -> hashType ,
664- #endif
665- ctx -> mgf , saltLen , wp_rsa_get_key (ctx -> rsa ),
666- & ctx -> rng );
667- PRIVATE_KEY_LOCK ();
668- if (rc < 0 ) {
669- ok = 0 ;
670- }
671- else {
672- * sigLen = rc ;
664+ if (ok ) {
665+ if (wp_lock (wp_rsa_get_mutex (ctx -> rsa )) != 1 ) {
666+ ok = 0 ;
667+ }
668+ if (ok ) {
669+ PRIVATE_KEY_UNLOCK ();
670+ rc = wc_RsaPSS_Sign_ex (tbs , (word32 )tbsLen , sig , (word32 )sigSize ,
671+ #if LIBWOLFSSL_VERSION_HEX >= 0x05007004
672+ ctx -> hash .type ,
673+ #else
674+ ctx -> hashType ,
675+ #endif
676+ ctx -> mgf , saltLen , wp_rsa_get_key (ctx -> rsa ),
677+ & ctx -> rng );
678+ PRIVATE_KEY_LOCK ();
679+ wp_unlock (wp_rsa_get_mutex (ctx -> rsa ));
680+ if (rc < 0 ) {
681+ ok = 0 ;
682+ }
683+ else {
684+ * sigLen = rc ;
685+ }
686+ }
673687 }
674688
675689 WOLFPROV_LEAVE (WP_LOG_PK , __FILE__ ":" WOLFPROV_STRINGIZE (__LINE__ ), ok );
@@ -749,16 +763,21 @@ static int wp_rsa_sign_no_pad(wp_RsaSigCtx* ctx, unsigned char* sig,
749763 if (ok ) {
750764 word32 len = (word32 )sigSize ;
751765 int rc ;
752-
753- PRIVATE_KEY_UNLOCK ();
754- rc = wc_RsaDirect ((byte * )tbs , (word32 )tbsLen , sig , & len ,
755- wp_rsa_get_key (ctx -> rsa ), RSA_PRIVATE_ENCRYPT , & ctx -> rng );
756- PRIVATE_KEY_LOCK ();
757- if (rc < 0 ) {
766+ if (wp_lock (wp_rsa_get_mutex (ctx -> rsa )) != 1 ) {
758767 ok = 0 ;
759768 }
760- else {
761- * sigLen = rc ;
769+ if (ok ) {
770+ PRIVATE_KEY_UNLOCK ();
771+ rc = wc_RsaDirect ((byte * )tbs , (word32 )tbsLen , sig , & len ,
772+ wp_rsa_get_key (ctx -> rsa ), RSA_PRIVATE_ENCRYPT , & ctx -> rng );
773+ PRIVATE_KEY_LOCK ();
774+ wp_unlock (wp_rsa_get_mutex (ctx -> rsa ));
775+ if (rc < 0 ) {
776+ ok = 0 ;
777+ }
778+ else {
779+ * sigLen = rc ;
780+ }
762781 }
763782 }
764783
@@ -841,16 +860,21 @@ static int wp_rsa_sign_x931(wp_RsaSigCtx* ctx, unsigned char* sig,
841860 }
842861 if (ok ) {
843862 word32 len = (word32 )sigSize ;
844-
845- PRIVATE_KEY_UNLOCK ();
846- rc = wc_RsaDirect (padded , paddedSz , sig , & len ,
847- wp_rsa_get_key (ctx -> rsa ), RSA_PRIVATE_ENCRYPT , & ctx -> rng );
848- PRIVATE_KEY_LOCK ();
849- if (rc < 0 ) {
863+ if (wp_lock (wp_rsa_get_mutex (ctx -> rsa )) != 1 ) {
850864 ok = 0 ;
851865 }
852- else {
853- * sigLen = rc ;
866+ if (ok ) {
867+ PRIVATE_KEY_UNLOCK ();
868+ rc = wc_RsaDirect (padded , paddedSz , sig , & len ,
869+ wp_rsa_get_key (ctx -> rsa ), RSA_PRIVATE_ENCRYPT , & ctx -> rng );
870+ PRIVATE_KEY_LOCK ();
871+ wp_unlock (wp_rsa_get_mutex (ctx -> rsa ));
872+ if (rc < 0 ) {
873+ ok = 0 ;
874+ }
875+ else {
876+ * sigLen = rc ;
877+ }
854878 }
855879 }
856880 if (padded != NULL ) {
@@ -914,6 +938,8 @@ static int wp_rsa_sign(wp_RsaSigCtx* ctx, unsigned char* sig, size_t* sigLen,
914938{
915939 int ok = 1 ;
916940
941+ WOLFPROV_ENTER (WP_LOG_PK , __FUNCTION__ );
942+
917943 if (!wolfssl_prov_is_running ()) {
918944 ok = 0 ;
919945 }
@@ -1311,6 +1337,8 @@ static int wp_rsa_verify(wp_RsaSigCtx* ctx, const unsigned char* sig,
13111337{
13121338 int ok = 1 ;
13131339
1340+ WOLFPROV_ENTER (WP_LOG_PK , __FUNCTION__ );
1341+
13141342 if (!wolfssl_prov_is_running ()) {
13151343 ok = 0 ;
13161344 }
0 commit comments