RSA/DH test: even number error check fixup

Configuration: --enable-sp=3072
Test only enabled when SP is used.
Return codes checked are those we expect from SP.
Code, with configuration, is compiled so that 2048-bit operations are
not going to SP and the error returns were not correct.
This commit is contained in:
Sean Parkinson
2021-01-06 09:39:24 +10:00
parent 54f072fd8d
commit 10722fba14

View File

@@ -13305,12 +13305,12 @@ static int rsa_even_mod_test(WC_RNG* rng, RsaKey* key)
outSz = wc_RsaEncryptSize(key); outSz = wc_RsaEncryptSize(key);
XMEMSET(tmp, 7, plainSz); XMEMSET(tmp, 7, plainSz);
ret = wc_RsaSSL_Sign(tmp, inLen, out, outSz, key, rng); ret = wc_RsaSSL_Sign(tmp, inLen, out, outSz, key, rng);
if (ret != MP_VAL) { if (ret != MP_VAL && ret != MP_EXPTMOD_E && ret != MP_INVMOD_E) {
ERROR_OUT(-7806, exit_rsa_even_mod); ERROR_OUT(-7806, exit_rsa_even_mod);
} }
ret = wc_RsaSSL_Verify(out, outSz, tmp, inLen, key); ret = wc_RsaSSL_Verify(out, outSz, tmp, inLen, key);
if (ret != MP_VAL) { if (ret != MP_VAL && ret != MP_EXPTMOD_E) {
ERROR_OUT(-7808, exit_rsa_even_mod); ERROR_OUT(-7808, exit_rsa_even_mod);
} }
#endif #endif
@@ -13325,14 +13325,14 @@ static int rsa_even_mod_test(WC_RNG* rng, RsaKey* key)
/* test encrypt and decrypt using WC_RSA_NO_PAD */ /* test encrypt and decrypt using WC_RSA_NO_PAD */
#ifndef WOLFSSL_RSA_VERIFY_ONLY #ifndef WOLFSSL_RSA_VERIFY_ONLY
ret = wc_RsaPublicEncrypt(tmp, inLen, out, (int)outSz, key, rng); ret = wc_RsaPublicEncrypt(tmp, inLen, out, (int)outSz, key, rng);
if (ret != MP_VAL) { if (ret != MP_VAL && ret != MP_EXPTMOD_E) {
ERROR_OUT(-7812, exit_rsa_even_mod); ERROR_OUT(-7812, exit_rsa_even_mod);
} }
#endif /* WOLFSSL_RSA_VERIFY_ONLY */ #endif /* WOLFSSL_RSA_VERIFY_ONLY */
#ifndef WOLFSSL_RSA_PUBLIC_ONLY #ifndef WOLFSSL_RSA_PUBLIC_ONLY
ret = wc_RsaPrivateDecrypt(out, outSz, plain, (int)plainSz, key); ret = wc_RsaPrivateDecrypt(out, outSz, plain, (int)plainSz, key);
if (ret != MP_VAL) { if (ret != MP_VAL && ret != MP_EXPTMOD_E && ret != MP_INVMOD_E) {
ERROR_OUT(-7813, exit_rsa_even_mod); ERROR_OUT(-7813, exit_rsa_even_mod);
} }
#endif /* WOLFSSL_RSA_PUBLIC_ONLY */ #endif /* WOLFSSL_RSA_PUBLIC_ONLY */
@@ -15618,23 +15618,24 @@ static int dh_ffdhe_test(WC_RNG *rng, const DhParams* params)
} }
#ifdef WOLFSSL_HAVE_SP_DH #ifdef WOLFSSL_HAVE_SP_DH
/* Make p even */
key->p.dp[0] &= (mp_digit)-2; key->p.dp[0] &= (mp_digit)-2;
if (ret != 0) { if (ret != 0) {
ERROR_OUT(-8058, done); ERROR_OUT(-8058, done);
} }
ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz); ret = wc_DhGenerateKeyPair(key, rng, priv, &privSz, pub, &pubSz);
if (ret != MP_VAL) { if (ret != MP_VAL && ret != MP_EXPTMOD_E) {
ERROR_OUT(-8058, done); ERROR_OUT(-8058, done);
} }
ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2); ret = wc_DhAgree(key, agree, &agreeSz, priv, privSz, pub2, pubSz2);
if (ret != MP_VAL) { if (ret != MP_VAL && ret != MP_EXPTMOD_E) {
ERROR_OUT(-8057, done); ERROR_OUT(-8057, done);
} }
ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz); ret = wc_DhCheckKeyPair(key, pub, pubSz, priv, privSz);
if (ret != MP_EXPTMOD_E) { if (ret != MP_VAL && ret != MP_EXPTMOD_E) {
ERROR_OUT(-8057, done); ERROR_OUT(-8057, done);
} }