ossl_method_construct.pod 4.8 KB

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