tb_eckey.c 1.9 KB

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