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_PKCS1_SIGN_KEY_MANAGER_H_ 17 #define TINK_SIGNATURE_RSA_SSA_PKCS1_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/private_key_type_manager.h" 25 #include "tink/public_key_sign.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/rsa_ssa_pkcs1.pb.h" 32 33 namespace crypto { 34 namespace tink { 35 36 class RsaSsaPkcs1SignKeyManager 37 : public PrivateKeyTypeManager<google::crypto::tink::RsaSsaPkcs1PrivateKey, 38 google::crypto::tink::RsaSsaPkcs1KeyFormat, 39 google::crypto::tink::RsaSsaPkcs1PublicKey, 40 List<PublicKeySign>> { 41 public: 42 class PublicKeySignFactory : public PrimitiveFactory<PublicKeySign> { 43 crypto::tink::util::StatusOr<std::unique_ptr<PublicKeySign>> Create( 44 const google::crypto::tink::RsaSsaPkcs1PrivateKey& private_key) 45 const override; 46 }; 47 RsaSsaPkcs1SignKeyManager()48 RsaSsaPkcs1SignKeyManager() 49 : PrivateKeyTypeManager(absl::make_unique<PublicKeySignFactory>()) {} 50 get_version()51 uint32_t get_version() const override { return 0; } 52 key_material_type()53 google::crypto::tink::KeyData::KeyMaterialType key_material_type() 54 const override { 55 return google::crypto::tink::KeyData::ASYMMETRIC_PRIVATE; 56 } 57 get_key_type()58 const std::string& get_key_type() const override { return key_type_; } 59 60 crypto::tink::util::Status ValidateKey( 61 const google::crypto::tink::RsaSsaPkcs1PrivateKey& key) const override; 62 63 crypto::tink::util::Status ValidateKeyFormat( 64 const google::crypto::tink::RsaSsaPkcs1KeyFormat& key_format) 65 const override; 66 67 crypto::tink::util::StatusOr<google::crypto::tink::RsaSsaPkcs1PrivateKey> 68 CreateKey(const google::crypto::tink::RsaSsaPkcs1KeyFormat& key_format) 69 const override; 70 71 crypto::tink::util::StatusOr<google::crypto::tink::RsaSsaPkcs1PublicKey> GetPublicKey(const google::crypto::tink::RsaSsaPkcs1PrivateKey & private_key)72 GetPublicKey(const google::crypto::tink::RsaSsaPkcs1PrivateKey& private_key) 73 const override { 74 return private_key.public_key(); 75 } 76 FipsStatus()77 internal::FipsCompatibility FipsStatus() const override { 78 return internal::FipsCompatibility::kRequiresBoringCrypto; 79 } 80 81 private: 82 const std::string key_type_ = 83 absl::StrCat(kTypeGoogleapisCom, 84 google::crypto::tink::RsaSsaPkcs1PrivateKey().GetTypeName()); 85 }; 86 87 } // namespace tink 88 } // namespace crypto 89 90 #endif // TINK_SIGNATURE_RSA_SSA_PKCS1_SIGN_KEY_MANAGER_H_ 91