From 938945238fdf94f22f908e0c97527c8ad8fd3e05 Mon Sep 17 00:00:00 2001 From: tholenst <tholenst@google.com> Date: Tue, 27 Aug 2019 04:25:10 -0700 Subject: [PATCH] Add a key format proto for Ed25519 and use it in C++. PiperOrigin-RevId: 265655364 --- cc/signature/ed25519_sign_key_manager.cc | 10 +++++----- cc/signature/ed25519_sign_key_manager_test.cc | 5 ++--- cc/signature/ed25519_verify_key_manager_test.cc | 5 ++--- cc/signature/signature_key_templates_test.cc | 7 +++---- proto/ed25519.proto | 2 ++ 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cc/signature/ed25519_sign_key_manager.cc b/cc/signature/ed25519_sign_key_manager.cc index 8950bef5d..9b9d27b65 100644 --- a/cc/signature/ed25519_sign_key_manager.cc +++ b/cc/signature/ed25519_sign_key_manager.cc @@ -31,7 +31,6 @@ #include "tink/util/statusor.h" #include "tink/util/validation.h" #include "proto/ed25519.pb.h" -#include "proto/empty.pb.h" #include "proto/tink.pb.h" namespace crypto { @@ -40,12 +39,12 @@ namespace tink { using crypto::tink::util::Status; using crypto::tink::util::StatusOr; using google::crypto::tink::Ed25519PrivateKey; -using google::crypto::tink::Empty; +using google::crypto::tink::Ed25519KeyFormat; using google::crypto::tink::KeyData; class Ed25519PrivateKeyFactory : public PrivateKeyFactory, - public KeyFactoryBase<Ed25519PrivateKey, Empty> { + public KeyFactoryBase<Ed25519PrivateKey, Ed25519KeyFormat> { public: Ed25519PrivateKeyFactory() {} @@ -61,11 +60,12 @@ class Ed25519PrivateKeyFactory protected: StatusOr<std::unique_ptr<Ed25519PrivateKey>> NewKeyFromFormat( - const Empty& unused) const override; + const Ed25519KeyFormat& unused) const override; }; StatusOr<std::unique_ptr<Ed25519PrivateKey>> -Ed25519PrivateKeyFactory::NewKeyFromFormat(const Empty& unused) const { +Ed25519PrivateKeyFactory::NewKeyFromFormat( + const Ed25519KeyFormat& unused) const { auto key = subtle::SubtleUtilBoringSSL::GetNewEd25519Key(); // Build Ed25519PrivateKey. diff --git a/cc/signature/ed25519_sign_key_manager_test.cc b/cc/signature/ed25519_sign_key_manager_test.cc index 5c1ccf6c1..36c4da86f 100644 --- a/cc/signature/ed25519_sign_key_manager_test.cc +++ b/cc/signature/ed25519_sign_key_manager_test.cc @@ -30,15 +30,14 @@ #include "proto/aes_eax.pb.h" #include "proto/common.pb.h" #include "proto/ed25519.pb.h" -#include "proto/empty.pb.h" #include "proto/tink.pb.h" namespace crypto { namespace tink { using google::crypto::tink::AesEaxKey; +using google::crypto::tink::Ed25519KeyFormat; using google::crypto::tink::Ed25519PrivateKey; -using google::crypto::tink::Empty; using google::crypto::tink::KeyData; namespace { @@ -178,7 +177,7 @@ TEST_F(Ed25519SignKeyManagerTest, testPublicKeyExtractionErrors) { TEST_F(Ed25519SignKeyManagerTest, testNewKey) { Ed25519SignKeyManager key_manager; const KeyFactory& key_factory = key_manager.get_key_factory(); - Empty key_format; + Ed25519KeyFormat key_format; auto result = key_factory.NewKey(key_format); EXPECT_TRUE(result.ok()); } diff --git a/cc/signature/ed25519_verify_key_manager_test.cc b/cc/signature/ed25519_verify_key_manager_test.cc index 77ffdb2b4..1629be082 100644 --- a/cc/signature/ed25519_verify_key_manager_test.cc +++ b/cc/signature/ed25519_verify_key_manager_test.cc @@ -27,16 +27,15 @@ #include "proto/aes_eax.pb.h" #include "proto/common.pb.h" #include "proto/ed25519.pb.h" -#include "proto/empty.pb.h" #include "proto/tink.pb.h" namespace crypto { namespace tink { using google::crypto::tink::AesEaxKey; +using google::crypto::tink::Ed25519KeyFormat; using google::crypto::tink::Ed25519PrivateKey; using google::crypto::tink::Ed25519PublicKey; -using google::crypto::tink::Empty; using google::crypto::tink::KeyData; namespace { @@ -146,7 +145,7 @@ TEST_F(Ed25519VerifyKeyManagerTest, testPrimitives) { TEST_F(Ed25519VerifyKeyManagerTest, testNewKey) { Ed25519VerifyKeyManager key_manager; const KeyFactory& key_factory = key_manager.get_key_factory(); - Empty key_format; + Ed25519KeyFormat key_format; auto result = key_factory.NewKey(key_format); EXPECT_FALSE(result.ok()); EXPECT_PRED_FORMAT2(testing::IsSubstring, diff --git a/cc/signature/signature_key_templates_test.cc b/cc/signature/signature_key_templates_test.cc index 448935dd3..7499dfa9e 100644 --- a/cc/signature/signature_key_templates_test.cc +++ b/cc/signature/signature_key_templates_test.cc @@ -29,7 +29,6 @@ #include "tink/subtle/subtle_util_boringssl.h" #include "proto/common.pb.h" #include "proto/ecdsa.pb.h" -#include "proto/empty.pb.h" #include "proto/rsa_ssa_pkcs1.pb.h" #include "proto/rsa_ssa_pss.pb.h" #include "proto/tink.pb.h" @@ -41,7 +40,7 @@ namespace { using google::crypto::tink::EcdsaKeyFormat; using google::crypto::tink::EcdsaSignatureEncoding; using google::crypto::tink::EllipticCurveType; -using google::crypto::tink::Empty; +using google::crypto::tink::Ed25519KeyFormat; using google::crypto::tink::HashType; using google::crypto::tink::KeyTemplate; using google::crypto::tink::OutputPrefixType; @@ -354,8 +353,8 @@ TEST(SignatureKeyTemplatesTest, KeyTemplatesWithEd25519) { // Check that the key manager works with the template. Ed25519SignKeyManager key_manager; EXPECT_EQ(key_manager.get_key_type(), key_template.type_url()); - Empty empty; - auto new_key_result = key_manager.get_key_factory().NewKey(empty); + Ed25519KeyFormat key_format; + auto new_key_result = key_manager.get_key_factory().NewKey(key_format); EXPECT_TRUE(new_key_result.ok()) << new_key_result.status(); } diff --git a/proto/ed25519.proto b/proto/ed25519.proto index 52a7b9ffa..19b8789d0 100644 --- a/proto/ed25519.proto +++ b/proto/ed25519.proto @@ -26,6 +26,8 @@ option java_multiple_files = true; option objc_class_prefix = "TINKPB"; option go_package = "github.com/google/tink/proto/ed25519_go_proto"; +message Ed25519KeyFormat {} + // key_type: type.googleapis.com/google.crypto.tink.Ed25519PublicKey message Ed25519PublicKey { // Required. -- GitLab