provider.pod 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. =pod
  2. =head1 NAME
  3. provider - OpenSSL operation implementation providers
  4. =head1 SYNOPSIS
  5. =for openssl generic
  6. #include <openssl/provider.h>
  7. =head1 DESCRIPTION
  8. =head2 General
  9. A I<provider>, in OpenSSL terms, is a unit of code that provides one
  10. or more implementations for various operations for diverse algorithms
  11. that one might want to perform.
  12. An I<operation> is something one wants to do, such as encryption and
  13. decryption, key derivation, MAC calculation, signing and verification,
  14. etc.
  15. An I<algorithm> is a named method to perform an operation.
  16. Very often, the algorithms revolve around cryptographic operations,
  17. but may also revolve around other types of operation, such as managing
  18. certain types of objects.
  19. =head2 Provider
  20. I<NOTE: This section is mostly interesting for provider authors.>
  21. A I<provider> offers an initialization function, as a set of base
  22. functions in the form of an B<OSSL_DISPATCH> array, and by extension,
  23. a set of B<OSSL_ALGORITHM>s (see L<openssl-core.h(7)>).
  24. It may be a dynamically loadable module, or may be built-in, in
  25. OpenSSL libraries or in the application.
  26. If it's a dynamically loadable module, the initialization function
  27. must be named C<OSSL_provider_init> and must be exported.
  28. If it's built-in, the initialization function may have any name.
  29. The initialization function must have the following signature:
  30. int NAME(const OSSL_PROVIDER *provider,
  31. const OSSL_DISPATCH *in, const OSSL_DISPATCH **out,
  32. void **provctx);
  33. I<provider> is the OpenSSL library object for the provider, and works
  34. as a handle for everything the OpenSSL libraries need to know about
  35. the provider.
  36. For the provider itself, it may hold some interesting information,
  37. and is also passed to some of the functions given in the dispatch
  38. array I<in>.
  39. I<in> is a dispatch array of base functions offered by the OpenSSL
  40. libraries, and the available functions are further described in
  41. L<provider-base(7)>.
  42. I<*out> must be assigned a dispatch array of base functions that the
  43. provider offers to the OpenSSL libraries.
  44. The functions that may be offered are further described in
  45. L<provider-base(7)>, and they are the central means of communication
  46. between the OpenSSL libraries and the provider.
  47. I<*provctx> should be assigned a provider specific context to allow
  48. the provider multiple simultaneous uses.
  49. This pointer will be passed to various operation functions offered by
  50. the provider.
  51. One of the functions the provider offers to the OpenSSL libraries is
  52. the central mechanism for the OpenSSL libraries to get access to
  53. operation implementations for diverse algorithms.
  54. Its referred to with the number B<OSSL_FUNC_PROVIDER_QUERY_OPERATION>
  55. and has the following signature:
  56. const OSSL_ALGORITHM *provider_query_operation(void *provctx,
  57. int operation_id,
  58. const int *no_store);
  59. I<provctx> is the provider specific context that was passed back by
  60. the initialization function.
  61. I<operation_id> is an operation identity (see L</Operations> below).
  62. I<no_store> is a flag back to the OpenSSL libraries which, when
  63. nonzero, signifies that the OpenSSL libraries will not store a
  64. reference to the returned data in their internal store of
  65. implementations.
  66. The returned B<OSSL_ALGORITHM> is the foundation of any OpenSSL
  67. library API that uses providers for their implementation, most
  68. commonly in the I<fetching> type of functions
  69. (see L</Fetching algorithms> below).
  70. =head2 Operations
  71. I<NOTE: This section is mostly interesting for provider authors.>
  72. Operations are referred to with numbers, via macros with names
  73. starting with C<OSSL_OP_>.
  74. With each operation comes a set of defined function types that a
  75. provider may or may not offer, depending on its needs.
  76. Currently available operations are:
  77. =over 4
  78. =item Digests
  79. In the OpenSSL libraries, the corresponding method object is
  80. B<EVP_MD>.
  81. The number for this operation is B<OSSL_OP_DIGEST>.
  82. The functions the provider can offer are described in
  83. L<provider-digest(7)>
  84. =item Symmetric ciphers
  85. In the OpenSSL libraries, the corresponding method object is
  86. B<EVP_CIPHER>.
  87. The number for this operation is B<OSSL_OP_CIPHER>.
  88. The functions the provider can offer are described in
  89. L<provider-cipher(7)>
  90. =item Message Authentication Code (MAC)
  91. In the OpenSSL libraries, the corresponding method object is
  92. B<EVP_MAC>.
  93. The number for this operation is B<OSSL_OP_MAC>.
  94. The functions the provider can offer are described in
  95. L<provider-mac(7)>
  96. =item Key Derivation Function (KDF)
  97. In the OpenSSL libraries, the corresponding method object is
  98. B<EVP_KDF>.
  99. The number for this operation is B<OSSL_OP_KDF>.
  100. The functions the provider can offer are described in
  101. L<provider-kdf(7)>
  102. =item Key Exchange
  103. In the OpenSSL libraries, the corresponding method object is
  104. B<EVP_KEYEXCH>.
  105. The number for this operation is B<OSSL_OP_KEYEXCH>.
  106. The functions the provider can offer are described in
  107. L<provider-keyexch(7)>
  108. =item Serialization
  109. In the OpenSSL libraries, the corresponding method object is
  110. B<OSSL_SERIALIZER>.
  111. The number for this operation is B<OSSL_OP_SERIALIZER>.
  112. The functions the provider can offer are described in
  113. L<provider-serializer(7)>
  114. =back
  115. =head2 Fetching algorithms
  116. =head3 Explicit fetch
  117. I<NOTE: This section is mostly interesting to OpenSSL users.>
  118. Users of the OpenSSL libraries never query the provider directly for
  119. its diverse implementations and dispatch tables.
  120. Instead, the diverse OpenSSL APIs often have fetching functions that
  121. do the work, and they return an appropriate method object back to the
  122. user.
  123. These functions usually have the name C<APINAME_fetch>, where
  124. C<APINAME> is the name of the API, for example L<EVP_MD_fetch(3)>.
  125. These fetching functions follow a fairly common pattern, where three
  126. arguments are passed:
  127. =over 4
  128. =item The library context
  129. See L<OPENSSL_CTX(3)> for a more detailed description.
  130. This may be NULL to signify the default (global) library context, or a
  131. context created by the user.
  132. Only providers loaded in this library context (see
  133. L<OSSL_PROVIDER_load(3)>) will be considered by the fetching
  134. function.
  135. =item An identifier
  136. This is most commonly an algorithm name (this is the case for all EVP
  137. methods), but may also be called something else.
  138. =for comment For example, an OSSL_STORE implementation would use the
  139. URI scheme as an identifier.
  140. =item A property query string
  141. See L<property(7)> for a more detailed description.
  142. This is used to select more exactly which providers will get to offer
  143. an implementation.
  144. =back
  145. The method object that is fetched can then be used with diverse other
  146. functions that use them, for example L<EVP_DigestInit_ex(3)>.
  147. =head3 Implicit fetch
  148. I<NOTE: This section is mostly interesting to OpenSSL users.>
  149. OpenSSL has a number of functions that return a method object with no
  150. associated implementation, such as L<EVP_sha256(3)>,
  151. L<EVP_blake2b512(3)> or L<EVP_aes_128_cbc(3)>, which are present for
  152. compatibility with OpenSSL before version 3.0.
  153. When they are used with functions like L<EVP_DigestInit_ex(3)> or
  154. L<EVP_CipherInit_ex(3)>, the actual implementation to be used is
  155. fetched implicitly using default search criteria.
  156. Implicit fetching can also occur when a NULL algorithm parameter is
  157. supplied.
  158. In this case an algorithm implementation is implicitly fetched using
  159. default search criteria and an algorithm name that is consistent with
  160. the type of EVP_PKEY being used.
  161. =head3 Algorithm naming
  162. Algorithm names are case insensitive. Any particular algorithm can have multiple
  163. aliases associated with it. The canonical OpenSSL naming scheme follows this
  164. format:
  165. ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?]
  166. VERSION is only present if there are multiple versions of an algorithm (e.g.
  167. MD2, MD4, MD5). It may be omitted if there is only one version.
  168. SUBNAME may be present where multiple algorithms are combined together,
  169. e.g. MD5-SHA1.
  170. SIZE is only present if multiple versions of an algorithm exist with different
  171. sizes (e.g. AES-128-CBC, AES-256-CBC)
  172. MODE is only present where applicable.
  173. Other aliases may exist for example where standards bodies or common practice
  174. use alternative names or names that OpenSSL has used historically.
  175. =head1 OPENSSL PROVIDERS
  176. OpenSSL comes with a set of providers.
  177. The algorithms available in each of these providers may vary due to build time
  178. configuration options. The L<openssl-list(1)> command can be used to list the
  179. currently available algorithms.
  180. The names of the algorithms shown from L<openssl-list(1)> can be used as an
  181. algorithm identifier to the appropriate fetching function.
  182. =head2 Default provider
  183. The default provider is built in as part of the F<libcrypto> library.
  184. Should it be needed (if other providers are loaded and offer
  185. implementations of the same algorithms), the property "default=yes"
  186. can be used as a search criterion for these implementations.
  187. =head2 FIPS provider
  188. The FIPS provider is a dynamically loadable module, and must therefore
  189. be loaded explicitly, either in code or through OpenSSL configuration
  190. (see L<config(5)>).
  191. Should it be needed (if other providers are loaded and offer
  192. implementations of the same algorithms), the property "fips=yes" can
  193. be used as a search criterion for these implementations.
  194. =head2 Legacy provider
  195. The legacy provider is a dynamically loadable module, and must therefore
  196. be loaded explicitly, either in code or through OpenSSL configuration
  197. (see L<config(5)>).
  198. Should it be needed (if other providers are loaded and offer
  199. implementations of the same algorithms), the property "legacy=yes" can be
  200. used as a search criterion for these implementations.
  201. =head1 EXAMPLES
  202. =head2 Fetching
  203. Fetch any available implementation of SHA2-256 in the default context:
  204. EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", NULL);
  205. ...
  206. EVP_MD_meth_free(md);
  207. Fetch any available implementation of AES-128-CBC in the default context:
  208. EVP_CIPHER *cipher = EVP_CIPHER_fetch(NULL, "AES-128-CBC", NULL);
  209. ...
  210. EVP_CIPHER_meth_free(cipher);
  211. Fetch an implementation of SHA2-256 from the default provider in the default
  212. context:
  213. EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", "default=yes");
  214. ...
  215. EVP_MD_meth_free(md);
  216. Fetch an implementation of SHA2-256 that is not from the default provider in the
  217. default context:
  218. EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", "default=no");
  219. ...
  220. EVP_MD_meth_free(md);
  221. Fetch an implementation of SHA2-256 from the default provider in the specified
  222. context:
  223. EVP_MD *md = EVP_MD_fetch(ctx, "SHA2-256", "default=yes");
  224. ...
  225. EVP_MD_meth_free(md);
  226. Load the legacy provider into the default context and then fetch an
  227. implementation of WHIRLPOOL from it:
  228. /* This only needs to be done once - usually at application start up */
  229. OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy");
  230. EVP_MD *md = EVP_MD_fetch(NULL, "WHIRLPOOL", "legacy=yes");
  231. ...
  232. EVP_MD_meth_free(md);
  233. Note that in the above example the property string "legacy=yes" is optional
  234. since, assuming no other providers have been loaded, the only implementation of
  235. the "whirlpool" algorithm is in the "legacy" provider. Also note that the
  236. default provider should be explicitly loaded if it is required in addition to
  237. other providers:
  238. /* This only needs to be done once - usually at application start up */
  239. OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy");
  240. OSSL_PROVIDER *default = OSSL_PROVIDER_load(NULL, "default");
  241. EVP_MD *md_whirlpool = EVP_MD_fetch(NULL, "whirlpool", NULL);
  242. EVP_MD *md_sha256 = EVP_MD_fetch(NULL, "SHA2-256", NULL);
  243. ...
  244. EVP_MD_meth_free(md_whirlpool);
  245. EVP_MD_meth_free(md_sha256);
  246. =head1 SEE ALSO
  247. L<EVP_DigestInit_ex(3)>, L<EVP_EncryptInit_ex(3)>,
  248. L<OPENSSL_CTX(3)>,
  249. L<EVP_set_default_properties(3)>,
  250. L<EVP_MD_fetch(3)>,
  251. L<EVP_CIPHER_fetch(3)>,
  252. L<EVP_KEYMGMT_fetch(3)>,
  253. L<openssl-core.h(7)>,
  254. L<provider-base(7)>,
  255. L<provider-digest(7)>,
  256. L<provider-cipher(7)>,
  257. L<provider-keyexch(7)>
  258. =head1 HISTORY
  259. The concept of providers and everything surrounding them was
  260. introduced in OpenSSL 3.0.
  261. =head1 COPYRIGHT
  262. Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  263. Licensed under the Apache License 2.0 (the "License"). You may not use
  264. this file except in compliance with the License. You can obtain a copy
  265. in the file LICENSE in the source distribution or at
  266. L<https://www.openssl.org/source/license.html>.
  267. =cut