core.h 7.9 KB

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