1 // Copyright 2017 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_ECDSA_SIGN_BORINGSSL_H_ 18 #define TINK_SUBTLE_ECDSA_SIGN_BORINGSSL_H_ 19 20 #include <memory> 21 #include <string> 22 #include <utility> 23 24 #include "absl/strings/string_view.h" 25 #include "openssl/evp.h" 26 #include "tink/internal/fips_utils.h" 27 #include "tink/public_key_sign.h" 28 #include "tink/signature/internal/ecdsa_raw_sign_boringssl.h" 29 #include "tink/subtle/common_enums.h" 30 #include "tink/subtle/subtle_util_boringssl.h" 31 #include "tink/util/statusor.h" 32 33 namespace crypto { 34 namespace tink { 35 namespace subtle { 36 37 // ECDSA signing using Boring SSL, generating signatures in DER-encoding. 38 class EcdsaSignBoringSsl : public PublicKeySign { 39 public: 40 static crypto::tink::util::StatusOr<std::unique_ptr<EcdsaSignBoringSsl>> New( 41 const SubtleUtilBoringSSL::EcKey& ec_key, HashType hash_type, 42 EcdsaSignatureEncoding encoding); 43 44 // Computes the signature for 'data'. 45 crypto::tink::util::StatusOr<std::string> Sign( 46 absl::string_view data) const override; 47 48 static constexpr crypto::tink::internal::FipsCompatibility kFipsStatus = 49 crypto::tink::internal::FipsCompatibility::kRequiresBoringCrypto; 50 51 private: EcdsaSignBoringSsl(const EVP_MD * hash,std::unique_ptr<internal::EcdsaRawSignBoringSsl> raw_signer)52 explicit EcdsaSignBoringSsl( 53 const EVP_MD* hash, 54 std::unique_ptr<internal::EcdsaRawSignBoringSsl> raw_signer) 55 : hash_(hash), raw_signer_(std::move(raw_signer)) {} 56 57 const EVP_MD* hash_; // Owned by BoringSSL. 58 std::unique_ptr<internal::EcdsaRawSignBoringSsl> raw_signer_; 59 }; 60 61 } // namespace subtle 62 } // namespace tink 63 } // namespace crypto 64 65 #endif // TINK_SUBTLE_ECDSA_SIGN_BORINGSSL_H_ 66