Skip to content

Commit 7129cd3

Browse files
committed
optimize key generation
1 parent 06db9e0 commit 7129cd3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/secure/utils.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ func bytesToKeys(private []byte, passphrase string, publics [][]byte) (crypto.Pr
8888
// so the same passphrase will always generate the same key, this is useful if you don't want to backup the key,
8989
// but it's less secure, you must use a strong passphrase.
9090
func GenerateKeyFile(deterministic bool, privateKeyPath, comment, passphrase string) error {
91+
var prvKeyPem *pem.Block
92+
9193
seed := rand.Reader
9294

93-
if deterministic {
95+
if passphrase != "" && deterministic {
9496
salt := sha256.Sum256([]byte(passphrase))
9597
derivedKey := argon2.IDKey([]byte(passphrase), salt[:], 128, 64*1024, 4, 32)
9698
seed = hkdf.New(sha256.New, derivedKey, nil, nil)
@@ -116,7 +118,11 @@ func GenerateKeyFile(deterministic bool, privateKeyPath, comment, passphrase str
116118
return err
117119
}
118120

119-
prvKeyPem, err := ssh.MarshalPrivateKeyWithPassphrase(privateKey, comment, []byte(passphrase))
121+
if passphrase != "" {
122+
prvKeyPem, err = ssh.MarshalPrivateKeyWithPassphrase(privateKey, comment, []byte(passphrase))
123+
} else {
124+
prvKeyPem, err = ssh.MarshalPrivateKey(privateKey, comment)
125+
}
120126
if err != nil {
121127
return err
122128
}

lib/whisper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
const (
15-
APIVersion = "v0.8.10"
15+
APIVersion = "v0.8.11"
1616
WireFormatVersion = byte(8)
1717
)
1818

0 commit comments

Comments
 (0)