@@ -63,6 +63,8 @@ typedef struct we_Rsa
6363 int privKeySet :1 ;
6464 /** Indicates public key has been set into wolfSSL structure. */
6565 int pubKeySet :1 ;
66+ /** Indicates message digest algorithm has been explicitly set. */
67+ int mdSet :1 ;
6668} we_Rsa ;
6769
6870
@@ -897,7 +899,7 @@ static int we_rsa_priv_enc(int fromLen, const unsigned char *from,
897899 * encrypt. */
898900 engineRsa -> padMode = padding ;
899901 #if OPENSSL_VERSION_NUMBER >= 0x10101000L
900- if ((padding == RSA_PKCS1_PADDING ) &&
902+ if ((padding == RSA_PKCS1_PADDING ) && engineRsa -> mdSet &&
901903 (EVP_MD_size (engineRsa -> md ) != fromLen )) {
902904 WOLFENGINE_ERROR_MSG (WE_LOG_PK , "Digest length invalid" );
903905 ret = -1 ;
@@ -1599,6 +1601,7 @@ static int we_rsa_pkey_ctrl(EVP_PKEY_CTX *ctx, int type, int num, void *ptr)
15991601 WOLFENGINE_MSG (WE_LOG_PK , "type: EVP_PKEY_CTRL_MD" );
16001602 /* ptr [in] Signing/verification digest. */
16011603 rsa -> md = (EVP_MD * )ptr ;
1604+ rsa -> mdSet = 1 ;
16021605 break ;
16031606 case EVP_PKEY_CTRL_GET_MD :
16041607 WOLFENGINE_MSG (WE_LOG_PK , "type: EVP_PKEY_CTRL_GET_MD" );
@@ -1616,6 +1619,7 @@ static int we_rsa_pkey_ctrl(EVP_PKEY_CTX *ctx, int type, int num, void *ptr)
16161619 }
16171620 else {
16181621 rsa -> md = (const EVP_MD * )ptr ;
1622+ rsa -> mdSet = 1 ;
16191623 }
16201624 break ;
16211625 case EVP_PKEY_CTRL_GET_RSA_OAEP_MD :
@@ -1932,6 +1936,9 @@ static int we_rsa_pkey_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
19321936 if (rsa -> md == NULL ) {
19331937 ret = 0 ;
19341938 }
1939+ else {
1940+ rsa -> mdSet = 1 ;
1941+ }
19351942 }
19361943 }
19371944 else {
0 commit comments