SSHSecure/sshkeys/ed25519.go
brent s 86266685f5
checking in for the night.
key generation should be done, need to finish packing/formatting.

also need to start on moduli generation.
2020-09-18 04:04:39 -04:00

25 lines
645 B
Go

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
}