Clarify CLI OCSP documentation
[openssl.git] / doc / man1 / pkeyutl.pod
1 =pod
2
3 =head1 NAME
4
5 pkeyutl - public key algorithm utility
6
7 =head1 SYNOPSIS
8
9 B<openssl> B<pkeyutl>
10 [B<-help>]
11 [B<-in file>]
12 [B<-out file>]
13 [B<-sigfile file>]
14 [B<-inkey file>]
15 [B<-keyform PEM|DER|ENGINE>]
16 [B<-passin arg>]
17 [B<-peerkey file>]
18 [B<-peerform PEM|DER|ENGINE>]
19 [B<-pubin>]
20 [B<-certin>]
21 [B<-rev>]
22 [B<-sign>]
23 [B<-verify>]
24 [B<-verifyrecover>]
25 [B<-encrypt>]
26 [B<-decrypt>]
27 [B<-derive>]
28 [B<-kdf algorithm>]
29 [B<-kdflen length>]
30 [B<-pkeyopt opt:value>]
31 [B<-hexdump>]
32 [B<-asn1parse>]
33 [B<-rand file...>]
34 [B<-writerand file>]
35 [B<-engine id>]
36 [B<-engine_impl>]
37
38 =head1 DESCRIPTION
39
40 The B<pkeyutl> command can be used to perform public key operations using
41 any supported algorithm.
42
43 =head1 OPTIONS
44
45 =over 4
46
47 =item B<-help>
48
49 Print out a usage message.
50
51 =item B<-in filename>
52
53 This specifies the input filename to read data from or standard input
54 if this option is not specified.
55
56 =item B<-out filename>
57
58 Specifies the output filename to write to or standard output by
59 default.
60
61 =item B<-sigfile file>
62
63 Signature file, required for B<verify> operations only
64
65 =item B<-inkey file>
66
67 The input key file, by default it should be a private key.
68
69 =item B<-keyform PEM|DER|ENGINE>
70
71 The key format PEM, DER or ENGINE. Default is PEM.
72
73 =item B<-passin arg>
74
75 The input key password source. For more information about the format of B<arg>
76 see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)>.
77
78 =item B<-peerkey file>
79
80 The peer key file, used by key derivation (agreement) operations.
81
82 =item B<-peerform PEM|DER|ENGINE>
83
84 The peer key format PEM, DER or ENGINE. Default is PEM.
85
86 =item B<-pubin>
87
88 The input file is a public key.
89
90 =item B<-certin>
91
92 The input is a certificate containing a public key.
93
94 =item B<-rev>
95
96 Reverse the order of the input buffer. This is useful for some libraries
97 (such as CryptoAPI) which represent the buffer in little endian format.
98
99 =item B<-sign>
100
101 Sign the input data and output the signed result. This requires
102 a private key.
103
104 =item B<-verify>
105
106 Verify the input data against the signature file and indicate if the
107 verification succeeded or failed.
108
109 =item B<-verifyrecover>
110
111 Verify the input data and output the recovered data.
112
113 =item B<-encrypt>
114
115 Encrypt the input data using a public key.
116
117 =item B<-decrypt>
118
119 Decrypt the input data using a private key.
120
121 =item B<-derive>
122
123 Derive a shared secret using the peer key.
124
125 =item B<-kdf algorithm>
126
127 Use key derivation function B<algorithm>.  The supported algorithms are
128 at present B<TLS1-PRF> and B<HKDF>.
129 Note: additional parameters and the KDF output length will normally have to be
130 set for this to work.
131 See L<EVP_PKEY_CTX_set_hkdf_md(3)> and L<EVP_PKEY_CTX_set_tls1_prf_md(3)>
132 for the supported string parameters of each algorithm.
133
134 =item B<-kdflen length>
135
136 Set the output length for KDF.
137
138 =item B<-pkeyopt opt:value>
139
140 Public key options specified as opt:value. See NOTES below for more details.
141
142 =item B<-hexdump>
143
144 hex dump the output data.
145
146 =item B<-asn1parse>
147
148 Parse the ASN.1 output data, this is useful when combined with the
149 B<-verifyrecover> option when an ASN1 structure is signed.
150
151 =item B<-rand file...>
152
153 A file or files containing random data used to seed the random number
154 generator.
155 Multiple files can be specified separated by an OS-dependent character.
156 The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
157 all others.
158
159 =item [B<-writerand file>]
160
161 Writes random data to the specified I<file> upon exit.
162 This can be used with a subsequent B<-rand> flag.
163
164 =item B<-engine id>
165
166 Specifying an engine (by its unique B<id> string) will cause B<pkeyutl>
167 to attempt to obtain a functional reference to the specified engine,
168 thus initialising it if needed. The engine will then be set as the default
169 for all available algorithms.
170
171 =item B<-engine_impl>
172
173 When used with the B<-engine> option, it specifies to also use
174 engine B<id> for crypto operations.
175
176 =back
177
178 =head1 NOTES
179
180 The operations and options supported vary according to the key algorithm
181 and its implementation. The OpenSSL operations and options are indicated below.
182
183 Unless otherwise mentioned all algorithms support the B<digest:alg> option
184 which specifies the digest in use for sign, verify and verifyrecover operations.
185 The value B<alg> should represent a digest name as used in the
186 EVP_get_digestbyname() function for example B<sha1>.
187 This value is used only for sanity-checking the lengths of data passed in to
188 the B<pkeyutl> and for creating the structures that make up the signature
189 (e.g. B<DigestInfo> in RSASSA PKCS#1 v1.5 signatures).
190 In case of RSA, ECDSA and DSA signatures, this utility
191 will not perform hashing on input data but rather use the data directly as
192 input of signature algorithm. Depending on key type, signature type and mode
193 of padding, the maximum acceptable lengths of input data differ. In general,
194 with RSA the signed data can't be longer than the key modulus, in case of ECDSA
195 and DSA the data shouldn't be longer than field size, otherwise it will be
196 silently truncated to field size.
197
198 In other words, if the value of digest is B<sha1> the input should be 20 bytes
199 long binary encoding of SHA-1 hash function output.
200
201 =head1 RSA ALGORITHM
202
203 The RSA algorithm generally supports the encrypt, decrypt, sign,
204 verify and verifyrecover operations. However, some padding modes
205 support only a subset of these operations. The following additional
206 B<pkeyopt> values are supported:
207
208 =over 4
209
210 =item B<rsa_padding_mode:mode>
211
212 This sets the RSA padding mode. Acceptable values for B<mode> are B<pkcs1> for
213 PKCS#1 padding, B<sslv23> for SSLv23 padding, B<none> for no padding, B<oaep>
214 for B<OAEP> mode, B<x931> for X9.31 mode and B<pss> for PSS.
215
216 In PKCS#1 padding if the message digest is not set then the supplied data is
217 signed or verified directly instead of using a B<DigestInfo> structure. If a
218 digest is set then the a B<DigestInfo> structure is used and its the length
219 must correspond to the digest type.
220
221 For B<oaep> mode only encryption and decryption is supported.
222
223 For B<x931> if the digest type is set it is used to format the block data
224 otherwise the first byte is used to specify the X9.31 digest ID. Sign,
225 verify and verifyrecover are can be performed in this mode.
226
227 For B<pss> mode only sign and verify are supported and the digest type must be
228 specified.
229
230 =item B<rsa_pss_saltlen:len>
231
232 For B<pss> mode only this option specifies the salt length. Three special
233 values are supported: "digest" sets the salt length to the digest length,
234 "max" sets the salt length to the maximum permissible value. When verifying
235 "auto" causes the salt length to be automatically determined based on the
236 B<PSS> block structure.
237
238 =item B<rsa_mgf1_md:digest>
239
240 For PSS and OAEP padding sets the MGF1 digest. If the MGF1 digest is not
241 explicitly set in PSS mode then the signing digest is used.
242
243 =back
244
245 =head1 RSA-PSS ALGORITHM
246
247 The RSA-PSS algorithm is a restricted version of the RSA algorithm which only
248 supports the sign and verify operations with PSS padding. The following
249 additional B<pkeyopt> values are supported:
250
251 =over 4
252
253 =item B<rsa_padding_mode:mode>, B<rsa_pss_saltlen:len>, B<rsa_mgf1_md:digest>
254
255 These have the same meaning as the B<RSA> algorithm with some additional
256 restrictions. The padding mode can only be set to B<pss> which is the
257 default value.
258
259 If the key has parameter restrictions than the digest, MGF1
260 digest and salt length are set to the values specified in the parameters.
261 The digest and MG cannot be changed and the salt length cannot be set to a
262 value less than the minimum restriction.
263
264 =back
265
266 =head1 DSA ALGORITHM
267
268 The DSA algorithm supports signing and verification operations only. Currently
269 there are no additional options other than B<digest>. Only the SHA1
270 digest can be used and this digest is assumed by default.
271
272 =head1 DH ALGORITHM
273
274 The DH algorithm only supports the derivation operation and no additional
275 options.
276
277 =head1 EC ALGORITHM
278
279 The EC algorithm supports sign, verify and derive operations. The sign and
280 verify operations use ECDSA and derive uses ECDH. Currently there are no
281 additional options other than B<digest>. Only the SHA1 digest can be used and
282 this digest is assumed by default.
283
284 =head1 X25519 ALGORITHM
285
286 The X25519 algorithm supports key derivation only. Currently there are no
287 additional options.
288
289 =head1 EXAMPLES
290
291 Sign some data using a private key:
292
293  openssl pkeyutl -sign -in file -inkey key.pem -out sig
294
295 Recover the signed data (e.g. if an RSA key is used):
296
297  openssl pkeyutl -verifyrecover -in sig -inkey key.pem
298
299 Verify the signature (e.g. a DSA key):
300
301  openssl pkeyutl -verify -in file -sigfile sig -inkey key.pem
302
303 Sign data using a message digest value (this is currently only valid for RSA):
304
305  openssl pkeyutl -sign -in file -inkey key.pem -out sig -pkeyopt digest:sha256
306
307 Derive a shared secret value:
308
309  openssl pkeyutl -derive -inkey key.pem -peerkey pubkey.pem -out secret
310
311 Hexdump 48 bytes of TLS1 PRF using digest B<SHA256> and shared secret and
312 seed consisting of the single byte 0xFF:
313
314  openssl pkeyutl -kdf TLS1-PRF -kdflen 48 -pkeyopt md:SHA256 \
315     -pkeyopt hexsecret:ff -pkeyopt hexseed:ff -hexdump
316
317 =head1 SEE ALSO
318
319 L<genpkey(1)>, L<pkey(1)>, L<rsautl(1)>
320 L<dgst(1)>, L<rsa(1)>, L<genrsa(1)>,
321 L<EVP_PKEY_CTX_set_hkdf_md(3)>, L<EVP_PKEY_CTX_set_tls1_prf_md(3)>
322
323 =head1 COPYRIGHT
324
325 Copyright 2006-2017 The OpenSSL Project Authors. All Rights Reserved.
326
327 Licensed under the OpenSSL license (the "License").  You may not use
328 this file except in compliance with the License.  You can obtain a copy
329 in the file LICENSE in the source distribution or at
330 L<https://www.openssl.org/source/license.html>.
331
332 =cut