2
0

tb_rand.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2001-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 *rand_table = NULL;
  11. static const int dummy_nid = 1;
  12. void ENGINE_unregister_RAND(ENGINE *e)
  13. {
  14. engine_table_unregister(&rand_table, e);
  15. }
  16. static void engine_unregister_all_RAND(void)
  17. {
  18. engine_table_cleanup(&rand_table);
  19. }
  20. int ENGINE_register_RAND(ENGINE *e)
  21. {
  22. if (e->rand_meth)
  23. return engine_table_register(&rand_table,
  24. engine_unregister_all_RAND, e,
  25. &dummy_nid, 1, 0);
  26. return 1;
  27. }
  28. void ENGINE_register_all_RAND(void)
  29. {
  30. ENGINE *e;
  31. for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e))
  32. ENGINE_register_RAND(e);
  33. }
  34. int ENGINE_set_default_RAND(ENGINE *e)
  35. {
  36. if (e->rand_meth)
  37. return engine_table_register(&rand_table,
  38. engine_unregister_all_RAND, e,
  39. &dummy_nid, 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_RAND(void)
  48. {
  49. return engine_table_select(&rand_table, dummy_nid);
  50. }
  51. /* Obtains an RAND implementation from an ENGINE functional reference */
  52. const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e)
  53. {
  54. return e->rand_meth;
  55. }
  56. /* Sets an RAND implementation in an ENGINE structure */
  57. int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth)
  58. {
  59. e->rand_meth = rand_meth;
  60. return 1;
  61. }