summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/engine.3
diff options
context:
space:
mode:
authorschwarze <>2016-11-05 13:36:33 +0000
committerschwarze <>2016-11-05 13:36:33 +0000
commit71b431bd059aaefaa67b54a34adfaadc4014902c (patch)
tree7bf60aef63735e9638d12b0d8302b14d9860466e /src/lib/libcrypto/man/engine.3
parent5074288f0801a2b426584402e81b5953f706a44f (diff)
downloadopenbsd-71b431bd059aaefaa67b54a34adfaadc4014902c.tar.gz
openbsd-71b431bd059aaefaa67b54a34adfaadc4014902c.tar.bz2
openbsd-71b431bd059aaefaa67b54a34adfaadc4014902c.zip
convert the remaining manual pages from pod to mdoc
Diffstat (limited to 'src/lib/libcrypto/man/engine.3')
-rw-r--r--src/lib/libcrypto/man/engine.31187
1 files changed, 1187 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/engine.3 b/src/lib/libcrypto/man/engine.3
new file mode 100644
index 0000000000..3624fa76e4
--- /dev/null
+++ b/src/lib/libcrypto/man/engine.3
@@ -0,0 +1,1187 @@
1.Dd $Mdocdate: November 5 2016 $
2.Dt ENGINE 3
3.Os
4.Sh NAME
5.Nm ENGINE_add ,
6.Nm ENGINE_by_id ,
7.Nm ENGINE_finish ,
8.Nm ENGINE_get_first ,
9.Nm ENGINE_get_last ,
10.Nm ENGINE_get_next ,
11.Nm ENGINE_get_prev ,
12.Nm ENGINE_init ,
13.Nm ENGINE_load_builtin_engines ,
14.Nm ENGINE_remove
15.Nd ENGINE cryptographic module support
16.Sh SYNOPSIS
17.In openssl/engine.h
18.Ft ENGINE *
19.Fn ENGINE_get_first void
20.Ft ENGINE *
21.Fn ENGINE_get_last void
22.Ft ENGINE *
23.Fo ENGINE_get_next
24.Fa "ENGINE *e"
25.Fc
26.Ft ENGINE *
27.Fo ENGINE_get_prev
28.Fa "ENGINE *e"
29.Fc
30.Ft int
31.Fo ENGINE_add
32.Fa "ENGINE *e"
33.Fc
34.Ft int
35.Fo ENGINE_remove
36.Fa "ENGINE *e"
37.Fc
38.Ft ENGINE *
39.Fo ENGINE_by_id
40.Fa "const char *id"
41.Fc
42.Ft int
43.Fo ENGINE_init
44.Fa "ENGINE *e"
45.Fc
46.Ft int
47.Fo ENGINE_finish
48.Fa "ENGINE *e"
49.Fc
50.Ft void
51.Fn ENGINE_load_openssl void
52.Ft void
53.Fn ENGINE_load_dynamic void
54.Ft void
55.Fn ENGINE_load_cryptodev void
56.Ft void
57.Fn ENGINE_load_builtin_engines void
58.Ft void
59.Fn ENGINE_cleanup void
60.Ft ENGINE *
61.Fn ENGINE_get_default_RSA void
62.Ft ENGINE *
63.Fn ENGINE_get_default_DSA void
64.Ft ENGINE *
65.Fn ENGINE_get_default_ECDH void
66.Ft ENGINE *
67.Fn ENGINE_get_default_ECDSA void
68.Ft ENGINE *
69.Fn ENGINE_get_default_DH void
70.Ft ENGINE *
71.Fn ENGINE_get_default_RAND void
72.Ft ENGINE *
73.Fo ENGINE_get_cipher_engine
74.Fa "int nid"
75.Fc
76.Ft ENGINE *
77.Fo ENGINE_get_digest_engine
78.Fa "int nid"
79.Fc
80.Ft int
81.Fo ENGINE_set_default_RSA
82.Fa "ENGINE *e"
83.Fc
84.Ft int
85.Fo ENGINE_set_default_DSA
86.Fa "ENGINE *e"
87.Fc
88.Ft int
89.Fo ENGINE_set_default_ECDH
90.Fa "ENGINE *e"
91.Fc
92.Ft int
93.Fo ENGINE_set_default_ECDSA
94.Fa "ENGINE *e"
95.Fc
96.Ft int
97.Fo ENGINE_set_default_DH
98.Fa "ENGINE *e"
99.Fc
100.Ft int
101.Fo ENGINE_set_default_RAND
102.Fa "ENGINE *e"
103.Fc
104.Ft int
105.Fo ENGINE_set_default_ciphers
106.Fa "ENGINE *e"
107.Fc
108.Ft int
109.Fo ENGINE_set_default_digests
110.Fa "ENGINE *e"
111.Fc
112.Ft int
113.Fo ENGINE_set_default_string
114.Fa "ENGINE *e"
115.Fa "const char *list"
116.Fc
117.Ft int
118.Fo ENGINE_set_default
119.Fa "ENGINE *e"
120.Fa "unsigned int flags"
121.Fc
122.Ft unsigned int
123.Fn ENGINE_get_table_flags void
124.Ft void
125.Fo ENGINE_set_table_flags
126.Fa "unsigned int flags"
127.Fc
128.Ft int
129.Fo ENGINE_register_RSA
130.Fa "ENGINE *e"
131.Fc
132.Ft void
133.Fo ENGINE_unregister_RSA
134.Fa "ENGINE *e"
135.Fc
136.Ft void
137.Fn ENGINE_register_all_RSA void
138.Ft int
139.Fo ENGINE_register_DSA
140.Fa "ENGINE *e"
141.Fc
142.Ft void
143.Fo ENGINE_unregister_DSA
144.Fa "ENGINE *e"
145.Fc
146.Ft void
147.Fn ENGINE_register_all_DSA void
148.Ft int
149.Fo ENGINE_register_ECDH
150.Fa "ENGINE *e"
151.Fc
152.Ft void
153.Fo ENGINE_unregister_ECDH
154.Fa "ENGINE *e"
155.Fc
156.Ft void
157.Fn ENGINE_register_all_ECDH void
158.Ft int
159.Fo ENGINE_register_ECDSA
160.Fa "ENGINE *e"
161.Fc
162.Ft void
163.Fo ENGINE_unregister_ECDSA
164.Fa "ENGINE *e"
165.Fc
166.Ft void
167.Fn ENGINE_register_all_ECDSA void
168.Ft int
169.Fo ENGINE_register_DH
170.Fa "ENGINE *e"
171.Fc
172.Ft void
173.Fo ENGINE_unregister_DH
174.Fa "ENGINE *e"
175.Fc
176.Ft void
177.Fn ENGINE_register_all_DH void
178.Ft int
179.Fo ENGINE_register_RAND
180.Fa "ENGINE *e"
181.Fc
182.Ft void
183.Fo ENGINE_unregister_RAND
184.Fa "ENGINE *e"
185.Fc
186.Ft void
187.Fn ENGINE_register_all_RAND void
188.Ft int
189.Fo ENGINE_register_STORE
190.Fa "ENGINE *e"
191.Fc
192.Ft void
193.Fo ENGINE_unregister_STORE
194.Fa "ENGINE *e"
195.Fc
196.Ft void
197.Fn ENGINE_register_all_STORE void
198.Ft int
199.Fo ENGINE_register_ciphers
200.Fa "ENGINE *e"
201.Fc
202.Ft void
203.Fo ENGINE_unregister_ciphers
204.Fa "ENGINE *e"
205.Fc
206.Ft void
207.Fn ENGINE_register_all_ciphers void
208.Ft int
209.Fo ENGINE_register_digests
210.Fa "ENGINE *e"
211.Fc
212.Ft void
213.Fo ENGINE_unregister_digests
214.Fa "ENGINE *e"
215.Fc
216.Ft void
217.Fn ENGINE_register_all_digests void
218.Ft int
219.Fo ENGINE_register_complete
220.Fa "ENGINE *e"
221.Fc
222.Ft int
223.Fn ENGINE_register_all_complete void
224.Ft int
225.Fo ENGINE_ctrl
226.Fa "ENGINE *e"
227.Fa "int cmd"
228.Fa "long i"
229.Fa "void *p"
230.Fa "void (*f)(void)"
231.Fc
232.Ft int
233.Fo ENGINE_cmd_is_executable
234.Fa "ENGINE *e"
235.Fa "int cmd"
236.Fc
237.Ft int
238.Fo ENGINE_ctrl_cmd
239.Fa "ENGINE *e"
240.Fa "const char *cmd_name"
241.Fa "long i"
242.Fa "void *p"
243.Fa "void (*f)(void)"
244.Fa "int cmd_optional"
245.Fc
246.Ft int
247.Fo ENGINE_ctrl_cmd_string
248.Fa "ENGINE *e"
249.Fa "const char *cmd_name"
250.Fa "const char *arg"
251.Fa "int cmd_optional"
252.Fc
253.Ft int
254.Fo ENGINE_set_ex_data
255.Fa "ENGINE *e"
256.Fa "int idx"
257.Fa "void *arg"
258.Fc
259.Ft void *
260.Fo ENGINE_get_ex_data
261.Fa "const ENGINE *e"
262.Fa "int idx"
263.Fc
264.Ft int
265.Fo ENGINE_get_ex_new_index
266.Fa "long argl"
267.Fa "void *argp"
268.Fa "CRYPTO_EX_new *new_func"
269.Fa "CRYPTO_EX_dup *dup_func"
270.Fa "CRYPTO_EX_free *free_func"
271.Fc
272.Ft ENGINE *
273.Fn ENGINE_new void
274.Ft int
275.Fo ENGINE_free
276.Fa "ENGINE *e"
277.Fc
278.Ft int
279.Fo ENGINE_up_ref
280.Fa "ENGINE *e"
281.Fc
282.Ft int
283.Fo ENGINE_set_id
284.Fa "ENGINE *e"
285.Fa "const char *id"
286.Fc
287.Ft int
288.Fo ENGINE_set_name
289.Fa "ENGINE *e"
290.Fa "const char *name"
291.Fc
292.Ft int
293.Fo ENGINE_set_RSA
294.Fa "ENGINE *e"
295.Fa "const RSA_METHOD *rsa_meth"
296.Fc
297.Ft int
298.Fo ENGINE_set_DSA
299.Fa "ENGINE *e"
300.Fa "const DSA_METHOD *dsa_meth"
301.Fc
302.Ft int
303.Fo ENGINE_set_ECDH
304.Fa "ENGINE *e"
305.Fa "const ECDH_METHOD *dh_meth"
306.Fc
307.Ft int
308.Fo ENGINE_set_ECDSA
309.Fa "ENGINE *e"
310.Fa "const ECDSA_METHOD *dh_meth"
311.Fc
312.Ft int
313.Fo ENGINE_set_DH
314.Fa "ENGINE *e"
315.Fa "const DH_METHOD *dh_meth"
316.Fc
317.Ft int
318.Fo ENGINE_set_RAND
319.Fa "ENGINE *e"
320.Fa "const RAND_METHOD *rand_meth"
321.Fc
322.Ft int
323.Fo ENGINE_set_STORE
324.Fa "ENGINE *e"
325.Fa "const STORE_METHOD *rand_meth"
326.Fc
327.Ft int
328.Fo ENGINE_set_destroy_function
329.Fa "ENGINE *e"
330.Fa "ENGINE_GEN_INT_FUNC_PTR destroy_f"
331.Fc
332.Ft int
333.Fo ENGINE_set_init_function
334.Fa "ENGINE *e"
335.Fa "ENGINE_GEN_INT_FUNC_PTR init_f"
336.Fc
337.Ft int
338.Fo ENGINE_set_finish_function
339.Fa "ENGINE *e"
340.Fa "ENGINE_GEN_INT_FUNC_PTR finish_f"
341.Fc
342.Ft int
343.Fo ENGINE_set_ctrl_function
344.Fa "ENGINE *e"
345.Fa "ENGINE_CTRL_FUNC_PTR ctrl_f"
346.Fc
347.Ft int
348.Fo ENGINE_set_load_privkey_function
349.Fa "ENGINE *e"
350.Fa "ENGINE_LOAD_KEY_PTR loadpriv_f"
351.Fc
352.Ft int
353.Fo ENGINE_set_load_pubkey_function
354.Fa "ENGINE *e"
355.Fa "ENGINE_LOAD_KEY_PTR loadpub_f"
356.Fc
357.Ft int
358.Fo ENGINE_set_ciphers
359.Fa "ENGINE *e"
360.Fa "ENGINE_CIPHERS_PTR f"
361.Fc
362.Ft int
363.Fo ENGINE_set_digests
364.Fa "ENGINE *e"
365.Fa "ENGINE_DIGESTS_PTR f"
366.Fc
367.Ft int
368.Fo ENGINE_set_flags
369.Fa "ENGINE *e"
370.Fa "int flags"
371.Fc
372.Ft int
373.Fo ENGINE_set_cmd_defns
374.Fa "ENGINE *e"
375.Fa "const ENGINE_CMD_DEFN *defns"
376.Fc
377.Ft const char *
378.Fo ENGINE_get_id
379.Fa "const ENGINE *e"
380.Fc
381.Ft const char *
382.Fo ENGINE_get_name
383.Fa "const ENGINE *e"
384.Fc
385.Ft const RSA_METHOD *
386.Fo ENGINE_get_RSA
387.Fa "const ENGINE *e"
388.Fc
389.Ft const DSA_METHOD *
390.Fo ENGINE_get_DSA
391.Fa "const ENGINE *e"
392.Fc
393.Ft const ECDH_METHOD *
394.Fo ENGINE_get_ECDH
395.Fa "const ENGINE *e"
396.Fc
397.Ft const ECDSA_METHOD *
398.Fo ENGINE_get_ECDSA
399.Fa "const ENGINE *e"
400.Fc
401.Ft const DH_METHOD *
402.Fo ENGINE_get_DH
403.Fa "const ENGINE *e"
404.Fc
405.Ft const RAND_METHOD *
406.Fo ENGINE_get_RAND
407.Fa "const ENGINE *e"
408.Fc
409.Ft const STORE_METHOD *
410.Fo ENGINE_get_STORE
411.Fa "const ENGINE *e"
412.Fc
413.Ft ENGINE_GEN_INT_FUNC_PTR
414.Fo ENGINE_get_destroy_function
415.Fa "const ENGINE *e"
416.Fc
417.Ft ENGINE_GEN_INT_FUNC_PTR
418.Fo ENGINE_get_init_function
419.Fa "const ENGINE *e"
420.Fc
421.Ft ENGINE_GEN_INT_FUNC_PTR
422.Fo ENGINE_get_finish_function
423.Fa "const ENGINE *e"
424.Fc
425.Ft ENGINE_CTRL_FUNC_PTR
426.Fo ENGINE_get_ctrl_function
427.Fa "const ENGINE *e"
428.Fc
429.Ft ENGINE_LOAD_KEY_PTR
430.Fo ENGINE_get_load_privkey_function
431.Fa "const ENGINE *e"
432.Fc
433.Ft ENGINE_LOAD_KEY_PTR
434.Fo ENGINE_get_load_pubkey_function
435.Fa "const ENGINE *e"
436.Fc
437.Ft ENGINE_CIPHERS_PTR
438.Fo ENGINE_get_ciphers
439.Fa "const ENGINE *e"
440.Fc
441.Ft ENGINE_DIGESTS_PTR
442.Fo ENGINE_get_digests
443.Fa "const ENGINE *e"
444.Fc
445.Ft const EVP_CIPHER *
446.Fo ENGINE_get_cipher
447.Fa "ENGINE *e"
448.Fa "int nid"
449.Fc
450.Ft const EVP_MD *
451.Fo ENGINE_get_digest
452.Fa "ENGINE *e"
453.Fa "int nid"
454.Fc
455.Ft int
456.Fo ENGINE_get_flags
457.Fa "const ENGINE *e"
458.Fc
459.Ft const ENGINE_CMD_DEFN *
460.Fo ENGINE_get_cmd_defns
461.Fa "const ENGINE *e"
462.Fc
463.Ft EVP_PKEY *
464.Fo ENGINE_load_private_key
465.Fa "ENGINE *e"
466.Fa "const char *key_id"
467.Fa "UI_METHOD *ui_method"
468.Fa "void *callback_data"
469.Fc
470.Ft EVP_PKEY *
471.Fo ENGINE_load_public_key
472.Fa "ENGINE *e"
473.Fa "const char *key_id"
474.Fa "UI_METHOD *ui_method"
475.Fa "void *callback_data"
476.Fc
477.Ft void
478.Fn ENGINE_add_conf_module void
479.Sh DESCRIPTION
480These functions create, manipulate, and use cryptographic modules
481in the form of
482.Vt ENGINE
483objects.
484These objects act as containers for implementations of cryptographic
485algorithms, and support a reference-counted mechanism to allow them to
486be dynamically loaded in and out of the running application.
487.Pp
488The cryptographic functionality that can be provided by an
489.Vt ENGINE
490implementation includes the following abstractions:
491.Pp
492.Bl -bullet -compact
493.It
494.Vt RSA_METHOD :
495for providing alternative RSA implementations
496.It
497.Vt DSA_METHOD , DH_METHOD , RAND_METHOD , ECDH_METHOD ,
498.Vt ECDSA_METHOD , STORE_METHOD :
499similarly for other OpenSSL APIs
500.It
501.Vt EVP_CIPHER :
502potentially multiple cipher algorithms (indexed by 'nid')
503.It
504.Vt EVP_DIGEST :
505potentially multiple hash algorithms (indexed by 'nid')
506.It
507key-loading: loading public and/or private EVP_PKEY keys
508.El
509.Ss Reference counting and handles
510Due to the modular nature of the
511.Nm engine
512API, pointers to
513.Vt ENGINE Ns s
514need to be treated as handles - ie. not only as pointers, but also
515as references to the underlying
516.Vt ENGINE
517object.
518One should obtain a new reference when making copies of an
519.Vt ENGINE
520pointer if the copies will be used (and released) independently.
521.Pp
522.Vt ENGINE
523objects have two levels of reference-counting to match the way in
524which the objects are used.
525At the most basic level, each
526.Vt ENGINE
527pointer is inherently a
528.Sy structural
529reference - a structural reference is required to use the pointer value
530at all, as this kind of reference is a guarantee that the structure can
531not be deallocated until the reference is released.
532.Pp
533However, a structural reference provides no guarantee that the
534.Vt ENGINE
535is initialised and able to use any of its cryptographic implementations.
536Indeed it's quite possible that most
537.Vt ENGINE Ns s
538will not initialise at all in typical environments, as
539.Vt ENGINE Ns s
540are typically used to support specialised hardware.
541To use an
542.Vt ENGINE Ap s
543functionality, you need a
544.Sy functional
545reference.
546This kind of reference can be considered a specialised form of
547structural reference, because each functional reference implicitly
548contains a structural reference as well - however to avoid
549difficult-to-find programming bugs, it is recommended to treat the two
550kinds of reference independently.
551If you have a functional reference to an
552.Vt ENGINE ,
553you have a guarantee that the
554.Vt ENGINE
555has been initialised ready to perform cryptographic operations and
556will remain uninitialised until after you have released your
557reference.
558.Pp
559.Em Structural references
560.Pp
561This basic type of reference is used for instantiating new
562.Vt ENGINE Ns s,
563iterating across OpenSSL's internal linked-list of loaded
564.Vt ENGINE Ns s,
565reading information about an
566.Vt ENGINE ,
567etc.
568Essentially a structural reference is sufficient if you only need to
569query or manipulate the data of an
570.Vt ENGINE
571implementation rather than use its functionality.
572.Pp
573The
574.Fn ENGINE_new
575function returns a structural reference to a new (empty)
576.Vt ENGINE
577object.
578There are other
579.Nm engine
580API functions that return structural references such as
581.Fn ENGINE_by_id ,
582.Fn ENGINE_get_first ,
583.Fn ENGINE_get_last ,
584.Fn ENGINE_get_next ,
585and
586.Fn ENGINE_get_prev .
587All structural references should be released by a corresponding call
588to the
589.Fn ENGINE_free
590function.
591The
592.Vt ENGINE
593object itself will only actually be cleaned up and deallocated when
594the last structural reference is released.
595.Pp
596It should also be noted that many
597.Nm engine
598API function calls that accept a structural reference will internally
599obtain another reference.
600Typically this happens whenever the supplied
601.Vt ENGINE
602will be needed by OpenSSL after the function has returned.
603For example, the function to add a new
604.Vt ENGINE
605to OpenSSL's internal list is
606.Fn ENGINE_add .
607If this function returns success, OpenSSL will have stored a new
608structural reference internally so the caller is still responsible for
609freeing their own reference with
610.Fn ENGINE_free
611when they are finished with it.
612In a similar way, some functions will automatically release the
613structural reference passed to it if part of the function's job is
614to do so.
615For example, the
616.Fn ENGINE_get_next
617and
618.Fn ENGINE_get_prev
619functions are used for iterating across the internal
620.Vt ENGINE
621list.
622They
623will return a new structural reference to the next (or previous)
624.Vt ENGINE
625in the list or
626.Dv NULL
627if at the end (or beginning) of the list, but in either case the
628structural reference passed to the function is released on behalf
629of the caller.
630.Pp
631To clarify a particular function's handling of references, one should
632always consult that function's manual page, or failing that the
633.In openssl/engine.h
634header file includes some hints.
635.Pp
636.Em Functional references
637.Pp
638As mentioned, functional references exist when the cryptographic
639functionality of an
640.Vt ENGINE
641is required to be available.
642A functional reference can be obtained in one of two ways; from an
643existing structural reference to the required
644.Vt ENGINE ,
645or by asking OpenSSL for the default operational
646.Vt ENGINE
647for a given cryptographic purpose.
648.Pp
649To obtain a functional reference from an existing structural reference,
650call the
651.Fn ENGINE_init
652function.
653This returns zero if the
654.Vt ENGINE
655was not already operational and couldn't be successfully initialised
656(eg. lack of system drivers, no special hardware attached, etc.),
657otherwise it will return non-zero to indicate that the
658.Vt ENGINE
659is now operational and will have allocated a new
660.Sy functional
661reference to the
662.Vt ENGINE .
663All functional references are released by calling
664.Fn ENGINE_finish ,
665which removes the implicit structural reference as well.
666.Pp
667The second way to get a functional reference is by asking OpenSSL for a
668default implementation for a given task, eg.
669by
670.Fn ENGINE_get_default_RSA ,
671.Fn ENGINE_get_default_cipher_engine ,
672etc.
673These are discussed in the next section, though they are not usually
674required by application programmers as they are used automatically when
675creating and using the relevant algorithm-specific types in OpenSSL,
676such as RSA, DSA, EVP_CIPHER_CTX, etc.
677.Ss Default implementations
678For each supported abstraction, the
679.Nm engine
680code maintains an internal table of state to control which
681implementations are available for a given abstraction and which
682should be used by default.
683These implementations are registered in the tables and indexed by an
684.Fa nid
685value, because abstractions like
686.Vt EVP_CIPHER
687and
688.Vt EVP_DIGEST
689support many distinct algorithms and modes, and
690.Vt ENGINE Ns s
691can support arbitrarily many of them.
692In the case of other abstractions like RSA, DSA, etc., there is
693only one "algorithm" so all implementations implicitly register
694using the same
695.Fa nid
696index.
697.Pp
698When a default
699.Vt ENGINE
700is requested for a given abstraction/algorithm/mode, (eg. when
701calling
702.Fn RSA_new_method NULL ) ,
703a "get_default" call will be made to the
704.Nm engine
705subsystem to process the corresponding state table and return
706a functional reference to an initialised
707.Vt ENGINE
708whose implementation should be used.
709If no
710.Vt ENGINE
711should (or can) be used, it will return
712.Dv NULL
713and the caller will operate with a
714.Dv NULL
715.Vt ENGINE
716handle.
717This usually equates to using the conventional software implementation.
718In the latter case, OpenSSL will from then on behave the way it used to
719before the
720.Nm engine
721API existed.
722.Pp
723Each state table has a flag to note whether it has processed this
724"get_default" query since the table was last modified, because to
725process this question it must iterate across all the registered
726.Vt ENGINE Ns s
727in the table trying to initialise each of them in turn, in case one of
728them is operational.
729If it returns a functional reference to an
730.Vt ENGINE ,
731it will also cache another reference to speed up processing future
732queries (without needing to iterate across the table).
733Likewise, it will cache a
734.Dv NULL
735response if no
736.Vt ENGINE
737was available so that future queries won't repeat the same iteration
738unless the state table changes.
739This behaviour can also be changed; if the
740.Dv ENGINE_TABLE_FLAG_NOINIT
741flag is set (using
742.Fn ENGINE_set_table_flags ) ,
743no attempted initialisations will take place, instead the only way for
744the state table to return a
745.Pf non- Dv NULL
746.Vt ENGINE
747to the "get_default" query will be if one is expressly set in the table.
748For example,
749.Fn ENGINE_set_default_RSA
750does the same job as
751.Fn ENGINE_register_RSA
752except that it also sets the state table's cached response for the
753"get_default" query.
754In the case of abstractions like
755.Vt EVP_CIPHER ,
756where implementations are indexed by
757.Fa nid ,
758these flags and cached-responses are distinct for each
759.Fa nid
760value.
761.Ss Application requirements
762This section will explain the basic things an application programmer
763should support to make the most useful elements of the
764.Nm engine
765functionality available to the user.
766The first thing to consider is whether the programmer wishes to make
767alternative
768.Vt ENGINE
769modules available to the application and user.
770OpenSSL maintains an internal linked list of "visible"
771.Vt ENGINE Ns s
772from which it has to operate.
773At start-up, this list is empty, and in fact if an application does
774not call any
775.Nm engine
776API calls and it uses static
777linking against openssl, then the resulting application binary will
778not contain any alternative
779.Nm engine
780code at all.
781So the first consideration is whether any/all available
782.Vt ENGINE
783implementations should be made visible to OpenSSL.
784This is controlled by calling the various "load" functions, eg.
785.Fn ENGINE_load_builtin_engines
786to make all
787.Vt ENGINE
788implementations bundled with OpenSSL available.
789.Pp
790Note that
791.Fn ENGINE_load_dynamic
792is a placeholder and does not enable dynamic engine loading support.
793.Pp
794Having called any of these functions,
795.Vt ENGINE
796objects would have been dynamically allocated and populated with
797these implementations and linked into OpenSSL's internal linked
798list.
799.Pp
800If no
801.Nm engine
802API functions are called at all in an application, then there are
803no inherent memory leaks to worry about from the
804.Nm engine
805functionality, however if any
806.Vt ENGINE Ns s
807are loaded, even if they are never registered or used, it is necessary
808to use the
809.Fn ENGINE_cleanup
810function to correspondingly cleanup before program exit, if the caller
811wishes to avoid memory leaks.
812This mechanism uses an internal callback registration table so that any
813.Nm engine
814API functionality that knows it requires cleanup can register its
815cleanup details to be called during
816.Fn ENGINE_cleanup .
817This approach allows
818.Fn ENGINE_cleanup
819to clean up after any
820.Nm engine
821functionality at all that your program uses, yet doesn't automatically
822create linker dependencies to all possible
823.Nm engine
824functionality - only the cleanup callbacks required by the functionality
825you do use will be required by the linker.
826.Pp
827The fact that
828.Vt ENGINE Ns s
829are made visible to OpenSSL (and thus are linked into the program
830and loaded into memory at run-time) does not mean they are "registered"
831or called into use by OpenSSL automatically - that behaviour is
832something for the application to control.
833Some applications will want to allow the user to specify exactly which
834.Vt ENGINE
835they want used if any is to be used at all.
836Others may prefer to load all support and have OpenSSL automatically use
837at run-time any
838.Vt ENGINE
839that is able to successfully initialised - ie. to assume that this
840corresponds to acceleration hardware attached to the machine or
841some such thing.
842There are probably numerous other ways in which applications may prefer
843to handle things, so we will simply illustrate the consequences as they
844apply to a couple of simple cases and leave developers to consider these
845and the source code to openssl's builtin utilities as guides.
846.Pp
847.Em Using a specific ENGINE implementation
848.Pp
849Here we'll assume an application has been configured by its user or
850admin to want to use the "ACME"
851.Vt ENGINE
852if it is available in the version of OpenSSL the application was
853compiled with.
854If it is available, it should be used by default for all RSA, DSA, and
855symmetric cipher operation, otherwise OpenSSL should use its builtin
856software as usual.
857The following code illustrates how to approach this:
858.Bd -literal
859ENGINE *e;
860const char *engine_id = "ACME";
861ENGINE_load_builtin_engines();
862e = ENGINE_by_id(engine_id);
863if (!e)
864 /* the engine isn't available */
865 return;
866if (!ENGINE_init(e)) {
867 /* the engine couldn't initialise, release 'e' */
868 ENGINE_free(e);
869 return;
870}
871if (!ENGINE_set_default_RSA(e))
872 /* This should only happen when 'e' can't initialise, but the previous
873 * statement suggests it did. */
874 abort();
875ENGINE_set_default_DSA(e);
876ENGINE_set_default_ciphers(e);
877/* Release the functional reference from ENGINE_init() */
878ENGINE_finish(e);
879/* Release the structural reference from ENGINE_by_id() */
880ENGINE_free(e);
881.Ed
882.Pp
883.Em Automatically using builtin ENGINE implementations
884.Pp
885Here we'll assume we want to load and register all
886.Vt ENGINE
887implementations bundled with OpenSSL, such that for any cryptographic
888algorithm required by OpenSSL - if there is an
889.Vt ENGINE
890that implements it and can be initialise, it should be used.
891The following code illustrates how this can work;
892.Bd -literal
893/* Load all bundled ENGINEs into memory and make them visible */
894ENGINE_load_builtin_engines();
895/* Register all of them for every algorithm they collectively implement */
896ENGINE_register_all_complete();
897.Ed
898.Pp
899That's all that's required.
900For example, the next time OpenSSL tries to set up an RSA key, any bundled
901.Vt ENGINE Ns s
902that implement
903.Vt RSA_METHOD
904will be passed to
905.Fn ENGINE_init
906and if any of those succeed, that
907.Vt ENGINE
908will be set as the default for RSA use from then on.
909.Ss Advanced configuration support
910There is a mechanism supported by the
911.Nm engine
912framework that allows each
913.Vt ENGINE
914implementation to define an arbitrary set of configuration
915"commands" and expose them to OpenSSL and any applications based on
916OpenSSL.
917This mechanism is entirely based on the use of name-value pairs
918and assumes ASCII input (no unicode or UTF for now!), so it is ideal if
919applications want to provide a transparent way for users to provide
920arbitrary configuration "directives" directly to such
921.Vt ENGINE Ns s.
922It is also possible for the application to dynamically interrogate the
923loaded
924.Vt ENGINE
925implementations for the names, descriptions, and input flags of
926their available "control commands", providing a more flexible
927configuration scheme.
928However, if the user is expected to know which
929.Vt ENGINE
930device he/she is using (in the case of specialised hardware, this
931goes without saying) then applications may not need to concern
932themselves with discovering the supported control commands and
933simply prefer to pass settings into
934.Vt ENGINE s
935exactly as they are provided by the user.
936.Pp
937Before illustrating how control commands work, it is worth mentioning
938what they are typically used for.
939Broadly speaking there are two uses for control commands; the first is
940to provide the necessary details to the implementation (which may know
941nothing at all specific to the host system) so that it can be
942initialised for use.
943This could include the path to any driver or config files it needs to
944load, required network addresses, smart-card identifiers, passwords to
945initialise protected devices, logging information, etc etc.
946This class of commands typically needs to be passed to an
947.Vt ENGINE
948.Sy before
949attempting to initialise it, ie. before calling
950.Fn ENGINE_init .
951The other class of commands consist of settings or operations that tweak
952certain behaviour or cause certain operations to take place, and these
953commands may work either before or after
954.Fn ENGINE_init ,
955or in some cases both.
956.Vt ENGINE
957implementations should provide indications of this in the descriptions
958attached to builtin control commands and/or in external product
959documentation.
960.Pp
961.Em Issuing control commands to an ENGINE
962.Pp
963Let's illustrate by example; a function for which the caller supplies
964the name of the
965.Vt ENGINE
966it wishes to use, a table of string-pairs for use before initialisation,
967and another table for use after initialisation.
968Note that the string-pairs used for control commands consist of a
969command "name" followed by the command "parameter" - the parameter
970could be
971.Dv NULL
972in some cases but the name can not.
973This function should initialise the
974.Vt ENGINE
975(issuing the "pre" commands beforehand and the "post" commands
976afterwards) and set it as the default for everything except RAND
977and then return a boolean success or failure.
978.Bd -literal
979int
980generic_load_engine_fn(const char *engine_id,
981 const char **pre_cmds, int pre_num,
982 const char **post_cmds, int post_num)
983{
984 ENGINE *e = ENGINE_by_id(engine_id);
985
986 if (!e)
987 return 0;
988 while (pre_num--) {
989 if (!ENGINE_ctrl_cmd_string(e,
990 pre_cmds[0], pre_cmds[1], 0)) {
991 fprintf(stderr,
992 "Failed command (%s - %s:%s)\en",
993 engine_id, pre_cmds[0],
994 pre_cmds[1] ? pre_cmds[1] : "(NULL)");
995 ENGINE_free(e);
996 return 0;
997 }
998 pre_cmds += 2;
999 }
1000 if (!ENGINE_init(e)) {
1001 fprintf(stderr, "Failed initialisation\en");
1002 ENGINE_free(e);
1003 return 0;
1004 }
1005 /*
1006 * ENGINE_init() returned a functional reference,
1007 * so free the structural reference from
1008 * ENGINE_by_id().
1009 */
1010 ENGINE_free(e);
1011 while (post_num--) {
1012 if (!ENGINE_ctrl_cmd_string(e,
1013 post_cmds[0], post_cmds[1], 0)) {
1014 fprintf(stderr,
1015 "Failed command (%s - %s:%s)\en",
1016 engine_id, post_cmds[0],
1017 post_cmds[1] ? post_cmds[1] : "(NULL)");
1018 ENGINE_finish(e);
1019 return 0;
1020 }
1021 post_cmds += 2;
1022 }
1023 ENGINE_set_default(e, ENGINE_METHOD_ALL & ~ENGINE_METHOD_RAND);
1024 /* Success */
1025 return 1;
1026}
1027.Ed
1028.Pp
1029Note that
1030.Fn ENGINE_ctrl_cmd_string
1031accepts a boolean argument that can relax the semantics of the function.
1032If set to non-zero it will only return failure if the
1033.Vt ENGINE
1034supported the given command name but failed while executing it, if the
1035.Vt ENGINE
1036doesn't support the command name it will simply return success without
1037doing anything.
1038In this case we assume the user is only supplying commands specific to
1039the given
1040.Vt ENGINE
1041so we set this to FALSE.
1042.Pp
1043.Em Discovering supported control commands
1044.Pp
1045It is possible to discover at run-time the names, numerical-ids,
1046descriptions and input parameters of the control commands supported by an
1047.Vt ENGINE
1048using a structural reference.
1049Note that some control commands are defined by OpenSSL itself and it
1050will intercept and handle these control commands on behalf of the
1051.Vt ENGINE ,
1052ie. the
1053.Vt ENGINE Ap s
1054ctrl() handler is not used for the control command.
1055.In openssl/engine.h
1056defines an index,
1057.Dv ENGINE_CMD_BASE ,
1058that all control commands implemented by
1059.Vt ENGINE Ns s
1060should be numbered from.
1061Any command value lower than this symbol is considered a "generic"
1062command is handled directly by the OpenSSL core routines.
1063.Pp
1064It is using these "core" control commands that one can discover the
1065control commands implemented by a given
1066.Vt ENGINE ,
1067specifically the commands:
1068.Bd -literal
1069#define ENGINE_HAS_CTRL_FUNCTION 10
1070#define ENGINE_CTRL_GET_FIRST_CMD_TYPE 11
1071#define ENGINE_CTRL_GET_NEXT_CMD_TYPE 12
1072#define ENGINE_CTRL_GET_CMD_FROM_NAME 13
1073#define ENGINE_CTRL_GET_NAME_LEN_FROM_CMD 14
1074#define ENGINE_CTRL_GET_NAME_FROM_CMD 15
1075#define ENGINE_CTRL_GET_DESC_LEN_FROM_CMD 16
1076#define ENGINE_CTRL_GET_DESC_FROM_CMD 17
1077#define ENGINE_CTRL_GET_CMD_FLAGS 18
1078.Ed
1079.Pp
1080Whilst these commands are automatically processed by the OpenSSL
1081framework code, they use various properties exposed by each
1082.Vt ENGINE
1083to process these queries.
1084An
1085.Vt ENGINE
1086has 3 properties it exposes that can affect how this behaves;
1087it can supply a ctrl() handler, it can specify
1088.Dv ENGINE_FLAGS_MANUAL_CMD_CTRL
1089in the
1090.Vt ENGINE Ap s
1091flags, and it can expose an array of control command descriptions.
1092If an
1093.Vt ENGINE
1094specifies the
1095.Dv ENGINE_FLAGS_MANUAL_CMD_CTRL
1096flag, then it will simply pass all these "core" control commands
1097directly to the
1098.Vt ENGINE Ap s
1099ctrl() handler (and thus, it must have supplied one), so it is up
1100to the
1101.Vt ENGINE
1102to reply to these "discovery" commands itself.
1103If that flag is not set, then the OpenSSL framework code will work with
1104the following rules;
1105.Bl -tag -width Ds
1106.It If no ctrl() handler is supplied:
1107.Dv ENGINE_HAS_CTRL_FUNCTION
1108returns FALSE (zero), all other commands fail.
1109.It If a ctrl() handler was supplied but no array of control commands:
1110.Dv ENGINE_HAS_CTRL_FUNCTION
1111returns TRUE, all other commands fail.
1112.It If a ctrl() handler and array of control commands was supplied:
1113.Dv ENGINE_HAS_CTRL_FUNCTION
1114returns TRUE, all other commands proceed processing...
1115.El
1116.Pp
1117If the
1118.Vt ENGINE Ns s
1119array of control commands is empty, then all other commands will fail.
1120Otherwise
1121.Dv ENGINE_CTRL_GET_FIRST_CMD_TYPE
1122returns the identifier of the first command supported by the
1123.Vt ENGINE ,
1124.Dv ENGINE_GET_NEXT_CMD_TYPE
1125takes the identifier of a command supported by the
1126.Vt ENGINE
1127and returns the next command identifier or fails if there are no more,
1128.Dv ENGINE_CMD_FROM_NAME
1129takes a string name for a command and returns the corresponding
1130identifier or fails if no such command name exists, and the remaining
1131commands take a command identifier and return properties of the
1132corresponding commands.
1133All except
1134.Dv ENGINE_CTRL_GET_FLAGS
1135return the string length of a command name or description, or
1136populate a supplied character buffer with a copy of the command
1137name or description.
1138.Dv ENGINE_CTRL_GET_FLAGS
1139returns a bitwise-OR'd mask of the following possible values:
1140.Bd -literal
1141#define ENGINE_CMD_FLAG_NUMERIC (unsigned int)0x0001
1142#define ENGINE_CMD_FLAG_STRING (unsigned int)0x0002
1143#define ENGINE_CMD_FLAG_NO_INPUT (unsigned int)0x0004
1144#define ENGINE_CMD_FLAG_INTERNAL (unsigned int)0x0008
1145.Ed
1146.Pp
1147If the
1148.Dv ENGINE_CMD_FLAG_INTERNAL
1149flag is set, then any other flags are purely informational to the caller.
1150This flag will prevent the command being usable for any higher-level
1151.Vt ENGINE
1152functions such as
1153.Fn ENGINE_ctrl_cmd_string .
1154"INTERNAL" commands are not intended to be exposed to text-based
1155configuration by applications, administrations, users, etc.
1156These can support arbitrary operations via
1157.Fn ENGINE_ctrl ,
1158including passing to and/or from the control commands data of any
1159arbitrary type.
1160These commands are supported in the discovery mechanisms simply allow
1161applications to determine if an
1162.Vt ENGINE
1163supports certain specific commands it might want to use (eg.
1164application "foo" might query various
1165.Vt ENGINE Ns s
1166to see if they implement "FOO_GET_VENDOR_LOGO_GIF" - and
1167.Vt ENGINE
1168could therefore decide whether or not to support this "foo"-specific
1169extension).
1170.Ss Future developments
1171The
1172.Nm engine
1173API and internal architecture is currently being reviewed.
1174Slated for possible release in 0.9.8 is support for transparent loading
1175of "dynamic"
1176.Vt ENGINE Ns s (built as self-contained shared libraries).
1177This would allow
1178.Vt ENGINE
1179implementations to be provided independently of
1180OpenSSL libraries and/or OpenSSL-based applications, and would also
1181remove any requirement for applications to explicitly use the "dynamic"
1182.Vt ENGINE
1183to bind to shared-library implementations.
1184.Sh SEE ALSO
1185.Xr dh 3 ,
1186.Xr dsa 3 ,
1187.Xr rsa 3