provider.pod 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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 with functions such as
  157. L<EVP_PKEY_CTX_derive_init_ex(3)> where a NULL algorithm parameter is
  158. supplied.
  159. In this case an algorithm implementation is implicitly fetched using
  160. default search criteria and an algorithm name that is consistent with
  161. the type of EVP_PKEY being used.
  162. =head3 Algorithm naming
  163. Algorithm names are case insensitive. Any particular algorithm can have multiple
  164. aliases associated with it. The canonical OpenSSL naming scheme follows this
  165. format:
  166. ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?]
  167. VERSION is only present if there are multiple versions of an algorithm (e.g.
  168. MD2, MD4, MD5). It may be omitted if there is only one version.
  169. SUBNAME may be present where multiple algorithms are combined together,
  170. e.g. MD5-SHA1.
  171. SIZE is only present if multiple versions of an algorithm exist with different
  172. sizes (e.g. AES-128-CBC, AES-256-CBC)
  173. MODE is only present where applicable.
  174. Other aliases may exist for example where standards bodies or common practice
  175. use alternative names or names that OpenSSL has used historically.
  176. =head1 OPENSSL PROVIDERS
  177. OpenSSL comes with a set of providers.
  178. The algorithms available in each of these providers may vary due to build time
  179. configuration options. The L<openssl-list(1)> command can be used to list the
  180. currently available algorithms.
  181. The names of the algorithms shown from L<openssl-list(1)> can be used as an
  182. algorithm identifier to the appropriate fetching function.
  183. =head2 Default provider
  184. The default provider is built in as part of the F<libcrypto> library.
  185. Should it be needed (if other providers are loaded and offer
  186. implementations of the same algorithms), the property "default=yes"
  187. can be used as a search criterion for these implementations.
  188. =head2 FIPS provider
  189. The FIPS provider is a dynamically loadable module, and must therefore
  190. be loaded explicitly, either in code or through OpenSSL configuration
  191. (see L<config(5)>).
  192. Should it be needed (if other providers are loaded and offer
  193. implementations of the same algorithms), the property "fips=yes" can
  194. be used as a search criterion for these implementations.
  195. =head2 Legacy provider
  196. The legacy provider is a dynamically loadable module, and must therefore
  197. be loaded explicitly, either in code or through OpenSSL configuration
  198. (see L<config(5)>).
  199. Should it be needed (if other providers are loaded and offer
  200. implementations of the same algorithms), the property "legacy=yes" can be
  201. used as a search criterion for these implementations.
  202. =head1 EXAMPLES
  203. =head2 Fetching
  204. Fetch any available implementation of SHA2-256 in the default context:
  205. EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", NULL);
  206. ...
  207. EVP_MD_meth_free(md);
  208. Fetch any available implementation of AES-128-CBC in the default context:
  209. EVP_CIPHER *cipher = EVP_CIPHER_fetch(NULL, "AES-128-CBC", NULL);
  210. ...
  211. EVP_CIPHER_meth_free(cipher);
  212. Fetch an implementation of SHA2-256 from the default provider in the default
  213. context:
  214. EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", "default=yes");
  215. ...
  216. EVP_MD_meth_free(md);
  217. Fetch an implementation of SHA2-256 that is not from the default provider in the
  218. default context:
  219. EVP_MD *md = EVP_MD_fetch(NULL, "SHA2-256", "default=no");
  220. ...
  221. EVP_MD_meth_free(md);
  222. Fetch an implementation of SHA2-256 from the default provider in the specified
  223. context:
  224. EVP_MD *md = EVP_MD_fetch(ctx, "SHA2-256", "default=yes");
  225. ...
  226. EVP_MD_meth_free(md);
  227. Load the legacy provider into the default context and then fetch an
  228. implementation of WHIRLPOOL from it:
  229. /* This only needs to be done once - usually at application start up */
  230. OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy");
  231. EVP_MD *md = EVP_MD_fetch(NULL, "WHIRLPOOL", "legacy=yes");
  232. ...
  233. EVP_MD_meth_free(md);
  234. Note that in the above example the property string "legacy=yes" is optional
  235. since, assuming no other providers have been loaded, the only implementation of
  236. the "whirlpool" algorithm is in the "legacy" provider. Also note that the
  237. default provider should be explicitly loaded if it is required in addition to
  238. other providers:
  239. /* This only needs to be done once - usually at application start up */
  240. OSSL_PROVIDER *legacy = OSSL_PROVIDER_load(NULL, "legacy");
  241. OSSL_PROVIDER *default = OSSL_PROVIDER_load(NULL, "default");
  242. EVP_MD *md_whirlpool = EVP_MD_fetch(NULL, "whirlpool", NULL);
  243. EVP_MD *md_sha256 = EVP_MD_fetch(NULL, "SHA2-256", NULL);
  244. ...
  245. EVP_MD_meth_free(md_whirlpool);
  246. EVP_MD_meth_free(md_sha256);
  247. =head1 SEE ALSO
  248. L<EVP_DigestInit_ex(3)>, L<EVP_EncryptInit_ex(3)>,
  249. L<EVP_PKEY_derive_init_ex(3)>,
  250. L<OPENSSL_CTX(3)>,
  251. L<EVP_set_default_properties(3)>,
  252. L<EVP_MD_fetch(3)>,
  253. L<EVP_CIPHER_fetch(3)>,
  254. L<EVP_KEYMGMT_fetch(3)>,
  255. L<openssl-core.h(7)>,
  256. L<provider-base(7)>,
  257. L<provider-digest(7)>,
  258. L<provider-cipher(7)>,
  259. L<provider-keyexch(7)>
  260. =head1 HISTORY
  261. The concept of providers and everything surrounding them was
  262. introduced in OpenSSL 3.0.
  263. =head1 COPYRIGHT
  264. Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  265. Licensed under the Apache License 2.0 (the "License"). You may not use
  266. this file except in compliance with the License. You can obtain a copy
  267. in the file LICENSE in the source distribution or at
  268. L<https://www.openssl.org/source/license.html>.
  269. =cut