From 4d2bb03c5914e21698cc8a420a7729c30f932e48 Mon Sep 17 00:00:00 2001 From: AlexanderTar Date: Thu, 11 Jan 2024 17:38:04 +0000 Subject: [PATCH] fix: Ecdsa384 signatures --- signer.go | 14 ++++++++++++-- verifier.go | 5 +++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/signer.go b/signer.go index 1cd76f6..2b3d512 100644 --- a/signer.go +++ b/signer.go @@ -311,7 +311,12 @@ func (k *EcdsaP256SigningKey) Sign(data []byte) ([]byte, error) { return nil, err } - return append(r.Bytes(), s.Bytes()...), nil + rBytes := make([]byte, 32) + sBytes := make([]byte, 32) + r.FillBytes(rBytes) + s.FillBytes(sBytes) + + return append(rBytes, sBytes...), nil } func (k *EcdsaP256SigningKey) GetKeyID() string { @@ -340,7 +345,12 @@ func (k *EcdsaP384SigningKey) Sign(data []byte) ([]byte, error) { return nil, err } - return append(r.Bytes(), s.Bytes()...), nil + rBytes := make([]byte, 48) + sBytes := make([]byte, 48) + r.FillBytes(rBytes) + s.FillBytes(sBytes) + + return append(rBytes, sBytes...), nil } func (k *EcdsaP384SigningKey) GetKeyID() string { diff --git a/verifier.go b/verifier.go index 832c66f..032e6ff 100644 --- a/verifier.go +++ b/verifier.go @@ -399,10 +399,11 @@ func (k *EcdsaP384VerifyingKey) Verify(data []byte, signature []byte) error { bytes := hash.Sum(nil) - if len(signature) != 64 { + if len(signature) != 96 { return errInvalidSignature } - rBytes, sBytes := signature[:32], signature[32:] + rBytes, sBytes := signature[:48], signature[48:] + var r, s big.Int r.SetBytes(rBytes) s.SetBytes(sBytes)