ENGINE_add.3ossl 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "ENGINE_ADD 3ossl"
  58. .TH ENGINE_ADD 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. ENGINE_get_DH, ENGINE_get_DSA,
  65. ENGINE_by_id, ENGINE_get_cipher_engine, ENGINE_get_default_DH,
  66. ENGINE_get_default_DSA,
  67. ENGINE_get_default_RAND,
  68. ENGINE_get_default_RSA, ENGINE_get_digest_engine, ENGINE_get_first,
  69. ENGINE_get_last, ENGINE_get_next, ENGINE_get_prev, ENGINE_new,
  70. ENGINE_get_ciphers, ENGINE_get_ctrl_function, ENGINE_get_digests,
  71. ENGINE_get_destroy_function, ENGINE_get_finish_function,
  72. ENGINE_get_init_function, ENGINE_get_load_privkey_function,
  73. ENGINE_get_load_pubkey_function, ENGINE_load_private_key,
  74. ENGINE_load_public_key, ENGINE_get_RAND, ENGINE_get_RSA, ENGINE_get_id,
  75. ENGINE_get_name, ENGINE_get_cmd_defns, ENGINE_get_cipher,
  76. ENGINE_get_digest, ENGINE_add, ENGINE_cmd_is_executable,
  77. ENGINE_ctrl, ENGINE_ctrl_cmd, ENGINE_ctrl_cmd_string,
  78. ENGINE_finish, ENGINE_free, ENGINE_get_flags, ENGINE_init,
  79. ENGINE_register_DH, ENGINE_register_DSA,
  80. ENGINE_register_RAND, ENGINE_register_RSA,
  81. ENGINE_register_all_complete, ENGINE_register_ciphers,
  82. ENGINE_register_complete, ENGINE_register_digests, ENGINE_remove,
  83. ENGINE_set_DH, ENGINE_set_DSA,
  84. ENGINE_set_RAND, ENGINE_set_RSA, ENGINE_set_ciphers,
  85. ENGINE_set_cmd_defns, ENGINE_set_ctrl_function, ENGINE_set_default,
  86. ENGINE_set_default_DH, ENGINE_set_default_DSA,
  87. ENGINE_set_default_RAND, ENGINE_set_default_RSA,
  88. ENGINE_set_default_ciphers, ENGINE_set_default_digests,
  89. ENGINE_set_default_string, ENGINE_set_destroy_function,
  90. ENGINE_set_digests, ENGINE_set_finish_function, ENGINE_set_flags,
  91. ENGINE_set_id, ENGINE_set_init_function, ENGINE_set_load_privkey_function,
  92. ENGINE_set_load_pubkey_function, ENGINE_set_name, ENGINE_up_ref,
  93. ENGINE_get_table_flags, ENGINE_cleanup,
  94. ENGINE_load_builtin_engines, ENGINE_register_all_DH,
  95. ENGINE_register_all_DSA,
  96. ENGINE_register_all_RAND,
  97. ENGINE_register_all_RSA, ENGINE_register_all_ciphers,
  98. ENGINE_register_all_digests, ENGINE_set_table_flags, ENGINE_unregister_DH,
  99. ENGINE_unregister_DSA,
  100. ENGINE_unregister_RAND, ENGINE_unregister_RSA, ENGINE_unregister_ciphers,
  101. ENGINE_unregister_digests
  102. \&\- ENGINE cryptographic module support
  103. .SH SYNOPSIS
  104. .IX Header "SYNOPSIS"
  105. .Vb 1
  106. \& #include <openssl/engine.h>
  107. .Ve
  108. .PP
  109. The following functions have been deprecated since OpenSSL 3.0, and can be
  110. hidden entirely by defining \fBOPENSSL_API_COMPAT\fR with a suitable version value,
  111. see \fBopenssl_user_macros\fR\|(7):
  112. .PP
  113. .Vb 4
  114. \& ENGINE *ENGINE_get_first(void);
  115. \& ENGINE *ENGINE_get_last(void);
  116. \& ENGINE *ENGINE_get_next(ENGINE *e);
  117. \& ENGINE *ENGINE_get_prev(ENGINE *e);
  118. \&
  119. \& int ENGINE_add(ENGINE *e);
  120. \& int ENGINE_remove(ENGINE *e);
  121. \&
  122. \& ENGINE *ENGINE_by_id(const char *id);
  123. \&
  124. \& int ENGINE_init(ENGINE *e);
  125. \& int ENGINE_finish(ENGINE *e);
  126. \&
  127. \& void ENGINE_load_builtin_engines(void);
  128. \&
  129. \& ENGINE *ENGINE_get_default_RSA(void);
  130. \& ENGINE *ENGINE_get_default_DSA(void);
  131. \& ENGINE *ENGINE_get_default_DH(void);
  132. \& ENGINE *ENGINE_get_default_RAND(void);
  133. \& ENGINE *ENGINE_get_cipher_engine(int nid);
  134. \& ENGINE *ENGINE_get_digest_engine(int nid);
  135. \&
  136. \& int ENGINE_set_default_RSA(ENGINE *e);
  137. \& int ENGINE_set_default_DSA(ENGINE *e);
  138. \& int ENGINE_set_default_DH(ENGINE *e);
  139. \& int ENGINE_set_default_RAND(ENGINE *e);
  140. \& int ENGINE_set_default_ciphers(ENGINE *e);
  141. \& int ENGINE_set_default_digests(ENGINE *e);
  142. \& int ENGINE_set_default_string(ENGINE *e, const char *list);
  143. \&
  144. \& int ENGINE_set_default(ENGINE *e, unsigned int flags);
  145. \&
  146. \& unsigned int ENGINE_get_table_flags(void);
  147. \& void ENGINE_set_table_flags(unsigned int flags);
  148. \&
  149. \& int ENGINE_register_RSA(ENGINE *e);
  150. \& void ENGINE_unregister_RSA(ENGINE *e);
  151. \& void ENGINE_register_all_RSA(void);
  152. \& int ENGINE_register_DSA(ENGINE *e);
  153. \& void ENGINE_unregister_DSA(ENGINE *e);
  154. \& void ENGINE_register_all_DSA(void);
  155. \& int ENGINE_register_DH(ENGINE *e);
  156. \& void ENGINE_unregister_DH(ENGINE *e);
  157. \& void ENGINE_register_all_DH(void);
  158. \& int ENGINE_register_RAND(ENGINE *e);
  159. \& void ENGINE_unregister_RAND(ENGINE *e);
  160. \& void ENGINE_register_all_RAND(void);
  161. \& int ENGINE_register_ciphers(ENGINE *e);
  162. \& void ENGINE_unregister_ciphers(ENGINE *e);
  163. \& void ENGINE_register_all_ciphers(void);
  164. \& int ENGINE_register_digests(ENGINE *e);
  165. \& void ENGINE_unregister_digests(ENGINE *e);
  166. \& void ENGINE_register_all_digests(void);
  167. \& int ENGINE_register_complete(ENGINE *e);
  168. \& int ENGINE_register_all_complete(void);
  169. \&
  170. \& int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void));
  171. \& int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
  172. \& int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
  173. \& long i, void *p, void (*f)(void), int cmd_optional);
  174. \& int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg,
  175. \& int cmd_optional);
  176. \&
  177. \& ENGINE *ENGINE_new(void);
  178. \& int ENGINE_free(ENGINE *e);
  179. \& int ENGINE_up_ref(ENGINE *e);
  180. \&
  181. \& int ENGINE_set_id(ENGINE *e, const char *id);
  182. \& int ENGINE_set_name(ENGINE *e, const char *name);
  183. \& int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
  184. \& int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
  185. \& int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
  186. \& int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
  187. \& int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
  188. \& int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
  189. \& int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
  190. \& int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f);
  191. \& int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f);
  192. \& int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f);
  193. \& int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
  194. \& int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
  195. \& int ENGINE_set_flags(ENGINE *e, int flags);
  196. \& int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
  197. \&
  198. \& const char *ENGINE_get_id(const ENGINE *e);
  199. \& const char *ENGINE_get_name(const ENGINE *e);
  200. \& const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
  201. \& const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
  202. \& const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
  203. \& const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
  204. \& ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
  205. \& ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
  206. \& ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
  207. \& ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e);
  208. \& ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e);
  209. \& ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e);
  210. \& ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e);
  211. \& ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e);
  212. \& const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
  213. \& const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
  214. \& int ENGINE_get_flags(const ENGINE *e);
  215. \& const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
  216. \&
  217. \& EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id,
  218. \& UI_METHOD *ui_method, void *callback_data);
  219. \& EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
  220. \& UI_METHOD *ui_method, void *callback_data);
  221. .Ve
  222. .PP
  223. The following function has been deprecated since OpenSSL 1.1.0, and can be
  224. hidden entirely by defining \fBOPENSSL_API_COMPAT\fR with a suitable version value,
  225. see \fBopenssl_user_macros\fR\|(7):
  226. .PP
  227. .Vb 1
  228. \& void ENGINE_cleanup(void);
  229. .Ve
  230. .SH DESCRIPTION
  231. .IX Header "DESCRIPTION"
  232. All of the functions described on this page are deprecated.
  233. Applications should instead use the provider APIs.
  234. .PP
  235. These functions create, manipulate, and use cryptographic modules in the
  236. form of \fBENGINE\fR objects. These objects act as containers for
  237. implementations of cryptographic algorithms, and support a
  238. reference-counted mechanism to allow them to be dynamically loaded in and
  239. out of the running application.
  240. .PP
  241. The cryptographic functionality that can be provided by an \fBENGINE\fR
  242. implementation includes the following abstractions;
  243. .PP
  244. .Vb 6
  245. \& RSA_METHOD \- for providing alternative RSA implementations
  246. \& DSA_METHOD, DH_METHOD, RAND_METHOD, ECDH_METHOD, ECDSA_METHOD,
  247. \& \- similarly for other OpenSSL APIs
  248. \& EVP_CIPHER \- potentially multiple cipher algorithms (indexed by \*(Aqnid\*(Aq)
  249. \& EVP_DIGEST \- potentially multiple hash algorithms (indexed by \*(Aqnid\*(Aq)
  250. \& key\-loading \- loading public and/or private EVP_PKEY keys
  251. .Ve
  252. .SS "Reference counting and handles"
  253. .IX Subsection "Reference counting and handles"
  254. Due to the modular nature of the ENGINE API, pointers to ENGINEs need to be
  255. treated as handles \- i.e. not only as pointers, but also as references to
  256. the underlying ENGINE object. Ie. one should obtain a new reference when
  257. making copies of an ENGINE pointer if the copies will be used (and
  258. released) independently.
  259. .PP
  260. ENGINE objects have two levels of reference-counting to match the way in
  261. which the objects are used. At the most basic level, each ENGINE pointer is
  262. inherently a \fBstructural\fR reference \- a structural reference is required
  263. to use the pointer value at all, as this kind of reference is a guarantee
  264. that the structure can not be deallocated until the reference is released.
  265. .PP
  266. However, a structural reference provides no guarantee that the ENGINE is
  267. initialised and able to use any of its cryptographic
  268. implementations. Indeed it's quite possible that most ENGINEs will not
  269. initialise at all in typical environments, as ENGINEs are typically used to
  270. support specialised hardware. To use an ENGINE's functionality, you need a
  271. \&\fBfunctional\fR reference. This kind of reference can be considered a
  272. specialised form of structural reference, because each functional reference
  273. implicitly contains a structural reference as well \- however to avoid
  274. difficult-to-find programming bugs, it is recommended to treat the two
  275. kinds of reference independently. If you have a functional reference to an
  276. ENGINE, you have a guarantee that the ENGINE has been initialised and
  277. is ready to perform cryptographic operations, and will remain initialised
  278. until after you have released your reference.
  279. .PP
  280. \&\fIStructural references\fR
  281. .PP
  282. This basic type of reference is used for instantiating new ENGINEs,
  283. iterating across OpenSSL's internal linked-list of loaded
  284. ENGINEs, reading information about an ENGINE, etc. Essentially a structural
  285. reference is sufficient if you only need to query or manipulate the data of
  286. an ENGINE implementation rather than use its functionality.
  287. .PP
  288. The \fBENGINE_new()\fR function returns a structural reference to a new (empty)
  289. ENGINE object. There are other ENGINE API functions that return structural
  290. references such as; \fBENGINE_by_id()\fR, \fBENGINE_get_first()\fR, \fBENGINE_get_last()\fR,
  291. \&\fBENGINE_get_next()\fR, \fBENGINE_get_prev()\fR. All structural references should be
  292. released by a corresponding to call to the \fBENGINE_free()\fR function \- the
  293. ENGINE object itself will only actually be cleaned up and deallocated when
  294. the last structural reference is released. If the argument to \fBENGINE_free()\fR
  295. is NULL, nothing is done.
  296. .PP
  297. It should also be noted that many ENGINE API function calls that accept a
  298. structural reference will internally obtain another reference \- typically
  299. this happens whenever the supplied ENGINE will be needed by OpenSSL after
  300. the function has returned. Eg. the function to add a new ENGINE to
  301. OpenSSL's internal list is \fBENGINE_add()\fR \- if this function returns success,
  302. then OpenSSL will have stored a new structural reference internally so the
  303. caller is still responsible for freeing their own reference with
  304. \&\fBENGINE_free()\fR when they are finished with it. In a similar way, some
  305. functions will automatically release the structural reference passed to it
  306. if part of the function's job is to do so. Eg. the \fBENGINE_get_next()\fR and
  307. \&\fBENGINE_get_prev()\fR functions are used for iterating across the internal
  308. ENGINE list \- they will return a new structural reference to the next (or
  309. previous) ENGINE in the list or NULL if at the end (or beginning) of the
  310. list, but in either case the structural reference passed to the function is
  311. released on behalf of the caller.
  312. .PP
  313. To clarify a particular function's handling of references, one should
  314. always consult that function's documentation "man" page, or failing that
  315. the \fI<openssl/engine.h>\fR header file includes some hints.
  316. .PP
  317. \&\fIFunctional references\fR
  318. .PP
  319. As mentioned, functional references exist when the cryptographic
  320. functionality of an ENGINE is required to be available. A functional
  321. reference can be obtained in one of two ways; from an existing structural
  322. reference to the required ENGINE, or by asking OpenSSL for the default
  323. operational ENGINE for a given cryptographic purpose.
  324. .PP
  325. To obtain a functional reference from an existing structural reference,
  326. call the \fBENGINE_init()\fR function. This returns zero if the ENGINE was not
  327. already operational and couldn't be successfully initialised (e.g. lack of
  328. system drivers, no special hardware attached, etc), otherwise it will
  329. return nonzero to indicate that the ENGINE is now operational and will
  330. have allocated a new \fBfunctional\fR reference to the ENGINE. All functional
  331. references are released by calling \fBENGINE_finish()\fR (which removes the
  332. implicit structural reference as well).
  333. .PP
  334. The second way to get a functional reference is by asking OpenSSL for a
  335. default implementation for a given task, e.g. by \fBENGINE_get_default_RSA()\fR,
  336. \&\fBENGINE_get_default_cipher_engine()\fR, etc. These are discussed in the next
  337. section, though they are not usually required by application programmers as
  338. they are used automatically when creating and using the relevant
  339. algorithm-specific types in OpenSSL, such as RSA, DSA, EVP_CIPHER_CTX, etc.
  340. .SS "Default implementations"
  341. .IX Subsection "Default implementations"
  342. For each supported abstraction, the ENGINE code maintains an internal table
  343. of state to control which implementations are available for a given
  344. abstraction and which should be used by default. These implementations are
  345. registered in the tables and indexed by an 'nid' value, because
  346. abstractions like EVP_CIPHER and EVP_DIGEST support many distinct
  347. algorithms and modes, and ENGINEs can support arbitrarily many of them.
  348. In the case of other abstractions like RSA, DSA, etc, there is only one
  349. "algorithm" so all implementations implicitly register using the same 'nid'
  350. index.
  351. .PP
  352. When a default ENGINE is requested for a given abstraction/algorithm/mode, (e.g.
  353. when calling RSA_new_method(NULL)), a "get_default" call will be made to the
  354. ENGINE subsystem to process the corresponding state table and return a
  355. functional reference to an initialised ENGINE whose implementation should be
  356. used. If no ENGINE should (or can) be used, it will return NULL and the caller
  357. will operate with a NULL ENGINE handle \- this usually equates to using the
  358. conventional software implementation. In the latter case, OpenSSL will from
  359. then on behave the way it used to before the ENGINE API existed.
  360. .PP
  361. Each state table has a flag to note whether it has processed this
  362. "get_default" query since the table was last modified, because to process
  363. this question it must iterate across all the registered ENGINEs in the
  364. table trying to initialise each of them in turn, in case one of them is
  365. operational. If it returns a functional reference to an ENGINE, it will
  366. also cache another reference to speed up processing future queries (without
  367. needing to iterate across the table). Likewise, it will cache a NULL
  368. response if no ENGINE was available so that future queries won't repeat the
  369. same iteration unless the state table changes. This behaviour can also be
  370. changed; if the ENGINE_TABLE_FLAG_NOINIT flag is set (using
  371. \&\fBENGINE_set_table_flags()\fR), no attempted initialisations will take place,
  372. instead the only way for the state table to return a non-NULL ENGINE to the
  373. "get_default" query will be if one is expressly set in the table. Eg.
  374. \&\fBENGINE_set_default_RSA()\fR does the same job as \fBENGINE_register_RSA()\fR except
  375. that it also sets the state table's cached response for the "get_default"
  376. query. In the case of abstractions like EVP_CIPHER, where implementations are
  377. indexed by 'nid', these flags and cached-responses are distinct for each 'nid'
  378. value.
  379. .SS "Application requirements"
  380. .IX Subsection "Application requirements"
  381. This section will explain the basic things an application programmer should
  382. support to make the most useful elements of the ENGINE functionality
  383. available to the user. The first thing to consider is whether the
  384. programmer wishes to make alternative ENGINE modules available to the
  385. application and user. OpenSSL maintains an internal linked list of
  386. "visible" ENGINEs from which it has to operate \- at start-up, this list is
  387. empty and in fact if an application does not call any ENGINE API calls and
  388. it uses static linking against openssl, then the resulting application
  389. binary will not contain any alternative ENGINE code at all. So the first
  390. consideration is whether any/all available ENGINE implementations should be
  391. made visible to OpenSSL \- this is controlled by calling the various "load"
  392. functions.
  393. .PP
  394. The fact that ENGINEs are made visible to OpenSSL (and thus are linked into
  395. the program and loaded into memory at run-time) does not mean they are
  396. "registered" or called into use by OpenSSL automatically \- that behaviour
  397. is something for the application to control. Some applications
  398. will want to allow the user to specify exactly which ENGINE they want used
  399. if any is to be used at all. Others may prefer to load all support and have
  400. OpenSSL automatically use at run-time any ENGINE that is able to
  401. successfully initialise \- i.e. to assume that this corresponds to
  402. acceleration hardware attached to the machine or some such thing. There are
  403. probably numerous other ways in which applications may prefer to handle
  404. things, so we will simply illustrate the consequences as they apply to a
  405. couple of simple cases and leave developers to consider these and the
  406. source code to openssl's built-in utilities as guides.
  407. .PP
  408. If no ENGINE API functions are called within an application, then OpenSSL
  409. will not allocate any internal resources. Prior to OpenSSL 1.1.0, however,
  410. if any ENGINEs are loaded, even if not registered or used, it was necessary to
  411. call \fBENGINE_cleanup()\fR before the program exits.
  412. .PP
  413. \&\fIUsing a specific ENGINE implementation\fR
  414. .PP
  415. Here we'll assume an application has been configured by its user or admin
  416. to want to use the "ACME" ENGINE if it is available in the version of
  417. OpenSSL the application was compiled with. If it is available, it should be
  418. used by default for all RSA, DSA, and symmetric cipher operations, otherwise
  419. OpenSSL should use its built-in software as per usual. The following code
  420. illustrates how to approach this;
  421. .PP
  422. .Vb 10
  423. \& ENGINE *e;
  424. \& const char *engine_id = "ACME";
  425. \& ENGINE_load_builtin_engines();
  426. \& e = ENGINE_by_id(engine_id);
  427. \& if (!e)
  428. \& /* the engine isn\*(Aqt available */
  429. \& return;
  430. \& if (!ENGINE_init(e)) {
  431. \& /* the engine couldn\*(Aqt initialise, release \*(Aqe\*(Aq */
  432. \& ENGINE_free(e);
  433. \& return;
  434. \& }
  435. \& if (!ENGINE_set_default_RSA(e))
  436. \& /*
  437. \& * This should only happen when \*(Aqe\*(Aq can\*(Aqt initialise, but the previous
  438. \& * statement suggests it did.
  439. \& */
  440. \& abort();
  441. \& ENGINE_set_default_DSA(e);
  442. \& ENGINE_set_default_ciphers(e);
  443. \& /* Release the functional reference from ENGINE_init() */
  444. \& ENGINE_finish(e);
  445. \& /* Release the structural reference from ENGINE_by_id() */
  446. \& ENGINE_free(e);
  447. .Ve
  448. .PP
  449. \&\fIAutomatically using built-in ENGINE implementations\fR
  450. .PP
  451. Here we'll assume we want to load and register all ENGINE implementations
  452. bundled with OpenSSL, such that for any cryptographic algorithm required by
  453. OpenSSL \- if there is an ENGINE that implements it and can be initialised,
  454. it should be used. The following code illustrates how this can work;
  455. .PP
  456. .Vb 4
  457. \& /* Load all bundled ENGINEs into memory and make them visible */
  458. \& ENGINE_load_builtin_engines();
  459. \& /* Register all of them for every algorithm they collectively implement */
  460. \& ENGINE_register_all_complete();
  461. .Ve
  462. .PP
  463. That's all that's required. Eg. the next time OpenSSL tries to set up an
  464. RSA key, any bundled ENGINEs that implement RSA_METHOD will be passed to
  465. \&\fBENGINE_init()\fR and if any of those succeed, that ENGINE will be set as the
  466. default for RSA use from then on.
  467. .SS "Advanced configuration support"
  468. .IX Subsection "Advanced configuration support"
  469. There is a mechanism supported by the ENGINE framework that allows each
  470. ENGINE implementation to define an arbitrary set of configuration
  471. "commands" and expose them to OpenSSL and any applications based on
  472. OpenSSL. This mechanism is entirely based on the use of name-value pairs
  473. and assumes ASCII input (no unicode or UTF for now!), so it is ideal if
  474. applications want to provide a transparent way for users to provide
  475. arbitrary configuration "directives" directly to such ENGINEs. It is also
  476. possible for the application to dynamically interrogate the loaded ENGINE
  477. implementations for the names, descriptions, and input flags of their
  478. available "control commands", providing a more flexible configuration
  479. scheme. However, if the user is expected to know which ENGINE device he/she
  480. is using (in the case of specialised hardware, this goes without saying)
  481. then applications may not need to concern themselves with discovering the
  482. supported control commands and simply prefer to pass settings into ENGINEs
  483. exactly as they are provided by the user.
  484. .PP
  485. Before illustrating how control commands work, it is worth mentioning what
  486. they are typically used for. Broadly speaking there are two uses for
  487. control commands; the first is to provide the necessary details to the
  488. implementation (which may know nothing at all specific to the host system)
  489. so that it can be initialised for use. This could include the path to any
  490. driver or config files it needs to load, required network addresses,
  491. smart-card identifiers, passwords to initialise protected devices,
  492. logging information, etc etc. This class of commands typically needs to be
  493. passed to an ENGINE \fBbefore\fR attempting to initialise it, i.e. before
  494. calling \fBENGINE_init()\fR. The other class of commands consist of settings or
  495. operations that tweak certain behaviour or cause certain operations to take
  496. place, and these commands may work either before or after \fBENGINE_init()\fR, or
  497. in some cases both. ENGINE implementations should provide indications of
  498. this in the descriptions attached to built-in control commands and/or in
  499. external product documentation.
  500. .PP
  501. \&\fIIssuing control commands to an ENGINE\fR
  502. .PP
  503. Let's illustrate by example; a function for which the caller supplies the
  504. name of the ENGINE it wishes to use, a table of string-pairs for use before
  505. initialisation, and another table for use after initialisation. Note that
  506. the string-pairs used for control commands consist of a command "name"
  507. followed by the command "parameter" \- the parameter could be NULL in some
  508. cases but the name can not. This function should initialise the ENGINE
  509. (issuing the "pre" commands beforehand and the "post" commands afterwards)
  510. and set it as the default for everything except RAND and then return a
  511. boolean success or failure.
  512. .PP
  513. .Vb 10
  514. \& int generic_load_engine_fn(const char *engine_id,
  515. \& const char **pre_cmds, int pre_num,
  516. \& const char **post_cmds, int post_num)
  517. \& {
  518. \& ENGINE *e = ENGINE_by_id(engine_id);
  519. \& if (!e) return 0;
  520. \& while (pre_num\-\-) {
  521. \& if (!ENGINE_ctrl_cmd_string(e, pre_cmds[0], pre_cmds[1], 0)) {
  522. \& fprintf(stderr, "Failed command (%s \- %s:%s)\en", engine_id,
  523. \& pre_cmds[0], pre_cmds[1] ? pre_cmds[1] : "(NULL)");
  524. \& ENGINE_free(e);
  525. \& return 0;
  526. \& }
  527. \& pre_cmds += 2;
  528. \& }
  529. \& if (!ENGINE_init(e)) {
  530. \& fprintf(stderr, "Failed initialisation\en");
  531. \& ENGINE_free(e);
  532. \& return 0;
  533. \& }
  534. \& /*
  535. \& * ENGINE_init() returned a functional reference, so free the structural
  536. \& * reference from ENGINE_by_id().
  537. \& */
  538. \& ENGINE_free(e);
  539. \& while (post_num\-\-) {
  540. \& if (!ENGINE_ctrl_cmd_string(e, post_cmds[0], post_cmds[1], 0)) {
  541. \& fprintf(stderr, "Failed command (%s \- %s:%s)\en", engine_id,
  542. \& post_cmds[0], post_cmds[1] ? post_cmds[1] : "(NULL)");
  543. \& ENGINE_finish(e);
  544. \& return 0;
  545. \& }
  546. \& post_cmds += 2;
  547. \& }
  548. \& ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
  549. \& /* Success */
  550. \& return 1;
  551. \& }
  552. .Ve
  553. .PP
  554. Note that \fBENGINE_ctrl_cmd_string()\fR accepts a boolean argument that can
  555. relax the semantics of the function \- if set nonzero it will only return
  556. failure if the ENGINE supported the given command name but failed while
  557. executing it, if the ENGINE doesn't support the command name it will simply
  558. return success without doing anything. In this case we assume the user is
  559. only supplying commands specific to the given ENGINE so we set this to
  560. FALSE.
  561. .PP
  562. \&\fIDiscovering supported control commands\fR
  563. .PP
  564. It is possible to discover at run-time the names, numerical-ids, descriptions
  565. and input parameters of the control commands supported by an ENGINE using a
  566. structural reference. Note that some control commands are defined by OpenSSL
  567. itself and it will intercept and handle these control commands on behalf of the
  568. ENGINE, i.e. the ENGINE's \fBctrl()\fR handler is not used for the control command.
  569. \&\fI<openssl/engine.h>\fR defines an index, ENGINE_CMD_BASE, that all control
  570. commands implemented by ENGINEs should be numbered from. Any command value
  571. lower than this symbol is considered a "generic" command is handled directly
  572. by the OpenSSL core routines.
  573. .PP
  574. It is using these "core" control commands that one can discover the control
  575. commands implemented by a given ENGINE, specifically the commands:
  576. .PP
  577. .Vb 9
  578. \& ENGINE_HAS_CTRL_FUNCTION
  579. \& ENGINE_CTRL_GET_FIRST_CMD_TYPE
  580. \& ENGINE_CTRL_GET_NEXT_CMD_TYPE
  581. \& ENGINE_CTRL_GET_CMD_FROM_NAME
  582. \& ENGINE_CTRL_GET_NAME_LEN_FROM_CMD
  583. \& ENGINE_CTRL_GET_NAME_FROM_CMD
  584. \& ENGINE_CTRL_GET_DESC_LEN_FROM_CMD
  585. \& ENGINE_CTRL_GET_DESC_FROM_CMD
  586. \& ENGINE_CTRL_GET_CMD_FLAGS
  587. .Ve
  588. .PP
  589. Whilst these commands are automatically processed by the OpenSSL framework code,
  590. they use various properties exposed by each ENGINE to process these
  591. queries. An ENGINE has 3 properties it exposes that can affect how this behaves;
  592. it can supply a \fBctrl()\fR handler, it can specify ENGINE_FLAGS_MANUAL_CMD_CTRL in
  593. the ENGINE's flags, and it can expose an array of control command descriptions.
  594. If an ENGINE specifies the ENGINE_FLAGS_MANUAL_CMD_CTRL flag, then it will
  595. simply pass all these "core" control commands directly to the ENGINE's \fBctrl()\fR
  596. handler (and thus, it must have supplied one), so it is up to the ENGINE to
  597. reply to these "discovery" commands itself. If that flag is not set, then the
  598. OpenSSL framework code will work with the following rules:
  599. .PP
  600. .Vb 9
  601. \& if no ctrl() handler supplied;
  602. \& ENGINE_HAS_CTRL_FUNCTION returns FALSE (zero),
  603. \& all other commands fail.
  604. \& if a ctrl() handler was supplied but no array of control commands;
  605. \& ENGINE_HAS_CTRL_FUNCTION returns TRUE,
  606. \& all other commands fail.
  607. \& if a ctrl() handler and array of control commands was supplied;
  608. \& ENGINE_HAS_CTRL_FUNCTION returns TRUE,
  609. \& all other commands proceed processing ...
  610. .Ve
  611. .PP
  612. If the ENGINE's array of control commands is empty then all other commands will
  613. fail, otherwise; ENGINE_CTRL_GET_FIRST_CMD_TYPE returns the identifier of
  614. the first command supported by the ENGINE, ENGINE_GET_NEXT_CMD_TYPE takes the
  615. identifier of a command supported by the ENGINE and returns the next command
  616. identifier or fails if there are no more, ENGINE_CMD_FROM_NAME takes a string
  617. name for a command and returns the corresponding identifier or fails if no such
  618. command name exists, and the remaining commands take a command identifier and
  619. return properties of the corresponding commands. All except
  620. ENGINE_CTRL_GET_FLAGS return the string length of a command name or description,
  621. or populate a supplied character buffer with a copy of the command name or
  622. description. ENGINE_CTRL_GET_FLAGS returns a bitwise-OR'd mask of the following
  623. possible values:
  624. .PP
  625. .Vb 4
  626. \& ENGINE_CMD_FLAG_NUMERIC
  627. \& ENGINE_CMD_FLAG_STRING
  628. \& ENGINE_CMD_FLAG_NO_INPUT
  629. \& ENGINE_CMD_FLAG_INTERNAL
  630. .Ve
  631. .PP
  632. If the ENGINE_CMD_FLAG_INTERNAL flag is set, then any other flags are purely
  633. informational to the caller \- this flag will prevent the command being usable
  634. for any higher-level ENGINE functions such as \fBENGINE_ctrl_cmd_string()\fR.
  635. "INTERNAL" commands are not intended to be exposed to text-based configuration
  636. by applications, administrations, users, etc. These can support arbitrary
  637. operations via \fBENGINE_ctrl()\fR, including passing to and/or from the control
  638. commands data of any arbitrary type. These commands are supported in the
  639. discovery mechanisms simply to allow applications to determine if an ENGINE
  640. supports certain specific commands it might want to use (e.g. application "foo"
  641. might query various ENGINEs to see if they implement "FOO_GET_VENDOR_LOGO_GIF" \-
  642. and ENGINE could therefore decide whether or not to support this "foo"\-specific
  643. extension).
  644. .SH ENVIRONMENT
  645. .IX Header "ENVIRONMENT"
  646. .IP \fBOPENSSL_ENGINES\fR 4
  647. .IX Item "OPENSSL_ENGINES"
  648. The path to the engines directory.
  649. Ignored in set-user-ID and set-group-ID programs.
  650. .SH "RETURN VALUES"
  651. .IX Header "RETURN VALUES"
  652. \&\fBENGINE_get_first()\fR, \fBENGINE_get_last()\fR, \fBENGINE_get_next()\fR and \fBENGINE_get_prev()\fR
  653. return a valid \fBENGINE\fR structure or NULL if an error occurred.
  654. .PP
  655. \&\fBENGINE_add()\fR and \fBENGINE_remove()\fR return 1 on success or 0 on error.
  656. .PP
  657. \&\fBENGINE_by_id()\fR returns a valid \fBENGINE\fR structure or NULL if an error occurred.
  658. .PP
  659. \&\fBENGINE_init()\fR and \fBENGINE_finish()\fR return 1 on success or 0 on error.
  660. .PP
  661. All \fBENGINE_get_default_TYPE()\fR functions, \fBENGINE_get_cipher_engine()\fR and
  662. \&\fBENGINE_get_digest_engine()\fR return a valid \fBENGINE\fR structure on success or NULL
  663. if an error occurred.
  664. .PP
  665. All \fBENGINE_set_default_TYPE()\fR functions return 1 on success or 0 on error.
  666. .PP
  667. \&\fBENGINE_set_default()\fR returns 1 on success or 0 on error.
  668. .PP
  669. \&\fBENGINE_get_table_flags()\fR returns an unsigned integer value representing the
  670. global table flags which are used to control the registration behaviour of
  671. \&\fBENGINE\fR implementations.
  672. .PP
  673. All \fBENGINE_register_TYPE()\fR functions return 1 on success or 0 on error.
  674. .PP
  675. \&\fBENGINE_register_complete()\fR and \fBENGINE_register_all_complete()\fR always return 1.
  676. .PP
  677. \&\fBENGINE_ctrl()\fR returns a positive value on success or others on error.
  678. .PP
  679. \&\fBENGINE_cmd_is_executable()\fR returns 1 if \fBcmd\fR is executable or 0 otherwise.
  680. .PP
  681. \&\fBENGINE_ctrl_cmd()\fR and \fBENGINE_ctrl_cmd_string()\fR return 1 on success or 0 on error.
  682. .PP
  683. \&\fBENGINE_new()\fR returns a valid \fBENGINE\fR structure on success or NULL if an error
  684. occurred.
  685. .PP
  686. \&\fBENGINE_free()\fR always returns 1.
  687. .PP
  688. \&\fBENGINE_up_ref()\fR returns 1 on success or 0 on error.
  689. .PP
  690. \&\fBENGINE_set_id()\fR and \fBENGINE_set_name()\fR return 1 on success or 0 on error.
  691. .PP
  692. All other \fBENGINE_set_*\fR functions return 1 on success or 0 on error.
  693. .PP
  694. \&\fBENGINE_get_id()\fR and \fBENGINE_get_name()\fR return a string representing the identifier
  695. and the name of the ENGINE \fBe\fR respectively.
  696. .PP
  697. \&\fBENGINE_get_RSA()\fR, \fBENGINE_get_DSA()\fR, \fBENGINE_get_DH()\fR and \fBENGINE_get_RAND()\fR
  698. return corresponding method structures for each algorithms.
  699. .PP
  700. \&\fBENGINE_get_destroy_function()\fR, \fBENGINE_get_init_function()\fR,
  701. \&\fBENGINE_get_finish_function()\fR, \fBENGINE_get_ctrl_function()\fR,
  702. \&\fBENGINE_get_load_privkey_function()\fR, \fBENGINE_get_load_pubkey_function()\fR,
  703. \&\fBENGINE_get_ciphers()\fR and \fBENGINE_get_digests()\fR return corresponding function
  704. pointers of the callbacks.
  705. .PP
  706. \&\fBENGINE_get_cipher()\fR returns a valid \fBEVP_CIPHER\fR structure on success or NULL
  707. if an error occurred.
  708. .PP
  709. \&\fBENGINE_get_digest()\fR returns a valid \fBEVP_MD\fR structure on success or NULL if an
  710. error occurred.
  711. .PP
  712. \&\fBENGINE_get_flags()\fR returns an integer representing the ENGINE flags which are
  713. used to control various behaviours of an ENGINE.
  714. .PP
  715. \&\fBENGINE_get_cmd_defns()\fR returns an \fBENGINE_CMD_DEFN\fR structure or NULL if it's
  716. not set.
  717. .PP
  718. \&\fBENGINE_load_private_key()\fR and \fBENGINE_load_public_key()\fR return a valid \fBEVP_PKEY\fR
  719. structure on success or NULL if an error occurred.
  720. .SH "SEE ALSO"
  721. .IX Header "SEE ALSO"
  722. \&\fBOPENSSL_init_crypto\fR\|(3), \fBRSA_new_method\fR\|(3), \fBDSA_new\fR\|(3), \fBDH_new\fR\|(3),
  723. \&\fBRAND_bytes\fR\|(3), \fBconfig\fR\|(5)
  724. .SH HISTORY
  725. .IX Header "HISTORY"
  726. All of these functions were deprecated in OpenSSL 3.0.
  727. .PP
  728. \&\fBENGINE_cleanup()\fR was deprecated in OpenSSL 1.1.0 by the automatic cleanup
  729. done by \fBOPENSSL_cleanup()\fR
  730. and should not be used.
  731. .SH COPYRIGHT
  732. .IX Header "COPYRIGHT"
  733. Copyright 2002\-2024 The OpenSSL Project Authors. All Rights Reserved.
  734. .PP
  735. Licensed under the Apache License 2.0 (the "License"). You may not use
  736. this file except in compliance with the License. You can obtain a copy
  737. in the file LICENSE in the source distribution or at
  738. <https://www.openssl.org/source/license.html>.