2020-09-18 18:01:16 -04:00
|
|
|
/*
|
|
|
|
SSHSecure - a program to harden OpenSSH from defaults
|
|
|
|
Copyright (C) 2020 Brent Saner
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-09-18 04:04:39 -04:00
|
|
|
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
|
|
|
|
}
|