ossl_method_construct.pod 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. /* Create store */
  9. void *(*alloc_tmp_store)(OSSL_LIB_CTX *ctx);
  10. /* Remove a store */
  11. void (*dealloc_tmp_store)(void *store);
  12. /* Get an already existing method from a store */
  13. void *(*get)(OSSL_LIB_CTX *libctx, void *store, void *data);
  14. /* Store a method in a store */
  15. int (*put)(OSSL_LIB_CTX *libctx, void *store, void *method,
  16. const OSSL_PROVIDER *prov, int operation_id, const char *name,
  17. const char *propdef, void *data);
  18. /* Construct a new method */
  19. void *(*construct)(const char *name, const OSSL_DISPATCH *fns,
  20. OSSL_PROVIDER *prov, void *data);
  21. /* Destruct a method */
  22. void (*destruct)(void *method);
  23. };
  24. typedef struct ossl_method_construct_method OSSL_METHOD_CONSTRUCT_METHOD;
  25. void *ossl_method_construct(OSSL_LIB_CTX *ctx, int operation_id,
  26. int force_cache,
  27. OSSL_METHOD_CONSTRUCT_METHOD *mcm, void *mcm_data);
  28. =head1 DESCRIPTION
  29. All libcrypto subsystems that want to create their own methods based
  30. on provider dispatch tables need to do so in exactly the same way.
  31. ossl_method_construct() does this while leaving it to the subsystems
  32. to define more precisely how the methods are created, stored, etc.
  33. It's important to keep in mind that a method is identified by three things:
  34. =over 4
  35. =item The operation identity
  36. =item The name of the algorithm
  37. =item The properties associated with the algorithm implementation
  38. =back
  39. =head2 Functions
  40. ossl_method_construct() creates a method by asking all available
  41. providers for a dispatch table given an I<operation_id>, and then
  42. calling the appropriate functions given by the subsystem specific
  43. method creator through I<mcm> and the data in I<mcm_data> (which is
  44. passed by ossl_method_construct()).
  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 alloc_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 dealloc_tmp_store()
  61. Remove a temporary store.
  62. =item get()
  63. Look up an already existing method from a store by name.
  64. The store may be given with I<store>.
  65. NULL is a valid value and means that a subsystem default store
  66. must be used.
  67. This default store should be stored in the library context I<libctx>.
  68. The method to be looked up should be identified with data found in I<data>
  69. (which is the I<mcm_data> that was passed to ossl_construct_method()).
  70. In other words, the ossl_method_construct() caller is entirely responsible
  71. for ensuring the necesssary data is made available.
  72. This function is expected to increment the 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 I<operation_id>,
  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-2020 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