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