EVP_PKEY_new.3ossl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "EVP_PKEY_NEW 3ossl"
  136. .TH EVP_PKEY_NEW 3ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. EVP_PKEY,
  143. EVP_PKEY_new,
  144. EVP_PKEY_up_ref,
  145. EVP_PKEY_dup,
  146. EVP_PKEY_free,
  147. EVP_PKEY_new_raw_private_key_ex,
  148. EVP_PKEY_new_raw_private_key,
  149. EVP_PKEY_new_raw_public_key_ex,
  150. EVP_PKEY_new_raw_public_key,
  151. EVP_PKEY_new_CMAC_key,
  152. EVP_PKEY_new_mac_key,
  153. EVP_PKEY_get_raw_private_key,
  154. EVP_PKEY_get_raw_public_key
  155. \&\- public/private key allocation and raw key handling functions
  156. .SH "SYNOPSIS"
  157. .IX Header "SYNOPSIS"
  158. .Vb 1
  159. \& #include <openssl/evp.h>
  160. \&
  161. \& typedef evp_pkey_st EVP_PKEY;
  162. \&
  163. \& EVP_PKEY *EVP_PKEY_new(void);
  164. \& int EVP_PKEY_up_ref(EVP_PKEY *key);
  165. \& EVP_PKEY *EVP_PKEY_dup(EVP_PKEY *key);
  166. \& void EVP_PKEY_free(EVP_PKEY *key);
  167. \&
  168. \& EVP_PKEY *EVP_PKEY_new_raw_private_key_ex(OSSL_LIB_CTX *libctx,
  169. \& const char *keytype,
  170. \& const char *propq,
  171. \& const unsigned char *key,
  172. \& size_t keylen);
  173. \& EVP_PKEY *EVP_PKEY_new_raw_private_key(int type, ENGINE *e,
  174. \& const unsigned char *key, size_t keylen);
  175. \& EVP_PKEY *EVP_PKEY_new_raw_public_key_ex(OSSL_LIB_CTX *libctx,
  176. \& const char *keytype,
  177. \& const char *propq,
  178. \& const unsigned char *key,
  179. \& size_t keylen);
  180. \& EVP_PKEY *EVP_PKEY_new_raw_public_key(int type, ENGINE *e,
  181. \& const unsigned char *key, size_t keylen);
  182. \& EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key,
  183. \& int keylen);
  184. \&
  185. \& int EVP_PKEY_get_raw_private_key(const EVP_PKEY *pkey, unsigned char *priv,
  186. \& size_t *len);
  187. \& int EVP_PKEY_get_raw_public_key(const EVP_PKEY *pkey, unsigned char *pub,
  188. \& size_t *len);
  189. .Ve
  190. .PP
  191. The following function has been deprecated since OpenSSL 3.0, and can be
  192. hidden entirely by defining \fB\s-1OPENSSL_API_COMPAT\s0\fR with a suitable version value,
  193. see \fBopenssl_user_macros\fR\|(7):
  194. .PP
  195. .Vb 2
  196. \& EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
  197. \& size_t len, const EVP_CIPHER *cipher);
  198. .Ve
  199. .SH "DESCRIPTION"
  200. .IX Header "DESCRIPTION"
  201. \&\fB\s-1EVP_PKEY\s0\fR is a generic structure to hold diverse types of asymmetric keys
  202. (also known as \*(L"key pairs\*(R"), and can be used for diverse operations, like
  203. signing, verifying signatures, key derivation, etc. The asymmetric keys
  204. themselves are often referred to as the \*(L"internal key\*(R", and are handled by
  205. backends, such as providers (through \s-1\fBEVP_KEYMGMT\s0\fR\|(3)) or \fB\s-1ENGINE\s0\fRs.
  206. .PP
  207. Conceptually, an \fB\s-1EVP_PKEY\s0\fR internal key may hold a private key, a public
  208. key, or both (a keypair), and along with those, key parameters if the key type
  209. requires them. The presence of these components determine what operations can
  210. be made; for example, signing normally requires the presence of a private key,
  211. and verifying normally requires the presence of a public key.
  212. .PP
  213. \&\fB\s-1EVP_PKEY\s0\fR has also been used for \s-1MAC\s0 algorithm that were conceived as
  214. producing signatures, although not being public key algorithms; \*(L"\s-1POLY1305\*(R",
  215. \&\*(L"SIPHASH\*(R", \*(L"HMAC\*(R", \*(L"CMAC\*(R".\s0 This usage is considered legacy and is discouraged
  216. in favor of the \s-1\fBEVP_MAC\s0\fR\|(3) \s-1API.\s0
  217. .PP
  218. The \fBEVP_PKEY_new()\fR function allocates an empty \fB\s-1EVP_PKEY\s0\fR structure which is
  219. used by OpenSSL to store public and private keys. The reference count is set to
  220. \&\fB1\fR.
  221. .PP
  222. \&\fBEVP_PKEY_up_ref()\fR increments the reference count of \fIkey\fR.
  223. .PP
  224. \&\fBEVP_PKEY_dup()\fR duplicates the \fIkey\fR. The \fIkey\fR must not be \s-1ENGINE\s0 based or
  225. a raw key, otherwise the duplication will fail.
  226. .PP
  227. \&\fBEVP_PKEY_free()\fR decrements the reference count of \fIkey\fR and, if the reference
  228. count is zero, frees it up. If \fIkey\fR is \s-1NULL,\s0 nothing is done.
  229. .PP
  230. \&\fBEVP_PKEY_new_raw_private_key_ex()\fR allocates a new \fB\s-1EVP_PKEY\s0\fR. Unless an
  231. engine should be used for the key type, a provider for the key is found using
  232. the library context \fIlibctx\fR and the property query string \fIpropq\fR. The
  233. \&\fIkeytype\fR argument indicates what kind of key this is. The value should be a
  234. string for a public key algorithm that supports raw private keys, i.e one of
  235. \&\*(L"X25519\*(R", \*(L"\s-1ED25519\*(R", \*(L"X448\*(R"\s0 or \*(L"\s-1ED448\*(R".\s0 \fIkey\fR points to the raw private key
  236. data for this \fB\s-1EVP_PKEY\s0\fR which should be of length \fIkeylen\fR. The length
  237. should be appropriate for the type of the key. The public key data will be
  238. automatically derived from the given private key data (if appropriate for the
  239. algorithm type).
  240. .PP
  241. \&\fBEVP_PKEY_new_raw_private_key()\fR does the same as
  242. \&\fBEVP_PKEY_new_raw_private_key_ex()\fR except that the default library context and
  243. default property query are used instead. If \fIe\fR is non-NULL then the new
  244. \&\fB\s-1EVP_PKEY\s0\fR structure is associated with the engine \fIe\fR. The \fItype\fR argument
  245. indicates what kind of key this is. The value should be a \s-1NID\s0 for a public key
  246. algorithm that supports raw private keys, i.e. one of \fB\s-1EVP_PKEY_X25519\s0\fR,
  247. \&\fB\s-1EVP_PKEY_ED25519\s0\fR, \fB\s-1EVP_PKEY_X448\s0\fR or \fB\s-1EVP_PKEY_ED448\s0\fR.
  248. .PP
  249. \&\fBEVP_PKEY_new_raw_private_key_ex()\fR and \fBEVP_PKEY_new_raw_private_key()\fR may also
  250. be used with most MACs implemented as public key algorithms, so key types such
  251. as \*(L"\s-1HMAC\*(R", \*(L"POLY1305\*(R", \*(L"SIPHASH\*(R",\s0 or their \s-1NID\s0 form \fB\s-1EVP_PKEY_POLY1305\s0\fR,
  252. \&\fB\s-1EVP_PKEY_SIPHASH\s0\fR, \fB\s-1EVP_PKEY_HMAC\s0\fR are also accepted. This usage is,
  253. as mentioned above, discouraged in favor of the \s-1\fBEVP_MAC\s0\fR\|(3) \s-1API.\s0
  254. .PP
  255. \&\fBEVP_PKEY_new_raw_public_key_ex()\fR works in the same way as
  256. \&\fBEVP_PKEY_new_raw_private_key_ex()\fR except that \fIkey\fR points to the raw
  257. public key data. The \fB\s-1EVP_PKEY\s0\fR structure will be initialised without any
  258. private key information. Algorithm types that support raw public keys are
  259. \&\*(L"X25519\*(R", \*(L"\s-1ED25519\*(R", \*(L"X448\*(R"\s0 or \*(L"\s-1ED448\*(R".\s0
  260. .PP
  261. \&\fBEVP_PKEY_new_raw_public_key()\fR works in the same way as
  262. \&\fBEVP_PKEY_new_raw_private_key()\fR except that \fIkey\fR points to the raw public key
  263. data. The \fB\s-1EVP_PKEY\s0\fR structure will be initialised without any private key
  264. information. Algorithm types that support raw public keys are
  265. \&\fB\s-1EVP_PKEY_X25519\s0\fR, \fB\s-1EVP_PKEY_ED25519\s0\fR, \fB\s-1EVP_PKEY_X448\s0\fR or \fB\s-1EVP_PKEY_ED448\s0\fR.
  266. .PP
  267. \&\fBEVP_PKEY_new_mac_key()\fR works in the same way as \fBEVP_PKEY_new_raw_private_key()\fR.
  268. New applications should use \fBEVP_PKEY_new_raw_private_key()\fR instead.
  269. .PP
  270. \&\fBEVP_PKEY_get_raw_private_key()\fR fills the buffer provided by \fIpriv\fR with raw
  271. private key data. The size of the \fIpriv\fR buffer should be in \fI*len\fR on entry
  272. to the function, and on exit \fI*len\fR is updated with the number of bytes
  273. actually written. If the buffer \fIpriv\fR is \s-1NULL\s0 then \fI*len\fR is populated with
  274. the number of bytes required to hold the key. The calling application is
  275. responsible for ensuring that the buffer is large enough to receive the private
  276. key data. This function only works for algorithms that support raw private keys.
  277. Currently this is: \fB\s-1EVP_PKEY_HMAC\s0\fR, \fB\s-1EVP_PKEY_POLY1305\s0\fR, \fB\s-1EVP_PKEY_SIPHASH\s0\fR,
  278. \&\fB\s-1EVP_PKEY_X25519\s0\fR, \fB\s-1EVP_PKEY_ED25519\s0\fR, \fB\s-1EVP_PKEY_X448\s0\fR or \fB\s-1EVP_PKEY_ED448\s0\fR.
  279. .PP
  280. \&\fBEVP_PKEY_get_raw_public_key()\fR fills the buffer provided by \fIpub\fR with raw
  281. public key data. The size of the \fIpub\fR buffer should be in \fI*len\fR on entry
  282. to the function, and on exit \fI*len\fR is updated with the number of bytes
  283. actually written. If the buffer \fIpub\fR is \s-1NULL\s0 then \fI*len\fR is populated with
  284. the number of bytes required to hold the key. The calling application is
  285. responsible for ensuring that the buffer is large enough to receive the public
  286. key data. This function only works for algorithms that support raw public keys.
  287. Currently this is: \fB\s-1EVP_PKEY_X25519\s0\fR, \fB\s-1EVP_PKEY_ED25519\s0\fR, \fB\s-1EVP_PKEY_X448\s0\fR or
  288. \&\fB\s-1EVP_PKEY_ED448\s0\fR.
  289. .PP
  290. \&\fBEVP_PKEY_new_CMAC_key()\fR works in the same way as \fBEVP_PKEY_new_raw_private_key()\fR
  291. except it is only for the \fB\s-1EVP_PKEY_CMAC\s0\fR algorithm type. In addition to the
  292. raw private key data, it also takes a cipher algorithm to be used during
  293. creation of a \s-1CMAC\s0 in the \fBcipher\fR argument. The cipher should be a standard
  294. encryption-only cipher. For example \s-1AEAD\s0 and \s-1XTS\s0 ciphers should not be used.
  295. .PP
  296. Applications should use the \s-1\fBEVP_MAC\s0\fR\|(3) \s-1API\s0 instead
  297. and set the \fB\s-1OSSL_MAC_PARAM_CIPHER\s0\fR parameter on the \fB\s-1EVP_MAC_CTX\s0\fR object
  298. with the name of the cipher being used.
  299. .SH "NOTES"
  300. .IX Header "NOTES"
  301. The \fB\s-1EVP_PKEY\s0\fR structure is used by various OpenSSL functions which require a
  302. general private key without reference to any particular algorithm.
  303. .PP
  304. The structure returned by \fBEVP_PKEY_new()\fR is empty. To add a private or public
  305. key to this empty structure use the appropriate functions described in
  306. \&\fBEVP_PKEY_set1_RSA\fR\|(3), \fBEVP_PKEY_set1_DSA\fR\|(3), \fBEVP_PKEY_set1_DH\fR\|(3) or
  307. \&\fBEVP_PKEY_set1_EC_KEY\fR\|(3).
  308. .SH "RETURN VALUES"
  309. .IX Header "RETURN VALUES"
  310. \&\fBEVP_PKEY_new()\fR, \fBEVP_PKEY_new_raw_private_key()\fR, \fBEVP_PKEY_new_raw_public_key()\fR,
  311. \&\fBEVP_PKEY_new_CMAC_key()\fR and \fBEVP_PKEY_new_mac_key()\fR return either the newly
  312. allocated \fB\s-1EVP_PKEY\s0\fR structure or \s-1NULL\s0 if an error occurred.
  313. .PP
  314. \&\fBEVP_PKEY_dup()\fR returns the key duplicate or \s-1NULL\s0 if an error occurred.
  315. .PP
  316. \&\fBEVP_PKEY_up_ref()\fR, \fBEVP_PKEY_get_raw_private_key()\fR and
  317. \&\fBEVP_PKEY_get_raw_public_key()\fR return 1 for success and 0 for failure.
  318. .SH "SEE ALSO"
  319. .IX Header "SEE ALSO"
  320. \&\fBEVP_PKEY_set1_RSA\fR\|(3), \fBEVP_PKEY_set1_DSA\fR\|(3), \fBEVP_PKEY_set1_DH\fR\|(3) or
  321. \&\fBEVP_PKEY_set1_EC_KEY\fR\|(3)
  322. .SH "HISTORY"
  323. .IX Header "HISTORY"
  324. The
  325. \&\fBEVP_PKEY_new()\fR and \fBEVP_PKEY_free()\fR functions exist in all versions of OpenSSL.
  326. .PP
  327. The \fBEVP_PKEY_up_ref()\fR function was added in OpenSSL 1.1.0.
  328. .PP
  329. The
  330. \&\fBEVP_PKEY_new_raw_private_key()\fR, \fBEVP_PKEY_new_raw_public_key()\fR,
  331. \&\fBEVP_PKEY_new_CMAC_key()\fR, \fBEVP_PKEY_new_raw_private_key()\fR and
  332. \&\fBEVP_PKEY_get_raw_public_key()\fR functions were added in OpenSSL 1.1.1.
  333. .PP
  334. The \fBEVP_PKEY_dup()\fR, \fBEVP_PKEY_new_raw_private_key_ex()\fR, and
  335. \&\fBEVP_PKEY_new_raw_public_key_ex()\fR
  336. functions were added in OpenSSL 3.0.
  337. .PP
  338. The \fBEVP_PKEY_new_CMAC_key()\fR was deprecated in OpenSSL 3.0.
  339. .PP
  340. The documentation of \fB\s-1EVP_PKEY\s0\fR was amended in OpenSSL 3.0 to allow there to
  341. be the private part of the keypair without the public part, where this was
  342. previously implied to be disallowed.
  343. .SH "COPYRIGHT"
  344. .IX Header "COPYRIGHT"
  345. Copyright 2002\-2022 The OpenSSL Project Authors. All Rights Reserved.
  346. .PP
  347. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  348. this file except in compliance with the License. You can obtain a copy
  349. in the file \s-1LICENSE\s0 in the source distribution or at
  350. <https://www.openssl.org/source/license.html>.