|
|
@@ -281,6 +281,12 @@ type PublicKey interface {
|
|
|
Verify(data []byte, sig *Signature) error
|
|
|
}
|
|
|
|
|
|
+// CryptoPublicKey, if implemented by a PublicKey,
|
|
|
+// returns the underlying crypto.PublicKey form of the key.
|
|
|
+type CryptoPublicKey interface {
|
|
|
+ CryptoPublicKey() crypto.PublicKey
|
|
|
+}
|
|
|
+
|
|
|
// A Signer can create signatures that verify against a public key.
|
|
|
type Signer interface {
|
|
|
// PublicKey returns an associated PublicKey instance.
|
|
|
@@ -348,6 +354,10 @@ func (r *rsaPublicKey) Verify(data []byte, sig *Signature) error {
|
|
|
return rsa.VerifyPKCS1v15((*rsa.PublicKey)(r), crypto.SHA1, digest, sig.Blob)
|
|
|
}
|
|
|
|
|
|
+func (r *rsaPublicKey) CryptoPublicKey() crypto.PublicKey {
|
|
|
+ return (*rsa.PublicKey)(r)
|
|
|
+}
|
|
|
+
|
|
|
type dsaPublicKey dsa.PublicKey
|
|
|
|
|
|
func (r *dsaPublicKey) Type() string {
|
|
|
@@ -416,6 +426,10 @@ func (k *dsaPublicKey) Verify(data []byte, sig *Signature) error {
|
|
|
return errors.New("ssh: signature did not verify")
|
|
|
}
|
|
|
|
|
|
+func (k *dsaPublicKey) CryptoPublicKey() crypto.PublicKey {
|
|
|
+ return (*dsa.PublicKey)(k)
|
|
|
+}
|
|
|
+
|
|
|
type dsaPrivateKey struct {
|
|
|
*dsa.PrivateKey
|
|
|
}
|
|
|
@@ -509,6 +523,10 @@ func (key ed25519PublicKey) Verify(b []byte, sig *Signature) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+func (k ed25519PublicKey) CryptoPublicKey() crypto.PublicKey {
|
|
|
+ return ed25519.PublicKey(k)
|
|
|
+}
|
|
|
+
|
|
|
func supportedEllipticCurve(curve elliptic.Curve) bool {
|
|
|
return curve == elliptic.P256() || curve == elliptic.P384() || curve == elliptic.P521()
|
|
|
}
|
|
|
@@ -604,6 +622,10 @@ func (key *ecdsaPublicKey) Verify(data []byte, sig *Signature) error {
|
|
|
return errors.New("ssh: signature did not verify")
|
|
|
}
|
|
|
|
|
|
+func (k *ecdsaPublicKey) CryptoPublicKey() crypto.PublicKey {
|
|
|
+ return (*ecdsa.PublicKey)(k)
|
|
|
+}
|
|
|
+
|
|
|
// NewSignerFromKey takes an *rsa.PrivateKey, *dsa.PrivateKey,
|
|
|
// *ecdsa.PrivateKey or any other crypto.Signer and returns a corresponding
|
|
|
// Signer instance. ECDSA keys must use P-256, P-384 or P-521.
|