Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

121 строка
3.6 KiB

  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. #include <openssl/engine.h>
  15. #include <string.h>
  16. #include <assert.h>
  17. #include <openssl/dh.h>
  18. #include <openssl/dsa.h>
  19. #include <openssl/ec_key.h>
  20. #include <openssl/err.h>
  21. #include <openssl/mem.h>
  22. #include <openssl/rsa.h>
  23. #include <openssl/thread.h>
  24. struct engine_st {
  25. DH_METHOD *dh_method;
  26. DSA_METHOD *dsa_method;
  27. RSA_METHOD *rsa_method;
  28. ECDSA_METHOD *ecdsa_method;
  29. };
  30. ENGINE *ENGINE_new(void) {
  31. ENGINE *engine = OPENSSL_malloc(sizeof(ENGINE));
  32. if (engine == NULL) {
  33. return NULL;
  34. }
  35. memset(engine, 0, sizeof(ENGINE));
  36. return engine;
  37. }
  38. void ENGINE_free(ENGINE *engine) {
  39. /* Methods are currently required to be static so are not unref'ed. */
  40. OPENSSL_free(engine);
  41. }
  42. /* set_method takes a pointer to a method and its given size and sets
  43. * |*out_member| to point to it. This function might want to be extended in the
  44. * future to support making a copy of the method so that a stable ABI for
  45. * ENGINEs can be supported. But, for the moment, all *_METHODS must be
  46. * static. */
  47. static int set_method(void **out_member, const void *method, size_t method_size,
  48. size_t compiled_size) {
  49. const struct openssl_method_common_st *common = method;
  50. if (method_size != compiled_size || !common->is_static) {
  51. return 0;
  52. }
  53. *out_member = (void*) method;
  54. return 1;
  55. }
  56. int ENGINE_set_DH_method(ENGINE *engine, const DH_METHOD *method,
  57. size_t method_size) {
  58. return set_method((void **)&engine->dh_method, method, method_size,
  59. sizeof(DH_METHOD));
  60. }
  61. DH_METHOD *ENGINE_get_DH_method(const ENGINE *engine) {
  62. return engine->dh_method;
  63. }
  64. int ENGINE_set_DSA_method(ENGINE *engine, const DSA_METHOD *method,
  65. size_t method_size) {
  66. return set_method((void **)&engine->dsa_method, method, method_size,
  67. sizeof(DSA_METHOD));
  68. }
  69. DSA_METHOD *ENGINE_get_DSA_method(const ENGINE *engine) {
  70. return engine->dsa_method;
  71. }
  72. int ENGINE_set_RSA_method(ENGINE *engine, const RSA_METHOD *method,
  73. size_t method_size) {
  74. return set_method((void **)&engine->rsa_method, method, method_size,
  75. sizeof(RSA_METHOD));
  76. }
  77. RSA_METHOD *ENGINE_get_RSA_method(const ENGINE *engine) {
  78. return engine->rsa_method;
  79. }
  80. int ENGINE_set_ECDSA_method(ENGINE *engine, const ECDSA_METHOD *method,
  81. size_t method_size) {
  82. return set_method((void **)&engine->ecdsa_method, method, method_size,
  83. sizeof(ECDSA_METHOD));
  84. }
  85. ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine) {
  86. return engine->ecdsa_method;
  87. }
  88. void METHOD_ref(void *method_in) {
  89. assert(((struct openssl_method_common_st*) method_in)->is_static);
  90. }
  91. void METHOD_unref(void *method_in) {
  92. struct openssl_method_common_st *method = method_in;
  93. if (method == NULL) {
  94. return;
  95. }
  96. assert(method->is_static);
  97. }
  98. OPENSSL_DECLARE_ERROR_REASON(ENGINE, OPERATION_NOT_SUPPORTED);