provider-kem.7ossl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "PROVIDER-KEM 7ossl"
  58. .TH PROVIDER-KEM 7ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. provider\-kem \- The kem library <\-> provider functions
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. .Vb 2
  68. \& #include <openssl/core_dispatch.h>
  69. \& #include <openssl/core_names.h>
  70. \&
  71. \& /*
  72. \& * None of these are actual functions, but are displayed like this for
  73. \& * the function signatures for functions that are offered as function
  74. \& * pointers in OSSL_DISPATCH arrays.
  75. \& */
  76. \&
  77. \& /* Context management */
  78. \& void *OSSL_FUNC_kem_newctx(void *provctx);
  79. \& void OSSL_FUNC_kem_freectx(void *ctx);
  80. \& void *OSSL_FUNC_kem_dupctx(void *ctx);
  81. \&
  82. \& /* Encapsulation */
  83. \& int OSSL_FUNC_kem_encapsulate_init(void *ctx, void *provkey,
  84. \& const OSSL_PARAM params[]);
  85. \& int OSSL_FUNC_kem_auth_encapsulate_init(void *ctx, void *provkey,
  86. \& void *provauthkey,
  87. \& const OSSL_PARAM params[]);
  88. \& int OSSL_FUNC_kem_encapsulate(void *ctx, unsigned char *out, size_t *outlen,
  89. \& unsigned char *secret, size_t *secretlen);
  90. \&
  91. \& /* Decapsulation */
  92. \& int OSSL_FUNC_kem_decapsulate_init(void *ctx, void *provkey);
  93. \& int OSSL_FUNC_kem_auth_decapsulate_init(void *ctx, void *provkey,
  94. \& void *provauthkey,
  95. \& const OSSL_PARAM params[]);
  96. \& int OSSL_FUNC_kem_decapsulate(void *ctx, unsigned char *out, size_t *outlen,
  97. \& const unsigned char *in, size_t inlen);
  98. \&
  99. \& /* KEM parameters */
  100. \& int OSSL_FUNC_kem_get_ctx_params(void *ctx, OSSL_PARAM params[]);
  101. \& const OSSL_PARAM *OSSL_FUNC_kem_gettable_ctx_params(void *ctx, void *provctx);
  102. \& int OSSL_FUNC_kem_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
  103. \& const OSSL_PARAM *OSSL_FUNC_kem_settable_ctx_params(void *ctx, void *provctx);
  104. .Ve
  105. .SH DESCRIPTION
  106. .IX Header "DESCRIPTION"
  107. This documentation is primarily aimed at provider authors. See \fBprovider\fR\|(7)
  108. for further information.
  109. .PP
  110. The asymmetric kem (OSSL_OP_KEM) operation enables providers to
  111. implement asymmetric kem algorithms and make them available to applications
  112. via the API functions \fBEVP_PKEY_encapsulate\fR\|(3),
  113. \&\fBEVP_PKEY_decapsulate\fR\|(3) and other related functions.
  114. .PP
  115. All "functions" mentioned here are passed as function pointers between
  116. \&\fIlibcrypto\fR and the provider in \fBOSSL_DISPATCH\fR\|(3) arrays via
  117. \&\fBOSSL_ALGORITHM\fR\|(3) arrays that are returned by the provider's
  118. \&\fBprovider_query_operation()\fR function
  119. (see "Provider Functions" in \fBprovider\-base\fR\|(7)).
  120. .PP
  121. All these "functions" have a corresponding function type definition
  122. named \fBOSSL_FUNC_{name}_fn\fR, and a helper function to retrieve the
  123. function pointer from an \fBOSSL_DISPATCH\fR\|(3) element named
  124. \&\fBOSSL_FUNC_{name}\fR.
  125. For example, the "function" \fBOSSL_FUNC_kem_newctx()\fR has these:
  126. .PP
  127. .Vb 3
  128. \& typedef void *(OSSL_FUNC_kem_newctx_fn)(void *provctx);
  129. \& static ossl_inline OSSL_FUNC_kem_newctx_fn
  130. \& OSSL_FUNC_kem_newctx(const OSSL_DISPATCH *opf);
  131. .Ve
  132. .PP
  133. \&\fBOSSL_DISPATCH\fR\|(3) arrays are indexed by numbers that are provided as
  134. macros in \fBopenssl\-core_dispatch.h\fR\|(7), as follows:
  135. .PP
  136. .Vb 3
  137. \& OSSL_FUNC_kem_newctx OSSL_FUNC_KEM_NEWCTX
  138. \& OSSL_FUNC_kem_freectx OSSL_FUNC_KEM_FREECTX
  139. \& OSSL_FUNC_kem_dupctx OSSL_FUNC_KEM_DUPCTX
  140. \&
  141. \& OSSL_FUNC_kem_encapsulate_init OSSL_FUNC_KEM_ENCAPSULATE_INIT
  142. \& OSSL_FUNC_kem_auth_encapsulate_init OSSL_FUNC_KEM_AUTH_ENCAPSULATE_INIT
  143. \& OSSL_FUNC_kem_encapsulate OSSL_FUNC_KEM_ENCAPSULATE
  144. \&
  145. \& OSSL_FUNC_kem_decapsulate_init OSSL_FUNC_KEM_DECAPSULATE_INIT
  146. \& OSSL_FUNC_kem_auth_decapsulate_init OSSL_FUNC_KEM_AUTH_DECAPSULATE_INIT
  147. \& OSSL_FUNC_kem_decapsulate OSSL_FUNC_KEM_DECAPSULATE
  148. \&
  149. \& OSSL_FUNC_kem_get_ctx_params OSSL_FUNC_KEM_GET_CTX_PARAMS
  150. \& OSSL_FUNC_kem_gettable_ctx_params OSSL_FUNC_KEM_GETTABLE_CTX_PARAMS
  151. \& OSSL_FUNC_kem_set_ctx_params OSSL_FUNC_KEM_SET_CTX_PARAMS
  152. \& OSSL_FUNC_kem_settable_ctx_params OSSL_FUNC_KEM_SETTABLE_CTX_PARAMS
  153. .Ve
  154. .PP
  155. An asymmetric kem algorithm implementation may not implement all of these
  156. functions.
  157. In order to be a consistent set of functions a provider must implement
  158. OSSL_FUNC_kem_newctx and OSSL_FUNC_kem_freectx.
  159. It must also implement both of OSSL_FUNC_kem_encapsulate_init and
  160. OSSL_FUNC_kem_encapsulate, or both of OSSL_FUNC_kem_decapsulate_init and
  161. OSSL_FUNC_kem_decapsulate.
  162. OSSL_FUNC_kem_auth_encapsulate_init is optional but if it is present then so
  163. must OSSL_FUNC_kem_auth_decapsulate_init.
  164. OSSL_FUNC_kem_get_ctx_params is optional but if it is present then so must
  165. OSSL_FUNC_kem_gettable_ctx_params.
  166. Similarly, OSSL_FUNC_kem_set_ctx_params is optional but if it is present then
  167. OSSL_FUNC_kem_settable_ctx_params must also be present.
  168. .PP
  169. An asymmetric kem algorithm must also implement some mechanism for generating,
  170. loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation.
  171. See \fBprovider\-keymgmt\fR\|(7) for further details.
  172. .SS "Context Management Functions"
  173. .IX Subsection "Context Management Functions"
  174. \&\fBOSSL_FUNC_kem_newctx()\fR should create and return a pointer to a provider side
  175. structure for holding context information during an asymmetric kem operation.
  176. A pointer to this context will be passed back in a number of the other
  177. asymmetric kem operation function calls.
  178. The parameter \fIprovctx\fR is the provider context generated during provider
  179. initialisation (see \fBprovider\fR\|(7)).
  180. .PP
  181. \&\fBOSSL_FUNC_kem_freectx()\fR is passed a pointer to the provider side asymmetric
  182. kem context in the \fIctx\fR parameter.
  183. This function should free any resources associated with that context.
  184. .PP
  185. \&\fBOSSL_FUNC_kem_dupctx()\fR should duplicate the provider side asymmetric kem
  186. context in the \fIctx\fR parameter and return the duplicate copy.
  187. .SS "Asymmetric Key Encapsulation Functions"
  188. .IX Subsection "Asymmetric Key Encapsulation Functions"
  189. \&\fBOSSL_FUNC_kem_encapsulate_init()\fR initialises a context for an asymmetric
  190. encapsulation given a provider side asymmetric kem context in the \fIctx\fR
  191. parameter, a pointer to a provider key object in the \fIprovkey\fR parameter and
  192. the \fIname\fR of the algorithm.
  193. The \fIparams\fR, if not NULL, should be set on the context in a manner similar to
  194. using \fBOSSL_FUNC_kem_set_ctx_params()\fR.
  195. The key object should have been previously generated, loaded or imported into
  196. the provider using the key management (OSSL_OP_KEYMGMT) operation (see
  197. \&\fBprovider\-keymgmt\fR\|(7)>.
  198. .PP
  199. \&\fBOSSL_FUNC_kem_auth_encapsulate_init()\fR is similar to
  200. \&\fBOSSL_FUNC_kem_encapsulate_init()\fR, but also passes an additional authentication
  201. key \fIprovauthkey\fR which cannot be NULL.
  202. .PP
  203. \&\fBOSSL_FUNC_kem_encapsulate()\fR performs the actual encapsulation itself.
  204. A previously initialised asymmetric kem context is passed in the \fIctx\fR
  205. parameter.
  206. Unless \fIout\fR is NULL, the data to be encapsulated is internally generated,
  207. and returned into the buffer pointed to by the \fIsecret\fR parameter and the
  208. encapsulated data should also be written to the location pointed to by the
  209. \&\fIout\fR parameter. The length of the encapsulated data should be written to
  210. \&\fI*outlen\fR and the length of the generated secret should be written to
  211. \&\fI*secretlen\fR.
  212. .PP
  213. If \fIout\fR is NULL then the maximum length of the encapsulated data should be
  214. written to \fI*outlen\fR, and the maximum length of the generated secret should be
  215. written to \fI*secretlen\fR.
  216. .SS "Decapsulation Functions"
  217. .IX Subsection "Decapsulation Functions"
  218. \&\fBOSSL_FUNC_kem_decapsulate_init()\fR initialises a context for an asymmetric
  219. decapsulation given a provider side asymmetric kem context in the \fIctx\fR
  220. parameter, a pointer to a provider key object in the \fIprovkey\fR parameter, and
  221. a \fIname\fR of the algorithm.
  222. The key object should have been previously generated, loaded or imported into
  223. the provider using the key management (OSSL_OP_KEYMGMT) operation (see
  224. \&\fBprovider\-keymgmt\fR\|(7)>.
  225. .PP
  226. \&\fBOSSL_FUNC_kem_auth_decapsulate_init()\fR is similar to
  227. \&\fBOSSL_FUNC_kem_decapsulate_init()\fR, but also passes an additional authentication
  228. key \fIprovauthkey\fR which cannot be NULL.
  229. .PP
  230. \&\fBOSSL_FUNC_kem_decapsulate()\fR performs the actual decapsulation itself.
  231. A previously initialised asymmetric kem context is passed in the \fIctx\fR
  232. parameter.
  233. The data to be decapsulated is pointed to by the \fIin\fR parameter which is \fIinlen\fR
  234. bytes long.
  235. Unless \fIout\fR is NULL, the decapsulated data should be written to the location
  236. pointed to by the \fIout\fR parameter.
  237. The length of the decapsulated data should be written to \fI*outlen\fR.
  238. If \fIout\fR is NULL then the maximum length of the decapsulated data should be
  239. written to \fI*outlen\fR.
  240. .SS "Asymmetric Key Encapsulation Parameters"
  241. .IX Subsection "Asymmetric Key Encapsulation Parameters"
  242. See \fBOSSL_PARAM\fR\|(3) for further details on the parameters structure used by
  243. the \fBOSSL_FUNC_kem_get_ctx_params()\fR and \fBOSSL_FUNC_kem_set_ctx_params()\fR
  244. functions.
  245. .PP
  246. The OpenSSL FIPS provider also supports the following parameters:
  247. .IP """fips-indicator"" (\fBOSSL_KEM_PARAM_FIPS_APPROVED_INDICATOR\fR) <integer>" 4
  248. .IX Item """fips-indicator"" (OSSL_KEM_PARAM_FIPS_APPROVED_INDICATOR) <integer>"
  249. A getter that returns 1 if the operation is FIPS approved, or 0 otherwise.
  250. This may be used after calling either \fBOSSL_FUNC_kem_encapsulate()\fR or
  251. \&\fBOSSL_FUNC_kem_decapsulate()\fR. It may return 0 if the "key-check" is set to 0.
  252. .IP """key-check"" (\fBOSSL_KEM_PARAM_FIPS_KEY_CHECK\fR) <integer>" 4
  253. .IX Item """key-check"" (OSSL_KEM_PARAM_FIPS_KEY_CHECK) <integer>"
  254. If required this parameter should be set using \fBOSSL_FUNC_kem_encapsulate_init()\fR
  255. or \fBOSSL_FUNC_kem_decapsulate_init()\fR.
  256. The default value of 1 causes an error during the init if the key is not FIPS
  257. approved (e.g. The key has a security strength of less than 112 bits). Setting
  258. this to 0 will ignore the error and set the approved "fips-indicator" to 0.
  259. This option breaks FIPS compliance if it causes the approved "fips-indicator"
  260. to return 0.
  261. .SS "Asymmetric Key Encapsulation Parameter Functions"
  262. .IX Subsection "Asymmetric Key Encapsulation Parameter Functions"
  263. \&\fBOSSL_FUNC_kem_get_ctx_params()\fR gets asymmetric KEM parameters associated
  264. with the given provider side asymmetric kem context \fIctx\fR and stores them in
  265. \&\fIparams\fR.
  266. Passing NULL for \fIparams\fR should return true.
  267. .PP
  268. \&\fBOSSL_FUNC_kem_set_ctx_params()\fR sets the asymmetric KEM parameters associated
  269. with the given provider side asymmetric kem context \fIctx\fR to \fIparams\fR.
  270. Any parameter settings are additional to any that were previously set.
  271. Passing NULL for \fIparams\fR should return true.
  272. .PP
  273. No parameters are currently recognised by built-in asymmetric kem algorithms.
  274. .PP
  275. \&\fBOSSL_FUNC_kem_gettable_ctx_params()\fR and \fBOSSL_FUNC_kem_settable_ctx_params()\fR
  276. get a constant \fBOSSL_PARAM\fR\|(3) array that describes the gettable and settable
  277. parameters, i.e. parameters that can be used with \fBOSSL_FUNC_kem_get_ctx_params()\fR
  278. and \fBOSSL_FUNC_kem_set_ctx_params()\fR respectively.
  279. .SH "RETURN VALUES"
  280. .IX Header "RETURN VALUES"
  281. \&\fBOSSL_FUNC_kem_newctx()\fR and \fBOSSL_FUNC_kem_dupctx()\fR should return the newly
  282. created provider side asymmetric kem context, or NULL on failure.
  283. .PP
  284. All other functions should return 1 for success or 0 on error.
  285. .SH "SEE ALSO"
  286. .IX Header "SEE ALSO"
  287. \&\fBprovider\fR\|(7)
  288. .SH HISTORY
  289. .IX Header "HISTORY"
  290. The provider KEM interface was introduced in OpenSSL 3.0.
  291. .PP
  292. \&\fBOSSL_FUNC_kem_auth_encapsulate_init()\fR and \fBOSSL_FUNC_kem_auth_decapsulate_init()\fR
  293. were added in OpenSSL 3.2.
  294. .PP
  295. The Asymmetric Key Encapsulation Parameters "fips-indicator" and "key-check"
  296. were added in OpenSSL 3.4.
  297. .SH COPYRIGHT
  298. .IX Header "COPYRIGHT"
  299. Copyright 2020\-2024 The OpenSSL Project Authors. All Rights Reserved.
  300. .PP
  301. Licensed under the Apache License 2.0 (the "License"). You may not use
  302. this file except in compliance with the License. You can obtain a copy
  303. in the file LICENSE in the source distribution or at
  304. <https://www.openssl.org/source/license.html>.