Skip to content

Commit a7dc215

Browse files
committed
Validate ECC curve when creating signer/verifier
1 parent b872bda commit a7dc215

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

crypto.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"crypto"
55
"crypto/ecdsa"
66
"crypto/ed25519"
7+
"crypto/elliptic"
78
"crypto/hmac"
89
"crypto/rand"
910
"crypto/rsa"
@@ -88,6 +89,9 @@ func NewP256Signer(keyID string, key ecdsa.PrivateKey, config *SignConfig, field
8889
if keyID == "" {
8990
return nil, fmt.Errorf("keyID must not be empty")
9091
}
92+
if key.Curve != elliptic.P256() {
93+
return nil, fmt.Errorf("key curve must be P-256")
94+
}
9195
if config == nil {
9296
config = NewSignConfig()
9397
}
@@ -279,6 +283,9 @@ func NewP256Verifier(keyID string, key ecdsa.PublicKey, config *VerifyConfig, fi
279283
if config.verifyKeyID && keyID == "" {
280284
return nil, fmt.Errorf("keyID should not be empty")
281285
}
286+
if key.Curve != elliptic.P256() {
287+
return nil, fmt.Errorf("key curve must be P-256")
288+
}
282289
return &Verifier{
283290
keyID: keyID,
284291
key: key,

0 commit comments

Comments
 (0)