Skip to content

Commit dcdf6d2

Browse files
committed
Align even modulus test guard and MP_VAL docs with sp_exptmod_nct
1 parent ee291fa commit dcdf6d2

2 files changed

Lines changed: 22 additions & 18 deletions

File tree

‎wolfcrypt/src/sp_int.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14200,7 +14200,7 @@ static int _sp_exptmod_base_2(const sp_int* e, int digits, const sp_int* m,
1420014200
* @return MP_OKAY on success.
1420114201
* @return MP_VAL when b, e, m or r is NULL, digits is negative, or m <= 0 or
1420214202
* e is negative; or m is even in an RSA verify/public only build
14203-
* without DH.
14203+
* without DH or OPENSSL_ALL.
1420414204
* @return MP_MEM when dynamic memory allocation fails.
1420514205
*/
1420614206
int sp_exptmod_ex(const sp_int* b, const sp_int* e, int digits, const sp_int* m,
@@ -14380,7 +14380,9 @@ int sp_exptmod_ex(const sp_int* b, const sp_int* e, int digits, const sp_int* m,
1438014380
* @param [out] r SP integer to hold result.
1438114381
*
1438214382
* @return MP_OKAY on success.
14383-
* @return MP_VAL when b, e, m or r is NULL; or m <= 0 or e is negative.
14383+
* @return MP_VAL when b, e, m or r is NULL; or m <= 0 or e is negative; or
14384+
* m is even in an RSA verify/public only build without DH or
14385+
* OPENSSL_ALL.
1438414386
* @return MP_MEM when dynamic memory allocation fails.
1438514387
*/
1438614388
int sp_exptmod(const sp_int* b, const sp_int* e, const sp_int* m, sp_int* r)
@@ -14841,7 +14843,8 @@ static int _sp_exptmod_nct(const sp_int* b, const sp_int* e, const sp_int* m,
1484114843
*
1484214844
* @return MP_OKAY on success.
1484314845
* @return MP_VAL when b, e, m or r is NULL; or m <= 0 or e is negative; or
14844-
* m is even in an RSA verify/public only build without DH.
14846+
* m is even in an RSA verify/public only build without DH or
14847+
* OPENSSL_ALL.
1484514848
* @return MP_MEM when dynamic memory allocation fails.
1484614849
*/
1484714850
int sp_exptmod_nct(const sp_int* b, const sp_int* e, const sp_int* m, sp_int* r)
@@ -14888,19 +14891,18 @@ int sp_exptmod_nct(const sp_int* b, const sp_int* e, const sp_int* m, sp_int* r)
1488814891
else if (m->used * 2 >= r->size) {
1488914892
err = MP_VAL;
1489014893
}
14894+
else if (mp_iseven(m)) {
1489114895
#if (defined(WOLFSSL_SP_MATH_ALL) && !defined(WOLFSSL_RSA_VERIFY_ONLY) && \
1489214896
!defined(WOLFSSL_RSA_PUBLIC_ONLY)) || !defined(NO_DH) || \
1489314897
defined(OPENSSL_ALL)
14894-
else if (mp_iseven(m)) {
1489514898
err = _sp_exptmod_ex(b, e, (int)(e->used * SP_WORD_SIZE), m, r);
14896-
}
1489714899
#else
14898-
/* Montgomery form requires an odd modulus and the generic implementation
14899-
* is not compiled in (RSA verify/public only without DH). */
14900-
else if (mp_iseven(m)) {
14900+
/* Montgomery form requires an odd modulus and the generic
14901+
* implementation is not compiled in (RSA verify/public only without
14902+
* DH). */
1490114903
err = MP_VAL;
14902-
}
1490314904
#endif
14905+
}
1490414906
else {
1490514907
err = _sp_exptmod_nct(b, e, m, r);
1490614908
}

‎wolfcrypt/test/test.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95261,17 +95261,11 @@ static wc_test_ret_t mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r,
9526195261
if ((ret = mp_set(m, 1)) != MP_OKAY ||
9526295262
(ret = mp_mul_2d(m, 521, m)) != MP_OKAY || /* m = 2^521 (even) */
9526395263
(ret = mp_set(b, 7)) != MP_OKAY ||
95264-
(ret = mp_set(e, 6)) != MP_OKAY ||
95265-
(ret = mp_set(t, 1)) != MP_OKAY) {
95264+
(ret = mp_set(e, 6)) != MP_OKAY) {
9526695265
return WC_TEST_RET_ENC_EC(ret);
9526795266
}
95268-
for (k = 0; k < 6; k++) {
95269-
if ((ret = mp_mulmod(t, b, m, t)) != MP_OKAY) {
95270-
return WC_TEST_RET_ENC_EC(ret);
95271-
}
95272-
}
95273-
#if defined(WOLFSSL_RSA_PUBLIC_ONLY) && defined(NO_DH) && \
95274-
!defined(OPENSSL_ALL)
95267+
#if (defined(WOLFSSL_RSA_VERIFY_ONLY) || defined(WOLFSSL_RSA_PUBLIC_ONLY)) && \
95268+
defined(NO_DH) && !defined(OPENSSL_ALL)
9527595269
ret = mp_exptmod_ex(b, e, (int)e->used, m, r);
9527695270
if (ret != WC_NO_ERR_TRACE(MP_VAL)) {
9527795271
return WC_TEST_RET_ENC_EC(ret);
@@ -95281,6 +95275,14 @@ static wc_test_ret_t mp_test_exptmod(mp_int* b, mp_int* e, mp_int* m, mp_int* r,
9528195275
return WC_TEST_RET_ENC_EC(ret);
9528295276
}
9528395277
#else
95278+
if ((ret = mp_set(t, 1)) != MP_OKAY) {
95279+
return WC_TEST_RET_ENC_EC(ret);
95280+
}
95281+
for (k = 0; k < 6; k++) {
95282+
if ((ret = mp_mulmod(t, b, m, t)) != MP_OKAY) {
95283+
return WC_TEST_RET_ENC_EC(ret);
95284+
}
95285+
}
9528495286
if ((ret = mp_exptmod_ex(b, e, (int)e->used, m, r)) != MP_OKAY) {
9528595287
return WC_TEST_RET_ENC_EC(ret);
9528695288
}

0 commit comments

Comments
 (0)