2
0

provider-kem.pod 8.8 KB

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