未验证 提交 4bb4fd6b 编写于 作者: O openharmony_ci 提交者: Gitee

!34 fix CVE-2022-0778

Merge pull request !34 from HaixiangW/cherry-pick-1647873389
...@@ -14,7 +14,8 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) ...@@ -14,7 +14,8 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
/* /*
* Returns 'ret' such that ret^2 == a (mod p), using the Tonelli/Shanks * Returns 'ret' such that ret^2 == a (mod p), using the Tonelli/Shanks
* algorithm (cf. Henri Cohen, "A Course in Algebraic Computational Number * algorithm (cf. Henri Cohen, "A Course in Algebraic Computational Number
* Theory", algorithm 1.5.1). 'p' must be prime! * Theory", algorithm 1.5.1). 'p' must be prime, otherwise an error or
* an incorrect "result" will be returned.
*/ */
{ {
BIGNUM *ret = in; BIGNUM *ret = in;
...@@ -301,17 +302,22 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) ...@@ -301,17 +302,22 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
goto vrfy; goto vrfy;
} }
/* find smallest i such that b^(2^i) = 1 */ /* Find the smallest i, 0 < i < e, such that b^(2^i) = 1. */
i = 1; for (i = 1; i < e; i++) {
if (i == 1) {
if (!BN_mod_sqr(t, b, p, ctx)) if (!BN_mod_sqr(t, b, p, ctx))
goto end; goto end;
while (!BN_is_one(t)) {
i++; } else {
if (i == e) { if (!BN_mod_mul(t, t, t, p, ctx))
BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
goto end; goto end;
} }
if (!BN_mod_mul(t, t, t, p, ctx)) if (BN_is_one(t))
break;
}
/* If not found, a is not a square or p is not prime. */
if (i >= e) {
BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
goto end; goto end;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册