Merge pull request #3912 from miyazakh/rsa_bits_

Added RSA_bits
This commit is contained in:
Chris Conlon
2021-03-26 17:00:56 -06:00
committed by GitHub
4 changed files with 24 additions and 2 deletions

View File

@ -52769,6 +52769,18 @@ int wolfSSL_RSA_size(const WOLFSSL_RSA* rsa)
}
return wc_RsaEncryptSize((RsaKey*)rsa->internal);
}
/* return RSA modulus in bits */
/* @param rsa a pointer to WOLFSSL_RSA structur */
/* @return RSA modulus size in bits, 0 if error */
int wolfSSL_RSA_bits(const WOLFSSL_RSA* rsa)
{
WOLFSSL_ENTER("wolfSSL_RSA_bits");
if (rsa == NULL)
return WOLFSSL_FAILURE;
return wolfSSL_BN_num_bits(rsa->n);
}
#endif
#if !defined(HAVE_USER_RSA) && !defined(HAVE_FAST_RSA) && \

View File

@ -33117,6 +33117,11 @@ static void test_wolfSSL_RSA(void)
AssertNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
AssertIntEQ(RSA_size(rsa), 256);
/* sanity check */
AssertIntEQ(RSA_bits(NULL), 0);
AssertIntEQ(RSA_bits(rsa), 2048);
RSA_get0_key(rsa, &n, &e, &d);
AssertPtrEq(rsa->n, n);
AssertPtrEq(rsa->e, e);
@ -33128,11 +33133,15 @@ static void test_wolfSSL_RSA(void)
AssertPtrEq(rsa->n, n);
AssertPtrEq(rsa->e, e);
AssertPtrEq(rsa->d, d);
AssertIntEQ(BN_hex2bn(&rsa->n, "1FFFFF"), 1);
AssertIntEQ(RSA_bits(rsa), 21);
RSA_free(rsa);
#if !defined(USE_FAST_MATH) || (FP_MAX_BITS >= (3072*2))
AssertNotNull(rsa = RSA_generate_key(3072, 17, NULL, NULL));
AssertIntEQ(RSA_size(rsa), 384);
AssertIntEQ(RSA_bits(rsa), 3072);
RSA_free(rsa);
#endif

View File

@ -111,6 +111,7 @@ WOLFSSL_API int wolfSSL_RSA_private_encrypt(int len, unsigned char* in,
unsigned char* out, WOLFSSL_RSA* rsa, int padding);
WOLFSSL_API int wolfSSL_RSA_size(const WOLFSSL_RSA*);
WOLFSSL_API int wolfSSL_RSA_bits(const WOLFSSL_RSA*);
WOLFSSL_API int wolfSSL_RSA_sign(int type, const unsigned char* m,
unsigned int mLen, unsigned char* sigRet,
unsigned int* sigLen, WOLFSSL_RSA*);

View File

@ -806,7 +806,7 @@ wolfSSL_X509_STORE_set_verify_cb((WOLFSSL_X509_STORE *)(s), (WOLFSSL_X509_STORE_
#define RSA_generate_key wolfSSL_RSA_generate_key
#define SSL_CTX_set_tmp_rsa_callback wolfSSL_CTX_set_tmp_rsa_callback
#define RSA_print wolfSSL_RSA_print
#define RSA_bits wolfSSL_RSA_size
#define RSA_bits wolfSSL_RSA_bits
#define RSA_up_ref wolfSSL_RSA_up_ref
#define RSA_padding_add_PKCS1_PSS wolfSSL_RSA_padding_add_PKCS1_PSS
#define RSA_verify_PKCS1_PSS wolfSSL_RSA_verify_PKCS1_PSS