tb_dh.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2001-2016 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_int.h"
  10. static ENGINE_TABLE *dh_table = NULL;
  11. static const int dummy_nid = 1;
  12. void ENGINE_unregister_DH(ENGINE *e)
  13. {
  14. engine_table_unregister(&dh_table, e);
  15. }
  16. static void engine_unregister_all_DH(void)
  17. {
  18. engine_table_cleanup(&dh_table);
  19. }
  20. int ENGINE_register_DH(ENGINE *e)
  21. {
  22. if (e->dh_meth)
  23. return engine_table_register(&dh_table,
  24. engine_unregister_all_DH, e, &dummy_nid,
  25. 1, 0);
  26. return 1;
  27. }
  28. void ENGINE_register_all_DH()
  29. {
  30. ENGINE *e;
  31. for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
  32. ENGINE_register_DH(e);
  33. }
  34. int ENGINE_set_default_DH(ENGINE *e)
  35. {
  36. if (e->dh_meth)
  37. return engine_table_register(&dh_table,
  38. engine_unregister_all_DH, 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_DH(void)
  48. {
  49. return engine_table_select(&dh_table, dummy_nid);
  50. }
  51. /* Obtains an DH implementation from an ENGINE functional reference */
  52. const DH_METHOD *ENGINE_get_DH(const ENGINE *e)
  53. {
  54. return e->dh_meth;
  55. }
  56. /* Sets an DH implementation in an ENGINE structure */
  57. int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth)
  58. {
  59. e->dh_meth = dh_meth;
  60. return 1;
  61. }