Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5542 from ethereum/verify-compressed-key
Browse files Browse the repository at this point in the history
Verify signature with compressed public key
  • Loading branch information
gumb0 authored Apr 8, 2019
2 parents 937236d + 0d8422a commit a611afe
Show file tree
Hide file tree
Showing 3 changed files with 683 additions and 637 deletions.
15 changes: 15 additions & 0 deletions libdevcrypto/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,21 @@ bool dev::verify(Public const& _p, Signature const& _s, h256 const& _hash)
return _p == recover(_s, _hash);
}

bool dev::verify(PublicCompressed const& _key, h512 const& _signature, h256 const& _hash)
{
auto* ctx = getCtx();

secp256k1_ecdsa_signature rawSig;
if (!secp256k1_ecdsa_signature_parse_compact(ctx, &rawSig, _signature.data()))
return false;

secp256k1_pubkey rawPubkey;
if (!secp256k1_ec_pubkey_parse(ctx, &rawPubkey, _key.data(), PublicCompressed::size))
return false; // Invalid public key.

return secp256k1_ecdsa_verify(ctx, &rawSig, _hash.data(), &rawPubkey);
}

bytesSec dev::pbkdf2(string const& _pass, bytes const& _salt, unsigned _iterations, unsigned _dkLen)
{
bytesSec ret(_dkLen);
Expand Down
3 changes: 3 additions & 0 deletions libdevcrypto/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ Signature sign(Secret const& _k, h256 const& _hash);
/// Verify signature.
bool verify(Public const& _k, Signature const& _s, h256 const& _hash);

// Verify signature with compressed public key
bool verify(PublicCompressed const& _key, h512 const& _signature, h256 const& _hash);

/// Derive key via PBKDF2.
bytesSec pbkdf2(std::string const& _pass, bytes const& _salt, unsigned _iterations, unsigned _dkLen = 32);

Expand Down
Loading

0 comments on commit a611afe

Please sign in to comment.