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