Skip to content

Commit 4d2bb03

Browse files
committed
fix: Ecdsa384 signatures
1 parent 4ce855e commit 4d2bb03

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

signer.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,12 @@ func (k *EcdsaP256SigningKey) Sign(data []byte) ([]byte, error) {
311311
return nil, err
312312
}
313313

314-
return append(r.Bytes(), s.Bytes()...), nil
314+
rBytes := make([]byte, 32)
315+
sBytes := make([]byte, 32)
316+
r.FillBytes(rBytes)
317+
s.FillBytes(sBytes)
318+
319+
return append(rBytes, sBytes...), nil
315320
}
316321

317322
func (k *EcdsaP256SigningKey) GetKeyID() string {
@@ -340,7 +345,12 @@ func (k *EcdsaP384SigningKey) Sign(data []byte) ([]byte, error) {
340345
return nil, err
341346
}
342347

343-
return append(r.Bytes(), s.Bytes()...), nil
348+
rBytes := make([]byte, 48)
349+
sBytes := make([]byte, 48)
350+
r.FillBytes(rBytes)
351+
s.FillBytes(sBytes)
352+
353+
return append(rBytes, sBytes...), nil
344354
}
345355

346356
func (k *EcdsaP384SigningKey) GetKeyID() string {

verifier.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,11 @@ func (k *EcdsaP384VerifyingKey) Verify(data []byte, signature []byte) error {
399399

400400
bytes := hash.Sum(nil)
401401

402-
if len(signature) != 64 {
402+
if len(signature) != 96 {
403403
return errInvalidSignature
404404
}
405-
rBytes, sBytes := signature[:32], signature[32:]
405+
rBytes, sBytes := signature[:48], signature[48:]
406+
406407
var r, s big.Int
407408
r.SetBytes(rBytes)
408409
s.SetBytes(sBytes)

0 commit comments

Comments
 (0)