ed25519KeyGen returns an ED25519-based SSH private key.
()
| 78 | |
| 79 | // ed25519KeyGen returns an ED25519-based SSH private key. |
| 80 | func ed25519KeyGen() (privateKey string, publicKey string, err error) { |
| 81 | _, privateKeyRaw, err := ed25519.GenerateKey(entropy()) |
| 82 | if err != nil { |
| 83 | return "", "", xerrors.Errorf("generate ed25519 private key: %w", err) |
| 84 | } |
| 85 | |
| 86 | // NOTE: as of the time of writing, x/crypto/ssh is unable to marshal an ED25519 private key |
| 87 | // into the format expected by OpenSSH. See: https://github.com/golang/go/issues/37132 |
| 88 | // Until this support is added, using a third-party implementation. |
| 89 | byt, err := MarshalED25519PrivateKey(privateKeyRaw) |
| 90 | if err != nil { |
| 91 | return "", "", xerrors.Errorf("marshal ed25519 private key: %w", err) |
| 92 | } |
| 93 | |
| 94 | return generateKeys(pem.Block{ |
| 95 | Type: "OPENSSH PRIVATE KEY", |
| 96 | Bytes: byt, |
| 97 | }, privateKeyRaw) |
| 98 | } |
| 99 | |
| 100 | // ecdsaKeyGen returns an ECDSA-based SSH private key. |
| 101 | func ecdsaKeyGen() (privateKey string, publicKey string, err error) { |
no test coverage detected