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