2
0

pkeyutl.pod 9.6 KB

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