Skip to content

Commit

Permalink
Handle 56 signature lenght
Browse files Browse the repository at this point in the history
  • Loading branch information
artemskriabin committed Jan 3, 2025
1 parent 882aebe commit 0f936a5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/types/signature_algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@ func verifyECDSA(data, sig []byte, publicKey *ecdsa.PublicKey) error {
}

// Handle raw (r || s) signature format
if len(sig) != 64 {
return fmt.Errorf("ECDSA signature length is not 64, but %d, with key %s", len(sig), publicKey.Curve.Params().Name)
var index int
switch len(sig) {
case 64:
index = 32
case 56:
index = 28
default:
return fmt.Errorf("ECDSA signature length is not 64 or 56, but %d, with key %s", len(sig), publicKey.Curve.Params().Name)
}

r, s := new(big.Int).SetBytes(sig[:32]), new(big.Int).SetBytes(sig[32:])
r, s := new(big.Int).SetBytes(sig[:index]), new(big.Int).SetBytes(sig[index:])
if ecdsa.Verify(publicKey, data, r, s) {
return nil
}
Expand Down

0 comments on commit 0f936a5

Please sign in to comment.