@@ -219,6 +219,7 @@ static int we_pss_salt_len_to_wc(int saltLen, const EVP_MD *md, RsaKey *key,
219219 return saltLen ;
220220}
221221
222+ #ifdef WE_HAVE_RSA_X931
222223/**
223224 * Add X9.31 padding to the input buffer, placing the result in the output
224225 * buffer.
@@ -426,6 +427,7 @@ static int we_rsa_add_x931_hash_code(const EVP_MD* md, unsigned char** to,
426427
427428 return ret ;
428429}
430+ #endif /* WE_HAVE_RSA_X931 */
429431
430432/**
431433 * Set the public key in a we_Rsa structure.
@@ -1015,11 +1017,13 @@ static int we_rsa_priv_enc_int(size_t fromLen, const unsigned char *from,
10151017 WC_RNG * rng = we_rng ;
10161018#endif
10171019 char errBuff [WOLFENGINE_MAX_LOG_WIDTH ];
1020+ #ifdef WE_HAVE_RSA_X931
10181021 unsigned char * padded = NULL ;
10191022 int paddedSz ;
10201023 mp_int toMp ;
10211024 mp_int nMinusTo ;
10221025 int rc ;
1026+ #endif
10231027
10241028 WOLFENGINE_ENTER (WE_LOG_PK , "we_rsa_priv_enc_int" );
10251029 WOLFENGINE_MSG_VERBOSE (WE_LOG_PK , "ARGS [fromLen = %zu, from = %p, "
@@ -1081,6 +1085,7 @@ static int we_rsa_priv_enc_int(size_t fromLen, const unsigned char *from,
10811085 }
10821086 }
10831087 break ;
1088+ #ifdef WE_HAVE_RSA_X931
10841089 case RSA_X931_PADDING :
10851090 WOLFENGINE_MSG (WE_LOG_PK , "padMode: RSA_X931_PADDING" );
10861091 paddedSz = wc_RsaEncryptSize (& rsa -> key );
@@ -1154,8 +1159,8 @@ static int we_rsa_priv_enc_int(size_t fromLen, const unsigned char *from,
11541159 mp_free (& nMinusTo );
11551160 }
11561161 }
1157-
11581162 break ;
1163+ #endif /* WE_HAVE_RSA_X931 */
11591164 default :
11601165 /* Unsupported padding mode for RSA private encryption. */
11611166 WOLFENGINE_ERROR_MSG (WE_LOG_PK ,
@@ -1279,10 +1284,12 @@ static int we_rsa_pub_dec_int(size_t fromLen, const unsigned char *from,
12791284 WC_RNG * rng = we_rng ;
12801285#endif
12811286 char errBuff [WOLFENGINE_MAX_LOG_WIDTH ];
1287+ #ifdef WE_HAVE_RSA_X931
12821288 unsigned char * unpadded = NULL ;
12831289 mp_int toMp ;
12841290 mp_int nMinusTo ;
12851291 int rc ;
1292+ #endif
12861293
12871294 WOLFENGINE_ENTER (WE_LOG_PK , "we_rsa_pub_dec_int" );
12881295 WOLFENGINE_MSG_VERBOSE (WE_LOG_PK , "ARGS [fromLen = %zu, from = %p, "
@@ -1357,6 +1364,7 @@ static int we_rsa_pub_dec_int(size_t fromLen, const unsigned char *from,
13571364 }
13581365 }
13591366 break ;
1367+ #ifdef WE_HAVE_RSA_X931
13601368 case RSA_X931_PADDING :
13611369 WOLFENGINE_MSG (WE_LOG_PK , "padMode: RSA_X931_PADDING" );
13621370 ret = wc_RsaDirect ((byte * )from , (unsigned int )fromLen , to ,
@@ -1424,6 +1432,7 @@ static int we_rsa_pub_dec_int(size_t fromLen, const unsigned char *from,
14241432 }
14251433 }
14261434 break ;
1435+ #endif /* WE_HAVE_RSA_X931 */
14271436 default :
14281437 /* Unsupported padding mode for RSA public decryption. */
14291438 XSNPRINTF (errBuff , sizeof (errBuff ), "Unknown padding mode: %d" ,
@@ -2008,8 +2017,11 @@ static int we_rsa_pkey_ctrl(EVP_PKEY_CTX *ctx, int type, int num, void *ptr)
20082017 if (num != RSA_PKCS1_PADDING &&
20092018 num != RSA_PKCS1_PSS_PADDING &&
20102019 num != RSA_PKCS1_OAEP_PADDING &&
2011- num != RSA_NO_PADDING &&
2012- num != RSA_X931_PADDING )
2020+ num != RSA_NO_PADDING
2021+ #ifdef WE_HAVE_RSA_X931
2022+ && num != RSA_X931_PADDING
2023+ #endif
2024+ )
20132025 {
20142026 WOLFENGINE_ERROR_MSG (WE_LOG_PK ,
20152027 "Unsupported RSA padding mode." );
@@ -2298,9 +2310,11 @@ static int we_rsa_pkey_ctrl_str(EVP_PKEY_CTX *ctx, const char *type,
22982310 else if (XSTRNCMP (value , "pss" , 4 ) == 0 ) {
22992311 rsa -> padMode = RSA_PKCS1_PSS_PADDING ;
23002312 }
2313+ #ifdef WE_HAVE_RSA_X931
23012314 else if (XSTRNCMP (value , "x931 ", 5 ) == 0 ) {
23022315 rsa -> padMode = RSA_X931_PADDING ;
23032316 }
2317+ #endif
23042318 else {
23052319 ret = 0 ;
23062320 }
@@ -2568,6 +2582,7 @@ static int we_rsa_pkey_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
25682582 }
25692583 }
25702584 if (ret == 1 ) {
2585+ #ifdef WE_HAVE_RSA_X931
25712586 if (rsa -> padMode == RSA_X931_PADDING ) {
25722587 if (rsa -> md == NULL ) {
25732588 WOLFENGINE_ERROR_MSG (WE_LOG_PK , "No digest specified for "
@@ -2588,6 +2603,7 @@ static int we_rsa_pkey_sign(EVP_PKEY_CTX *ctx, unsigned char *sig,
25882603 }
25892604 }
25902605 }
2606+ #endif
25912607 /* Pad and private encrypt. */
25922608 actualSigLen = we_rsa_priv_enc_int (tbsLen , tbs , * sigLen , sig , rsa );
25932609 if (actualSigLen == -1 ) {
@@ -2637,9 +2653,11 @@ static int we_rsa_pkey_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
26372653 unsigned char * encodedDigest = NULL;
26382654 int encodedDigestLen = 0 ;
26392655 int keySize = 0 ;
2656+ #ifdef WE_HAVE_RSA_X931
26402657 int nid ;
26412658 unsigned char hashCode ;
26422659 char errBuff [WOLFENGINE_MAX_LOG_WIDTH ];
2660+ #endif
26432661
26442662 WOLFENGINE_ENTER (WE_LOG_PK , "we_rsa_pkey_verify ");
26452663 WOLFENGINE_MSG_VERBOSE (WE_LOG_PK , "ARGS [ctx = %p, sig = %p, sigLen = %zu, "
@@ -2744,6 +2762,7 @@ static int we_rsa_pkey_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
27442762 tbsLen = encodedDigestLen ;
27452763 }
27462764 }
2765+ #ifdef WE_HAVE_RSA_X931
27472766 if (ret == 1 && rsa -> padMode == RSA_X931_PADDING ) {
27482767 if (rsa -> md == NULL ) {
27492768 WOLFENGINE_ERROR_MSG (WE_LOG_PK , "No digest specified for "
@@ -2778,6 +2797,7 @@ static int we_rsa_pkey_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig,
27782797 }
27792798 }
27802799 }
2800+ #endif
27812801 if ((ret == 1 ) && (tbsLen != (size_t )rc )) {
27822802 WOLFENGINE_ERROR_MSG (WE_LOG_PK , "Encoding different size" );
27832803 ret = 0 ;
0 commit comments