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