core.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright 2019 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. # include <stddef.h>
  12. # include <openssl/types.h>
  13. # ifdef __cplusplus
  14. extern "C" {
  15. # endif
  16. /*-
  17. * Base types
  18. * ----------
  19. *
  20. * These are the types that the OpenSSL core and providers have in common
  21. * to communicate data between them.
  22. */
  23. /*
  24. * Dispatch table element. function_id numbers are defined further down,
  25. * see macros with '_FUNC' in their names.
  26. *
  27. * An array of these is always terminated by function_id == 0
  28. */
  29. struct ossl_dispatch_st {
  30. int function_id;
  31. void (*function)(void);
  32. };
  33. /*
  34. * Other items, essentially an int<->pointer map element.
  35. *
  36. * We make this type distinct from OSSL_DISPATCH to ensure that dispatch
  37. * tables remain tables with function pointers only.
  38. *
  39. * This is used whenever we need to pass things like a table of error reason
  40. * codes <-> reason string maps, ...
  41. *
  42. * Usage determines which field works as key if any, rather than field order.
  43. *
  44. * An array of these is always terminated by id == 0 && ptr == NULL
  45. */
  46. struct ossl_item_st {
  47. unsigned int id;
  48. void *ptr;
  49. };
  50. /*
  51. * Type to tie together algorithm names, property definition string and
  52. * the algorithm implementation in the form of a dispatch table.
  53. *
  54. * An array of these is always terminated by algorithm_names == NULL
  55. */
  56. struct ossl_algorithm_st {
  57. const char *algorithm_names; /* key */
  58. const char *property_definition; /* key */
  59. const OSSL_DISPATCH *implementation;
  60. };
  61. /*
  62. * Type to pass object data in a uniform way, without exposing the object
  63. * structure.
  64. *
  65. * An array of these is always terminated by key == NULL
  66. */
  67. struct ossl_param_st {
  68. const char *key; /* the name of the parameter */
  69. unsigned int data_type; /* declare what kind of content is in buffer */
  70. void *data; /* value being passed in or out */
  71. size_t data_size; /* data size */
  72. size_t return_size; /* returned content size */
  73. };
  74. /* Currently supported OSSL_PARAM data types */
  75. /*
  76. * OSSL_PARAM_INTEGER and OSSL_PARAM_UNSIGNED_INTEGER
  77. * are arbitrary length and therefore require an arbitrarily sized buffer,
  78. * since they may be used to pass numbers larger than what is natively
  79. * available.
  80. *
  81. * The number must be buffered in native form, i.e. MSB first on B_ENDIAN
  82. * systems and LSB first on L_ENDIAN systems. This means that arbitrary
  83. * native integers can be stored in the buffer, just make sure that the
  84. * buffer size is correct and the buffer itself is properly aligned (for
  85. * example by having the buffer field point at a C integer).
  86. */
  87. # define OSSL_PARAM_INTEGER 1
  88. # define OSSL_PARAM_UNSIGNED_INTEGER 2
  89. /*-
  90. * OSSL_PARAM_REAL
  91. * is a C binary floating point values in native form and alignment.
  92. */
  93. # define OSSL_PARAM_REAL 3
  94. /*-
  95. * OSSL_PARAM_UTF8_STRING
  96. * is a printable string. Is expteced to be printed as it is.
  97. */
  98. # define OSSL_PARAM_UTF8_STRING 4
  99. /*-
  100. * OSSL_PARAM_OCTET_STRING
  101. * is a string of bytes with no further specification. Is expected to be
  102. * printed as a hexdump.
  103. */
  104. # define OSSL_PARAM_OCTET_STRING 5
  105. /*-
  106. * OSSL_PARAM_UTF8_PTR
  107. * is a pointer to a printable string. Is expteced to be printed as it is.
  108. *
  109. * The difference between this and OSSL_PARAM_UTF8_STRING is that only pointers
  110. * are manipulated for this type.
  111. *
  112. * This is more relevant for parameter requests, where the responding
  113. * function doesn't need to copy the data to the provided buffer, but
  114. * sets the provided buffer to point at the actual data instead.
  115. *
  116. * WARNING! Using these is FRAGILE, as it assumes that the actual
  117. * data and its location are constant.
  118. */
  119. # define OSSL_PARAM_UTF8_PTR 6
  120. /*-
  121. * OSSL_PARAM_OCTET_PTR
  122. * is a pointer to a string of bytes with no further specification. It is
  123. * expected to be printed as a hexdump.
  124. *
  125. * The difference between this and OSSL_PARAM_OCTET_STRING is that only pointers
  126. * are manipulated for this type.
  127. *
  128. * This is more relevant for parameter requests, where the responding
  129. * function doesn't need to copy the data to the provided buffer, but
  130. * sets the provided buffer to point at the actual data instead.
  131. *
  132. * WARNING! Using these is FRAGILE, as it assumes that the actual
  133. * data and its location are constant.
  134. */
  135. # define OSSL_PARAM_OCTET_PTR 7
  136. /*
  137. * Typedef for the thread stop handling callback. Used both internally and by
  138. * providers.
  139. *
  140. * Providers may register for notifications about threads stopping by
  141. * registering a callback to hear about such events. Providers register the
  142. * callback using the OSSL_FUNC_CORE_THREAD_START function in the |in| dispatch
  143. * table passed to OSSL_provider_init(). The arg passed back to a provider will
  144. * be the provider side context object.
  145. */
  146. typedef void (*OSSL_thread_stop_handler_fn)(void *arg);
  147. /*-
  148. * Provider entry point
  149. * --------------------
  150. *
  151. * This function is expected to be present in any dynamically loadable
  152. * provider module. By definition, if this function doesn't exist in a
  153. * module, that module is not an OpenSSL provider module.
  154. */
  155. /*-
  156. * |provider| pointer to opaque type OSSL_PROVIDER. This can be used
  157. * together with some functions passed via |in| to query data.
  158. * |in| is the array of functions that the Core passes to the provider.
  159. * |out| will be the array of base functions that the provider passes
  160. * back to the Core.
  161. * |provctx| a provider side context object, optionally created if the
  162. * provider needs it. This value is passed to other provider
  163. * functions, notably other context constructors.
  164. */
  165. typedef int (OSSL_provider_init_fn)(const OSSL_PROVIDER *provider,
  166. const OSSL_DISPATCH *in,
  167. const OSSL_DISPATCH **out,
  168. void **provctx);
  169. # ifdef __VMS
  170. # pragma names save
  171. # pragma names uppercase,truncated
  172. # endif
  173. extern OSSL_provider_init_fn OSSL_provider_init;
  174. # ifdef __VMS
  175. # pragma names restore
  176. # endif
  177. # ifdef __cplusplus
  178. }
  179. # endif
  180. #endif