Don't allow BN_mod_sqrt(0) to return P in tests.
Zero only has one allowed square root, not two. Change-Id: I1dbd2137a7011d2f327b271b267099771e5499c3 Reviewed-on: https://boringssl-review.googlesource.com/12461 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
parent
3d622e554e
commit
55a1eccc0c
@ -568,21 +568,25 @@ static bool TestModSqrt(FileTest *t, BN_CTX *ctx) {
|
||||
bssl::UniquePtr<BIGNUM> a = GetBIGNUM(t, "A");
|
||||
bssl::UniquePtr<BIGNUM> p = GetBIGNUM(t, "P");
|
||||
bssl::UniquePtr<BIGNUM> mod_sqrt = GetBIGNUM(t, "ModSqrt");
|
||||
if (!a || !p || !mod_sqrt) {
|
||||
bssl::UniquePtr<BIGNUM> mod_sqrt2(BN_new());
|
||||
if (!a || !p || !mod_sqrt || !mod_sqrt2 ||
|
||||
// There are two possible answers.
|
||||
!BN_sub(mod_sqrt2.get(), p.get(), mod_sqrt.get())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// -0 is 0, not P.
|
||||
if (BN_is_zero(mod_sqrt.get())) {
|
||||
BN_zero(mod_sqrt2.get());
|
||||
}
|
||||
|
||||
bssl::UniquePtr<BIGNUM> ret(BN_new());
|
||||
bssl::UniquePtr<BIGNUM> ret2(BN_new());
|
||||
if (!ret ||
|
||||
!ret2 ||
|
||||
!BN_mod_sqrt(ret.get(), a.get(), p.get(), ctx) ||
|
||||
// There are two possible answers.
|
||||
!BN_sub(ret2.get(), p.get(), ret.get())) {
|
||||
!BN_mod_sqrt(ret.get(), a.get(), p.get(), ctx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (BN_cmp(ret2.get(), mod_sqrt.get()) != 0 &&
|
||||
if (BN_cmp(ret.get(), mod_sqrt2.get()) != 0 &&
|
||||
!ExpectBIGNUMsEqual(t, "sqrt(A) (mod P)", mod_sqrt.get(), ret.get())) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user