ossl_method_construct.pod 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. =pod
  2. =head1 NAME
  3. OSSL_METHOD_CONSTRUCT_METHOD, ossl_method_construct
  4. - generic method constructor
  5. =head1 SYNOPSIS
  6. #include "internal/core.h"
  7. struct ossl_method_construct_method_st {
  8. /* Get a temporary store */
  9. void *(*get_tmp_store)(void *data);
  10. /* Get an already existing method from a store */
  11. void *(*get)(void *store, const OSSL_PROVIDER *prov, void *data);
  12. /* Store a method in a store */
  13. int (*put)(void *store, void *method, const OSSL_PROVIDER *prov,
  14. const char *name, const char *propdef, void *data);
  15. /* Construct a new method */
  16. void *(*construct)(const OSSL_ALGORITHM *algodef, OSSL_PROVIDER *prov,
  17. void *data);
  18. /* Destruct a method */
  19. void (*destruct)(void *method, void *data);
  20. };
  21. typedef struct ossl_method_construct_method OSSL_METHOD_CONSTRUCT_METHOD;
  22. void *ossl_method_construct(OSSL_LIB_CTX *ctx, int operation_id,
  23. OSSL_PROVIDER *prov, int force_cache,
  24. OSSL_METHOD_CONSTRUCT_METHOD *mcm, void *mcm_data);
  25. =head1 DESCRIPTION
  26. All libcrypto subsystems that want to create their own methods based
  27. on provider dispatch tables need to do so in exactly the same way.
  28. ossl_method_construct() does this while leaving it to the subsystems
  29. to define more precisely how the methods are created, stored, etc.
  30. It's important to keep in mind that a method is identified by three things:
  31. =over 4
  32. =item The operation identity
  33. =item The name of the algorithm
  34. =item The properties associated with the algorithm implementation
  35. =back
  36. =head2 Functions
  37. ossl_method_construct() creates a method by asking all available
  38. providers for a dispatch table given an I<operation_id>, and then
  39. calling the appropriate functions given by the subsystem specific
  40. method creator through I<mcm> and the data in I<mcm_data> (which is
  41. passed by ossl_method_construct()).
  42. If I<prov> is not NULL, only that provider is considered, which is
  43. useful in the case a method must be found in that particular
  44. provider.
  45. This function assumes that the subsystem method creator implements
  46. reference counting and acts accordingly (i.e. it will call the
  47. subsystem destruct() method to decrement the reference count when
  48. appropriate).
  49. =head2 Structures
  50. A central part of constructing a subsystem specific method is to give
  51. ossl_method_construct a set of functions, all in the
  52. B<OSSL_METHOD_CONSTRUCT_METHOD> structure, which holds the following
  53. function pointers:
  54. =over 4
  55. =item get_tmp_store()
  56. Create a temporary method store in the scope of the library context I<ctx>.
  57. This store is used to temporarily store methods for easier lookup, for
  58. when the provider doesn't want its dispatch table stored in a longer
  59. term cache.
  60. =item get()
  61. Look up an already existing method from a store by name.
  62. The store may be given with I<store>.
  63. NULL is a valid value and means that a subsystem default store
  64. must be used.
  65. This default store should be stored in the library context I<libctx>.
  66. The method to be looked up should be identified with data found in I<data>
  67. (which is the I<mcm_data> that was passed to ossl_construct_method()).
  68. In other words, the ossl_method_construct() caller is entirely responsible
  69. for ensuring the necesssary data is made available.
  70. Optionally, I<prov> may be given as a search criterion, to narrow down the
  71. search of a method belonging to just one provider.
  72. This function is expected to increment the resulting method's reference count.
  73. =item put()
  74. Places the I<method> created by the construct() function (see below)
  75. in a store.
  76. The store may be given with I<store>.
  77. NULL is a valid value and means that a subsystem default store
  78. must be used.
  79. This default store should be stored in the library context I<libctx>.
  80. The method should be associated with the given provider I<prov>,
  81. I<name> and property definition I<propdef> as well as any
  82. identification data given through I<data> (which is the I<mcm_data>
  83. that was passed to ossl_construct_method()).
  84. This function is expected to increment the I<method>'s reference count.
  85. =item construct()
  86. Constructs a subsystem method for the given I<name> and the given
  87. dispatch table I<fns>.
  88. The associated provider object I<prov> is passed as well, to make
  89. it possible for the subsystem constructor to keep a reference, which
  90. is recommended.
  91. If such a reference is kept, the I<provider object> reference counter
  92. must be incremented, using ossl_provider_up_ref().
  93. This function is expected to set the method's reference count to 1.
  94. =item destruct()
  95. Decrement the I<method>'s reference count, and destruct it when
  96. the reference count reaches zero.
  97. =back
  98. =head1 RETURN VALUES
  99. ossl_method_construct() returns a constructed method on success, or
  100. NULL on error.
  101. =head1 HISTORY
  102. This functionality was added to OpenSSL 3.0.
  103. =head1 COPYRIGHT
  104. Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
  105. Licensed under the Apache License 2.0 (the "License"). You may not use this
  106. file except in compliance with the License. You can obtain a copy in the file
  107. LICENSE in the source distribution or at
  108. L<https://www.openssl.org/source/license.html>.
  109. =cut