]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man1/openssl-pkeyutl.pod
Replace '=for comment ifdef' with '=for openssl'
[thirdparty/openssl.git] / doc / man1 / openssl-pkeyutl.pod
CommitLineData
5ce60a20
DSH
1=pod
2
3=head1 NAME
4
b6b66573 5openssl-pkeyutl - public key algorithm utility
5ce60a20
DSH
6
7=head1 SYNOPSIS
8
9B<openssl> B<pkeyutl>
169394d4 10[B<-help>]
e8769719 11[B<-in> I<file>]
a7cef52f 12[B<-rawin>]
e8769719
RS
13[B<-digest> I<algorithm>]
14[B<-out> I<file>]
15[B<-sigfile> I<file>]
16[B<-inkey> I<file>]
17[B<-keyform> B<DER>|B<PEM>|B<ENGINE>]
18[B<-passin> I<arg>]
19[B<-peerkey> I<file>]
20[B<-peerform> B<DER>|B<PEM>|B<ENGINE>]
5ce60a20
DSH
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>]
e8769719
RS
30[B<-kdf> I<algorithm>]
31[B<-kdflen> I<length>]
2f0ea936
RL
32[B<-pkeyopt> I<opt>:I<value>]
33[B<-pkeyopt_passin> I<opt>[:I<passarg>]]
5ce60a20
DSH
34[B<-hexdump>]
35[B<-asn1parse>]
fed8bd90 36[B<-rand> I<files>]
e8769719
RS
37[B<-writerand> I<file>]
38[B<-engine> I<id>]
a173a7ee 39[B<-engine_impl>]
5ce60a20 40
9f3c076b 41=for openssl ifdef engine engine_impl
1738c0ce 42
5ce60a20
DSH
43=head1 DESCRIPTION
44
35a810bb
RL
45This command can be used to perform low level public key
46operations using any supported algorithm.
5ce60a20 47
3dfda1a6 48=head1 OPTIONS
5ce60a20
DSH
49
50=over 4
51
169394d4
MR
52=item B<-help>
53
54Print out a usage message.
55
e8769719 56=item B<-in> I<filename>
5ce60a20
DSH
57
58This specifies the input filename to read data from or standard input
59if this option is not specified.
60
a7cef52f
PY
61=item B<-rawin>
62
63This indicates that the input data is raw data, which is not hashed by any
64message digest algorithm. The user can specify a digest algorithm by using
65the B<-digest> option. This option can only be used with B<-sign> and
ee633ace 66B<-verify> and must be used with the Ed25519 and Ed448 algorithms.
a7cef52f 67
e8769719 68=item B<-digest> I<algorithm>
a7cef52f
PY
69
70This specifies the digest algorithm which is used to hash the input data before
71signing or verifying it with the input key. This option could be omitted if the
72signature algorithm does not require one (for instance, EdDSA). If this option
73is omitted but the signature algorithm requires one, a default value will be
74used. For signature algorithms like RSA, DSA and ECDSA, SHA-256 will be the
75default digest algorithm. For SM2, it will be SM3. If this option is present,
35a810bb 76then the B<-rawin> option must be also specified.
a7cef52f 77
e8769719 78=item B<-out> I<filename>
5ce60a20 79
c4de074e 80Specifies the output filename to write to or standard output by
5ce60a20
DSH
81default.
82
e8769719 83=item B<-sigfile> I<file>
a173a7ee 84
2f0ea936 85Signature file, required for B<-verify> operations only
a173a7ee 86
e8769719 87=item B<-inkey> I<file>
5ce60a20 88
c4de074e 89The input key file, by default it should be a private key.
5ce60a20 90
e8769719 91=item B<-keyform> B<DER>|B<PEM>|B<ENGINE>
5ce60a20 92
c4de074e 93The key format PEM, DER or ENGINE. Default is PEM.
e5fa864f 94
e8769719 95=item B<-passin> I<arg>
e5fa864f 96
2f0ea936 97The input key password source. For more information about the format of I<arg>
3a4e43de 98see L<openssl(1)/Pass Phrase Options>.
e5fa864f 99
e8769719 100=item B<-peerkey> I<file>
5ce60a20 101
c4de074e 102The peer key file, used by key derivation (agreement) operations.
5ce60a20 103
e8769719 104=item B<-peerform> B<DER>|B<PEM>|B<ENGINE>
5ce60a20 105
2f0ea936 106The peer key format B<PEM>, B<DER> or B<ENGINE>. Default is B<PEM>.
5ce60a20
DSH
107
108=item B<-pubin>
109
c4de074e 110The input file is a public key.
5ce60a20
DSH
111
112=item B<-certin>
113
c4de074e 114The input is a certificate containing a public key.
5ce60a20 115
8d970ca7
DSH
116=item B<-rev>
117
c4de074e 118Reverse the order of the input buffer. This is useful for some libraries
8d970ca7
DSH
119(such as CryptoAPI) which represent the buffer in little endian format.
120
5ce60a20
DSH
121=item B<-sign>
122
a0abb6a1
MC
123Sign the input data (which must be a hash) and output the signed result. This
124requires a private key.
5ce60a20
DSH
125
126=item B<-verify>
127
a0abb6a1
MC
128Verify the input data (which must be a hash) against the signature file and
129indicate if the verification succeeded or failed.
5ce60a20
DSH
130
131=item B<-verifyrecover>
132
a0abb6a1 133Verify the input data (which must be a hash) and output the recovered data.
5ce60a20
DSH
134
135=item B<-encrypt>
136
c4de074e 137Encrypt the input data using a public key.
5ce60a20
DSH
138
139=item B<-decrypt>
140
c4de074e 141Decrypt the input data using a private key.
5ce60a20
DSH
142
143=item B<-derive>
144
c4de074e 145Derive a shared secret using the peer key.
5ce60a20 146
e8769719 147=item B<-kdf> I<algorithm>
924ec89a 148
2f0ea936 149Use key derivation function I<algorithm>. The supported algorithms are
f04abe7d 150at present B<TLS1-PRF> and B<HKDF>.
77a795e4 151Note: additional parameters and the KDF output length will normally have to be
b275f3b6
RL
152set for this to work.
153See L<EVP_PKEY_CTX_set_hkdf_md(3)> and L<EVP_PKEY_CTX_set_tls1_prf_md(3)>
f04abe7d 154for the supported string parameters of each algorithm.
924ec89a 155
e8769719 156=item B<-kdflen> I<length>
924ec89a 157
f04abe7d 158Set the output length for KDF.
924ec89a 159
2f0ea936 160=item B<-pkeyopt> I<opt>:I<value>
a173a7ee
RS
161
162Public key options specified as opt:value. See NOTES below for more details.
163
2f0ea936 164=item B<-pkeyopt_passin> I<opt>[:I<passarg>]
6dfcea3d 165
2f0ea936
RL
166Allows reading a public key option I<opt> from stdin or a password source.
167If only I<opt> is specified, the user will be prompted to enter a password on
168stdin. Alternatively, I<passarg> can be specified which can be any value
f5c14c63 169supported by L<openssl(1)/Pass phrase options>.
6dfcea3d 170
5ce60a20
DSH
171=item B<-hexdump>
172
173hex dump the output data.
174
175=item B<-asn1parse>
176
c4de074e 177Parse the ASN.1 output data, this is useful when combined with the
5ce60a20
DSH
178B<-verifyrecover> option when an ASN1 structure is signed.
179
fed8bd90 180=item B<-rand> I<files>
3ee1eac2 181
fed8bd90 182The files containing random data used to seed the random number generator.
3ee1eac2
RS
183Multiple files can be specified separated by an OS-dependent character.
184The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
185all others.
186
e8769719 187=item B<-writerand> I<file>
3ee1eac2
RS
188
189Writes random data to the specified I<file> upon exit.
190This can be used with a subsequent B<-rand> flag.
191
e8769719 192=item B<-engine> I<id>
a173a7ee 193
35a810bb 194Specifying an engine (by its unique I<id> string) will cause this command
a173a7ee
RS
195to attempt to obtain a functional reference to the specified engine,
196thus initialising it if needed. The engine will then be set as the default
197for all available algorithms.
198
199=item B<-engine_impl>
200
201When used with the B<-engine> option, it specifies to also use
2f0ea936 202engine I<id> for crypto operations.
a173a7ee 203
5ce60a20
DSH
204=back
205
206=head1 NOTES
207
208The operations and options supported vary according to the key algorithm
209and its implementation. The OpenSSL operations and options are indicated below.
210
2f0ea936 211Unless otherwise mentioned all algorithms support the B<digest:>I<alg> option
8d970ca7 212which specifies the digest in use for sign, verify and verifyrecover operations.
2f0ea936 213The value I<alg> should represent a digest name as used in the
a0abb6a1
MC
214EVP_get_digestbyname() function for example B<sha1>. This value is not used to
215hash the input data. It is used (by some algorithms) for sanity-checking the
35a810bb
RL
216lengths of data passed in and for creating the structures that make up the
217signature (e.g. B<DigestInfo> in RSASSA PKCS#1 v1.5 signatures).
a0abb6a1 218
35a810bb 219This command does not hash the input data (except where -rawin is used) but
ee633ace
MC
220rather it will use the data directly as input to the signature algorithm.
221Depending on the key type, signature type, and mode of padding, the maximum
222acceptable lengths of input data differ. The signed data can't be longer than
223the key modulus with RSA. In case of ECDSA and DSA the data shouldn't be longer
224than the field size, otherwise it will be silently truncated to the field size.
225In any event the input size must not be larger than the largest supported digest
226size.
a0abb6a1
MC
227
228In other words, if the value of digest is B<sha1> the input should be the 20
229bytes long binary encoding of the SHA-1 hash function output.
230
5ce60a20
DSH
231=head1 RSA ALGORITHM
232
d231a401
VD
233The RSA algorithm generally supports the encrypt, decrypt, sign,
234verify and verifyrecover operations. However, some padding modes
235support only a subset of these operations. The following additional
236B<pkeyopt> values are supported:
5ce60a20 237
8d970ca7
DSH
238=over 4
239
2f0ea936 240=item B<rsa_padding_mode:>I<mode>
8d970ca7 241
2f0ea936 242This sets the RSA padding mode. Acceptable values for I<mode> are B<pkcs1> for
8d970ca7
DSH
243PKCS#1 padding, B<sslv23> for SSLv23 padding, B<none> for no padding, B<oaep>
244for B<OAEP> mode, B<x931> for X9.31 mode and B<pss> for PSS.
5ce60a20 245
1bc74519 246In PKCS#1 padding if the message digest is not set then the supplied data is
8d970ca7
DSH
247signed or verified directly instead of using a B<DigestInfo> structure. If a
248digest is set then the a B<DigestInfo> structure is used and its the length
249must correspond to the digest type.
250
7b1d9460 251For B<oaep> mode only encryption and decryption is supported.
8d970ca7
DSH
252
253For B<x931> if the digest type is set it is used to format the block data
254otherwise the first byte is used to specify the X9.31 digest ID. Sign,
255verify and verifyrecover are can be performed in this mode.
256
257For B<pss> mode only sign and verify are supported and the digest type must be
258specified.
259
2f0ea936 260=item B<rsa_pss_saltlen:>I<len>
8d970ca7 261
137096a7 262For B<pss> mode only this option specifies the salt length. Three special
2f0ea936
RL
263values are supported: B<digest> sets the salt length to the digest length,
264B<max> sets the salt length to the maximum permissible value. When verifying
265B<auto> causes the salt length to be automatically determined based on the
137096a7 266B<PSS> block structure.
8d970ca7 267
2f0ea936 268=item B<rsa_mgf1_md:>I<digest>
7751098e
DSH
269
270For PSS and OAEP padding sets the MGF1 digest. If the MGF1 digest is not
271explicitly set in PSS mode then the signing digest is used.
272
273=back
274
275=head1 RSA-PSS ALGORITHM
276
277The RSA-PSS algorithm is a restricted version of the RSA algorithm which only
278supports the sign and verify operations with PSS padding. The following
2f0ea936 279additional B<-pkeyopt> values are supported:
7751098e
DSH
280
281=over 4
282
2f0ea936
RL
283=item B<rsa_padding_mode:>I<mode>, B<rsa_pss_saltlen:>I<len>,
284B<rsa_mgf1_md:>I<digest>
7751098e
DSH
285
286These have the same meaning as the B<RSA> algorithm with some additional
287restrictions. The padding mode can only be set to B<pss> which is the
288default value.
289
290If the key has parameter restrictions than the digest, MGF1
291digest and salt length are set to the values specified in the parameters.
292The digest and MG cannot be changed and the salt length cannot be set to a
293value less than the minimum restriction.
294
8d970ca7
DSH
295=back
296
297=head1 DSA ALGORITHM
298
299The DSA algorithm supports signing and verification operations only. Currently
6a6d9ecd
MC
300there are no additional B<-pkeyopt> options other than B<digest>. The SHA1
301digest is assumed by default.
8d970ca7
DSH
302
303=head1 DH ALGORITHM
304
305The DH algorithm only supports the derivation operation and no additional
6a6d9ecd 306B<-pkeyopt> options.
8d970ca7
DSH
307
308=head1 EC ALGORITHM
309
310The EC algorithm supports sign, verify and derive operations. The sign and
6a6d9ecd
MC
311verify operations use ECDSA and derive uses ECDH. SHA1 is assumed by default for
312the B<-pkeyopt> B<digest> option.
5ce60a20 313
485d3361 314=head1 X25519 AND X448 ALGORITHMS
c082201a 315
a2eecb5d
MC
316The X25519 and X448 algorithms support key derivation only. Currently there are
317no additional options.
c082201a 318
485d3361 319=head1 ED25519 AND ED448 ALGORITHMS
ee633ace
MC
320
321These algorithms only support signing and verifying. OpenSSL only implements the
322"pure" variants of these algorithms so raw data can be passed directly to them
2f0ea936
RL
323without hashing them first. The option B<-rawin> must be used with these
324algorithms with no B<-digest> specified. Additionally OpenSSL only supports
ee633ace
MC
325"oneshot" operation with these algorithms. This means that the entire file to
326be signed/verified must be read into memory before processing it. Signing or
327Verifying very large files should be avoided. Additionally the size of the file
328must be known for this to work. If the size of the file cannot be determined
329(for example if the input is stdin) then the sign or verify operation will fail.
330
a7cef52f
PY
331=head1 SM2
332
333The SM2 algorithm supports sign, verify, encrypt and decrypt operations. For
334the sign and verify operations, SM2 requires an ID string to be passed in. The
2f0ea936 335following B<-pkeyopt> value is supported:
a7cef52f
PY
336
337=over 4
338
2f0ea936 339=item B<sm2_id:>I<string>
a7cef52f
PY
340
341This sets the ID string used in SM2 sign or verify operations. While verifying
342an SM2 signature, the ID string must be the same one used when signing the data.
343Otherwise the verification will fail.
344
2f0ea936 345=item B<sm2_hex_id:>I<hex_string>
a45eb7e8
PY
346
347This sets the ID string used in SM2 sign or verify operations. While verifying
348an SM2 signature, the ID string must be the same one used when signing the data.
349Otherwise the verification will fail. The ID string provided with this option
350should be a valid hexadecimal value.
351
a7cef52f
PY
352=back
353
5ce60a20
DSH
354=head1 EXAMPLES
355
356Sign some data using a private key:
357
358 openssl pkeyutl -sign -in file -inkey key.pem -out sig
359
360Recover the signed data (e.g. if an RSA key is used):
361
362 openssl pkeyutl -verifyrecover -in sig -inkey key.pem
363
364Verify the signature (e.g. a DSA key):
365
383b8b8c 366 openssl pkeyutl -verify -in file -sigfile sig -inkey key.pem
5ce60a20 367
8d970ca7
DSH
368Sign data using a message digest value (this is currently only valid for RSA):
369
370 openssl pkeyutl -sign -in file -inkey key.pem -out sig -pkeyopt digest:sha256
371
372Derive a shared secret value:
373
374 openssl pkeyutl -derive -inkey key.pem -peerkey pubkey.pem -out secret
375
924ec89a 376Hexdump 48 bytes of TLS1 PRF using digest B<SHA256> and shared secret and
95e040bb 377seed consisting of the single byte 0xFF:
924ec89a
DSH
378
379 openssl pkeyutl -kdf TLS1-PRF -kdflen 48 -pkeyopt md:SHA256 \
380 -pkeyopt hexsecret:ff -pkeyopt hexseed:ff -hexdump
381
6dfcea3d
JB
382Derive a key using B<scrypt> where the password is read from command line:
383
384 openssl pkeyutl -kdf scrypt -kdflen 16 -pkeyopt_passin pass \
385 -pkeyopt hexsalt:aabbcc -pkeyopt N:16384 -pkeyopt r:8 -pkeyopt p:1
386
387Derive using the same algorithm, but read key from environment variable MYPASS:
388
389 openssl pkeyutl -kdf scrypt -kdflen 16 -pkeyopt_passin pass:env:MYPASS \
390 -pkeyopt hexsalt:aabbcc -pkeyopt N:16384 -pkeyopt r:8 -pkeyopt p:1
391
a7cef52f
PY
392Sign some data using an L<SM2(7)> private key and a specific ID:
393
394 openssl pkeyutl -sign -in file -inkey sm2.key -out sig -rawin -digest sm3 \
395 -pkeyopt sm2_id:someid
396
397Verify some data using an L<SM2(7)> certificate and a specific ID:
398
399 openssl pkeyutl -verify -certin -in file -inkey sm2.cert -sigfile sig \
400 -rawin -digest sm3 -pkeyopt sm2_id:someid
401
5ce60a20 402=head1 SEE ALSO
383b8b8c 403
b6b66573
DMSP
404L<openssl(1)>,
405L<openssl-genpkey(1)>,
406L<openssl-pkey(1)>,
407L<openssl-rsautl(1)>
408L<openssl-dgst(1)>,
409L<openssl-rsa(1)>,
410L<openssl-genrsa(1)>,
411L<openssl-kdf(1)>
412L<EVP_PKEY_CTX_set_hkdf_md(3)>,
413L<EVP_PKEY_CTX_set_tls1_prf_md(3)>,
414
99ec4fdb 415
e2f92610
RS
416=head1 COPYRIGHT
417
b6b66573 418Copyright 2006-2019 The OpenSSL Project Authors. All Rights Reserved.
e2f92610 419
449040b4 420Licensed under the Apache License 2.0 (the "License"). You may not use
e2f92610
RS
421this file except in compliance with the License. You can obtain a copy
422in the file LICENSE in the source distribution or at
423L<https://www.openssl.org/source/license.html>.
424
425=cut