2
0

provider-keyexch.pod 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. =pod
  2. =head1 NAME
  3. provider-keyexch - The keyexch 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_keyexch_newctx(void *provctx);
  15. void OSSL_FUNC_keyexch_freectx(void *ctx);
  16. void *OSSL_FUNC_keyexch_dupctx(void *ctx);
  17. /* Shared secret derivation */
  18. int OSSL_FUNC_keyexch_init(void *ctx, void *provkey,
  19. const OSSL_PARAM params[]);
  20. int OSSL_FUNC_keyexch_set_peer(void *ctx, void *provkey);
  21. int OSSL_FUNC_keyexch_derive(void *ctx, unsigned char *secret, size_t *secretlen,
  22. size_t outlen);
  23. /* Key Exchange parameters */
  24. int OSSL_FUNC_keyexch_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
  25. const OSSL_PARAM *OSSL_FUNC_keyexch_settable_ctx_params(void *ctx,
  26. void *provctx);
  27. int OSSL_FUNC_keyexch_get_ctx_params(void *ctx, OSSL_PARAM params[]);
  28. const OSSL_PARAM *OSSL_FUNC_keyexch_gettable_ctx_params(void *ctx,
  29. void *provctx);
  30. =head1 DESCRIPTION
  31. This documentation is primarily aimed at provider authors. See L<provider(7)>
  32. for further information.
  33. The key exchange (OSSL_OP_KEYEXCH) operation enables providers to implement key
  34. exchange algorithms and make them available to applications via
  35. L<EVP_PKEY_derive(3)> and
  36. other related functions).
  37. All "functions" mentioned here are passed as function pointers between
  38. F<libcrypto> and the provider in L<OSSL_DISPATCH(3)> arrays via
  39. L<OSSL_ALGORITHM(3)> arrays that are returned by the provider's
  40. provider_query_operation() function
  41. (see L<provider-base(7)/Provider Functions>).
  42. All these "functions" have a corresponding function type definition
  43. named B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the
  44. function pointer from an L<OSSL_DISPATCH(3)> element named
  45. B<OSSL_FUNC_{name}>.
  46. For example, the "function" OSSL_FUNC_keyexch_newctx() has these:
  47. typedef void *(OSSL_FUNC_keyexch_newctx_fn)(void *provctx);
  48. static ossl_inline OSSL_FUNC_keyexch_newctx_fn
  49. OSSL_FUNC_keyexch_newctx(const OSSL_DISPATCH *opf);
  50. L<OSSL_DISPATCH(3)> arrays are indexed by numbers that are provided as
  51. macros in L<openssl-core_dispatch.h(7)>, as follows:
  52. OSSL_FUNC_keyexch_newctx OSSL_FUNC_KEYEXCH_NEWCTX
  53. OSSL_FUNC_keyexch_freectx OSSL_FUNC_KEYEXCH_FREECTX
  54. OSSL_FUNC_keyexch_dupctx OSSL_FUNC_KEYEXCH_DUPCTX
  55. OSSL_FUNC_keyexch_init OSSL_FUNC_KEYEXCH_INIT
  56. OSSL_FUNC_keyexch_set_peer OSSL_FUNC_KEYEXCH_SET_PEER
  57. OSSL_FUNC_keyexch_derive OSSL_FUNC_KEYEXCH_DERIVE
  58. OSSL_FUNC_keyexch_set_ctx_params OSSL_FUNC_KEYEXCH_SET_CTX_PARAMS
  59. OSSL_FUNC_keyexch_settable_ctx_params OSSL_FUNC_KEYEXCH_SETTABLE_CTX_PARAMS
  60. OSSL_FUNC_keyexch_get_ctx_params OSSL_FUNC_KEYEXCH_GET_CTX_PARAMS
  61. OSSL_FUNC_keyexch_gettable_ctx_params OSSL_FUNC_KEYEXCH_GETTABLE_CTX_PARAMS
  62. A key exchange algorithm implementation may not implement all of these functions.
  63. In order to be a consistent set of functions a provider must implement
  64. OSSL_FUNC_keyexch_newctx, OSSL_FUNC_keyexch_freectx, OSSL_FUNC_keyexch_init and OSSL_FUNC_keyexch_derive.
  65. All other functions are optional.
  66. A key exchange algorithm must also implement some mechanism for generating,
  67. loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation.
  68. See L<provider-keymgmt(7)> for further details.
  69. =head2 Context Management Functions
  70. OSSL_FUNC_keyexch_newctx() should create and return a pointer to a provider side
  71. structure for holding context information during a key exchange operation.
  72. A pointer to this context will be passed back in a number of the other key
  73. exchange operation function calls.
  74. The parameter I<provctx> is the provider context generated during provider
  75. initialisation (see L<provider(7)>).
  76. OSSL_FUNC_keyexch_freectx() is passed a pointer to the provider side key exchange
  77. context in the I<ctx> parameter.
  78. This function should free any resources associated with that context.
  79. OSSL_FUNC_keyexch_dupctx() should duplicate the provider side key exchange context in
  80. the I<ctx> parameter and return the duplicate copy.
  81. =head2 Shared Secret Derivation Functions
  82. OSSL_FUNC_keyexch_init() initialises a key exchange operation given a provider side key
  83. exchange context in the I<ctx> parameter, and a pointer to a provider key object
  84. in the I<provkey> parameter.
  85. The I<params>, if not NULL, should be set on the context in a manner similar to
  86. using OSSL_FUNC_keyexch_set_params().
  87. The key object should have been previously
  88. generated, loaded or imported into the provider using the key management
  89. (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)>.
  90. OSSL_FUNC_keyexch_set_peer() is called to supply the peer's public key (in the
  91. I<provkey> parameter) to be used when deriving the shared secret.
  92. It is also passed a previously initialised key exchange context in the I<ctx>
  93. parameter.
  94. The key object should have been previously generated, loaded or imported into
  95. the provider using the key management (OSSL_OP_KEYMGMT) operation (see
  96. provider-keymgmt(7)>.
  97. OSSL_FUNC_keyexch_derive() performs the actual key exchange itself by deriving a shared
  98. secret.
  99. A previously initialised key exchange context is passed in the I<ctx>
  100. parameter.
  101. The derived secret should be written to the location I<secret> which should not
  102. exceed I<outlen> bytes.
  103. The length of the shared secret should be written to I<*secretlen>.
  104. If I<secret> is NULL then the maximum length of the shared secret should be
  105. written to I<*secretlen>.
  106. =head2 Key Exchange Parameters Functions
  107. OSSL_FUNC_keyexch_set_ctx_params() sets key exchange parameters associated with the
  108. given provider side key exchange context I<ctx> to I<params>,
  109. see L</Common Key Exchange parameters>.
  110. Any parameter settings are additional to any that were previously set.
  111. Passing NULL for I<params> should return true.
  112. OSSL_FUNC_keyexch_get_ctx_params() gets key exchange parameters associated with the
  113. given provider side key exchange context I<ctx> into I<params>,
  114. see L</Common Key Exchange parameters>.
  115. Passing NULL for I<params> should return true.
  116. OSSL_FUNC_keyexch_settable_ctx_params() yields a constant L<OSSL_PARAM(3)> array that
  117. describes the settable parameters, i.e. parameters that can be used with
  118. OP_signature_set_ctx_params().
  119. If OSSL_FUNC_keyexch_settable_ctx_params() is present, OSSL_FUNC_keyexch_set_ctx_params() must
  120. also be present, and vice versa.
  121. Similarly, OSSL_FUNC_keyexch_gettable_ctx_params() yields a constant L<OSSL_PARAM(3)>
  122. array that describes the gettable parameters, i.e. parameters that can be
  123. handled by OP_signature_get_ctx_params().
  124. If OSSL_FUNC_keyexch_gettable_ctx_params() is present, OSSL_FUNC_keyexch_get_ctx_params() must
  125. also be present, and vice versa.
  126. Notice that not all settable parameters are also gettable, and vice versa.
  127. =head2 Common Key Exchange parameters
  128. See L<OSSL_PARAM(3)> for further details on the parameters structure used by
  129. the OSSL_FUNC_keyexch_set_ctx_params() and OSSL_FUNC_keyexch_get_ctx_params() functions.
  130. Common parameters currently recognised by built-in key exchange algorithms are
  131. as follows.
  132. =over 4
  133. =item "kdf-type" (B<OSSL_EXCHANGE_PARAM_KDF_TYPE>) <UTF8 string>
  134. Sets or gets the Key Derivation Function type to apply within the associated key
  135. exchange ctx.
  136. =item "kdf-digest" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST>) <UTF8 string>
  137. Sets or gets the Digest algorithm to be used as part of the Key Derivation Function
  138. associated with the given key exchange ctx.
  139. =item "kdf-digest-props" (B<OSSL_EXCHANGE_PARAM_KDF_DIGEST_PROPS>) <UTF8 string>
  140. Sets properties to be used upon look up of the implementation for the selected
  141. Digest algorithm for the Key Derivation Function associated with the given key
  142. exchange ctx.
  143. =item "kdf-outlen" (B<OSSL_EXCHANGE_PARAM_KDF_OUTLEN>) <unsigned integer>
  144. Sets or gets the desired size for the output of the chosen Key Derivation Function
  145. associated with the given key exchange ctx.
  146. The length of the "kdf-outlen" parameter should not exceed that of a B<size_t>.
  147. =item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet string>
  148. Sets the User Key Material to be used as part of the selected Key Derivation
  149. Function associated with the given key exchange ctx.
  150. =item "kdf-ukm" (B<OSSL_EXCHANGE_PARAM_KDF_UKM>) <octet string ptr>
  151. Gets a pointer to the User Key Material to be used as part of the selected
  152. Key Derivation Function associated with the given key exchange ctx. Providers
  153. usually do not need to support this gettable parameter as its sole purpose
  154. is to support functionality of the deprecated EVP_PKEY_CTX_get0_ecdh_kdf_ukm()
  155. and EVP_PKEY_CTX_get0_dh_kdf_ukm() functions.
  156. =back
  157. =head1 RETURN VALUES
  158. OSSL_FUNC_keyexch_newctx() and OSSL_FUNC_keyexch_dupctx() should return the newly created
  159. provider side key exchange context, or NULL on failure.
  160. OSSL_FUNC_keyexch_init(), OSSL_FUNC_keyexch_set_peer(), OSSL_FUNC_keyexch_derive(),
  161. OSSL_FUNC_keyexch_set_params(), and OSSL_FUNC_keyexch_get_params() should return 1 for success
  162. or 0 on error.
  163. OSSL_FUNC_keyexch_settable_ctx_params() and OSSL_FUNC_keyexch_gettable_ctx_params() should
  164. always return a constant L<OSSL_PARAM(3)> array.
  165. =head1 SEE ALSO
  166. L<provider(7)>
  167. =head1 HISTORY
  168. The provider KEYEXCH interface was introduced in OpenSSL 3.0.
  169. =head1 COPYRIGHT
  170. Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
  171. Licensed under the Apache License 2.0 (the "License"). You may not use
  172. this file except in compliance with the License. You can obtain a copy
  173. in the file LICENSE in the source distribution or at
  174. L<https://www.openssl.org/source/license.html>.
  175. =cut