provider-kem.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?xml version="1.0" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <title>provider-kem</title>
  6. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  7. <link rev="made" href="mailto:root@localhost" />
  8. </head>
  9. <body>
  10. <ul id="index">
  11. <li><a href="#NAME">NAME</a></li>
  12. <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
  13. <li><a href="#DESCRIPTION">DESCRIPTION</a>
  14. <ul>
  15. <li><a href="#Context-Management-Functions">Context Management Functions</a></li>
  16. <li><a href="#Asymmetric-Key-Encapsulation-Functions">Asymmetric Key Encapsulation Functions</a></li>
  17. <li><a href="#Decapsulation-Functions">Decapsulation Functions</a></li>
  18. <li><a href="#Asymmetric-Key-Encapsulation-Parameters">Asymmetric Key Encapsulation Parameters</a></li>
  19. </ul>
  20. </li>
  21. <li><a href="#RETURN-VALUES">RETURN VALUES</a></li>
  22. <li><a href="#SEE-ALSO">SEE ALSO</a></li>
  23. <li><a href="#HISTORY">HISTORY</a></li>
  24. <li><a href="#COPYRIGHT">COPYRIGHT</a></li>
  25. </ul>
  26. <h1 id="NAME">NAME</h1>
  27. <p>provider-kem - The kem library &lt;-&gt; provider functions</p>
  28. <h1 id="SYNOPSIS">SYNOPSIS</h1>
  29. <pre><code>#include &lt;openssl/core_dispatch.h&gt;
  30. #include &lt;openssl/core_names.h&gt;
  31. /*
  32. * None of these are actual functions, but are displayed like this for
  33. * the function signatures for functions that are offered as function
  34. * pointers in OSSL_DISPATCH arrays.
  35. */
  36. /* Context management */
  37. void *OSSL_FUNC_kem_newctx(void *provctx);
  38. void OSSL_FUNC_kem_freectx(void *ctx);
  39. void *OSSL_FUNC_kem_dupctx(void *ctx);
  40. /* Encapsulation */
  41. int OSSL_FUNC_kem_encapsulate_init(void *ctx, void *provkey,
  42. const OSSL_PARAM params[]);
  43. int OSSL_FUNC_kem_auth_encapsulate_init(void *ctx, void *provkey,
  44. void *provauthkey,
  45. const OSSL_PARAM params[]);
  46. int OSSL_FUNC_kem_encapsulate(void *ctx, unsigned char *out, size_t *outlen,
  47. unsigned char *secret, size_t *secretlen);
  48. /* Decapsulation */
  49. int OSSL_FUNC_kem_decapsulate_init(void *ctx, void *provkey);
  50. int OSSL_FUNC_kem_auth_decapsulate_init(void *ctx, void *provkey,
  51. void *provauthkey,
  52. const OSSL_PARAM params[]);
  53. int OSSL_FUNC_kem_decapsulate(void *ctx, unsigned char *out, size_t *outlen,
  54. const unsigned char *in, size_t inlen);
  55. /* KEM parameters */
  56. int OSSL_FUNC_kem_get_ctx_params(void *ctx, OSSL_PARAM params[]);
  57. const OSSL_PARAM *OSSL_FUNC_kem_gettable_ctx_params(void *ctx, void *provctx);
  58. int OSSL_FUNC_kem_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
  59. const OSSL_PARAM *OSSL_FUNC_kem_settable_ctx_params(void *ctx, void *provctx);</code></pre>
  60. <h1 id="DESCRIPTION">DESCRIPTION</h1>
  61. <p>This documentation is primarily aimed at provider authors. See <a href="../man7/provider.html">provider(7)</a> for further information.</p>
  62. <p>The asymmetric kem (OSSL_OP_KEM) operation enables providers to implement asymmetric kem algorithms and make them available to applications via the API functions <a href="../man3/EVP_PKEY_encapsulate.html">EVP_PKEY_encapsulate(3)</a>, <a href="../man3/EVP_PKEY_decapsulate.html">EVP_PKEY_decapsulate(3)</a> and other related functions.</p>
  63. <p>All &quot;functions&quot; mentioned here are passed as function pointers between <i>libcrypto</i> and the provider in <a href="../man3/OSSL_DISPATCH.html">OSSL_DISPATCH(3)</a> arrays via <a href="../man3/OSSL_ALGORITHM.html">OSSL_ALGORITHM(3)</a> arrays that are returned by the provider&#39;s provider_query_operation() function (see <a href="../man7/provider-base.html">&quot;Provider Functions&quot; in provider-base(7)</a>).</p>
  64. <p>All these &quot;functions&quot; have a corresponding function type definition named <b>OSSL_FUNC_{name}_fn</b>, and a helper function to retrieve the function pointer from an <a href="../man3/OSSL_DISPATCH.html">OSSL_DISPATCH(3)</a> element named <b>OSSL_FUNC_{name}</b>. For example, the &quot;function&quot; OSSL_FUNC_kem_newctx() has these:</p>
  65. <pre><code>typedef void *(OSSL_FUNC_kem_newctx_fn)(void *provctx);
  66. static ossl_inline OSSL_FUNC_kem_newctx_fn
  67. OSSL_FUNC_kem_newctx(const OSSL_DISPATCH *opf);</code></pre>
  68. <p><a href="../man3/OSSL_DISPATCH.html">OSSL_DISPATCH(3)</a> arrays are indexed by numbers that are provided as macros in <a href="../man7/openssl-core_dispatch.h.html">openssl-core_dispatch.h(7)</a>, as follows:</p>
  69. <pre><code>OSSL_FUNC_kem_newctx OSSL_FUNC_KEM_NEWCTX
  70. OSSL_FUNC_kem_freectx OSSL_FUNC_KEM_FREECTX
  71. OSSL_FUNC_kem_dupctx OSSL_FUNC_KEM_DUPCTX
  72. OSSL_FUNC_kem_encapsulate_init OSSL_FUNC_KEM_ENCAPSULATE_INIT
  73. OSSL_FUNC_kem_auth_encapsulate_init OSSL_FUNC_KEM_AUTH_ENCAPSULATE_INIT
  74. OSSL_FUNC_kem_encapsulate OSSL_FUNC_KEM_ENCAPSULATE
  75. OSSL_FUNC_kem_decapsulate_init OSSL_FUNC_KEM_DECAPSULATE_INIT
  76. OSSL_FUNC_kem_auth_decapsulate_init OSSL_FUNC_KEM_AUTH_DECAPSULATE_INIT
  77. OSSL_FUNC_kem_decapsulate OSSL_FUNC_KEM_DECAPSULATE
  78. OSSL_FUNC_kem_get_ctx_params OSSL_FUNC_KEM_GET_CTX_PARAMS
  79. OSSL_FUNC_kem_gettable_ctx_params OSSL_FUNC_KEM_GETTABLE_CTX_PARAMS
  80. OSSL_FUNC_kem_set_ctx_params OSSL_FUNC_KEM_SET_CTX_PARAMS
  81. OSSL_FUNC_kem_settable_ctx_params OSSL_FUNC_KEM_SETTABLE_CTX_PARAMS</code></pre>
  82. <p>An asymmetric kem algorithm implementation may not implement all of these functions. In order to be a consistent set of functions a provider must implement OSSL_FUNC_kem_newctx and OSSL_FUNC_kem_freectx. It must also implement both of OSSL_FUNC_kem_encapsulate_init and OSSL_FUNC_kem_encapsulate, or both of OSSL_FUNC_kem_decapsulate_init and OSSL_FUNC_kem_decapsulate. OSSL_FUNC_kem_auth_encapsulate_init is optional but if it is present then so must OSSL_FUNC_kem_auth_decapsulate_init. OSSL_FUNC_kem_get_ctx_params is optional but if it is present then so must OSSL_FUNC_kem_gettable_ctx_params. Similarly, OSSL_FUNC_kem_set_ctx_params is optional but if it is present then OSSL_FUNC_kem_settable_ctx_params must also be present.</p>
  83. <p>An asymmetric kem algorithm must also implement some mechanism for generating, loading or importing keys via the key management (OSSL_OP_KEYMGMT) operation. See <a href="../man7/provider-keymgmt.html">provider-keymgmt(7)</a> for further details.</p>
  84. <h2 id="Context-Management-Functions">Context Management Functions</h2>
  85. <p>OSSL_FUNC_kem_newctx() should create and return a pointer to a provider side structure for holding context information during an asymmetric kem operation. A pointer to this context will be passed back in a number of the other asymmetric kem operation function calls. The parameter <i>provctx</i> is the provider context generated during provider initialisation (see <a href="../man7/provider.html">provider(7)</a>).</p>
  86. <p>OSSL_FUNC_kem_freectx() is passed a pointer to the provider side asymmetric kem context in the <i>ctx</i> parameter. This function should free any resources associated with that context.</p>
  87. <p>OSSL_FUNC_kem_dupctx() should duplicate the provider side asymmetric kem context in the <i>ctx</i> parameter and return the duplicate copy.</p>
  88. <h2 id="Asymmetric-Key-Encapsulation-Functions">Asymmetric Key Encapsulation Functions</h2>
  89. <p>OSSL_FUNC_kem_encapsulate_init() initialises a context for an asymmetric encapsulation given a provider side asymmetric kem context in the <i>ctx</i> parameter, a pointer to a provider key object in the <i>provkey</i> parameter and the <i>name</i> of the algorithm. The <i>params</i>, if not NULL, should be set on the context in a manner similar to using OSSL_FUNC_kem_set_ctx_params(). The key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)&gt;.</p>
  90. <p>OSSL_FUNC_kem_auth_encapsulate_init() is similar to OSSL_FUNC_kem_encapsulate_init(), but also passes an additional authentication key <i>provauthkey</i> which cannot be NULL.</p>
  91. <p>OSSL_FUNC_kem_encapsulate() performs the actual encapsulation itself. A previously initialised asymmetric kem context is passed in the <i>ctx</i> parameter. Unless <i>out</i> is NULL, the data to be encapsulated is internally generated, and returned into the buffer pointed to by the <i>secret</i> parameter and the encapsulated data should also be written to the location pointed to by the <i>out</i> parameter. The length of the encapsulated data should be written to <i>*outlen</i> and the length of the generated secret should be written to <i>*secretlen</i>.</p>
  92. <p>If <i>out</i> is NULL then the maximum length of the encapsulated data should be written to <i>*outlen</i>, and the maximum length of the generated secret should be written to <i>*secretlen</i>.</p>
  93. <h2 id="Decapsulation-Functions">Decapsulation Functions</h2>
  94. <p>OSSL_FUNC_kem_decapsulate_init() initialises a context for an asymmetric decapsulation given a provider side asymmetric kem context in the <i>ctx</i> parameter, a pointer to a provider key object in the <i>provkey</i> parameter, and a <i>name</i> of the algorithm. The key object should have been previously generated, loaded or imported into the provider using the key management (OSSL_OP_KEYMGMT) operation (see provider-keymgmt(7)&gt;.</p>
  95. <p>OSSL_FUNC_kem_auth_decapsulate_init() is similar to OSSL_FUNC_kem_decapsulate_init(), but also passes an additional authentication key <i>provauthkey</i> which cannot be NULL.</p>
  96. <p>OSSL_FUNC_kem_decapsulate() performs the actual decapsulation itself. A previously initialised asymmetric kem context is passed in the <i>ctx</i> parameter. The data to be decapsulated is pointed to by the <i>in</i> parameter which is <i>inlen</i> bytes long. Unless <i>out</i> is NULL, the decapsulated data should be written to the location pointed to by the <i>out</i> parameter. The length of the decapsulated data should be written to <i>*outlen</i>. If <i>out</i> is NULL then the maximum length of the decapsulated data should be written to <i>*outlen</i>.</p>
  97. <h2 id="Asymmetric-Key-Encapsulation-Parameters">Asymmetric Key Encapsulation Parameters</h2>
  98. <p>See <a href="../man3/OSSL_PARAM.html">OSSL_PARAM(3)</a> for further details on the parameters structure used by the OSSL_FUNC_kem_get_ctx_params() and OSSL_FUNC_kem_set_ctx_params() functions.</p>
  99. <p>OSSL_FUNC_kem_get_ctx_params() gets asymmetric kem parameters associated with the given provider side asymmetric kem context <i>ctx</i> and stores them in <i>params</i>. Passing NULL for <i>params</i> should return true.</p>
  100. <p>OSSL_FUNC_kem_set_ctx_params() sets the asymmetric kem parameters associated with the given provider side asymmetric kem context <i>ctx</i> to <i>params</i>. Any parameter settings are additional to any that were previously set. Passing NULL for <i>params</i> should return true.</p>
  101. <p>No parameters are currently recognised by built-in asymmetric kem algorithms.</p>
  102. <p>OSSL_FUNC_kem_gettable_ctx_params() and OSSL_FUNC_kem_settable_ctx_params() get a constant <a href="../man3/OSSL_PARAM.html">OSSL_PARAM(3)</a> array that describes the gettable and settable parameters, i.e. parameters that can be used with OSSL_FUNC_kem_get_ctx_params() and OSSL_FUNC_kem_set_ctx_params() respectively.</p>
  103. <h1 id="RETURN-VALUES">RETURN VALUES</h1>
  104. <p>OSSL_FUNC_kem_newctx() and OSSL_FUNC_kem_dupctx() should return the newly created provider side asymmetric kem context, or NULL on failure.</p>
  105. <p>All other functions should return 1 for success or 0 on error.</p>
  106. <h1 id="SEE-ALSO">SEE ALSO</h1>
  107. <p><a href="../man7/provider.html">provider(7)</a></p>
  108. <h1 id="HISTORY">HISTORY</h1>
  109. <p>The provider KEM interface was introduced in OpenSSL 3.0.</p>
  110. <p>OSSL_FUNC_kem_auth_encapsulate_init() and OSSL_FUNC_kem_auth_decapsulate_init() were added in OpenSSL 3.2.</p>
  111. <h1 id="COPYRIGHT">COPYRIGHT</h1>
  112. <p>Copyright 2020-2023 The OpenSSL Project Authors. All Rights Reserved.</p>
  113. <p>Licensed under the Apache License 2.0 (the &quot;License&quot;). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <a href="https://www.openssl.org/source/license.html">https://www.openssl.org/source/license.html</a>.</p>
  114. </body>
  115. </html>