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