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 17 #ifndef TINK_SUBTLE_RSA_SSA_PSS_SIGN_BORINGSSL_H_ 18 #define TINK_SUBTLE_RSA_SSA_PSS_SIGN_BORINGSSL_H_ 19 20 #include <memory> 21 #include <string> 22 #include <utility> 23 24 #include "absl/strings/string_view.h" 25 #include "openssl/ec.h" 26 #include "openssl/rsa.h" 27 #include "tink/internal/fips_utils.h" 28 #include "tink/internal/rsa_util.h" 29 #include "tink/internal/ssl_unique_ptr.h" 30 #include "tink/public_key_sign.h" 31 #include "tink/subtle/common_enums.h" 32 #include "tink/util/statusor.h" 33 34 namespace crypto { 35 namespace tink { 36 namespace subtle { 37 38 // The RSA SSA (Signature Schemes with Appendix) using PSS (Probabilistic 39 // Signature Scheme) encoding is defined at 40 // https://tools.ietf.org/html/rfc8017#section-8.1). 41 class RsaSsaPssSignBoringSsl : public PublicKeySign { 42 public: 43 static crypto::tink::util::StatusOr<std::unique_ptr<PublicKeySign>> New( 44 const crypto::tink::internal::RsaPrivateKey& private_key, 45 const crypto::tink::internal::RsaSsaPssParams& params); 46 47 ~RsaSsaPssSignBoringSsl() override = default; 48 49 crypto::tink::util::StatusOr<std::string> Sign( 50 absl::string_view data) const override; 51 52 static constexpr crypto::tink::internal::FipsCompatibility kFipsStatus = 53 crypto::tink::internal::FipsCompatibility::kRequiresBoringCrypto; 54 55 private: RsaSsaPssSignBoringSsl(crypto::tink::internal::SslUniquePtr<RSA> private_key,const EVP_MD * sig_hash,const EVP_MD * mgf1_hash,int32_t salt_length)56 RsaSsaPssSignBoringSsl(crypto::tink::internal::SslUniquePtr<RSA> private_key, 57 const EVP_MD* sig_hash, const EVP_MD* mgf1_hash, 58 int32_t salt_length) 59 : private_key_(std::move(private_key)), 60 sig_hash_(sig_hash), 61 mgf1_hash_(mgf1_hash), 62 salt_length_(salt_length) {} 63 64 const crypto::tink::internal::SslUniquePtr<RSA> private_key_; 65 // Pointers to singletons owned by OpenSSL/BoringSSL. 66 const EVP_MD* sig_hash_; 67 const EVP_MD* mgf1_hash_; 68 const int32_t salt_length_; 69 }; 70 71 } // namespace subtle 72 } // namespace tink 73 } // namespace crypto 74 75 #endif // TINK_SUBTLE_RSA_SSA_PSS_SIGN_BORINGSSL_H_ 76