core.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OPENSSL_CORE_H
  10. # define OPENSSL_CORE_H
  11. # pragma once
  12. # include <stddef.h>
  13. # include <openssl/types.h>
  14. # ifdef __cplusplus
  15. extern "C" {
  16. # endif
  17. /*-
  18. * Base types
  19. * ----------
  20. *
  21. * These are the types that the OpenSSL core and providers have in common
  22. * to communicate data between them.
  23. */
  24. /* Opaque handles to be used with core upcall functions from providers */
  25. typedef struct ossl_core_handle_st OSSL_CORE_HANDLE;
  26. typedef struct openssl_core_ctx_st OPENSSL_CORE_CTX;
  27. typedef struct ossl_core_bio_st OSSL_CORE_BIO;
  28. /*
  29. * Dispatch table element. function_id numbers and the functions are defined
  30. * in core_dispatch.h, see macros with 'OSSL_CORE_MAKE_FUNC' in their names.
  31. *
  32. * An array of these is always terminated by function_id == 0
  33. */
  34. struct ossl_dispatch_st {
  35. int function_id;
  36. void (*function)(void);
  37. };
  38. # define OSSL_DISPATCH_END \
  39. { 0, NULL }
  40. /*
  41. * Other items, essentially an int<->pointer map element.
  42. *
  43. * We make this type distinct from OSSL_DISPATCH to ensure that dispatch
  44. * tables remain tables with function pointers only.
  45. *
  46. * This is used whenever we need to pass things like a table of error reason
  47. * codes <-> reason string maps, ...
  48. *
  49. * Usage determines which field works as key if any, rather than field order.
  50. *
  51. * An array of these is always terminated by id == 0 && ptr == NULL
  52. */
  53. struct ossl_item_st {
  54. unsigned int id;
  55. void *ptr;
  56. };
  57. /*
  58. * Type to tie together algorithm names, property definition string and
  59. * the algorithm implementation in the form of a dispatch table.
  60. *
  61. * An array of these is always terminated by algorithm_names == NULL
  62. */
  63. struct ossl_algorithm_st {
  64. const char *algorithm_names; /* key */
  65. const char *property_definition; /* key */
  66. const OSSL_DISPATCH *implementation;
  67. const char *algorithm_description;
  68. };
  69. /*
  70. * Type to pass object data in a uniform way, without exposing the object
  71. * structure.
  72. *
  73. * An array of these is always terminated by key == NULL
  74. */
  75. struct ossl_param_st {
  76. const char *key; /* the name of the parameter */
  77. unsigned int data_type; /* declare what kind of content is in buffer */
  78. void *data; /* value being passed in or out */
  79. size_t data_size; /* data size */
  80. size_t return_size; /* returned content size */
  81. };
  82. /* Currently supported OSSL_PARAM data types */
  83. /*
  84. * OSSL_PARAM_INTEGER and OSSL_PARAM_UNSIGNED_INTEGER
  85. * are arbitrary length and therefore require an arbitrarily sized buffer,
  86. * since they may be used to pass numbers larger than what is natively
  87. * available.
  88. *
  89. * The number must be buffered in native form, i.e. MSB first on B_ENDIAN
  90. * systems and LSB first on L_ENDIAN systems. This means that arbitrary
  91. * native integers can be stored in the buffer, just make sure that the
  92. * buffer size is correct and the buffer itself is properly aligned (for
  93. * example by having the buffer field point at a C integer).
  94. */
  95. # define OSSL_PARAM_INTEGER 1
  96. # define OSSL_PARAM_UNSIGNED_INTEGER 2
  97. /*-
  98. * OSSL_PARAM_REAL
  99. * is a C binary floating point values in native form and alignment.
  100. */
  101. # define OSSL_PARAM_REAL 3
  102. /*-
  103. * OSSL_PARAM_UTF8_STRING
  104. * is a printable string. It is expected to be printed as it is.
  105. */
  106. # define OSSL_PARAM_UTF8_STRING 4
  107. /*-
  108. * OSSL_PARAM_OCTET_STRING
  109. * is a string of bytes with no further specification. It is expected to be
  110. * printed as a hexdump.
  111. */
  112. # define OSSL_PARAM_OCTET_STRING 5
  113. /*-
  114. * OSSL_PARAM_UTF8_PTR
  115. * is a pointer to a printable string. It is expected to be printed as it is.
  116. *
  117. * The difference between this and OSSL_PARAM_UTF8_STRING is that only pointers
  118. * are manipulated for this type.
  119. *
  120. * This is more relevant for parameter requests, where the responding
  121. * function doesn't need to copy the data to the provided buffer, but
  122. * sets the provided buffer to point at the actual data instead.
  123. *
  124. * WARNING! Using these is FRAGILE, as it assumes that the actual
  125. * data and its location are constant.
  126. *
  127. * EXTRA WARNING! If you are not completely sure you most likely want
  128. * to use the OSSL_PARAM_UTF8_STRING type.
  129. */
  130. # define OSSL_PARAM_UTF8_PTR 6
  131. /*-
  132. * OSSL_PARAM_OCTET_PTR
  133. * is a pointer to a string of bytes with no further specification. It is
  134. * expected to be printed as a hexdump.
  135. *
  136. * The difference between this and OSSL_PARAM_OCTET_STRING is that only pointers
  137. * are manipulated for this type.
  138. *
  139. * This is more relevant for parameter requests, where the responding
  140. * function doesn't need to copy the data to the provided buffer, but
  141. * sets the provided buffer to point at the actual data instead.
  142. *
  143. * WARNING! Using these is FRAGILE, as it assumes that the actual
  144. * data and its location are constant.
  145. *
  146. * EXTRA WARNING! If you are not completely sure you most likely want
  147. * to use the OSSL_PARAM_OCTET_STRING type.
  148. */
  149. # define OSSL_PARAM_OCTET_PTR 7
  150. /*
  151. * Typedef for the thread stop handling callback. Used both internally and by
  152. * providers.
  153. *
  154. * Providers may register for notifications about threads stopping by
  155. * registering a callback to hear about such events. Providers register the
  156. * callback using the OSSL_FUNC_CORE_THREAD_START function in the |in| dispatch
  157. * table passed to OSSL_provider_init(). The arg passed back to a provider will
  158. * be the provider side context object.
  159. */
  160. typedef void (*OSSL_thread_stop_handler_fn)(void *arg);
  161. /*-
  162. * Provider entry point
  163. * --------------------
  164. *
  165. * This function is expected to be present in any dynamically loadable
  166. * provider module. By definition, if this function doesn't exist in a
  167. * module, that module is not an OpenSSL provider module.
  168. */
  169. /*-
  170. * |handle| pointer to opaque type OSSL_CORE_HANDLE. This can be used
  171. * together with some functions passed via |in| to query data.
  172. * |in| is the array of functions that the Core passes to the provider.
  173. * |out| will be the array of base functions that the provider passes
  174. * back to the Core.
  175. * |provctx| a provider side context object, optionally created if the
  176. * provider needs it. This value is passed to other provider
  177. * functions, notably other context constructors.
  178. */
  179. typedef int (OSSL_provider_init_fn)(const OSSL_CORE_HANDLE *handle,
  180. const OSSL_DISPATCH *in,
  181. const OSSL_DISPATCH **out,
  182. void **provctx);
  183. # ifdef __VMS
  184. # pragma names save
  185. # pragma names uppercase,truncated
  186. # endif
  187. OPENSSL_EXPORT OSSL_provider_init_fn OSSL_provider_init;
  188. # ifdef __VMS
  189. # pragma names restore
  190. # endif
  191. /*
  192. * Generic callback function signature.
  193. *
  194. * The expectation is that any provider function that wants to offer
  195. * a callback / hook can do so by taking an argument with this type,
  196. * as well as a pointer to caller-specific data. When calling the
  197. * callback, the provider function can populate an OSSL_PARAM array
  198. * with data of its choice and pass that in the callback call, along
  199. * with the caller data argument.
  200. *
  201. * libcrypto may use the OSSL_PARAM array to create arguments for an
  202. * application callback it knows about.
  203. */
  204. typedef int (OSSL_CALLBACK)(const OSSL_PARAM params[], void *arg);
  205. typedef int (OSSL_INOUT_CALLBACK)(const OSSL_PARAM in_params[],
  206. OSSL_PARAM out_params[], void *arg);
  207. /*
  208. * Passphrase callback function signature
  209. *
  210. * This is similar to the generic callback function above, but adds a
  211. * result parameter.
  212. */
  213. typedef int (OSSL_PASSPHRASE_CALLBACK)(char *pass, size_t pass_size,
  214. size_t *pass_len,
  215. const OSSL_PARAM params[], void *arg);
  216. # ifdef __cplusplus
  217. }
  218. # endif
  219. #endif