forked from wolfSSL/wolfssl
1. Added the pair-wise consistency test to the RSA Key Gen.
2. Modified an RSA key size test case so it didn't try to make a key that was too big.
This commit is contained in:
@ -10298,8 +10298,6 @@ static int test_wc_RsaEncryptSize (void)
|
|||||||
#if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
|
#if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
|
||||||
RsaKey key;
|
RsaKey key;
|
||||||
WC_RNG rng;
|
WC_RNG rng;
|
||||||
int enc128 = 128;
|
|
||||||
int enc512 = 512;
|
|
||||||
|
|
||||||
ret = wc_InitRsaKey(&key, NULL);
|
ret = wc_InitRsaKey(&key, NULL);
|
||||||
|
|
||||||
@ -10313,7 +10311,7 @@ static int test_wc_RsaEncryptSize (void)
|
|||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
ret = wc_RsaEncryptSize(&key);
|
ret = wc_RsaEncryptSize(&key);
|
||||||
}
|
}
|
||||||
if (ret == enc128) {
|
if (ret == 128) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
} else {
|
} else {
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
@ -10326,11 +10324,11 @@ static int test_wc_RsaEncryptSize (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
ret = MAKE_RSA_KEY(&key, FOURK_BUF, WC_RSA_EXPONENT, &rng);
|
ret = MAKE_RSA_KEY(&key, 2048, WC_RSA_EXPONENT, &rng);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
ret = wc_RsaEncryptSize(&key);
|
ret = wc_RsaEncryptSize(&key);
|
||||||
}
|
}
|
||||||
if (ret == enc512) {
|
if (ret == 256) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
} else {
|
} else {
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
|
@ -411,6 +411,7 @@ int wc_FreeRsaKey(RsaKey* key)
|
|||||||
|
|
||||||
|
|
||||||
/* Check the pair-wise consistency of the RSA key.
|
/* Check the pair-wise consistency of the RSA key.
|
||||||
|
* From NIST SP 800-56B, section 6.4.1.1.
|
||||||
* Verify that k = (k^e)^d, for some k: 1 < k < n-1. */
|
* Verify that k = (k^e)^d, for some k: 1 < k < n-1. */
|
||||||
int wc_CheckRsaKey(RsaKey* key)
|
int wc_CheckRsaKey(RsaKey* key)
|
||||||
{
|
{
|
||||||
@ -2901,7 +2902,11 @@ int wc_MakeRsaKey(RsaKey* key, int size, long e, WC_RNG* rng)
|
|||||||
mp_clear(&p);
|
mp_clear(&p);
|
||||||
mp_clear(&q);
|
mp_clear(&q);
|
||||||
|
|
||||||
if (err != MP_OKAY) {
|
/* Perform the pair-wise consistency test on the new key. */
|
||||||
|
if (err == 0)
|
||||||
|
err = wc_CheckRsaKey(key);
|
||||||
|
|
||||||
|
if (err != 0) {
|
||||||
wc_FreeRsaKey(key);
|
wc_FreeRsaKey(key);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user