2
0

tb_rsa.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2001-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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. #include "eng_local.h"
  10. static ENGINE_TABLE *rsa_table = NULL;
  11. static const int dummy_nid = 1;
  12. void ENGINE_unregister_RSA(ENGINE *e)
  13. {
  14. engine_table_unregister(&rsa_table, e);
  15. }
  16. static void engine_unregister_all_RSA(void)
  17. {
  18. engine_table_cleanup(&rsa_table);
  19. }
  20. int ENGINE_register_RSA(ENGINE *e)
  21. {
  22. if (e->rsa_meth)
  23. return engine_table_register(&rsa_table,
  24. engine_unregister_all_RSA, e, &dummy_nid,
  25. 1, 0);
  26. return 1;
  27. }
  28. void ENGINE_register_all_RSA(void)
  29. {
  30. ENGINE *e;
  31. for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
  32. ENGINE_register_RSA(e);
  33. }
  34. int ENGINE_set_default_RSA(ENGINE *e)
  35. {
  36. if (e->rsa_meth)
  37. return engine_table_register(&rsa_table,
  38. engine_unregister_all_RSA, e, &dummy_nid,
  39. 1, 1);
  40. return 1;
  41. }
  42. /*
  43. * Exposed API function to get a functional reference from the implementation
  44. * table (ie. try to get a functional reference from the tabled structural
  45. * references).
  46. */
  47. ENGINE *ENGINE_get_default_RSA(void)
  48. {
  49. return engine_table_select(&rsa_table, dummy_nid);
  50. }
  51. /* Obtains an RSA implementation from an ENGINE functional reference */
  52. const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e)
  53. {
  54. return e->rsa_meth;
  55. }
  56. /* Sets an RSA implementation in an ENGINE structure */
  57. int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth)
  58. {
  59. e->rsa_meth = rsa_meth;
  60. return 1;
  61. }