You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

core.h 8.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. {
  17. #endif
  18. /*-
  19. * Base types
  20. * ----------
  21. *
  22. * These are the types that the OpenSSL core and providers have in common
  23. * to communicate data between them.
  24. */
  25. /* Opaque handles to be used with core upcall functions from providers */
  26. typedef struct ossl_core_handle_st OSSL_CORE_HANDLE;
  27. typedef struct openssl_core_ctx_st OPENSSL_CORE_CTX;
  28. typedef struct ossl_core_bio_st OSSL_CORE_BIO;
  29. /*
  30. * Dispatch table element. function_id numbers and the functions are defined
  31. * in core_dispatch.h, see macros with 'OSSL_CORE_MAKE_FUNC' in their names.
  32. *
  33. * An array of these is always terminated by function_id == 0
  34. */
  35. struct ossl_dispatch_st
  36. {
  37. int function_id;
  38. void (*function)(void);
  39. };
  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. {
  55. unsigned int id;
  56. void* ptr;
  57. };
  58. /*
  59. * Type to tie together algorithm names, property definition string and
  60. * the algorithm implementation in the form of a dispatch table.
  61. *
  62. * An array of these is always terminated by algorithm_names == NULL
  63. */
  64. struct ossl_algorithm_st
  65. {
  66. const char* algorithm_names; /* key */
  67. const char* property_definition; /* key */
  68. const OSSL_DISPATCH* implementation;
  69. const char* algorithm_description;
  70. };
  71. /*
  72. * Type to pass object data in a uniform way, without exposing the object
  73. * structure.
  74. *
  75. * An array of these is always terminated by key == NULL
  76. */
  77. struct ossl_param_st
  78. {
  79. const char* key; /* the name of the parameter */
  80. unsigned int data_type; /* declare what kind of content is in buffer */
  81. void* data; /* value being passed in or out */
  82. size_t data_size; /* data size */
  83. size_t return_size; /* returned content size */
  84. };
  85. /* Currently supported OSSL_PARAM data types */
  86. /*
  87. * OSSL_PARAM_INTEGER and OSSL_PARAM_UNSIGNED_INTEGER
  88. * are arbitrary length and therefore require an arbitrarily sized buffer,
  89. * since they may be used to pass numbers larger than what is natively
  90. * available.
  91. *
  92. * The number must be buffered in native form, i.e. MSB first on B_ENDIAN
  93. * systems and LSB first on L_ENDIAN systems. This means that arbitrary
  94. * native integers can be stored in the buffer, just make sure that the
  95. * buffer size is correct and the buffer itself is properly aligned (for
  96. * example by having the buffer field point at a C integer).
  97. */
  98. #define OSSL_PARAM_INTEGER 1
  99. #define OSSL_PARAM_UNSIGNED_INTEGER 2
  100. /*-
  101. * OSSL_PARAM_REAL
  102. * is a C binary floating point values in native form and alignment.
  103. */
  104. #define OSSL_PARAM_REAL 3
  105. /*-
  106. * OSSL_PARAM_UTF8_STRING
  107. * is a printable string. It is expected to be printed as it is.
  108. */
  109. #define OSSL_PARAM_UTF8_STRING 4
  110. /*-
  111. * OSSL_PARAM_OCTET_STRING
  112. * is a string of bytes with no further specification. It is expected to be
  113. * printed as a hexdump.
  114. */
  115. #define OSSL_PARAM_OCTET_STRING 5
  116. /*-
  117. * OSSL_PARAM_UTF8_PTR
  118. * is a pointer to a printable string. It is expected to be printed as it is.
  119. *
  120. * The difference between this and OSSL_PARAM_UTF8_STRING is that only pointers
  121. * are manipulated for this type.
  122. *
  123. * This is more relevant for parameter requests, where the responding
  124. * function doesn't need to copy the data to the provided buffer, but
  125. * sets the provided buffer to point at the actual data instead.
  126. *
  127. * WARNING! Using these is FRAGILE, as it assumes that the actual
  128. * data and its location are constant.
  129. *
  130. * EXTRA WARNING! If you are not completely sure you most likely want
  131. * to use the OSSL_PARAM_UTF8_STRING type.
  132. */
  133. #define OSSL_PARAM_UTF8_PTR 6
  134. /*-
  135. * OSSL_PARAM_OCTET_PTR
  136. * is a pointer to a string of bytes with no further specification. It is
  137. * expected to be printed as a hexdump.
  138. *
  139. * The difference between this and OSSL_PARAM_OCTET_STRING is that only pointers
  140. * are manipulated for this type.
  141. *
  142. * This is more relevant for parameter requests, where the responding
  143. * function doesn't need to copy the data to the provided buffer, but
  144. * sets the provided buffer to point at the actual data instead.
  145. *
  146. * WARNING! Using these is FRAGILE, as it assumes that the actual
  147. * data and its location are constant.
  148. *
  149. * EXTRA WARNING! If you are not completely sure you most likely want
  150. * to use the OSSL_PARAM_OCTET_STRING type.
  151. */
  152. #define OSSL_PARAM_OCTET_PTR 7
  153. /*
  154. * Typedef for the thread stop handling callback. Used both internally and by
  155. * providers.
  156. *
  157. * Providers may register for notifications about threads stopping by
  158. * registering a callback to hear about such events. Providers register the
  159. * callback using the OSSL_FUNC_CORE_THREAD_START function in the |in| dispatch
  160. * table passed to OSSL_provider_init(). The arg passed back to a provider will
  161. * be the provider side context object.
  162. */
  163. typedef void (*OSSL_thread_stop_handler_fn)(void* arg);
  164. /*-
  165. * Provider entry point
  166. * --------------------
  167. *
  168. * This function is expected to be present in any dynamically loadable
  169. * provider module. By definition, if this function doesn't exist in a
  170. * module, that module is not an OpenSSL provider module.
  171. */
  172. /*-
  173. * |handle| pointer to opaque type OSSL_CORE_HANDLE. This can be used
  174. * together with some functions passed via |in| to query data.
  175. * |in| is the array of functions that the Core passes to the provider.
  176. * |out| will be the array of base functions that the provider passes
  177. * back to the Core.
  178. * |provctx| a provider side context object, optionally created if the
  179. * provider needs it. This value is passed to other provider
  180. * functions, notably other context constructors.
  181. */
  182. typedef int(OSSL_provider_init_fn)(const OSSL_CORE_HANDLE* handle, const OSSL_DISPATCH* in, const OSSL_DISPATCH** out, 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[], OSSL_PARAM out_params[], void* arg);
  206. /*
  207. * Passphrase callback function signature
  208. *
  209. * This is similar to the generic callback function above, but adds a
  210. * result parameter.
  211. */
  212. typedef int(OSSL_PASSPHRASE_CALLBACK)(char* pass, size_t pass_size, size_t* pass_len, const OSSL_PARAM params[], void* arg);
  213. #ifdef __cplusplus
  214. }
  215. #endif
  216. #endif