SSHSecure/sshkeys/ed25519.go

25 lines
645 B
Go
Raw Normal View History

package sshkeys
import (
"crypto/ed25519"
)
func (k *SSHPrivKey) generateEd25519() error {
if k.Key != nil || k.PublicKey.Key != nil {
return nil // Just no-op; already generated.
}
// We cast "pk" (public key) to _ because it's an interface{} that we can't seem to
// assert to []byte. I've tried iterating, a type assertion, initializing,... nada.
// Luckily it's at a fixed half of the secret key.
if _, s, err := ed25519.GenerateKey(nil); err != nil {
return err
} else {
k.Key = s
ks := len(s) - ed25519.PublicKeySize
k.PublicKey.Key = s[ks:]
k.BitSize = ed25519Len
k.PublicKey.KeyType = KeyEd25519
}
return nil
}