provider-kem.pod 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. =pod
  2. =head1 NAME
  3. provider-kem - The kem library E<lt>-E<gt> provider functions
  4. =head1 SYNOPSIS
  5. =for openssl multiple includes
  6. #include <openssl/core_dispatch.h>
  7. #include <openssl/core_names.h>
  8. /*
  9. * None of these are actual functions, but are displayed like this for
  10. * the function signatures for functions that are offered as function
  11. * pointers in OSSL_DISPATCH arrays.
  12. */
  13. /* Context management */
  14. void *OSSL_FUNC_kem_newctx(void *provctx);
  15. void OSSL_FUNC_kem_freectx(void *ctx);
  16. void *OSSL_FUNC_kem_dupctx(void *ctx);
  17. /* Encapsulation */
  18. int OSSL_FUNC_kem_encapsulate_init(void *ctx, void *provkey,
  19. const OSSL_PARAM params[]);
  20. int OSSL_FUNC_kem_auth_encapsulate_init(void *ctx, void *provkey,
  21. void *provauthkey,
  22. const OSSL_PARAM params[]);
  23. int OSSL_FUNC_kem_encapsulate(void *ctx, unsigned char *out, size_t *outlen,
  24. unsigned char *secret, size_t *secretlen);
  25. /* Decapsulation */
  26. int OSSL_FUNC_kem_decapsulate_init(void *ctx, void *provkey);
  27. int OSSL_FUNC_kem_auth_decapsulate_init(void *ctx, void *provkey,
  28. void *provauthkey,
  29. const OSSL_PARAM params[]);
  30. int OSSL_FUNC_kem_decapsulate(void *ctx, unsigned char *out, size_t *outlen,
  31. const unsigned char *in, size_t inlen);
  32. /* KEM parameters */
  33. int OSSL_FUNC_kem_get_ctx_params(void *ctx, OSSL_PARAM params[]);
  34. const OSSL_PARAM *OSSL_FUNC_kem_gettable_ctx_params(void *ctx, void *provctx);
  35. int OSSL_FUNC_kem_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
  36. const OSSL_PARAM *OSSL_FUNC_kem_settable_ctx_params(void *ctx, void *provctx);
  37. =head1 DESCRIPTION
  38. This documentation is primarily aimed at provider authors. See L<provider(7)>
  39. for further information.
  40. The asymmetric kem (OSSL_OP_KEM) operation enables providers to
  41. implement asymmetric kem algorithms and make them available to applications
  42. via the API functions L<EVP_PKEY_encapsulate(3)>,
  43. L<EVP_PKEY_decapsulate(3)> and other related functions.
  44. All "functions" mentioned here are passed as function pointers between
  45. F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
  46. B<OSSL_ALGORITHM> arrays that are returned by the provider's
  47. provider_query_operation() function
  48. (see L<provider-base(7)/Provider Functions>).
  49. All these "functions" have a corresponding function type definition
  50. named B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the
  51. function pointer from an B<OSSL_DISPATCH> element named
  52. B<OSSL_FUNC_{name}>.
  53. For example, the "function" OSSL_FUNC_kem_newctx() has these:
  54. typedef void *(OSSL_FUNC_kem_newctx_fn)(void *provctx);
  55. static ossl_inline OSSL_FUNC_kem_newctx_fn
  56. OSSL_FUNC_kem_newctx(const OSSL_DISPATCH *opf);
  57. B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
  58. macros in L<openssl-core_dispatch.h(7)>, as follows:
  59. OSSL_FUNC_kem_newctx OSSL_FUNC_KEM_NEWCTX
  60. OSSL_FUNC_kem_freectx OSSL_FUNC_KEM_FREECTX
  61. OSSL_FUNC_kem_dupctx OSSL_FUNC_KEM_DUPCTX
  62. OSSL_FUNC_kem_encapsulate_init OSSL_FUNC_KEM_ENCAPSULATE_INIT
  63. OSSL_FUNC_kem_auth_encapsulate_init OSSL_FUNC_KEM_AUTH_ENCAPSULATE_INIT
  64. OSSL_FUNC_kem_encapsulate OSSL_FUNC_KEM_ENCAPSULATE
  65. OSSL_FUNC_kem_decapsulate_init OSSL_FUNC_KEM_DECAPSULATE_INIT
  66. OSSL_FUNC_kem_auth_decapsulate_init OSSL_FUNC_KEM_AUTH_DECAPSULATE_INIT
  67. OSSL_FUNC_kem_decapsulate OSSL_FUNC_KEM_DECAPSULATE
  68. OSSL_FUNC_kem_get_ctx_params OSSL_FUNC_KEM_GET_CTX_PARAMS
  69. OSSL_FUNC_kem_gettable_ctx_params OSSL_FUNC_KEM_GETTABLE_CTX_PARAMS
  70. OSSL_FUNC_kem_set_ctx_params OSSL_FUNC_KEM_SET_CTX_PARAMS
  71. OSSL_FUNC_kem_settable_ctx_params OSSL_FUNC_KEM_SETTABLE_CTX_PARAMS
  72. An asymmetric kem algorithm implementation may not implement all of these
  73. functions.
  74. In order to be a consistent set of functions a provider must implement
  75. OSSL_FUNC_kem_newctx and OSSL_FUNC_kem_freectx.
  76. It must also implement both of OSSL_FUNC_kem_encapsulate_init and
  77. OSSL_FUNC_kem_encapsulate, or both of OSSL_FUNC_kem_decapsulate_init and
  78. OSSL_FUNC_kem_decapsulate.
  79. OSSL_FUNC_kem_auth_encapsulate_init is optional but if it is present then so
  80. must OSSL_FUNC_kem_auth_decapsulate_init.
  81. OSSL_FUNC_kem_get_ctx_params is optional but if it is present then so must
  82. OSSL_FUNC_kem_gettable_ctx_params.
  83. Similarly, OSSL_FUNC_kem_set_ctx_params is optional but if it is present then
  84. OSSL_FUNC_kem_settable_ctx_params must also be present.
  85. An asymmetric kem algorithm must also implement some mechanism for generating,
  86. loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation.
  87. See L<provider-keymgmt(7)> for further details.
  88. =head2 Context Management Functions
  89. OSSL_FUNC_kem_newctx() should create and return a pointer to a provider side
  90. structure for holding context information during an asymmetric kem operation.
  91. A pointer to this context will be passed back in a number of the other
  92. asymmetric kem operation function calls.
  93. The parameter I<provctx> is the provider context generated during provider
  94. initialisation (see L<provider(7)>).
  95. OSSL_FUNC_kem_freectx() is passed a pointer to the provider side asymmetric
  96. kem context in the I<ctx> parameter.
  97. This function should free any resources associated with that context.
  98. OSSL_FUNC_kem_dupctx() should duplicate the provider side asymmetric kem
  99. context in the I<ctx> parameter and return the duplicate copy.
  100. =head2 Asymmetric Key Encapsulation Functions
  101. OSSL_FUNC_kem_encapsulate_init() initialises a context for an asymmetric
  102. encapsulation given a provider side asymmetric kem context in the I<ctx>
  103. parameter, a pointer to a provider key object in the I<provkey> parameter and
  104. the I<name> of the algorithm.
  105. The I<params>, if not NULL, should be set on the context in a manner similar to
  106. using OSSL_FUNC_kem_set_ctx_params().
  107. The key object should have been previously generated, loaded or imported into
  108. the provider using the key management (OSSL_OP_KEYMGMT) operation (see
  109. provider-keymgmt(7)>.
  110. OSSL_FUNC_kem_auth_encapsulate_init() is similiar to
  111. OSSL_FUNC_kem_encapsulate_init(), but also passes an additional authentication
  112. key I<provauthkey> which cannot be NULL.
  113. OSSL_FUNC_kem_encapsulate() performs the actual encapsulation itself.
  114. A previously initialised asymmetric kem context is passed in the I<ctx>
  115. parameter.
  116. Unless I<out> is NULL, the data to be encapsulated is internally generated,
  117. and returned into the buffer pointed to by the I<secret> parameter and the
  118. encapsulated data should also be written to the location pointed to by the
  119. I<out> parameter. The length of the encapsulated data should be written to
  120. I<*outlen> and the length of the generated secret should be written to
  121. I<*secretlen>.
  122. If I<out> is NULL then the maximum length of the encapsulated data should be
  123. written to I<*outlen>, and the maximum length of the generated secret should be
  124. written to I<*secretlen>.
  125. =head2 Decapsulation Functions
  126. OSSL_FUNC_kem_decapsulate_init() initialises a context for an asymmetric
  127. decapsulation given a provider side asymmetric kem context in the I<ctx>
  128. parameter, a pointer to a provider key object in the I<provkey> parameter, and
  129. a I<name> of the algorithm.
  130. The key object should have been previously generated, loaded or imported into
  131. the provider using the key management (OSSL_OP_KEYMGMT) operation (see
  132. provider-keymgmt(7)>.
  133. OSSL_FUNC_kem_auth_decapsulate_init() is similiar to
  134. OSSL_FUNC_kem_decapsulate_init(), but also passes an additional authentication
  135. key I<provauthkey> which cannot be NULL.
  136. OSSL_FUNC_kem_decapsulate() performs the actual decapsulation itself.
  137. A previously initialised asymmetric kem context is passed in the I<ctx>
  138. parameter.
  139. The data to be decapsulated is pointed to by the I<in> parameter which is I<inlen>
  140. bytes long.
  141. Unless I<out> is NULL, the decapsulated data should be written to the location
  142. pointed to by the I<out> parameter.
  143. The length of the decapsulated data should be written to I<*outlen>.
  144. If I<out> is NULL then the maximum length of the decapsulated data should be
  145. written to I<*outlen>.
  146. =head2 Asymmetric Key Encapsulation Parameters
  147. See L<OSSL_PARAM(3)> for further details on the parameters structure used by
  148. the OSSL_FUNC_kem_get_ctx_params() and OSSL_FUNC_kem_set_ctx_params()
  149. functions.
  150. OSSL_FUNC_kem_get_ctx_params() gets asymmetric kem parameters associated
  151. with the given provider side asymmetric kem context I<ctx> and stores them in
  152. I<params>.
  153. Passing NULL for I<params> should return true.
  154. OSSL_FUNC_kem_set_ctx_params() sets the asymmetric kem parameters associated
  155. with the given provider side asymmetric kem context I<ctx> to I<params>.
  156. Any parameter settings are additional to any that were previously set.
  157. Passing NULL for I<params> should return true.
  158. No parameters are currently recognised by built-in asymmetric kem algorithms.
  159. OSSL_FUNC_kem_gettable_ctx_params() and OSSL_FUNC_kem_settable_ctx_params()
  160. get a constant B<OSSL_PARAM> array that describes the gettable and settable
  161. parameters, i.e. parameters that can be used with OSSL_FUNC_kem_get_ctx_params()
  162. and OSSL_FUNC_kem_set_ctx_params() respectively.
  163. See L<OSSL_PARAM(3)> for the use of B<OSSL_PARAM> as parameter descriptor.
  164. =head1 RETURN VALUES
  165. OSSL_FUNC_kem_newctx() and OSSL_FUNC_kem_dupctx() should return the newly
  166. created provider side asymmetric kem context, or NULL on failure.
  167. All other functions should return 1 for success or 0 on error.
  168. =head1 SEE ALSO
  169. L<provider(7)>
  170. =head1 HISTORY
  171. The provider KEM interface was introduced in OpenSSL 3.0.
  172. OSSL_FUNC_kem_auth_encapsulate_init() and OSSL_FUNC_kem_auth_decapsulate_init()
  173. were added in OpenSSL 3.2.
  174. =head1 COPYRIGHT
  175. Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
  176. Licensed under the Apache License 2.0 (the "License"). You may not use
  177. this file except in compliance with the License. You can obtain a copy
  178. in the file LICENSE in the source distribution or at
  179. L<https://www.openssl.org/source/license.html>.
  180. =cut