Skip to content

Commit

Permalink
ECDSA public key recovery: improve validation of r/s/v
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed Apr 5, 2021
1 parent 8ba41c3 commit 631e22b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lib/pubkey/ecdsa/ecdsa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ PointGFp recover_ecdsa_public_key(const EC_Group& group,
if(group.get_cofactor() != 1)
throw Invalid_Argument("ECDSA public key recovery only supported for prime order groups");

if(v > 4)
if(v >= 4)
throw Invalid_Argument("Unexpected v param for ECDSA public key recovery");

const BigInt& group_order = group.get_order();

if(r <= 0 || r >= group_order || s <= 0 || s >= group_order)
{
throw Invalid_Argument("Out of range r/s cannot recover ECDSA public key");
}

const uint8_t y_odd = v % 2;
const uint8_t add_order = v >> 1;

const BigInt& group_order = group.get_order();
const size_t p_bytes = group.get_p_bytes();

try
Expand Down

0 comments on commit 631e22b

Please sign in to comment.