Skip to content

Commit

Permalink
fix: Ecdsa384 signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderTar committed Jan 11, 2024
1 parent 4ce855e commit 4d2bb03
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 12 additions & 2 deletions signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4d2bb03

Please sign in to comment.