提交 eb1f1b0a 编写于 作者: B Bodo Möller

Fix BN_kronecker so that it works correctly if 'a' is negative

(we need the two's complement of BN_lsw then).
上级 a9376dbf
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{ {
int i; int i;
int ret; int ret = -2; /* avoid 'uninitialized' warning */
int err = 0; int err = 0;
BIGNUM *A, *B, *tmp; BIGNUM *A, *B, *tmp;
/* In 'tab', only odd-indexed entries are relevant: /* In 'tab', only odd-indexed entries are relevant:
...@@ -165,7 +165,7 @@ int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) ...@@ -165,7 +165,7 @@ int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
/* Cohen's step 4: */ /* Cohen's step 4: */
/* multiply 'ret' by $(-1)^{(A-1)(B-1)/4}$ */ /* multiply 'ret' by $(-1)^{(A-1)(B-1)/4}$ */
if (BN_lsw(A) & BN_lsw(B) & 2) if ((A->neg ? ~BN_lsw(A) : BN_lsw(A)) & BN_lsw(B) & 2)
ret = -ret; ret = -ret;
/* (A, B) := (B mod |A|, |A|) */ /* (A, B) := (B mod |A|, |A|) */
......
...@@ -949,7 +949,7 @@ int test_kron(BIO *bp, BN_CTX *ctx) ...@@ -949,7 +949,7 @@ int test_kron(BIO *bp, BN_CTX *ctx)
for (i = 0; i < num0; i++) for (i = 0; i < num0; i++)
{ {
if (!BN_rand(a, 512, 0, 0)) goto err; if (!BN_rand(a, 512, 0, 0)) goto err;
if (!BN_nnmod(a, a, b, ctx)) goto err; a->neg = rand_neg();
/* r := (b-1)/2 (note that b is odd) */ /* r := (b-1)/2 (note that b is odd) */
if (!BN_copy(r, b)) goto err; if (!BN_copy(r, b)) goto err;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册