tb_dsa.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2001-2020 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. /* We need to use some engine deprecated APIs */
  10. #define OPENSSL_SUPPRESS_DEPRECATED
  11. #include "eng_local.h"
  12. static ENGINE_TABLE *dsa_table = NULL;
  13. static const int dummy_nid = 1;
  14. void ENGINE_unregister_DSA(ENGINE *e)
  15. {
  16. engine_table_unregister(&dsa_table, e);
  17. }
  18. static void engine_unregister_all_DSA(void)
  19. {
  20. engine_table_cleanup(&dsa_table);
  21. }
  22. int ENGINE_register_DSA(ENGINE *e)
  23. {
  24. if (e->dsa_meth)
  25. return engine_table_register(&dsa_table,
  26. engine_unregister_all_DSA, e, &dummy_nid,
  27. 1, 0);
  28. return 1;
  29. }
  30. void ENGINE_register_all_DSA(void)
  31. {
  32. ENGINE *e;
  33. for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
  34. ENGINE_register_DSA(e);
  35. }
  36. int ENGINE_set_default_DSA(ENGINE *e)
  37. {
  38. if (e->dsa_meth)
  39. return engine_table_register(&dsa_table,
  40. engine_unregister_all_DSA, e, &dummy_nid,
  41. 1, 1);
  42. return 1;
  43. }
  44. /*
  45. * Exposed API function to get a functional reference from the implementation
  46. * table (ie. try to get a functional reference from the tabled structural
  47. * references).
  48. */
  49. ENGINE *ENGINE_get_default_DSA(void)
  50. {
  51. return engine_table_select(&dsa_table, dummy_nid);
  52. }
  53. /* Obtains an DSA implementation from an ENGINE functional reference */
  54. const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e)
  55. {
  56. return e->dsa_meth;
  57. }
  58. /* Sets an DSA implementation in an ENGINE structure */
  59. int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth)
  60. {
  61. e->dsa_meth = dsa_meth;
  62. return 1;
  63. }