Home / Alt manpages / openssl-ecparam(1ssl)

  • openssl-ecparam(1ssl)
  • OpenSSL command
  • linux

Create, Inspect and Validate OpenSSL EC Parameters Safely

You will create an elliptic-curve (EC) parameter file with OpenSSL, check that it is valid, inspect its human-readable form, and optionally generate a private key from it. The examples use the openssl ecparam command from the locally installed OpenSSL package, version 3.0.13-0ubuntu3.15. Allow about 15 minutes if you are following the examples in a scratch directory.

You need a shell and a writable working directory. These commands normally run as an ordinary user. Do not use sudo unless the directory you chose is deliberately restricted. The examples use prime256v1, also known as NIST P-256. OpenSSL can use known, named curves here; this command does not invent new elliptic-curve groups.

1. Confirm the command and choose a curve

Check which executable is first in your path, then list the curve names available to that installation:

$ command -v openssl
/home/linuxbrew/.linuxbrew/bin/openssl
$ openssl ecparam -list_curves | grep -E 'prime256v1|secp384r1'
secp384r1 : NIST/SECG curve over a 384 bit prime field
prime256v1: NIST/X9.62/SECG curve over a 256 bit prime field

The list is the authority for names accepted by this installation. If your required curve is absent, stop and check the application's compatibility requirements rather than substituting a similarly named curve.

Checkpoint

Record the exact curve name you intend to use. A spelling error is an input error, not a request for OpenSSL to find the closest match.

2. Create a named-curve parameter file

Use a new destination for the first run. The default output format is PEM, and the default parameter encoding is named_curve:

$ openssl ecparam -name prime256v1 -out ec-param.pem
$ sed -n '1,3p' ec-param.pem
-----BEGIN EC PARAMETERS-----
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----

A named-curve file records the curve by its identifier rather than spelling out every domain parameter. It is compact and is usually the sensible format when the consumer already knows the curve. The command writes to standard output if -out is omitted; keep that behaviour in mind before redirecting output into a valuable file.

Redirection and -out can overwrite an existing destination. Do not use the input and output path together: the manual explicitly warns that they should not be the same. For a replacement, write a new file, validate it, then move it into place after checking the result.

3. Validate the parameters

Run both checks when a parameter file has arrived from another system or is about to enter a deployment:

$ openssl ecparam -in ec-param.pem -check -noout
checking elliptic curve parameters: ok
$ openssl ecparam -in ec-param.pem -check_named -noout
checking elliptic curve parameters: ok

-check validates the elliptic-curve parameters. -check_named additionally checks that named-curve parameters match one of OpenSSL's built-in curves. -noout suppresses the encoded parameter block, leaving the diagnostic easier to read.

A successful check is not proof that an application will accept the file. The application may require a particular curve, encoding, provider or file format. Treat the command's zero exit status as a successful OpenSSL validation, then perform the consumer's own test.

Checkpoint

The command must print ok and return zero. Check the status immediately when scripting:

$ openssl ecparam -in ec-param.pem -check -noout
checking elliptic curve parameters: ok
$ printf '%s\n' "$?"
0

4. Inspect the curve in readable form

Use -text with -noout when you need to review the parameters without printing the PEM or DER representation:

$ openssl ecparam -in ec-param.pem -noout -text
EC-Parameters: (256 bit)
ASN1 OID: prime256v1
NIST CURVE: P-256

For a quick identity check, the OID and curve description are more useful than copying a long block of hexadecimal values. Keep the full output for an audit only when you have a reason to compare low-level details.

5. Choose explicit parameters or DER

Some older or specialised consumers require explicit parameters. Generate that form deliberately:

$ openssl ecparam -name prime256v1 -param_enc explicit -out ec-param-explicit.pem
$ openssl ecparam -in ec-param-explicit.pem -check -noout
checking elliptic curve parameters: ok

Explicit encoding is much larger and can expose more implementation detail. It is not automatically more trustworthy. Use it only when the receiving software requires it. The default is named_curve.

PEM is the default output format. Use DER when a binary ASN.1 file is required, and specify -inform DER when reading it back:

$ openssl ecparam -in ec-param.pem -outform DER -out ec-param.der
$ file ec-param.der
ec-param.der: data
$ openssl ecparam -in ec-param.der -inform DER -check -noout
checking elliptic curve parameters: ok

Do not infer a format from the filename alone. The format flags describe the bytes OpenSSL should read or write.

6. Generate a private key only when you mean to

-genkey generates an EC private key using the selected parameters. It writes sensitive key material, so use a private directory with restrictive permissions and do not paste the output into a ticket or terminal transcript:

$ umask 077
$ openssl ecparam -name prime256v1 -genkey -out ec-private-key.pem
$ openssl pkey -in ec-private-key.pem -text -noout | sed -n '1,4p'
Private-Key: (256 bit)
priv:
    ...

On this OpenSSL installation the resulting PEM contains an EC parameters block followed by an EC private key block. The key is not protected by a passphrase by this command. If the key must be stored on disk, decide separately how it will be encrypted, backed up and eventually revoked. Do not publish or commit ec-private-key.pem.

Warning

Deleting a private key can make any data or identity that depends on it unusable. If you created it by mistake, restrict it first with chmod 600 ec-private-key.pem, then remove it only after checking that it is not needed and that no backup or service refers to it.

7. Diagnose the common failures

  • Unknown curve: rerun openssl ecparam -list_curves and copy an exact short name. Do not guess from a marketing name.
  • Unreadable input: check the path and permissions with ls -l ec-param.pem. Reading a system-owned file may need elevated access, but changing its permissions is not a fix.
  • Failed validation: keep the original input, capture the diagnostic, and obtain a new parameter file from the producer. Do not silence a failed -check by adding -noout; that option only controls output.
  • Unexpected binary or text: make -inform and -outform explicit and validate the destination with the matching command.
  • Lost output: remember that omitting -out sends the result to standard output. In a script, write to a new temporary name, check it, and then perform the final rename.

Done means

  • The curve name came from -list_curves and matches the consumer's requirements.
  • The parameter file was written in the intended PEM or DER format.
  • -check succeeded, and -check_named was used where named-curve identity matters.
  • Readable inspection confirmed the expected curve and bit size.
  • Any private key was created deliberately, kept private, and not overwritten or published.