2
0

provider_seeding.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 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. #include <openssl/core_dispatch.h>
  10. #include "prov/seeding.h"
  11. static OSSL_FUNC_get_entropy_fn *c_get_entropy = NULL;
  12. static OSSL_FUNC_cleanup_entropy_fn *c_cleanup_entropy = NULL;
  13. static OSSL_FUNC_get_nonce_fn *c_get_nonce = NULL;
  14. static OSSL_FUNC_cleanup_nonce_fn *c_cleanup_nonce = NULL;
  15. int ossl_prov_seeding_from_dispatch(const OSSL_DISPATCH *fns)
  16. {
  17. for (; fns->function_id != 0; fns++) {
  18. switch (fns->function_id) {
  19. case OSSL_FUNC_GET_ENTROPY:
  20. if (c_get_entropy == NULL)
  21. c_get_entropy = OSSL_FUNC_get_entropy(fns);
  22. break;
  23. case OSSL_FUNC_CLEANUP_ENTROPY:
  24. if (c_cleanup_entropy == NULL)
  25. c_cleanup_entropy = OSSL_FUNC_cleanup_entropy(fns);
  26. break;
  27. case OSSL_FUNC_GET_NONCE:
  28. if (c_get_nonce == NULL)
  29. c_get_nonce = OSSL_FUNC_get_nonce(fns);
  30. break;
  31. case OSSL_FUNC_CLEANUP_NONCE:
  32. if (c_cleanup_nonce == NULL)
  33. c_cleanup_nonce = OSSL_FUNC_cleanup_nonce(fns);
  34. break;
  35. }
  36. }
  37. return 1;
  38. }
  39. size_t ossl_prov_get_entropy(PROV_CTX *prov_ctx, unsigned char **pout,
  40. int entropy, size_t min_len, size_t max_len)
  41. {
  42. if (c_get_entropy == NULL)
  43. return 0;
  44. return c_get_entropy(ossl_prov_ctx_get0_handle(prov_ctx),
  45. pout, entropy, min_len, max_len);
  46. }
  47. void ossl_prov_cleanup_entropy(PROV_CTX *prov_ctx, unsigned char *buf,
  48. size_t len)
  49. {
  50. if (c_cleanup_entropy != NULL)
  51. c_cleanup_entropy(ossl_prov_ctx_get0_handle(prov_ctx), buf, len);
  52. }
  53. size_t ossl_prov_get_nonce(PROV_CTX *prov_ctx, unsigned char **pout,
  54. size_t min_len, size_t max_len,
  55. const void *salt,size_t salt_len)
  56. {
  57. if (c_get_nonce == NULL)
  58. return 0;
  59. return c_get_nonce(ossl_prov_ctx_get0_handle(prov_ctx), pout,
  60. min_len, max_len, salt, salt_len);
  61. }
  62. void ossl_prov_cleanup_nonce(PROV_CTX *prov_ctx, unsigned char *buf, size_t len)
  63. {
  64. if (c_cleanup_nonce != NULL)
  65. c_cleanup_nonce(ossl_prov_ctx_get0_handle(prov_ctx), buf, len);
  66. }