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

Commit a611afe

Browse files
authored
Merge pull request #5542 from ethereum/verify-compressed-key
Verify signature with compressed public key
2 parents 937236d + 0d8422a commit a611afe

File tree

3 files changed

+683
-637
lines changed

3 files changed

+683
-637
lines changed

libdevcrypto/Common.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,21 @@ bool dev::verify(Public const& _p, Signature const& _s, h256 const& _hash)
277277
return _p == recover(_s, _hash);
278278
}
279279

280+
bool dev::verify(PublicCompressed const& _key, h512 const& _signature, h256 const& _hash)
281+
{
282+
auto* ctx = getCtx();
283+
284+
secp256k1_ecdsa_signature rawSig;
285+
if (!secp256k1_ecdsa_signature_parse_compact(ctx, &rawSig, _signature.data()))
286+
return false;
287+
288+
secp256k1_pubkey rawPubkey;
289+
if (!secp256k1_ec_pubkey_parse(ctx, &rawPubkey, _key.data(), PublicCompressed::size))
290+
return false; // Invalid public key.
291+
292+
return secp256k1_ecdsa_verify(ctx, &rawSig, _hash.data(), &rawPubkey);
293+
}
294+
280295
bytesSec dev::pbkdf2(string const& _pass, bytes const& _salt, unsigned _iterations, unsigned _dkLen)
281296
{
282297
bytesSec ret(_dkLen);

libdevcrypto/Common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ Signature sign(Secret const& _k, h256 const& _hash);
133133
/// Verify signature.
134134
bool verify(Public const& _k, Signature const& _s, h256 const& _hash);
135135

136+
// Verify signature with compressed public key
137+
bool verify(PublicCompressed const& _key, h512 const& _signature, h256 const& _hash);
138+
136139
/// Derive key via PBKDF2.
137140
bytesSec pbkdf2(std::string const& _pass, bytes const& _salt, unsigned _iterations, unsigned _dkLen = 32);
138141

0 commit comments

Comments
 (0)