legacyprov.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2019 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 <string.h>
  10. #include <stdio.h>
  11. #include <openssl/core.h>
  12. #include <openssl/core_numbers.h>
  13. #include <openssl/core_names.h>
  14. #include <openssl/params.h>
  15. /* Functions provided by the core */
  16. static OSSL_core_get_param_types_fn *c_get_param_types = NULL;
  17. static OSSL_core_get_params_fn *c_get_params = NULL;
  18. /* Parameters we provide to the core */
  19. static const OSSL_ITEM legacy_param_types[] = {
  20. { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_NAME },
  21. { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_VERSION },
  22. { OSSL_PARAM_UTF8_PTR, OSSL_PROV_PARAM_BUILDINFO },
  23. { 0, NULL }
  24. };
  25. static const OSSL_ITEM *legacy_get_param_types(const OSSL_PROVIDER *prov)
  26. {
  27. return legacy_param_types;
  28. }
  29. static int legacy_get_params(const OSSL_PROVIDER *prov,
  30. const OSSL_PARAM params[])
  31. {
  32. const OSSL_PARAM *p;
  33. p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
  34. if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Legacy Provider"))
  35. return 0;
  36. p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
  37. if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
  38. return 0;
  39. p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
  40. if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
  41. return 0;
  42. return 1;
  43. }
  44. extern const OSSL_DISPATCH md2_functions[];
  45. static const OSSL_ALGORITHM legacy_digests[] = {
  46. #ifndef OPENSSL_NO_MD2
  47. { "MD2", "legacy=yes", md2_functions },
  48. #endif
  49. { NULL, NULL, NULL }
  50. };
  51. static const OSSL_ALGORITHM *legacy_query(OSSL_PROVIDER *prov,
  52. int operation_id,
  53. int *no_cache)
  54. {
  55. *no_cache = 0;
  56. switch (operation_id) {
  57. case OSSL_OP_DIGEST:
  58. return legacy_digests;
  59. }
  60. return NULL;
  61. }
  62. /* Functions we provide to the core */
  63. static const OSSL_DISPATCH legacy_dispatch_table[] = {
  64. { OSSL_FUNC_PROVIDER_GET_PARAM_TYPES, (void (*)(void))legacy_get_param_types },
  65. { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))legacy_get_params },
  66. { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))legacy_query },
  67. { 0, NULL }
  68. };
  69. int OSSL_provider_init(const OSSL_PROVIDER *provider,
  70. const OSSL_DISPATCH *in,
  71. const OSSL_DISPATCH **out,
  72. void **provctx)
  73. {
  74. for (; in->function_id != 0; in++) {
  75. switch (in->function_id) {
  76. case OSSL_FUNC_CORE_GET_PARAM_TYPES:
  77. c_get_param_types = OSSL_get_core_get_param_types(in);
  78. break;
  79. case OSSL_FUNC_CORE_GET_PARAMS:
  80. c_get_params = OSSL_get_core_get_params(in);
  81. break;
  82. /* Just ignore anything we don't understand */
  83. default:
  84. break;
  85. }
  86. }
  87. *out = legacy_dispatch_table;
  88. return 1;
  89. }