| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "OPENSSL-PKEYUTL 1SSL" |
| 58 |
.TH OPENSSL-PKEYUTL 1SSL 2026-04-07 3.6.2 OpenSSL |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
openssl\-pkeyutl \- asymmetric key command |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
\&\fBopenssl\fR \fBpkeyutl\fR |
| 68 |
[\fB\-help\fR] |
| 69 |
[\fB\-in\fR \fIfile\fR] |
| 70 |
[\fB\-rawin\fR] |
| 71 |
[\fB\-digest\fR \fIalgorithm\fR] |
| 72 |
[\fB\-out\fR \fIfile\fR] |
| 73 |
[\fB\-secret\fR \fIfile\fR] |
| 74 |
[\fB\-sigfile\fR \fIfile\fR] |
| 75 |
[\fB\-inkey\fR \fIfilename\fR|\fIuri\fR] |
| 76 |
[\fB\-keyform\fR \fBDER\fR|\fBPEM\fR|\fBP12\fR|\fBENGINE\fR] |
| 77 |
[\fB\-passin\fR \fIarg\fR] |
| 78 |
[\fB\-pubin\fR] |
| 79 |
[\fB\-certin\fR] |
| 80 |
[\fB\-rev\fR] |
| 81 |
[\fB\-sign\fR] |
| 82 |
[\fB\-verify\fR] |
| 83 |
[\fB\-verifyrecover\fR] |
| 84 |
[\fB\-encrypt\fR] |
| 85 |
[\fB\-decrypt\fR] |
| 86 |
[\fB\-derive\fR] |
| 87 |
[\fB\-peerkey\fR \fIfile\fR] |
| 88 |
[\fB\-peerform\fR \fBDER\fR|\fBPEM\fR|\fBP12\fR|\fBENGINE\fR] |
| 89 |
[\fB\-encap\fR] |
| 90 |
[\fB\-decap\fR] |
| 91 |
[\fB\-kdf\fR \fIalgorithm\fR] |
| 92 |
[\fB\-kdflen\fR \fIlength\fR] |
| 93 |
[\fB\-kemop\fR \fImode\fR] |
| 94 |
[\fB\-pkeyopt\fR \fIopt\fR:\fIvalue\fR] |
| 95 |
[\fB\-pkeyopt_passin\fR \fIopt\fR[:\fIpassarg\fR]] |
| 96 |
[\fB\-hexdump\fR] |
| 97 |
[\fB\-asn1parse\fR] |
| 98 |
[\fB\-engine\fR \fIid\fR] |
| 99 |
[\fB\-engine_impl\fR] |
| 100 |
[\fB\-rand\fR \fIfiles\fR] |
| 101 |
[\fB\-writerand\fR \fIfile\fR] |
| 102 |
[\fB\-provider\fR \fIname\fR] |
| 103 |
[\fB\-provider\-path\fR \fIpath\fR] |
| 104 |
[\fB\-provparam\fR \fI[name:]key=value\fR] |
| 105 |
[\fB\-propquery\fR \fIpropq\fR] |
| 106 |
[\fB\-config\fR \fIconfigfile\fR] |
| 107 |
.SH DESCRIPTION |
| 108 |
.IX Header "DESCRIPTION" |
| 109 |
This command can be used to perform low-level operations |
| 110 |
on asymmetric (public or private) keys using any supported algorithm. |
| 111 |
.PP |
| 112 |
By default the signing operation (see \fB\-sign\fR option) is assumed. |
| 113 |
.SH OPTIONS |
| 114 |
.IX Header "OPTIONS" |
| 115 |
.IP \fB\-help\fR 4 |
| 116 |
.IX Item "-help" |
| 117 |
Print out a usage message. |
| 118 |
.IP "\fB\-in\fR \fIfilename\fR" 4 |
| 119 |
.IX Item "-in filename" |
| 120 |
This specifies the input filename to read data from or standard input |
| 121 |
if this option is not specified. |
| 122 |
.IP \fB\-rawin\fR 4 |
| 123 |
.IX Item "-rawin" |
| 124 |
This indicates that the signature or verification input data is raw data, |
| 125 |
which is not hashed by any message digest algorithm. |
| 126 |
Except with EdDSA, |
| 127 |
the user can specify a digest algorithm by using the \fB\-digest\fR option. |
| 128 |
For signature algorithms like RSA, DSA and ECDSA, |
| 129 |
the default digest algorithm is SHA256. For SM2, it is SM3. |
| 130 |
.Sp |
| 131 |
This option can only be used with \fB\-sign\fR and \fB\-verify\fR. |
| 132 |
For EdDSA (the Ed25519 and Ed448 algorithms) this option |
| 133 |
is implied since OpenSSL 3.5, and required in earlier versions. |
| 134 |
.Sp |
| 135 |
The \fB\-digest\fR option implies \fB\-rawin\fR since OpenSSL 3.5. |
| 136 |
.IP "\fB\-digest\fR \fIalgorithm\fR" 4 |
| 137 |
.IX Item "-digest algorithm" |
| 138 |
This option can only be used with \fB\-sign\fR and \fB\-verify\fR. |
| 139 |
It specifies the digest algorithm that is used to hash the input data |
| 140 |
before signing or verifying it with the input key. This option could be omitted |
| 141 |
if the signature algorithm does not require preprocessing the input through |
| 142 |
a pluggable hash function before signing (for instance, EdDSA). If this option |
| 143 |
is omitted but the signature algorithm requires one and the \fB\-rawin\fR option |
| 144 |
is given, a default value will be used (see \fB\-rawin\fR for details). |
| 145 |
If this option is present, then the \fB\-rawin\fR option |
| 146 |
is implied since OpenSSL 3.5, and required in earlier versions. |
| 147 |
.Sp |
| 148 |
At this time, HashEdDSA (the ph or "prehash" variant of EdDSA) is not supported, |
| 149 |
so the \fB\-digest\fR option cannot be used with EdDSA. |
| 150 |
.IP "\fB\-out\fR \fIfilename\fR" 4 |
| 151 |
.IX Item "-out filename" |
| 152 |
Specifies the output filename to write to or standard output by default. |
| 153 |
.IP "\fB\-secret\fR \fIfilename\fR" 4 |
| 154 |
.IX Item "-secret filename" |
| 155 |
Specifies the shared-secret output filename for when performing encapsulation |
| 156 |
via the \fB\-encap\fR option or decapsulation via the \fB\-decap\fR option. |
| 157 |
The \fB\-encap\fR option also produces a separate (public) ciphertext output which |
| 158 |
is by default written to standard output, but being \fIbinary\fR non-text data, |
| 159 |
is typically also redirected to a file selected via the \fI\-out\fR option. |
| 160 |
.IP "\fB\-sigfile\fR \fIfile\fR" 4 |
| 161 |
.IX Item "-sigfile file" |
| 162 |
Signature file, required and allowed for \fB\-verify\fR operations only. |
| 163 |
.IP "\fB\-inkey\fR \fIfilename\fR|\fIuri\fR" 4 |
| 164 |
.IX Item "-inkey filename|uri" |
| 165 |
The input key, by default it should be a private key. |
| 166 |
.IP "\fB\-keyform\fR \fBDER\fR|\fBPEM\fR|\fBP12\fR|\fBENGINE\fR" 4 |
| 167 |
.IX Item "-keyform DER|PEM|P12|ENGINE" |
| 168 |
The key format; unspecified by default. |
| 169 |
See \fBopenssl\-format\-options\fR\|(1) for details. |
| 170 |
.IP "\fB\-passin\fR \fIarg\fR" 4 |
| 171 |
.IX Item "-passin arg" |
| 172 |
The input key password source. For more information about the format of \fIarg\fR |
| 173 |
see \fBopenssl\-passphrase\-options\fR\|(1). |
| 174 |
.IP \fB\-pubin\fR 4 |
| 175 |
.IX Item "-pubin" |
| 176 |
By default a private key is read from the key input. |
| 177 |
With this option a public key is read instead. |
| 178 |
If the input contains no public key but a private key, its public part is used. |
| 179 |
.IP \fB\-certin\fR 4 |
| 180 |
.IX Item "-certin" |
| 181 |
The input is a certificate containing a public key. |
| 182 |
.IP \fB\-rev\fR 4 |
| 183 |
.IX Item "-rev" |
| 184 |
Reverse the order of the input buffer. This is useful for some libraries |
| 185 |
(such as CryptoAPI) which represent the buffer in little-endian format. |
| 186 |
This cannot be used in conjunction with \fB\-rawin\fR. |
| 187 |
.IP \fB\-sign\fR 4 |
| 188 |
.IX Item "-sign" |
| 189 |
Sign the input data and output the signed result. This requires a private key. |
| 190 |
Using a message digest operation along with this is recommended, |
| 191 |
when applicable, see the \fB\-rawin\fR and \fB\-digest\fR options for details. |
| 192 |
Otherwise, the input data given with the \fB\-in\fR option is assumed to already |
| 193 |
be a digest, but this may then require an additional \fB\-pkeyopt\fR \f(CW\*(C`digest:\*(C'\fR\fImd\fR |
| 194 |
in some cases (e.g., RSA with the default PKCS#1 padding mode). |
| 195 |
Even for other algorithms like ECDSA, where the additional \fB\-pkeyopt\fR option |
| 196 |
does not affect signature output, it is recommended, as it enables |
| 197 |
checking that the input length is consistent with the intended digest. |
| 198 |
.IP \fB\-verify\fR 4 |
| 199 |
.IX Item "-verify" |
| 200 |
Verify the input data against the signature given with the \fB\-sigfile\fR option |
| 201 |
and indicate if the verification succeeded or failed. |
| 202 |
The input data given with the \fB\-in\fR option is assumed to be a hash value |
| 203 |
unless the \fB\-rawin\fR option is specified or implied. |
| 204 |
With raw data, when a digest algorithm is applicable, though it may be inferred |
| 205 |
from the signature or take a default value, it should also be specified. |
| 206 |
.IP \fB\-verifyrecover\fR 4 |
| 207 |
.IX Item "-verifyrecover" |
| 208 |
Verify the given signature and output the recovered data (signature payload). |
| 209 |
For example, in case of RSA PKCS#1 the recovered data is the \fBEMSA\-PKCS\-v1_5\fR |
| 210 |
DER encoding of the digest algorithm OID and value as specified in |
| 211 |
RFC8017 Section 9.2 <https://datatracker.ietf.org/doc/html/rfc8017#section-9.2>. |
| 212 |
.Sp |
| 213 |
Note that here the input given with the \fB\-in\fR option is not a signature input |
| 214 |
(as with the \fB\-sign\fR and \fB\-verify\fR options) but a signature output value, |
| 215 |
typically produced using the \fB\-sign\fR option. |
| 216 |
.Sp |
| 217 |
This option is available only for use with RSA keys. |
| 218 |
.IP \fB\-encrypt\fR 4 |
| 219 |
.IX Item "-encrypt" |
| 220 |
Encrypt the input data using a public key. |
| 221 |
.IP \fB\-decrypt\fR 4 |
| 222 |
.IX Item "-decrypt" |
| 223 |
Decrypt the input data using a private key. |
| 224 |
.IP \fB\-derive\fR 4 |
| 225 |
.IX Item "-derive" |
| 226 |
Derive a shared secret using own private (EC)DH key and peer key. |
| 227 |
.IP "\fB\-peerkey\fR \fIfile\fR" 4 |
| 228 |
.IX Item "-peerkey file" |
| 229 |
File containing the peer public or private (EC)DH key |
| 230 |
to use with the key derivation (agreement) operation. |
| 231 |
Its type must match the type of the own private key given with \fB\-inkey\fR. |
| 232 |
.IP "\fB\-peerform\fR \fBDER\fR|\fBPEM\fR|\fBP12\fR|\fBENGINE\fR" 4 |
| 233 |
.IX Item "-peerform DER|PEM|P12|ENGINE" |
| 234 |
The peer key format; unspecified by default. |
| 235 |
See \fBopenssl\-format\-options\fR\|(1) for details. |
| 236 |
.IP \fB\-encap\fR 4 |
| 237 |
.IX Item "-encap" |
| 238 |
Use a Key Encapsulation Mechanism (\fBKEM\fR) to \fBencapsulate\fR a shared-secret to |
| 239 |
a peer's \fBpublic\fR key. |
| 240 |
The encapsulated result (or ciphertext, non-text binary data) is written to |
| 241 |
standard output by default, or else to the file specified with \fI\-out\fR. |
| 242 |
The \fI\-secret\fR option must also be provided to specify the output file for the |
| 243 |
derived shared-secret value generated in the encapsulation process. |
| 244 |
Encapsulation is supported with a number of public key algorithms, currently: |
| 245 |
ML-KEM, |
| 246 |
X25519, |
| 247 |
X448, |
| 248 |
and |
| 249 |
EC. |
| 250 |
The ECX and EC algorithms use the |
| 251 |
RFC9180 <https://www.rfc-editor.org/rfc/rfc9180> DHKEM construction. |
| 252 |
Encapsulation is also supported with RSA keys via the |
| 253 |
\&\fBRSASVE\fR construction. |
| 254 |
.Sp |
| 255 |
At the API level, encapsulation and decapsulation are also supported for a few |
| 256 |
hybrid ECDHE (no DHKEM) plus \fBML-KEM\fR algorithms, but these are intended |
| 257 |
primarily for use with TLS and should not be used standalone. |
| 258 |
There are in any case no standard public and private key formats for the hybrid |
| 259 |
algorithms, so it is not possible to provide the required key material. |
| 260 |
.IP \fB\-decap\fR 4 |
| 261 |
.IX Item "-decap" |
| 262 |
Decode an encapsulated secret, with the use of a \fB\-private\fR key, to derive the |
| 263 |
same shared-secret as that obtained when the secret was encapsulated to the |
| 264 |
corresponding public key. |
| 265 |
The encapsulated secret is by default read from the standard input, or else |
| 266 |
from the file specified with \fB\-in\fR. |
| 267 |
The derived shared-secret is written to the file specified with the \fB\-secret\fR |
| 268 |
option, which \fImust\fR also be provided. |
| 269 |
Decapsulation is supported with a number of public key algorithms, currently: |
| 270 |
ML-KEM, |
| 271 |
X25519, |
| 272 |
X448, |
| 273 |
and |
| 274 |
EC. |
| 275 |
The ECX and EC algorithms use the |
| 276 |
RFC9180 <https://www.rfc-editor.org/rfc/rfc9180> DHKEM construction. |
| 277 |
Decapsulation is also supported with RSA keys via the |
| 278 |
\&\fBRSASVE\fR construction. |
| 279 |
.IP "\fB\-kemop\fR \fImode\fR" 4 |
| 280 |
.IX Item "-kemop mode" |
| 281 |
This option is used with the \fI\-encap\fR/\fI\-decap\fR commands and specifies the KEM |
| 282 |
\&\fImode\fR specific for the key algorithm when there is no default way to |
| 283 |
encapsulate and decapsulate shared secrets with the chosen key type. |
| 284 |
All the supported algorithms presently support only their default \fImode\fR, and |
| 285 |
this option, though available, is not required. |
| 286 |
.IP "\fB\-kdf\fR \fIalgorithm\fR" 4 |
| 287 |
.IX Item "-kdf algorithm" |
| 288 |
Use key derivation function \fIalgorithm\fR. The supported algorithms are |
| 289 |
at present \fBTLS1\-PRF\fR and \fBHKDF\fR. |
| 290 |
Note: additional parameters and the KDF output length will normally have to be |
| 291 |
set for this to work. |
| 292 |
See \fBEVP_PKEY_CTX_set_hkdf_md\fR\|(3) and \fBEVP_PKEY_CTX_set_tls1_prf_md\fR\|(3) |
| 293 |
for the supported string parameters of each algorithm. |
| 294 |
.IP "\fB\-kdflen\fR \fIlength\fR" 4 |
| 295 |
.IX Item "-kdflen length" |
| 296 |
Set the output length for KDF. |
| 297 |
.IP "\fB\-pkeyopt\fR \fIopt\fR:\fIvalue\fR" 4 |
| 298 |
.IX Item "-pkeyopt opt:value" |
| 299 |
Public key options specified as opt:value. See NOTES below for more details. |
| 300 |
.IP "\fB\-pkeyopt_passin\fR \fIopt\fR[:\fIpassarg\fR]" 4 |
| 301 |
.IX Item "-pkeyopt_passin opt[:passarg]" |
| 302 |
Allows reading a public key option \fIopt\fR from stdin or a password source. |
| 303 |
If only \fIopt\fR is specified, the user will be prompted to enter a password on |
| 304 |
stdin. Alternatively, \fIpassarg\fR can be specified which can be any value |
| 305 |
supported by \fBopenssl\-passphrase\-options\fR\|(1). |
| 306 |
.IP \fB\-hexdump\fR 4 |
| 307 |
.IX Item "-hexdump" |
| 308 |
hex dump the output data. |
| 309 |
.IP \fB\-asn1parse\fR 4 |
| 310 |
.IX Item "-asn1parse" |
| 311 |
Parse the ASN.1 output data to check its DER encoding and print any errors. |
| 312 |
When combined with the \fB\-verifyrecover\fR option, this may be useful in case |
| 313 |
an ASN.1 DER-encoded structure had been signed directly (without hashing it) |
| 314 |
and when checking a signature in PKCS#1 v1.5 format, which has a DER encoding. |
| 315 |
.IP "\fB\-engine\fR \fIid\fR" 4 |
| 316 |
.IX Item "-engine id" |
| 317 |
See "Engine Options" in \fBopenssl\fR\|(1). |
| 318 |
This option is deprecated. |
| 319 |
.IP \fB\-engine_impl\fR 4 |
| 320 |
.IX Item "-engine_impl" |
| 321 |
When used with the \fB\-engine\fR option, it specifies to also use |
| 322 |
engine \fIid\fR for crypto operations. |
| 323 |
.IP "\fB\-rand\fR \fIfiles\fR, \fB\-writerand\fR \fIfile\fR" 4 |
| 324 |
.IX Item "-rand files, -writerand file" |
| 325 |
See "Random State Options" in \fBopenssl\fR\|(1) for details. |
| 326 |
.IP "\fB\-provider\fR \fIname\fR" 4 |
| 327 |
.IX Item "-provider name" |
| 328 |
.PD 0 |
| 329 |
.IP "\fB\-provider\-path\fR \fIpath\fR" 4 |
| 330 |
.IX Item "-provider-path path" |
| 331 |
.IP "\fB\-provparam\fR \fI[name:]key=value\fR" 4 |
| 332 |
.IX Item "-provparam [name:]key=value" |
| 333 |
.IP "\fB\-propquery\fR \fIpropq\fR" 4 |
| 334 |
.IX Item "-propquery propq" |
| 335 |
.PD |
| 336 |
See "Provider Options" in \fBopenssl\fR\|(1), \fBprovider\fR\|(7), and \fBproperty\fR\|(7). |
| 337 |
.IP "\fB\-config\fR \fIconfigfile\fR" 4 |
| 338 |
.IX Item "-config configfile" |
| 339 |
See "Configuration Option" in \fBopenssl\fR\|(1). |
| 340 |
.SH NOTES |
| 341 |
.IX Header "NOTES" |
| 342 |
The operations and options supported vary according to the key algorithm |
| 343 |
and its implementation. The OpenSSL operations and options are indicated below. |
| 344 |
.PP |
| 345 |
Unless otherwise mentioned, the \fB\-pkeyopt\fR option supports |
| 346 |
for all public-key types the \f(CW\*(C`digest:\*(C'\fR\fIalg\fR argument, |
| 347 |
which specifies the digest in use for the signing and verification operations. |
| 348 |
The value \fIalg\fR should represent a digest name as used in the |
| 349 |
\&\fBEVP_get_digestbyname()\fR function for example \fBsha256\fR. This value is not used to |
| 350 |
hash the input data. It is used (by some algorithms) for sanity-checking the |
| 351 |
lengths of data passed in and for creating the structures that make up the |
| 352 |
signature (e.g., \fBDigestInfo\fR in RSASSA PKCS#1 v1.5 signatures). |
| 353 |
.PP |
| 354 |
For instance, |
| 355 |
if the value of the \fB\-pkeyopt\fR option \f(CW\*(C`digest\*(C'\fR argument is \fBsha256\fR, |
| 356 |
the signature or verification input should be the 32 bytes long binary value |
| 357 |
of the SHA256 hash function output. |
| 358 |
.PP |
| 359 |
Unless \fB\-rawin\fR is used or implied, this command does not hash the input data |
| 360 |
but rather it will use the data directly as input to the signature algorithm. |
| 361 |
Depending on the key type, signature type, and mode of padding, the maximum |
| 362 |
sensible lengths of input data differ. With RSA the signed data cannot be longer |
| 363 |
than the key modulus. In case of ECDSA and DSA the data should not be longer |
| 364 |
than the field size, otherwise it will be silently truncated to the field size. |
| 365 |
In any event the input size must not be larger than the largest supported digest |
| 366 |
output size \fBEVP_MAX_MD_SIZE\fR, which currently is 64 bytes. |
| 367 |
.SH "RSA ALGORITHM" |
| 368 |
.IX Header "RSA ALGORITHM" |
| 369 |
The RSA algorithm generally supports the encrypt, decrypt, sign, |
| 370 |
verify and verifyrecover operations. However, some padding modes |
| 371 |
support only a subset of these operations. The following additional |
| 372 |
\&\fBpkeyopt\fR values are supported: |
| 373 |
.IP \fBrsa_padding_mode:\fR\fImode\fR 4 |
| 374 |
.IX Item "rsa_padding_mode:mode" |
| 375 |
This sets the RSA padding mode. Acceptable values for \fImode\fR are \fBpkcs1\fR for |
| 376 |
PKCS#1 padding, \fBnone\fR for no padding, \fBoaep\fR |
| 377 |
for \fBOAEP\fR mode, \fBx931\fR for X9.31 mode and \fBpss\fR for PSS. |
| 378 |
.Sp |
| 379 |
In PKCS#1 padding, if the message digest is not set, then the supplied data is |
| 380 |
signed or verified directly instead of using a \fBDigestInfo\fR structure. If a |
| 381 |
digest is set, then the \fBDigestInfo\fR structure is used and its length |
| 382 |
must correspond to the digest type. |
| 383 |
.Sp |
| 384 |
Note, for \fBpkcs1\fR padding, as a protection against the Bleichenbacher attack, |
| 385 |
the decryption will not fail in case of padding check failures. Use \fBnone\fR |
| 386 |
and manual inspection of the decrypted message to verify if the decrypted |
| 387 |
value has correct PKCS#1 v1.5 padding. |
| 388 |
.Sp |
| 389 |
For \fBoaep\fR mode only encryption and decryption is supported. |
| 390 |
.Sp |
| 391 |
For \fBx931\fR if the digest type is set it is used to format the block data |
| 392 |
otherwise the first byte is used to specify the X9.31 digest ID. Sign, |
| 393 |
verify and verifyrecover are can be performed in this mode. |
| 394 |
.Sp |
| 395 |
For \fBpss\fR mode only sign and verify are supported and the digest type must be |
| 396 |
specified. |
| 397 |
.IP \fBrsa_pss_saltlen:\fR\fIlen\fR 4 |
| 398 |
.IX Item "rsa_pss_saltlen:len" |
| 399 |
For \fBpss\fR mode only this option specifies the salt length. Three special |
| 400 |
values are supported: \fBdigest\fR sets the salt length to the digest length, |
| 401 |
\&\fBmax\fR sets the salt length to the maximum permissible value. When verifying |
| 402 |
\&\fBauto\fR causes the salt length to be automatically determined based on the |
| 403 |
\&\fBPSS\fR block structure. |
| 404 |
.IP \fBrsa_mgf1_md:\fR\fIdigest\fR 4 |
| 405 |
.IX Item "rsa_mgf1_md:digest" |
| 406 |
For PSS and OAEP padding sets the MGF1 digest. If the MGF1 digest is not |
| 407 |
explicitly set in PSS mode then the signing digest is used. |
| 408 |
.IP \fBrsa_oaep_md:\fR\fIdigest\fR 4 |
| 409 |
.IX Item "rsa_oaep_md:digest" |
| 410 |
Sets the digest used for the OAEP hash function. If not explicitly set then |
| 411 |
SHA256 is used. |
| 412 |
.IP \fBrsa_pkcs1_implicit_rejection:\fR\fIflag\fR 4 |
| 413 |
.IX Item "rsa_pkcs1_implicit_rejection:flag" |
| 414 |
Disables (when set to 0) or enables (when set to 1) the use of implicit |
| 415 |
rejection with PKCS#1 v1.5 decryption. When enabled (the default), as a |
| 416 |
protection against Bleichenbacher attack, the library will generate a |
| 417 |
deterministic random plaintext that it will return to the caller in case |
| 418 |
of padding check failure. |
| 419 |
When disabled, it's the callers' responsibility to handle the returned |
| 420 |
errors in a side-channel free manner. |
| 421 |
.SH "RSA-PSS ALGORITHM" |
| 422 |
.IX Header "RSA-PSS ALGORITHM" |
| 423 |
The RSA-PSS algorithm is a restricted version of the RSA algorithm which only |
| 424 |
supports the sign and verify operations with PSS padding. The following |
| 425 |
additional \fB\-pkeyopt\fR values are supported: |
| 426 |
.IP "\fBrsa_padding_mode:\fR\fImode\fR, \fBrsa_pss_saltlen:\fR\fIlen\fR, \fBrsa_mgf1_md:\fR\fIdigest\fR" 4 |
| 427 |
.IX Item "rsa_padding_mode:mode, rsa_pss_saltlen:len, rsa_mgf1_md:digest" |
| 428 |
These have the same meaning as the \fBRSA\fR algorithm with some additional |
| 429 |
restrictions. The padding mode can only be set to \fBpss\fR which is the |
| 430 |
default value. |
| 431 |
.Sp |
| 432 |
If the key has parameter restrictions then the digest, MGF1 |
| 433 |
digest and salt length are set to the values specified in the parameters. |
| 434 |
The digest and MG cannot be changed and the salt length cannot be set to a |
| 435 |
value less than the minimum restriction. |
| 436 |
.SH "DSA ALGORITHM" |
| 437 |
.IX Header "DSA ALGORITHM" |
| 438 |
The DSA algorithm supports signing and verification operations only. Currently |
| 439 |
there are no additional \fB\-pkeyopt\fR options other than \fBdigest\fR. The SHA256 |
| 440 |
digest is assumed by default. |
| 441 |
.SH "DH ALGORITHM" |
| 442 |
.IX Header "DH ALGORITHM" |
| 443 |
The DH algorithm only supports the derivation operation and no additional |
| 444 |
\&\fB\-pkeyopt\fR options. |
| 445 |
.SH "EC ALGORITHM" |
| 446 |
.IX Header "EC ALGORITHM" |
| 447 |
The EC algorithm supports sign, verify and derive operations. The sign and |
| 448 |
verify operations use ECDSA and derive uses ECDH. SHA256 is assumed by default |
| 449 |
for the \fB\-pkeyopt\fR \fBdigest\fR option. |
| 450 |
.SH "X25519 AND X448 ALGORITHMS" |
| 451 |
.IX Header "X25519 AND X448 ALGORITHMS" |
| 452 |
The X25519 and X448 algorithms support key derivation only. Currently there are |
| 453 |
no additional options. |
| 454 |
.SS "SLH-DSA ALGORITHMS" |
| 455 |
.IX Subsection "SLH-DSA ALGORITHMS" |
| 456 |
The SLH-DSA algorithms (SLH\-DSA\-SHA2\-128s, SLH\-DSA\-SHA2\-128f, SLH\-DSA\-SHA2\-192s, SLH\-DSA\-SHA2\-192f, SLH\-DSA\-SHA2\-256s, SLH\-DSA\-SHA2\-256f) are post-quantum signature algorithms. When using SLH-DSA with pkeyutl, the following options are available: |
| 457 |
.IP \fB\-sign\fR 4 |
| 458 |
.IX Item "-sign" |
| 459 |
Sign the input data using an SLH-DSA private key. For example: |
| 460 |
.Sp |
| 461 |
.Vb 1 |
| 462 |
\& $ openssl pkeyutl \-sign \-in file.txt \-inkey slhdsa.pem \-out sig |
| 463 |
.Ve |
| 464 |
.IP \fB\-verify\fR 4 |
| 465 |
.IX Item "-verify" |
| 466 |
Verify the signature using an SLH-DSA public key. For example: |
| 467 |
.Sp |
| 468 |
.Vb 1 |
| 469 |
\& $ openssl pkeyutl \-verify \-in file.txt \-inkey slhdsa.pem \-sigfile sig |
| 470 |
.Ve |
| 471 |
.PP |
| 472 |
See \fBEVP_PKEY\-SLH\-DSA\fR\|(7) and \fBEVP_SIGNATURE\-SLH\-DSA\fR\|(7) for additional details about the SLH-DSA algorithm and its implementation. |
| 473 |
.SH "ML\-DSA\-44, ML\-DSA\-65 AND ML\-DSA\-87 ALGORITHMS" |
| 474 |
.IX Header "ML-DSA-44, ML-DSA-65 AND ML-DSA-87 ALGORITHMS" |
| 475 |
The ML-DSA algorithms are post-quantum signature algorithms that support signing and verification of "raw" messages. |
| 476 |
No preliminary hashing is performed. When using ML-DSA with pkeyutl, the following options are available: |
| 477 |
.IP \fB\-sign\fR 4 |
| 478 |
.IX Item "-sign" |
| 479 |
Sign the input data using an ML-DSA private key. For example: |
| 480 |
.Sp |
| 481 |
.Vb 1 |
| 482 |
\& $ openssl pkeyutl \-sign \-in file.txt \-inkey mldsa65.pem \-out sig |
| 483 |
.Ve |
| 484 |
.IP \fB\-verify\fR 4 |
| 485 |
.IX Item "-verify" |
| 486 |
Verify the signature using an ML-DSA public key. For example: |
| 487 |
.Sp |
| 488 |
.Vb 1 |
| 489 |
\& $ openssl pkeyutl \-verify \-in file.txt \-inkey mldsa65.pem \-sigfile sig |
| 490 |
.Ve |
| 491 |
.IP "\fB\-pkeyopt\fR \fIopt\fR:\fIvalue\fR" 4 |
| 492 |
.IX Item "-pkeyopt opt:value" |
| 493 |
Additional options for ML-DSA signing and verification: |
| 494 |
.RS 4 |
| 495 |
.IP \fBmessage-encoding\fR:\fIvalue\fR 4 |
| 496 |
.IX Item "message-encoding:value" |
| 497 |
Specifies the message encoding mode used for signing. This controls how the input message is processed before signing. Valid values are described in \fBEVP_SIGNATURE\-ML\-DSA\fR\|(7). For example: |
| 498 |
.Sp |
| 499 |
.Vb 1 |
| 500 |
\& $ openssl pkeyutl \-sign \-in file.txt \-inkey mldsa65.pem \-out sig \-pkeyopt message\-encoding:1 |
| 501 |
.Ve |
| 502 |
.IP \fBtest-entropy\fR:\fIvalue\fR 4 |
| 503 |
.IX Item "test-entropy:value" |
| 504 |
Specifies a test entropy value for deterministic signing. For example: |
| 505 |
.Sp |
| 506 |
.Vb 1 |
| 507 |
\& $ openssl pkeyutl \-sign \-in file.txt \-inkey mldsa65.pem \-out sig \-pkeyopt test\-entropy:abcdefghijklmnopqrstuvwxyz012345 |
| 508 |
.Ve |
| 509 |
.IP \fBhextest-entropy\fR:\fIvalue\fR 4 |
| 510 |
.IX Item "hextest-entropy:value" |
| 511 |
Specifies a test entropy value in hex format. For example: |
| 512 |
.Sp |
| 513 |
.Vb 1 |
| 514 |
\& $ openssl pkeyutl \-sign \-in file.txt \-inkey mldsa65.pem \-out sig \-pkeyopt hextest\-entropy:000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f |
| 515 |
.Ve |
| 516 |
.IP \fBdeterministic\fR:\fIvalue\fR 4 |
| 517 |
.IX Item "deterministic:value" |
| 518 |
Enables deterministic signing. For example: |
| 519 |
.Sp |
| 520 |
.Vb 1 |
| 521 |
\& $ openssl pkeyutl \-sign \-in file.txt \-inkey mldsa65.pem \-out sig \-pkeyopt deterministic:1 |
| 522 |
.Ve |
| 523 |
.IP \fBmu\fR:\fIvalue\fR 4 |
| 524 |
.IX Item "mu:value" |
| 525 |
Specifies the mu parameter. For example: |
| 526 |
.Sp |
| 527 |
.Vb 2 |
| 528 |
\& $ echo \-n "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" >file.txt |
| 529 |
\& $ openssl pkeyutl \-sign \-in file.txt \-inkey mldsa65.pem \-out sig \-pkeyopt mu:1 |
| 530 |
.Ve |
| 531 |
.RE |
| 532 |
.RS 4 |
| 533 |
.RE |
| 534 |
.IP \fBcontext-string\fR:\fIstring\fR 4 |
| 535 |
.IX Item "context-string:string" |
| 536 |
Specifies a context string for both signing and verification operations. The context string must be the same for verification to succeed. For example: |
| 537 |
.Sp |
| 538 |
.Vb 2 |
| 539 |
\& $ openssl pkeyutl \-sign \-in file.txt \-inkey mldsa65.pem \-out sig \-pkeyopt context\-string:mycontext |
| 540 |
\& $ openssl pkeyutl \-verify \-in file.txt \-inkey mldsa65.pem \-sigfile sig \-pkeyopt context\-string:mycontext |
| 541 |
.Ve |
| 542 |
.IP \fBhexcontext-string\fR:\fIstring\fR 4 |
| 543 |
.IX Item "hexcontext-string:string" |
| 544 |
Specifies a context string in hex format, allowing binary control values. For example: |
| 545 |
.Sp |
| 546 |
.Vb 1 |
| 547 |
\& $ openssl pkeyutl \-sign \-in file.txt \-inkey mldsa65.pem \-out sig \-pkeyopt hexcontext\-string:6d79636f6e74657874 |
| 548 |
.Ve |
| 549 |
.PP |
| 550 |
The signing operation supports a \fBdeterministic\fR:\fIbool\fR option, |
| 551 |
with \fIbool\fR set to \f(CW1\fR if a deterministic signature is to be generated |
| 552 |
with a fixed all zero random input. |
| 553 |
By default, or if the \fIbool\fR is \f(CW0\fR a random entropy value is used. |
| 554 |
A deterministic result can also be obtained by specifying an explicit |
| 555 |
entropy value via the \fBhextest-entropy\fR:\fIvalue\fR parameter. |
| 556 |
Deterministic \fBML-DSA\fR signing should only be used in tests. |
| 557 |
.PP |
| 558 |
See \fBEVP_SIGNATURE\-ML\-DSA\fR\|(7) for additional details about the ML-DSA algorithms and their implementation. |
| 559 |
.SH "ML\-KEM\-512, ML\-KEM\-768 AND ML\-KEM\-1024 ALGORITHMS" |
| 560 |
.IX Header "ML-KEM-512, ML-KEM-768 AND ML-KEM-1024 ALGORITHMS" |
| 561 |
The ML-KEM algorithms support encapsulation and decapsulation only. |
| 562 |
The encapsulation operation supports a \fBhexikme\fR:\fIentropy\fR option, |
| 563 |
with \fIentropy\fR the 64 hexadecimal digit encoding of a 32\-byte value. |
| 564 |
This should only be used in tests, known or leaked values of the option may |
| 565 |
compromise the generated shared secret. |
| 566 |
.PP |
| 567 |
See \fBEVP_KEM\-ML\-KEM\fR\|(7) for additional detail. |
| 568 |
.SH "ED25519 AND ED448 ALGORITHMS" |
| 569 |
.IX Header "ED25519 AND ED448 ALGORITHMS" |
| 570 |
These algorithms only support signing and verifying. OpenSSL only implements the |
| 571 |
"pure" variants of these algorithms so raw data can be passed directly to them |
| 572 |
without hashing them first. OpenSSL only supports |
| 573 |
"oneshot" operation with these algorithms. This means that the entire file to |
| 574 |
be signed/verified must be read into memory before processing it. Signing or |
| 575 |
Verifying very large files should be avoided. Additionally the size of the file |
| 576 |
must be known for this to work. If the size of the file cannot be determined |
| 577 |
(for example if the input is stdin) then the sign or verify operation will fail. |
| 578 |
.SH SM2 |
| 579 |
.IX Header "SM2" |
| 580 |
The SM2 algorithm supports sign, verify, encrypt and decrypt operations. For |
| 581 |
the sign and verify operations, SM2 requires an Distinguishing ID string to |
| 582 |
be passed in. The following \fB\-pkeyopt\fR value is supported: |
| 583 |
.IP \fBdistid:\fR\fIstring\fR 4 |
| 584 |
.IX Item "distid:string" |
| 585 |
This sets the ID string used in SM2 sign or verify operations. While verifying |
| 586 |
an SM2 signature, the ID string must be the same one used when signing the data. |
| 587 |
Otherwise the verification will fail. |
| 588 |
.IP \fBhexdistid:\fR\fIhex_string\fR 4 |
| 589 |
.IX Item "hexdistid:hex_string" |
| 590 |
This sets the ID string used in SM2 sign or verify operations. While verifying |
| 591 |
an SM2 signature, the ID string must be the same one used when signing the data. |
| 592 |
Otherwise the verification will fail. The ID string provided with this option |
| 593 |
should be a valid hexadecimal value. |
| 594 |
.SH EXAMPLES |
| 595 |
.IX Header "EXAMPLES" |
| 596 |
Sign some data using a private key: |
| 597 |
.PP |
| 598 |
.Vb 1 |
| 599 |
\& openssl pkeyutl \-sign \-in file \-inkey key.pem \-out sig |
| 600 |
.Ve |
| 601 |
.PP |
| 602 |
Recover the signed data (e.g. if an RSA key is used): |
| 603 |
.PP |
| 604 |
.Vb 1 |
| 605 |
\& openssl pkeyutl \-verifyrecover \-in sig \-inkey key.pem |
| 606 |
.Ve |
| 607 |
.PP |
| 608 |
Verify the signature (e.g. a DSA key): |
| 609 |
.PP |
| 610 |
.Vb 1 |
| 611 |
\& openssl pkeyutl \-verify \-in file \-sigfile sig \-inkey key.pem |
| 612 |
.Ve |
| 613 |
.PP |
| 614 |
Sign data using a message digest value (this is currently only valid for RSA): |
| 615 |
.PP |
| 616 |
.Vb 1 |
| 617 |
\& openssl pkeyutl \-sign \-in file \-inkey key.pem \-out sig \-pkeyopt digest:sha256 |
| 618 |
.Ve |
| 619 |
.PP |
| 620 |
Derive a shared secret value: |
| 621 |
.PP |
| 622 |
.Vb 1 |
| 623 |
\& openssl pkeyutl \-derive \-inkey key.pem \-peerkey pubkey.pem \-out secret |
| 624 |
.Ve |
| 625 |
.PP |
| 626 |
Hexdump 48 bytes of TLS1 PRF using digest \fBSHA256\fR and shared secret and |
| 627 |
seed consisting of the single byte 0xFF: |
| 628 |
.PP |
| 629 |
.Vb 2 |
| 630 |
\& openssl pkeyutl \-kdf TLS1\-PRF \-kdflen 48 \-pkeyopt md:SHA256 \e |
| 631 |
\& \-pkeyopt hexsecret:ff \-pkeyopt hexseed:ff \-hexdump |
| 632 |
.Ve |
| 633 |
.PP |
| 634 |
Derive a key using \fBscrypt\fR where the password is read from command line: |
| 635 |
.PP |
| 636 |
.Vb 2 |
| 637 |
\& openssl pkeyutl \-kdf scrypt \-kdflen 16 \-pkeyopt_passin pass \e |
| 638 |
\& \-pkeyopt hexsalt:aabbcc \-pkeyopt N:16384 \-pkeyopt r:8 \-pkeyopt p:1 |
| 639 |
.Ve |
| 640 |
.PP |
| 641 |
Derive using the same algorithm, but read key from environment variable MYPASS: |
| 642 |
.PP |
| 643 |
.Vb 2 |
| 644 |
\& openssl pkeyutl \-kdf scrypt \-kdflen 16 \-pkeyopt_passin pass:env:MYPASS \e |
| 645 |
\& \-pkeyopt hexsalt:aabbcc \-pkeyopt N:16384 \-pkeyopt r:8 \-pkeyopt p:1 |
| 646 |
.Ve |
| 647 |
.PP |
| 648 |
Sign some data using an \fBSM2\fR\|(7) private key and a specific ID: |
| 649 |
.PP |
| 650 |
.Vb 2 |
| 651 |
\& openssl pkeyutl \-sign \-in file \-inkey sm2.key \-out sig \-rawin \-digest sm3 \e |
| 652 |
\& \-pkeyopt distid:someid |
| 653 |
.Ve |
| 654 |
.PP |
| 655 |
Verify some data using an \fBSM2\fR\|(7) certificate and a specific ID: |
| 656 |
.PP |
| 657 |
.Vb 2 |
| 658 |
\& openssl pkeyutl \-verify \-certin \-in file \-inkey sm2.cert \-sigfile sig \e |
| 659 |
\& \-rawin \-digest sm3 \-pkeyopt distid:someid |
| 660 |
.Ve |
| 661 |
.PP |
| 662 |
Decrypt some data using a private key with OAEP padding using SHA256: |
| 663 |
.PP |
| 664 |
.Vb 2 |
| 665 |
\& openssl pkeyutl \-decrypt \-in file \-inkey key.pem \-out secret \e |
| 666 |
\& \-pkeyopt rsa_padding_mode:oaep \-pkeyopt rsa_oaep_md:sha256 |
| 667 |
.Ve |
| 668 |
.PP |
| 669 |
Create an ML-DSA key pair and sign data with a specific context string: |
| 670 |
.PP |
| 671 |
.Vb 2 |
| 672 |
\& $ openssl genpkey \-algorithm ML\-DSA\-65 \-out mldsa65.pem |
| 673 |
\& $ openssl pkeyutl \-sign \-in file.txt \-inkey mldsa65.pem \-out sig \-pkeyopt context\-string:example |
| 674 |
.Ve |
| 675 |
.PP |
| 676 |
Verify a signature using ML-DSA with the same context string: |
| 677 |
.PP |
| 678 |
.Vb 1 |
| 679 |
\& $ openssl pkeyutl \-verify \-in file.txt \-inkey mldsa65.pem \-sigfile sig \-pkeyopt context\-string:example |
| 680 |
.Ve |
| 681 |
.PP |
| 682 |
Generate an ML-KEM key pair and use it for encapsulation: |
| 683 |
.PP |
| 684 |
.Vb 3 |
| 685 |
\& $ openssl genpkey \-algorithm ML\-KEM\-768 \-out mlkem768.pem |
| 686 |
\& $ openssl pkey \-in mlkem768.pem \-pubout \-out mlkem768_pub.pem |
| 687 |
\& $ openssl pkeyutl \-encap \-inkey mlkem768_pub.pem \-pubin \-out ciphertext \-secret shared_secret.bin |
| 688 |
.Ve |
| 689 |
.PP |
| 690 |
Decapsulate a shared secret using an ML-KEM private key: |
| 691 |
.PP |
| 692 |
.Vb 1 |
| 693 |
\& $ openssl pkeyutl \-decap \-inkey mlkem768.pem \-in ciphertext \-secret decapsulated_secret.bin |
| 694 |
.Ve |
| 695 |
.PP |
| 696 |
Create an SLH-DSA key pair and sign data: |
| 697 |
.PP |
| 698 |
.Vb 2 |
| 699 |
\& $ openssl genpkey \-algorithm SLH\-DSA\-SHA2\-128s \-out slh\-dsa.pem |
| 700 |
\& $ openssl pkeyutl \-sign \-in file.txt \-inkey slh\-dsa.pem \-out sig |
| 701 |
.Ve |
| 702 |
.PP |
| 703 |
Verify a signature using SLH-DSA: |
| 704 |
.PP |
| 705 |
.Vb 1 |
| 706 |
\& $ openssl pkeyutl \-verify \-in file.txt \-inkey slh\-dsa.pem \-sigfile sig |
| 707 |
.Ve |
| 708 |
.SH "SEE ALSO" |
| 709 |
.IX Header "SEE ALSO" |
| 710 |
\&\fBopenssl\fR\|(1), |
| 711 |
\&\fBopenssl\-genpkey\fR\|(1), |
| 712 |
\&\fBopenssl\-pkey\fR\|(1), |
| 713 |
\&\fBopenssl\-rsautl\fR\|(1) |
| 714 |
\&\fBopenssl\-dgst\fR\|(1), |
| 715 |
\&\fBopenssl\-rsa\fR\|(1), |
| 716 |
\&\fBopenssl\-genrsa\fR\|(1), |
| 717 |
\&\fBopenssl\-kdf\fR\|(1) |
| 718 |
\&\fBEVP_PKEY_CTX_set_hkdf_md\fR\|(3), |
| 719 |
\&\fBEVP_PKEY_CTX_set_tls1_prf_md\fR\|(3), |
| 720 |
.SH HISTORY |
| 721 |
.IX Header "HISTORY" |
| 722 |
Since OpenSSL 3.5, |
| 723 |
the \fB\-digest\fR option implies \fB\-rawin\fR, and these two options are |
| 724 |
no longer required when signing or verifying with an Ed25519 or Ed448 key. |
| 725 |
.PP |
| 726 |
Also since OpenSSL 3.5, the \fB\-kemop\fR option is no longer required for any of |
| 727 |
the supported algorithms, the only supported \fBmode\fR is now the default. |
| 728 |
.PP |
| 729 |
The \fB\-engine\fR option was deprecated in OpenSSL 3.0. |
| 730 |
.SH COPYRIGHT |
| 731 |
.IX Header "COPYRIGHT" |
| 732 |
Copyright 2006\-2026 The OpenSSL Project Authors. All Rights Reserved. |
| 733 |
.PP |
| 734 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 735 |
this file except in compliance with the License. You can obtain a copy |
| 736 |
in the file LICENSE in the source distribution or at |
| 737 |
<https://www.openssl.org/source/license.html>. |