engine.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* Copyright (c) 2014, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #ifndef OPENSSL_HEADER_ENGINE_H
  15. #define OPENSSL_HEADER_ENGINE_H
  16. #include <openssl/base.h>
  17. #if defined(__cplusplus)
  18. extern "C" {
  19. #endif
  20. // Engines are collections of methods. Methods are tables of function pointers,
  21. // defined for certain algorithms, that allow operations on those algorithms to
  22. // be overridden via a callback. This can be used, for example, to implement an
  23. // RSA* that forwards operations to a hardware module.
  24. //
  25. // Methods are reference counted but |ENGINE|s are not. When creating a method,
  26. // you should zero the whole structure and fill in the function pointers that
  27. // you wish before setting it on an |ENGINE|. Any functions pointers that
  28. // are NULL indicate that the default behaviour should be used.
  29. // Allocation and destruction.
  30. // ENGINE_new returns an empty ENGINE that uses the default method for all
  31. // algorithms.
  32. OPENSSL_EXPORT ENGINE *ENGINE_new(void);
  33. // ENGINE_free decrements the reference counts for all methods linked from
  34. // |engine| and frees |engine| itself. It returns one.
  35. OPENSSL_EXPORT int ENGINE_free(ENGINE *engine);
  36. // Method accessors.
  37. //
  38. // Method accessors take a method pointer and the size of the structure. The
  39. // size allows for ABI compatibility in the case that the method structure is
  40. // extended with extra elements at the end. Methods are always copied by the
  41. // set functions.
  42. //
  43. // Set functions return one on success and zero on allocation failure.
  44. OPENSSL_EXPORT int ENGINE_set_RSA_method(ENGINE *engine,
  45. const RSA_METHOD *method,
  46. size_t method_size);
  47. OPENSSL_EXPORT RSA_METHOD *ENGINE_get_RSA_method(const ENGINE *engine);
  48. OPENSSL_EXPORT int ENGINE_set_ECDSA_method(ENGINE *engine,
  49. const ECDSA_METHOD *method,
  50. size_t method_size);
  51. OPENSSL_EXPORT ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine);
  52. // Generic method functions.
  53. //
  54. // These functions take a void* type but actually operate on all method
  55. // structures.
  56. // METHOD_ref increments the reference count of |method|. This is a no-op for
  57. // now because all methods are currently static.
  58. void METHOD_ref(void *method);
  59. // METHOD_unref decrements the reference count of |method| and frees it if the
  60. // reference count drops to zero. This is a no-op for now because all methods
  61. // are currently static.
  62. void METHOD_unref(void *method);
  63. // Private functions.
  64. // openssl_method_common_st contains the common part of all method structures.
  65. // This must be the first member of all method structures.
  66. struct openssl_method_common_st {
  67. int references; // dummy – not used.
  68. char is_static;
  69. };
  70. #if defined(__cplusplus)
  71. } // extern C
  72. extern "C++" {
  73. BSSL_NAMESPACE_BEGIN
  74. BORINGSSL_MAKE_DELETER(ENGINE, ENGINE_free)
  75. BSSL_NAMESPACE_END
  76. } // extern C++
  77. #endif
  78. #define ENGINE_R_OPERATION_NOT_SUPPORTED 100
  79. #endif // OPENSSL_HEADER_ENGINE_H