Convert ed25519_test to GTest.

BUG=129

Change-Id: I784a745f102d9d09d35b27542d94b2b85dfb332e
Reviewed-on: https://boringssl-review.googlesource.com/16508
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
David Benjamin 2017-05-22 16:33:29 -04:00 committed by Adam Langley
parent 3ecd0a5fca
commit 8c2e8282ab
5 changed files with 25 additions and 58 deletions

View File

@ -244,6 +244,7 @@ add_executable(
cmac/cmac_test.cc
compiler_test.cc
constant_time_test.cc
curve25519/ed25519_test.cc
curve25519/spake25519_test.cc
curve25519/x25519_test.cc
dh/dh_test.cc

View File

@ -27,13 +27,3 @@ add_library(
${CURVE25519_ARCH_SOURCES}
)
add_executable(
ed25519_test
ed25519_test.cc
$<TARGET_OBJECTS:test_support>
)
target_link_libraries(ed25519_test crypto)
add_dependencies(all_tests ed25519_test)

View File

@ -15,46 +15,36 @@
#include <stdint.h>
#include <string.h>
#include <gtest/gtest.h>
#include <openssl/curve25519.h>
#include "../internal.h"
#include "../test/file_test.h"
#include "../test/test_util.h"
static bool TestSignature(FileTest *t, void *arg) {
TEST(Ed25519Test, TestVectors) {
FileTestGTest("crypto/curve25519/ed25519_tests.txt", [](FileTest *t) {
std::vector<uint8_t> private_key, public_key, message, expected_signature;
if (!t->GetBytes(&private_key, "PRIV") ||
private_key.size() != 64 ||
!t->GetBytes(&public_key, "PUB") ||
public_key.size() != 32 ||
!t->GetBytes(&message, "MESSAGE") ||
!t->GetBytes(&expected_signature, "SIG") ||
expected_signature.size() != 64) {
return false;
}
ASSERT_TRUE(t->GetBytes(&private_key, "PRIV"));
ASSERT_EQ(64u, private_key.size());
ASSERT_TRUE(t->GetBytes(&public_key, "PUB"));
ASSERT_EQ(32u, public_key.size());
ASSERT_TRUE(t->GetBytes(&message, "MESSAGE"));
ASSERT_TRUE(t->GetBytes(&expected_signature, "SIG"));
ASSERT_EQ(64u, expected_signature.size());
uint8_t signature[64];
if (!ED25519_sign(signature, message.data(), message.size(),
private_key.data())) {
t->PrintLine("ED25519_sign failed");
return false;
}
if (!t->ExpectBytesEqual(expected_signature.data(), expected_signature.size(),
signature, sizeof(signature))) {
return false;
}
if (!ED25519_verify(message.data(), message.size(), signature,
public_key.data())) {
t->PrintLine("ED25519_verify failed");
return false;
}
return true;
ASSERT_TRUE(ED25519_sign(signature, message.data(), message.size(),
private_key.data()));
EXPECT_EQ(Bytes(expected_signature), Bytes(signature));
EXPECT_TRUE(ED25519_verify(message.data(), message.size(), signature,
public_key.data()));
});
}
static bool TestKeypairFromSeed() {
TEST(Ed25519Test, KeypairFromSeed) {
uint8_t public_key1[32], private_key1[64];
ED25519_keypair(public_key1, private_key1);
@ -64,20 +54,6 @@ static bool TestKeypairFromSeed() {
uint8_t public_key2[32], private_key2[64];
ED25519_keypair_from_seed(public_key2, private_key2, seed);
if (OPENSSL_memcmp(public_key1, public_key2, sizeof(public_key1)) != 0 ||
OPENSSL_memcmp(private_key1, private_key2, sizeof(private_key1)) != 0) {
fprintf(stderr, "TestKeypairFromSeed: resulting keypairs did not match.\n");
return false;
}
return true;
}
int main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "%s <test input.txt>\n", argv[0]);
return 1;
}
return TestKeypairFromSeed() && FileTestMain(TestSignature, nullptr, argv[1]);
EXPECT_EQ(Bytes(public_key1), Bytes(public_key2));
EXPECT_EQ(Bytes(private_key1), Bytes(private_key2));
}

View File

@ -6,5 +6,6 @@
set(
CRYPTO_TEST_DATA
crypto/curve25519/ed25519_tests.txt
crypto/fipsmodule/aes/aes_tests.txt
)

View File

@ -32,7 +32,6 @@
["crypto/cipher_extra/cipher_test", "crypto/cipher_extra/test/nist_cavp/tdes_cbc.txt"],
["crypto/cipher_extra/cipher_test", "crypto/cipher_extra/test/nist_cavp/tdes_ecb.txt"],
["crypto/crypto_test"],
["crypto/curve25519/ed25519_test", "crypto/curve25519/ed25519_tests.txt"],
["crypto/ecdh/ecdh_test", "crypto/ecdh/ecdh_tests.txt"],
["crypto/evp/evp_test", "crypto/evp/evp_tests.txt"],
["crypto/evp/pbkdf_test"],