25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

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