xref: /aosp_15_r20/external/tink/cc/subtle/rsa_ssa_pkcs1_sign_boringssl.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
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_PKCS1_SIGN_BORINGSSL_H_
18 #define TINK_SUBTLE_RSA_SSA_PKCS1_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 PKCS1 (Public-Key
39 // Cryptography Standards) encoding is defined at
40 // https://tools.ietf.org/html/rfc8017#section-8.2). This implemention uses
41 // Boring SSL for the underlying cryptographic operations.
42 class RsaSsaPkcs1SignBoringSsl : public PublicKeySign {
43  public:
44   static crypto::tink::util::StatusOr<std::unique_ptr<PublicKeySign>> New(
45       const internal::RsaPrivateKey& private_key,
46       const internal::RsaSsaPkcs1Params& params);
47 
48   // Computes the signature for 'data'.
49   crypto::tink::util::StatusOr<std::string> Sign(
50       absl::string_view data) const override;
51 
52   ~RsaSsaPkcs1SignBoringSsl() override = default;
53 
54   static constexpr crypto::tink::internal::FipsCompatibility kFipsStatus =
55       crypto::tink::internal::FipsCompatibility::kRequiresBoringCrypto;
56 
57  private:
RsaSsaPkcs1SignBoringSsl(internal::SslUniquePtr<RSA> private_key,const EVP_MD * sig_hash)58   RsaSsaPkcs1SignBoringSsl(internal::SslUniquePtr<RSA> private_key,
59                            const EVP_MD* sig_hash)
60       : private_key_(std::move(private_key)), sig_hash_(sig_hash) {}
61 
62   const internal::SslUniquePtr<RSA> private_key_;
63   const EVP_MD* const sig_hash_;  // Owned by BoringSSL.
64 };
65 
66 }  // namespace subtle
67 }  // namespace tink
68 }  // namespace crypto
69 
70 #endif  // TINK_SUBTLE_RSA_SSA_PKCS1_SIGN_BORINGSSL_H_
71