Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Ed25519 signature algorithm #248

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions v2/internal/cryptoutil/keys.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package cryptoutil

import (
"bytes"
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rsa"
"fmt"
)
Expand All @@ -15,6 +17,9 @@ func PublicKeyEqual(a, b crypto.PublicKey) (bool, error) {
case *ecdsa.PublicKey:
ecdsaPublicKey, ok := b.(*ecdsa.PublicKey)
return ok && ECDSAPublicKeyEqual(a, ecdsaPublicKey), nil
case ed25519.PublicKey:
ed25519PublicKey, ok := b.(ed25519.PublicKey)
return ok && bytes.Equal(a, ed25519PublicKey), nil
default:
return false, fmt.Errorf("unsupported public key type %T", a)
}
Expand Down
3 changes: 3 additions & 0 deletions v2/svid/jwtsvid/svid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package jwtsvid_test
import (
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
Expand Down Expand Up @@ -502,6 +503,8 @@ func getSignerAlgorithm(signer crypto.Signer) (jose.SignatureAlgorithm, error) {
default:
return "", fmt.Errorf("unable to determine signature algorithm for EC public key size %d", params.BitSize)
}
case ed25519.PublicKey:
return jose.EdDSA, nil
default:
return "", fmt.Errorf("unable to determine signature algorithm for public key type %T", publicKey)
}
Expand Down
5 changes: 5 additions & 0 deletions v2/svid/x509svid/svid.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package x509svid

import (
"bytes"
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rsa"
"crypto/x509"
"os"
Expand Down Expand Up @@ -229,6 +231,9 @@ func keyMatches(privateKey crypto.PrivateKey, publicKey crypto.PublicKey) (bool,
case *ecdsa.PrivateKey:
ecdsaPublicKey, ok := publicKey.(*ecdsa.PublicKey)
return ok && ecdsaPublicKeyEqual(&privateKey.PublicKey, ecdsaPublicKey), nil
case ed25519.PrivateKey:
ed25519PublicKey, ok := publicKey.(ed25519.PublicKey)
return ok && bytes.Equal(privateKey.Public().(ed25519.PublicKey), ed25519PublicKey), nil
default:
return false, errs.New("unsupported private key type %T", privateKey)
}
Expand Down