Update ECDH and EVP tests to accept latest Wycheproof vectors.

(This upstreams a change that was landed internally.)

Change-Id: Ic32793f8b1ae2d03e8ccbb0a9ac5f62add4c295b
Reviewed-on: https://boringssl-review.googlesource.com/28984
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
Adam Langley 2018-06-07 09:29:54 -07:00 committed by CQ bot account: commit-bot@chromium.org
parent 1c68fa2350
commit 070151c96f
2 changed files with 19 additions and 4 deletions

View File

@ -122,6 +122,7 @@ TEST(ECDHTest, Wycheproof) {
FileTestGTest("third_party/wycheproof_testvectors/ecdh_test.txt",
[](FileTest *t) {
t->IgnoreInstruction("curve"); // This is redundant with the per-test one.
t->IgnoreInstruction("encoding");
bssl::UniquePtr<EC_GROUP> group = GetWycheproofCurve(t, "curve", false);
ASSERT_TRUE(group);

View File

@ -425,6 +425,7 @@ static void RunWycheproofTest(const char *path) {
t->IgnoreInstruction("key.keySize");
t->IgnoreInstruction("key.wx");
t->IgnoreInstruction("key.wy");
t->IgnoreInstruction("key.uncompressed");
// Extra RSA fields.
t->IgnoreInstruction("e");
t->IgnoreInstruction("keyAsn");
@ -470,14 +471,27 @@ static void RunWycheproofTest(const char *path) {
bool sig_ok = DSA_check_signature(&valid, digest, digest_len, sig.data(),
sig.size(), dsa) &&
valid;
EXPECT_EQ(result == WycheproofResult::kValid, sig_ok);
if (result == WycheproofResult::kValid) {
EXPECT_TRUE(sig_ok);
} else if (result == WycheproofResult::kInvalid) {
EXPECT_FALSE(sig_ok);
} else {
// this is a legacy signature, which may or may not be accepted.
}
} else {
bssl::ScopedEVP_MD_CTX ctx;
ASSERT_TRUE(
EVP_DigestVerifyInit(ctx.get(), nullptr, md, nullptr, key.get()));
EXPECT_EQ(result == WycheproofResult::kValid ? 1 : 0,
EVP_DigestVerify(ctx.get(), sig.data(), sig.size(), msg.data(),
msg.size()));
int ret = EVP_DigestVerify(ctx.get(), sig.data(), sig.size(), msg.data(),
msg.size());
if (result == WycheproofResult::kValid) {
EXPECT_EQ(1, ret);
} else if (result == WycheproofResult::kInvalid) {
EXPECT_EQ(0, ret);
} else {
// this is a legacy signature, which may or may not be accepted.
EXPECT_TRUE(ret == 1 || ret == 0);
}
}
});
}