From 0f936a583acb75874417df40518eb423bee359d7 Mon Sep 17 00:00:00 2001 From: Artem Skriabin Date: Fri, 3 Jan 2025 20:56:30 +0200 Subject: [PATCH] Handle 56 signature lenght --- internal/types/signature_algorithm.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/types/signature_algorithm.go b/internal/types/signature_algorithm.go index 4d3f235..55ca2c1 100644 --- a/internal/types/signature_algorithm.go +++ b/internal/types/signature_algorithm.go @@ -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 }