tb_eckey.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2015-2018 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. #include "eng_int.h"
  10. static ENGINE_TABLE *dh_table = NULL;
  11. static const int dummy_nid = 1;
  12. void ENGINE_unregister_EC(ENGINE *e)
  13. {
  14. engine_table_unregister(&dh_table, e);
  15. }
  16. static void engine_unregister_all_EC(void)
  17. {
  18. engine_table_cleanup(&dh_table);
  19. }
  20. int ENGINE_register_EC(ENGINE *e)
  21. {
  22. if (e->ec_meth != NULL)
  23. return engine_table_register(&dh_table,
  24. engine_unregister_all_EC, e, &dummy_nid,
  25. 1, 0);
  26. return 1;
  27. }
  28. void ENGINE_register_all_EC(void)
  29. {
  30. ENGINE *e;
  31. for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
  32. ENGINE_register_EC(e);
  33. }
  34. int ENGINE_set_default_EC(ENGINE *e)
  35. {
  36. if (e->ec_meth != NULL)
  37. return engine_table_register(&dh_table,
  38. engine_unregister_all_EC, 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_EC(void)
  48. {
  49. return engine_table_select(&dh_table, dummy_nid);
  50. }
  51. /* Obtains an EC_KEY implementation from an ENGINE functional reference */
  52. const EC_KEY_METHOD *ENGINE_get_EC(const ENGINE *e)
  53. {
  54. return e->ec_meth;
  55. }
  56. /* Sets an EC_KEY implementation in an ENGINE structure */
  57. int ENGINE_set_EC(ENGINE *e, const EC_KEY_METHOD *ec_meth)
  58. {
  59. e->ec_meth = ec_meth;
  60. return 1;
  61. }