Skip to content

Commit d3b4308

Browse files
committed
deprecate AlgorithmEd25519 and provide AlgorithmEdDSA instead
Signed-off-by: qmuntal <[email protected]>
1 parent 5446214 commit d3b4308

File tree

12 files changed

+44
-38
lines changed

12 files changed

+44
-38
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ These are the required packages for each built-in cose.Algorithm:
154154

155155
- cose.AlgorithmPS256, cose.AlgorithmES256: `crypto/sha256`
156156
- cose.AlgorithmPS384, cose.AlgorithmPS512, cose.AlgorithmES384, cose.AlgorithmES512: `crypto/sha512`
157-
- cose.AlgorithmEd25519: none
157+
- cose.AlgorithmEdDSA: none
158158

159159
## Features
160160

algorithm.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ const (
3535
AlgorithmES512 Algorithm = -36
3636

3737
// PureEdDSA by RFC 8152.
38+
//
39+
// Deprecated: use AlgorithmEdDSA instead, which has
40+
// the same value but with a more accurate name.
3841
AlgorithmEd25519 Algorithm = -8
3942

43+
// PureEdDSA by RFC 8152.
44+
AlgorithmEdDSA Algorithm = -8
45+
4046
// An invalid/unrecognised algorithm.
4147
AlgorithmInvalid Algorithm = 0
4248
)
@@ -65,7 +71,7 @@ func (a Algorithm) String() string {
6571
return "ES384"
6672
case AlgorithmES512:
6773
return "ES512"
68-
case AlgorithmEd25519:
74+
case AlgorithmEdDSA:
6975
// As stated in RFC 8152 8.2, only the pure EdDSA version is used for
7076
// COSE.
7177
return "EdDSA"

algorithm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestAlgorithm_computeHash(t *testing.T) {
9696
},
9797
{
9898
name: "Ed25519",
99-
alg: AlgorithmEd25519,
99+
alg: AlgorithmEdDSA,
100100
wantErr: ErrUnavailableHashFunc,
101101
},
102102
{

ed25519.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type ed25519Signer struct {
1313

1414
// Algorithm returns the signing algorithm associated with the private key.
1515
func (es *ed25519Signer) Algorithm() Algorithm {
16-
return AlgorithmEd25519
16+
return AlgorithmEdDSA
1717
}
1818

1919
// Sign signs message content with the private key, possibly using entropy from
@@ -34,7 +34,7 @@ type ed25519Verifier struct {
3434

3535
// Algorithm returns the signing algorithm associated with the public key.
3636
func (ev *ed25519Verifier) Algorithm() Algorithm {
37-
return AlgorithmEd25519
37+
return AlgorithmEdDSA
3838
}
3939

4040
// Verify verifies message content with the public key, returning nil for

ed25519_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func generateTestEd25519Key(t *testing.T) (ed25519.PublicKey, ed25519.PrivateKey
1717

1818
func Test_ed25519Signer(t *testing.T) {
1919
// generate key
20-
alg := AlgorithmEd25519
20+
alg := AlgorithmEdDSA
2121
_, key := generateTestEd25519Key(t)
2222

2323
// set up signer
@@ -51,7 +51,7 @@ func Test_ed25519Signer(t *testing.T) {
5151

5252
func Test_ed25519Verifier_Verify_Success(t *testing.T) {
5353
// generate key
54-
alg := AlgorithmEd25519
54+
alg := AlgorithmEdDSA
5555
_, key := generateTestEd25519Key(t)
5656

5757
// generate a valid signature
@@ -77,7 +77,7 @@ func Test_ed25519Verifier_Verify_Success(t *testing.T) {
7777

7878
func Test_ed25519Verifier_Verify_KeyMismatch(t *testing.T) {
7979
// generate key
80-
alg := AlgorithmEd25519
80+
alg := AlgorithmEdDSA
8181
_, key := generateTestEd25519Key(t)
8282

8383
// generate a valid signature
@@ -97,7 +97,7 @@ func Test_ed25519Verifier_Verify_KeyMismatch(t *testing.T) {
9797

9898
func Test_ed25519Verifier_Verify_InvalidSignature(t *testing.T) {
9999
// generate key
100-
alg := AlgorithmEd25519
100+
alg := AlgorithmEdDSA
101101
vk, sk := generateTestEd25519Key(t)
102102

103103
// generate a valid signature with a tampered one

fuzz_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
var supportedAlgorithms = [...]cose.Algorithm{
2525
cose.AlgorithmPS256, cose.AlgorithmPS384, cose.AlgorithmPS512,
2626
cose.AlgorithmES256, cose.AlgorithmES384, cose.AlgorithmES512,
27-
cose.AlgorithmEd25519,
27+
cose.AlgorithmEdDSA,
2828
}
2929

3030
func FuzzSign1Message_UnmarshalCBOR(f *testing.F) {
@@ -181,7 +181,7 @@ func newSignerWithEphemeralKey(alg cose.Algorithm) (sv signVerifier, err error)
181181
key, err = ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
182182
case cose.AlgorithmES512:
183183
key, err = ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
184-
case cose.AlgorithmEd25519:
184+
case cose.AlgorithmEdDSA:
185185
_, key, err = ed25519.GenerateKey(rand.Reader)
186186
default:
187187
err = cose.ErrAlgorithmNotSupported

key.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ type Key struct {
240240

241241
// NewOKPKey returns a Key created using the provided Octet Key Pair data.
242242
func NewOKPKey(alg Algorithm, x, d []byte) (*Key, error) {
243-
if alg != AlgorithmEd25519 {
243+
if alg != AlgorithmEdDSA {
244244
return nil, fmt.Errorf("unsupported algorithm %q", alg)
245245
}
246246

@@ -389,7 +389,7 @@ func NewKeyFromPublic(pub crypto.PublicKey) (*Key, error) {
389389

390390
return NewEC2Key(alg, vk.X.Bytes(), vk.Y.Bytes(), nil)
391391
case ed25519.PublicKey:
392-
return NewOKPKey(AlgorithmEd25519, []byte(vk), nil)
392+
return NewOKPKey(AlgorithmEdDSA, []byte(vk), nil)
393393
default:
394394
return nil, ErrInvalidPubKey
395395
}
@@ -408,7 +408,7 @@ func NewKeyFromPrivate(priv crypto.PrivateKey) (*Key, error) {
408408

409409
return NewEC2Key(alg, sk.X.Bytes(), sk.Y.Bytes(), sk.D.Bytes())
410410
case ed25519.PrivateKey:
411-
return NewOKPKey(AlgorithmEd25519, []byte(sk[32:]), []byte(sk[:32]))
411+
return NewOKPKey(AlgorithmEdDSA, []byte(sk[32:]), []byte(sk[:32]))
412412
default:
413413
return nil, ErrInvalidPrivKey
414414
}
@@ -685,7 +685,7 @@ func (k *Key) PublicKey() (crypto.PublicKey, error) {
685685
pub.Y.SetBytes(y)
686686

687687
return pub, nil
688-
case AlgorithmEd25519:
688+
case AlgorithmEdDSA:
689689
_, x, _ := k.OKP()
690690
return ed25519.PublicKey(x), nil
691691
default:
@@ -730,7 +730,7 @@ func (k *Key) PrivateKey() (crypto.PrivateKey, error) {
730730
PublicKey: ecdsa.PublicKey{Curve: curve, X: bx, Y: by},
731731
D: bd,
732732
}, nil
733-
case AlgorithmEd25519:
733+
case AlgorithmEdDSA:
734734
_, x, d := k.OKP()
735735
if len(x) == 0 {
736736
return ed25519.NewKeyFromSeed(d), nil
@@ -823,7 +823,7 @@ func (k *Key) deriveAlgorithm() (Algorithm, error) {
823823
crv, _, _ := k.OKP()
824824
switch crv {
825825
case CurveEd25519:
826-
return AlgorithmEd25519, nil
826+
return AlgorithmEdDSA, nil
827827
default:
828828
return AlgorithmInvalid, fmt.Errorf(
829829
"unsupported curve %q for key type OKP", crv.String())

key_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func TestKey_UnmarshalCBOR(t *testing.T) {
457457
},
458458
want: &Key{
459459
KeyType: KeyTypeOKP,
460-
Algorithm: AlgorithmEd25519,
460+
Algorithm: AlgorithmEdDSA,
461461
KeyOps: []KeyOp{KeyOpVerify, KeyOpSign},
462462
BaseIV: []byte{0x03, 0x02, 0x01},
463463
Params: map[interface{}]interface{}{
@@ -644,7 +644,7 @@ func TestKey_MarshalCBOR(t *testing.T) {
644644
name: "OKP with kty and alg",
645645
key: &Key{
646646
KeyType: KeyTypeOKP,
647-
Algorithm: AlgorithmEd25519,
647+
Algorithm: AlgorithmEdDSA,
648648
},
649649
want: []byte{
650650
0xa2, // map (2)
@@ -730,7 +730,7 @@ func TestKey_MarshalCBOR(t *testing.T) {
730730
name: "OKP",
731731
key: &Key{
732732
KeyType: KeyTypeOKP,
733-
Algorithm: AlgorithmEd25519,
733+
Algorithm: AlgorithmEdDSA,
734734
KeyOps: []KeyOp{KeyOpVerify, KeyOpEncrypt},
735735
Params: map[interface{}]interface{}{
736736
KeyLabelOKPCurve: CurveEd25519,
@@ -846,10 +846,10 @@ func TestNewOKPKey(t *testing.T) {
846846
wantErr string
847847
}{
848848
{
849-
name: "valid", args: args{AlgorithmEd25519, x, d},
849+
name: "valid", args: args{AlgorithmEdDSA, x, d},
850850
want: &Key{
851851
KeyType: KeyTypeOKP,
852-
Algorithm: AlgorithmEd25519,
852+
Algorithm: AlgorithmEdDSA,
853853
Params: map[interface{}]interface{}{
854854
KeyLabelOKPCurve: CurveEd25519,
855855
KeyLabelOKPX: x,
@@ -862,7 +862,7 @@ func TestNewOKPKey(t *testing.T) {
862862
want: nil,
863863
wantErr: `unsupported algorithm "unknown algorithm value -100"`,
864864
}, {
865-
name: "x and d missing", args: args{AlgorithmEd25519, nil, nil},
865+
name: "x and d missing", args: args{AlgorithmEdDSA, nil, nil},
866866
want: nil,
867867
wantErr: ErrInvalidKey.Error(),
868868
},
@@ -1061,7 +1061,7 @@ func TestKey_AlgorithmOrDefault(t *testing.T) {
10611061
KeyLabelOKPCurve: CurveEd25519,
10621062
},
10631063
},
1064-
AlgorithmEd25519,
1064+
AlgorithmEdDSA,
10651065
"",
10661066
},
10671067
{
@@ -1170,7 +1170,7 @@ func TestNewKeyFromPrivate(t *testing.T) {
11701170
{
11711171
"ed25519", ed25519.PrivateKey(append(okpd, okpx...)),
11721172
&Key{
1173-
Algorithm: AlgorithmEd25519, KeyType: KeyTypeOKP,
1173+
Algorithm: AlgorithmEdDSA, KeyType: KeyTypeOKP,
11741174
Params: map[interface{}]interface{}{
11751175
KeyLabelOKPCurve: CurveEd25519,
11761176
KeyLabelOKPX: okpx,
@@ -1228,7 +1228,7 @@ func TestNewKeyFromPublic(t *testing.T) {
12281228
{
12291229
"ed25519", ed25519.PublicKey(okpx),
12301230
&Key{
1231-
Algorithm: AlgorithmEd25519,
1231+
Algorithm: AlgorithmEdDSA,
12321232
KeyType: KeyTypeOKP,
12331233
Params: map[interface{}]interface{}{
12341234
KeyLabelOKPCurve: CurveEd25519,
@@ -1275,20 +1275,20 @@ func TestKey_Signer(t *testing.T) {
12751275
KeyLabelOKPD: d,
12761276
},
12771277
},
1278-
AlgorithmEd25519,
1278+
AlgorithmEdDSA,
12791279
"",
12801280
},
12811281
{
12821282
"without key_ops", &Key{
12831283
KeyType: KeyTypeOKP,
1284-
Algorithm: AlgorithmEd25519,
1284+
Algorithm: AlgorithmEdDSA,
12851285
Params: map[interface{}]interface{}{
12861286
KeyLabelOKPCurve: CurveEd25519,
12871287
KeyLabelOKPX: x,
12881288
KeyLabelOKPD: d,
12891289
},
12901290
},
1291-
AlgorithmEd25519,
1291+
AlgorithmEdDSA,
12921292
"",
12931293
},
12941294
{
@@ -1361,19 +1361,19 @@ func TestKey_Verifier(t *testing.T) {
13611361
KeyLabelOKPX: x,
13621362
},
13631363
},
1364-
AlgorithmEd25519,
1364+
AlgorithmEdDSA,
13651365
"",
13661366
},
13671367
{
13681368
"without key_ops", &Key{
13691369
KeyType: KeyTypeOKP,
1370-
Algorithm: AlgorithmEd25519,
1370+
Algorithm: AlgorithmEdDSA,
13711371
Params: map[interface{}]interface{}{
13721372
KeyLabelOKPCurve: CurveEd25519,
13731373
KeyLabelOKPX: x,
13741374
},
13751375
},
1376-
AlgorithmEd25519,
1376+
AlgorithmEdDSA,
13771377
"",
13781378
},
13791379
{

signer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func NewSigner(alg Algorithm, key crypto.Signer) (Signer, error) {
6868
key: vk,
6969
signer: key,
7070
}, nil
71-
case AlgorithmEd25519:
71+
case AlgorithmEdDSA:
7272
if _, ok := key.Public().(ed25519.PublicKey); !ok {
7373
return nil, fmt.Errorf("%v: %w", alg, ErrInvalidPubKey)
7474
}

signer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ func TestNewSigner(t *testing.T) {
7777
},
7878
{
7979
name: "ed25519 signer",
80-
alg: AlgorithmEd25519,
80+
alg: AlgorithmEdDSA,
8181
key: ed25519Key,
8282
want: &ed25519Signer{
8383
key: ed25519Key,
8484
},
8585
},
8686
{
8787
name: "ed25519 key mismatch",
88-
alg: AlgorithmEd25519,
88+
alg: AlgorithmEdDSA,
8989
key: rsaKey,
9090
wantErr: "EdDSA: invalid public key",
9191
},

0 commit comments

Comments
 (0)