1 // Copyright 2018 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_RSA_SSA_PSS_SIGN_KEY_MANAGER_H_ 17 #define TINK_SIGNATURE_RSA_SSA_PSS_SIGN_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/core/private_key_type_manager.h" 26 #include "tink/public_key_sign.h" 27 #include "tink/util/constants.h" 28 #include "tink/util/errors.h" 29 #include "tink/util/protobuf_helper.h" 30 #include "tink/util/status.h" 31 #include "tink/util/statusor.h" 32 #include "proto/rsa_ssa_pss.pb.h" 33 #include "proto/tink.pb.h" 34 35 namespace crypto { 36 namespace tink { 37 38 class RsaSsaPssSignKeyManager 39 : public PrivateKeyTypeManager<google::crypto::tink::RsaSsaPssPrivateKey, 40 google::crypto::tink::RsaSsaPssKeyFormat, 41 google::crypto::tink::RsaSsaPssPublicKey, 42 List<PublicKeySign>> { 43 public: 44 class PublicKeySignFactory : public PrimitiveFactory<PublicKeySign> { 45 crypto::tink::util::StatusOr<std::unique_ptr<PublicKeySign>> Create( 46 const google::crypto::tink::RsaSsaPssPrivateKey& private_key) 47 const override; 48 }; 49 RsaSsaPssSignKeyManager()50 RsaSsaPssSignKeyManager() 51 : PrivateKeyTypeManager(absl::make_unique<PublicKeySignFactory>()) {} 52 get_version()53 uint32_t get_version() const override { return 0; } 54 key_material_type()55 google::crypto::tink::KeyData::KeyMaterialType key_material_type() 56 const override { 57 return google::crypto::tink::KeyData::ASYMMETRIC_PRIVATE; 58 } 59 get_key_type()60 const std::string& get_key_type() const override { return key_type_; } 61 62 crypto::tink::util::Status ValidateKey( 63 const google::crypto::tink::RsaSsaPssPrivateKey& key) const override; 64 65 crypto::tink::util::Status ValidateKeyFormat( 66 const google::crypto::tink::RsaSsaPssKeyFormat& key_format) 67 const override; 68 69 crypto::tink::util::StatusOr<google::crypto::tink::RsaSsaPssPrivateKey> 70 CreateKey(const google::crypto::tink::RsaSsaPssKeyFormat& key_format) 71 const override; 72 73 crypto::tink::util::StatusOr<google::crypto::tink::RsaSsaPssPublicKey> GetPublicKey(const google::crypto::tink::RsaSsaPssPrivateKey & private_key)74 GetPublicKey(const google::crypto::tink::RsaSsaPssPrivateKey& private_key) 75 const override { 76 return private_key.public_key(); 77 } 78 FipsStatus()79 internal::FipsCompatibility FipsStatus() const override { 80 return internal::FipsCompatibility::kRequiresBoringCrypto; 81 } 82 83 private: 84 const std::string key_type_ = 85 absl::StrCat(kTypeGoogleapisCom, 86 google::crypto::tink::RsaSsaPssPrivateKey().GetTypeName()); 87 }; 88 89 } // namespace tink 90 } // namespace crypto 91 92 #endif // TINK_SIGNATURE_RSA_SSA_PSS_SIGN_KEY_MANAGER_H_ 93