1 // Copyright 2017 Google Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 /////////////////////////////////////////////////////////////////////////////// 16 #ifndef TINK_SIGNATURE_ECDSA_VERIFY_KEY_MANAGER_H_ 17 #define TINK_SIGNATURE_ECDSA_VERIFY_KEY_MANAGER_H_ 18 19 #include <memory> 20 #include <string> 21 22 #include "absl/memory/memory.h" 23 #include "absl/strings/str_cat.h" 24 #include "tink/core/key_type_manager.h" 25 #include "tink/public_key_verify.h" 26 #include "tink/util/constants.h" 27 #include "tink/util/errors.h" 28 #include "tink/util/protobuf_helper.h" 29 #include "tink/util/status.h" 30 #include "tink/util/statusor.h" 31 #include "proto/ecdsa.pb.h" 32 33 namespace crypto { 34 namespace tink { 35 36 class EcdsaVerifyKeyManager 37 : public KeyTypeManager<google::crypto::tink::EcdsaPublicKey, void, 38 List<PublicKeyVerify>> { 39 public: 40 class PublicKeyVerifyFactory : public PrimitiveFactory<PublicKeyVerify> { 41 crypto::tink::util::StatusOr<std::unique_ptr<PublicKeyVerify>> Create( 42 const google::crypto::tink::EcdsaPublicKey& ecdsa_public_key) 43 const override; 44 }; 45 EcdsaVerifyKeyManager()46 EcdsaVerifyKeyManager() 47 : KeyTypeManager(absl::make_unique<PublicKeyVerifyFactory>()) {} 48 get_version()49 uint32_t get_version() const override { return 0; } 50 key_material_type()51 google::crypto::tink::KeyData::KeyMaterialType key_material_type() 52 const override { 53 return google::crypto::tink::KeyData::ASYMMETRIC_PUBLIC; 54 } 55 get_key_type()56 const std::string& get_key_type() const override { return key_type_; } 57 58 crypto::tink::util::Status ValidateKey( 59 const google::crypto::tink::EcdsaPublicKey& key) const override; 60 61 crypto::tink::util::Status ValidateParams( 62 const google::crypto::tink::EcdsaParams& params) const; 63 FipsStatus()64 internal::FipsCompatibility FipsStatus() const override { 65 return internal::FipsCompatibility::kRequiresBoringCrypto; 66 } 67 68 private: 69 const std::string key_type_ = absl::StrCat( 70 kTypeGoogleapisCom, google::crypto::tink::EcdsaPublicKey().GetTypeName()); 71 }; 72 73 } // namespace tink 74 } // namespace crypto 75 76 #endif // TINK_SIGNATURE_ECDSA_VERIFY_KEY_MANAGER_H_ 77