ossl_method_construct.pod 5.1 KB

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