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_SIGNATURE_INTERNAL_ECDSA_RAW_SIGN_BORINGSSL_H_ 18 #define TINK_SIGNATURE_INTERNAL_ECDSA_RAW_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/evp.h" 27 #include "tink/internal/fips_utils.h" 28 #include "tink/internal/ssl_unique_ptr.h" 29 #include "tink/public_key_sign.h" 30 #include "tink/subtle/common_enums.h" 31 #include "tink/subtle/subtle_util_boringssl.h" 32 #include "tink/util/statusor.h" 33 34 namespace crypto { 35 namespace tink { 36 namespace internal { 37 38 // ECDSA raw signing using Boring SSL, generating signatures in DER-encoding. 39 class EcdsaRawSignBoringSsl : public PublicKeySign { 40 public: 41 static crypto::tink::util::StatusOr<std::unique_ptr<EcdsaRawSignBoringSsl>> 42 New(const crypto::tink::internal::EcKey& ec_key, 43 subtle::EcdsaSignatureEncoding encoding); 44 45 // Computes the signature for 'data'. 46 crypto::tink::util::StatusOr<std::string> Sign( 47 absl::string_view data) const override; 48 49 static constexpr crypto::tink::internal::FipsCompatibility kFipsStatus = 50 crypto::tink::internal::FipsCompatibility::kRequiresBoringCrypto; 51 52 private: EcdsaRawSignBoringSsl(internal::SslUniquePtr<EC_KEY> key,subtle::EcdsaSignatureEncoding encoding)53 EcdsaRawSignBoringSsl(internal::SslUniquePtr<EC_KEY> key, 54 subtle::EcdsaSignatureEncoding encoding) 55 : key_(std::move(key)), encoding_(encoding) {} 56 57 internal::SslUniquePtr<EC_KEY> key_; 58 subtle::EcdsaSignatureEncoding encoding_; 59 }; 60 61 } // namespace internal 62 } // namespace tink 63 } // namespace crypto 64 65 #endif // TINK_SIGNATURE_INTERNAL_ECDSA_RAW_SIGN_BORINGSSL_H_ 66