1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "crypto/ec_signature_creator.h"
13 #include "crypto/ec_private_key.h"
14 #include "crypto/signature_verifier.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 // TODO(rch): Add some exported keys from each to
18 // test interop between NSS and OpenSSL.
20 TEST(ECSignatureCreatorTest, BasicTest) {
21 // Do a verify round trip.
22 std::unique_ptr<crypto::ECPrivateKey> key_original(
23 crypto::ECPrivateKey::Create());
24 ASSERT_TRUE(key_original);
26 std::vector<uint8_t> key_info;
27 ASSERT_TRUE(key_original->ExportPrivateKey(&key_info));
29 std::unique_ptr<crypto::ECPrivateKey> key(
30 crypto::ECPrivateKey::CreateFromPrivateKeyInfo(key_info));
32 ASSERT_TRUE(key->key());
34 std::unique_ptr<crypto::ECSignatureCreator> signer(
35 crypto::ECSignatureCreator::Create(key.get()));
38 std::string data("Hello, World!");
39 std::vector<uint8_t> signature;
40 ASSERT_TRUE(signer->Sign(base::as_bytes(base::make_span(data)), &signature));
42 std::vector<uint8_t> public_key_info;
43 ASSERT_TRUE(key_original->ExportPublicKey(&public_key_info));
45 crypto::SignatureVerifier verifier;
46 ASSERT_TRUE(verifier.VerifyInit(crypto::SignatureVerifier::ECDSA_SHA256,
47 signature, public_key_info));
49 verifier.VerifyUpdate(base::as_bytes(base::make_span(data)));
50 ASSERT_TRUE(verifier.VerifyFinal());