Skip to content

Commit

Permalink
Add constructor for ECDSA verifier which takes an EC_KEY.
Browse files Browse the repository at this point in the history
Key Transparency gets keys in DER format, which can be easily deserialized into an EC_KEY. Extracting the curve and x,y points to make an EcKey struct which will then be converted back to an EC_KEY seemed unnecessary.

PiperOrigin-RevId: 215790073
GitOrigin-RevId: 55ec839d1cf516c8ab7ba9461d854b542643bc16
  • Loading branch information
ise-crypto authored and Tink Team committed Oct 9, 2018
1 parent 91b6f87 commit 9b1116f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
26 changes: 16 additions & 10 deletions cc/subtle/ecdsa_verify_boringssl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ crypto::tink::util::StatusOr<std::string> IeeeToDer(absl::string_view ieee,
util::StatusOr<std::unique_ptr<EcdsaVerifyBoringSsl>> EcdsaVerifyBoringSsl::New(
const SubtleUtilBoringSSL::EcKey& ec_key, HashType hash_type,
EcdsaSignatureEncoding encoding) {
// Check hash.
auto hash_status = SubtleUtilBoringSSL::ValidateSignatureHash(hash_type);
if (!hash_status.ok()) {
return hash_status;
}
auto hash_result = SubtleUtilBoringSSL::EvpHash(hash_type);
if (!hash_result.ok()) return hash_result.status();
const EVP_MD* hash = hash_result.ValueOrDie();

// Check curve.
auto group_result(SubtleUtilBoringSSL::GetEcGroup(ec_key.curve));
if (!group_result.ok()) return group_result.status();
Expand All @@ -109,8 +100,23 @@ util::StatusOr<std::unique_ptr<EcdsaVerifyBoringSsl>> EcdsaVerifyBoringSsl::New(
absl::StrCat("Invalid public key: ",
SubtleUtilBoringSSL::GetErrors()));
}
return New(std::move(key), hash_type, encoding);
}

// static
util::StatusOr<std::unique_ptr<EcdsaVerifyBoringSsl>> EcdsaVerifyBoringSsl::New(
bssl::UniquePtr<EC_KEY> ec_key, HashType hash_type,
EcdsaSignatureEncoding encoding) {
// Check hash.
auto hash_status = SubtleUtilBoringSSL::ValidateSignatureHash(hash_type);
if (!hash_status.ok()) {
return hash_status;
}
auto hash_result = SubtleUtilBoringSSL::EvpHash(hash_type);
if (!hash_result.ok()) return hash_result.status();
const EVP_MD* hash = hash_result.ValueOrDie();
std::unique_ptr<EcdsaVerifyBoringSsl> verify(
new EcdsaVerifyBoringSsl(key.release(), hash, encoding));
new EcdsaVerifyBoringSsl(ec_key.release(), hash, encoding));
return std::move(verify);
}

Expand Down
4 changes: 4 additions & 0 deletions cc/subtle/ecdsa_verify_boringssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class EcdsaVerifyBoringSsl : public PublicKeyVerify {
New(const SubtleUtilBoringSSL::EcKey& ec_key, HashType hash_type,
EcdsaSignatureEncoding encoding);

static crypto::tink::util::StatusOr<std::unique_ptr<EcdsaVerifyBoringSsl>>
New(bssl::UniquePtr<EC_KEY> ec_key, HashType hash_type,
EcdsaSignatureEncoding encoding);

// Verifies that 'signature' is a digital signature for 'data'.
crypto::tink::util::Status Verify(
absl::string_view signature,
Expand Down

0 comments on commit 9b1116f

Please sign in to comment.