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