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_VERIFY_BORINGSSL_H_ 18 #define TINK_SUBTLE_ECDSA_VERIFY_BORINGSSL_H_ 19 20 #include <memory> 21 #include <utility> 22 23 #include "absl/strings/string_view.h" 24 #include "openssl/ec.h" 25 #include "openssl/evp.h" 26 #include "tink/internal/fips_utils.h" 27 #include "tink/internal/ssl_unique_ptr.h" 28 #include "tink/public_key_verify.h" 29 #include "tink/subtle/common_enums.h" 30 #include "tink/subtle/subtle_util_boringssl.h" 31 #include "tink/util/status.h" 32 33 namespace crypto { 34 namespace tink { 35 namespace subtle { 36 37 // ECDSA verification using Boring SSL, accepting signatures in DER-encoding. 38 class EcdsaVerifyBoringSsl : public PublicKeyVerify { 39 public: 40 static crypto::tink::util::StatusOr<std::unique_ptr<EcdsaVerifyBoringSsl>> 41 New(const SubtleUtilBoringSSL::EcKey& ec_key, HashType hash_type, 42 EcdsaSignatureEncoding encoding); 43 44 static crypto::tink::util::StatusOr<std::unique_ptr<EcdsaVerifyBoringSsl>> 45 New(internal::SslUniquePtr<EC_KEY> ec_key, HashType hash_type, 46 EcdsaSignatureEncoding encoding); 47 48 // Verifies that 'signature' is a digital signature for 'data'. 49 crypto::tink::util::Status Verify( 50 absl::string_view signature, 51 absl::string_view data) const override; 52 53 static constexpr crypto::tink::internal::FipsCompatibility kFipsStatus = 54 crypto::tink::internal::FipsCompatibility::kRequiresBoringCrypto; 55 56 private: EcdsaVerifyBoringSsl(internal::SslUniquePtr<EC_KEY> key,const EVP_MD * hash,EcdsaSignatureEncoding encoding)57 EcdsaVerifyBoringSsl(internal::SslUniquePtr<EC_KEY> key, const EVP_MD* hash, 58 EcdsaSignatureEncoding encoding) 59 : key_(std::move(key)), hash_(hash), encoding_(encoding) {} 60 61 internal::SslUniquePtr<EC_KEY> key_; 62 const EVP_MD* hash_; // Owned by BoringSSL. 63 EcdsaSignatureEncoding encoding_; 64 }; 65 66 } // namespace subtle 67 } // namespace tink 68 } // namespace crypto 69 70 #endif // TINK_SUBTLE_ECDSA_VERIFY_BORINGSSL_H_ 71