engine.3 35 KB

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