diff --git a/crypto.go b/crypto.go index b63623e8..1efaef3d 100644 --- a/crypto.go +++ b/crypto.go @@ -186,9 +186,13 @@ func generatePrivateKey(typ string) string { } err = dsa.GenerateKey(key, rand.Reader) priv = key - case "ecdsa": + case "ecdsa", "ec_p256": // again, good enough for government work priv, err = ecdsa.GenerateKey(elliptic.P256(), rand.Reader) + case "ec_p384": + priv, err = ecdsa.GenerateKey(elliptic.P384(), rand.Reader) + case "ec_p521": + priv, err = ecdsa.GenerateKey(elliptic.P521(), rand.Reader) case "ed25519": _, priv, err = ed25519.GenerateKey(rand.Reader) default: diff --git a/crypto_test.go b/crypto_test.go index fc34ee0a..6df7afaf 100644 --- a/crypto_test.go +++ b/crypto_test.go @@ -161,6 +161,30 @@ func TestGenPrivateKey(t *testing.T) { if !strings.Contains(out, "EC PRIVATE KEY") { t.Error("Expected EC PRIVATE KEY") } + tpl = `{{genPrivateKey "ec_p256"}}` + out, err = runRaw(tpl, nil) + if err != nil { + t.Error(err) + } + if !strings.Contains(out, "EC PRIVATE KEY") { + t.Error("Expected EC PRIVATE KEY") + } + tpl = `{{genPrivateKey "ec_p384"}}` + out, err = runRaw(tpl, nil) + if err != nil { + t.Error(err) + } + if !strings.Contains(out, "EC PRIVATE KEY") { + t.Error("Expected EC PRIVATE KEY") + } + tpl = `{{genPrivateKey "ec_p521"}}` + out, err = runRaw(tpl, nil) + if err != nil { + t.Error(err) + } + if !strings.Contains(out, "EC PRIVATE KEY") { + t.Error("Expected EC PRIVATE KEY") + } tpl = `{{genPrivateKey "ed25519"}}` out, err = runRaw(tpl, nil) if err != nil { diff --git a/docs/crypto.md b/docs/crypto.md index 35dbaa9c..c2e6510c 100644 --- a/docs/crypto.md +++ b/docs/crypto.md @@ -86,7 +86,9 @@ block. It takes one of the values for its first param: -- `ecdsa`: Generate an elliptic curve DSA key (P256) +- `ecdsa`, `ec_p256`: Generate an elliptic curve DSA key (P-256) +- `ec_p384`: Generate an elliptic curve DSA key (P-384) +- `ec_p521`: Generate an elliptic curve DSA key (P-521) - `dsa`: Generate a DSA key (L2048N256) - `rsa`: Generate an RSA 4096 key - `ed25519`: Generate an Ed25519 key