📄 engine.pod
字号:
=pod=head1 NAMEengine - ENGINE cryptographic module support=head1 SYNOPSIS #include <openssl/engine.h> ENGINE *ENGINE_get_first(void); ENGINE *ENGINE_get_last(void); ENGINE *ENGINE_get_next(ENGINE *e); ENGINE *ENGINE_get_prev(ENGINE *e); int ENGINE_add(ENGINE *e); int ENGINE_remove(ENGINE *e); ENGINE *ENGINE_by_id(const char *id); int ENGINE_init(ENGINE *e); int ENGINE_finish(ENGINE *e); void ENGINE_load_openssl(void); void ENGINE_load_dynamic(void); #ifndef OPENSSL_NO_STATIC_ENGINE void ENGINE_load_4758cca(void); void ENGINE_load_aep(void); void ENGINE_load_atalla(void); void ENGINE_load_chil(void); void ENGINE_load_cswift(void); void ENGINE_load_gmp(void); void ENGINE_load_nuron(void); void ENGINE_load_sureware(void); void ENGINE_load_ubsec(void); #endif void ENGINE_load_cryptodev(void); void ENGINE_load_builtin_engines(void); void ENGINE_cleanup(void); ENGINE *ENGINE_get_default_RSA(void); ENGINE *ENGINE_get_default_DSA(void); ENGINE *ENGINE_get_default_ECDH(void); ENGINE *ENGINE_get_default_ECDSA(void); ENGINE *ENGINE_get_default_DH(void); ENGINE *ENGINE_get_default_RAND(void); ENGINE *ENGINE_get_cipher_engine(int nid); ENGINE *ENGINE_get_digest_engine(int nid); int ENGINE_set_default_RSA(ENGINE *e); int ENGINE_set_default_DSA(ENGINE *e); int ENGINE_set_default_ECDH(ENGINE *e); int ENGINE_set_default_ECDSA(ENGINE *e); int ENGINE_set_default_DH(ENGINE *e); int ENGINE_set_default_RAND(ENGINE *e); int ENGINE_set_default_ciphers(ENGINE *e); int ENGINE_set_default_digests(ENGINE *e); int ENGINE_set_default_string(ENGINE *e, const char *list); int ENGINE_set_default(ENGINE *e, unsigned int flags); unsigned int ENGINE_get_table_flags(void); void ENGINE_set_table_flags(unsigned int flags); int ENGINE_register_RSA(ENGINE *e); void ENGINE_unregister_RSA(ENGINE *e); void ENGINE_register_all_RSA(void); int ENGINE_register_DSA(ENGINE *e); void ENGINE_unregister_DSA(ENGINE *e); void ENGINE_register_all_DSA(void); int ENGINE_register_ECDH(ENGINE *e); void ENGINE_unregister_ECDH(ENGINE *e); void ENGINE_register_all_ECDH(void); int ENGINE_register_ECDSA(ENGINE *e); void ENGINE_unregister_ECDSA(ENGINE *e); void ENGINE_register_all_ECDSA(void); int ENGINE_register_DH(ENGINE *e); void ENGINE_unregister_DH(ENGINE *e); void ENGINE_register_all_DH(void); int ENGINE_register_RAND(ENGINE *e); void ENGINE_unregister_RAND(ENGINE *e); void ENGINE_register_all_RAND(void); int ENGINE_register_STORE(ENGINE *e); void ENGINE_unregister_STORE(ENGINE *e); void ENGINE_register_all_STORE(void); int ENGINE_register_ciphers(ENGINE *e); void ENGINE_unregister_ciphers(ENGINE *e); void ENGINE_register_all_ciphers(void); int ENGINE_register_digests(ENGINE *e); void ENGINE_unregister_digests(ENGINE *e); void ENGINE_register_all_digests(void); int ENGINE_register_complete(ENGINE *e); int ENGINE_register_all_complete(void); int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)); int ENGINE_cmd_is_executable(ENGINE *e, int cmd); int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, long i, void *p, void (*f)(void), int cmd_optional); int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, int cmd_optional); int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg); void *ENGINE_get_ex_data(const ENGINE *e, int idx); int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); ENGINE *ENGINE_new(void); int ENGINE_free(ENGINE *e); int ENGINE_up_ref(ENGINE *e); int ENGINE_set_id(ENGINE *e, const char *id); int ENGINE_set_name(ENGINE *e, const char *name); int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *dh_meth); int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *dh_meth); int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *rand_meth); int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f); int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f); int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f); int ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f); int ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f); int ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f); int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f); int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f); int ENGINE_set_flags(ENGINE *e, int flags); int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns); const char *ENGINE_get_id(const ENGINE *e); const char *ENGINE_get_name(const ENGINE *e); const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e); const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e); const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e); const DH_METHOD *ENGINE_get_DH(const ENGINE *e); const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e); ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e); ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e); ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e); ENGINE_CTRL_FUNC_PTR ENGINE_get_ctrl_function(const ENGINE *e); ENGINE_LOAD_KEY_PTR ENGINE_get_load_privkey_function(const ENGINE *e); ENGINE_LOAD_KEY_PTR ENGINE_get_load_pubkey_function(const ENGINE *e); ENGINE_CIPHERS_PTR ENGINE_get_ciphers(const ENGINE *e); ENGINE_DIGESTS_PTR ENGINE_get_digests(const ENGINE *e); const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid); const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid); int ENGINE_get_flags(const ENGINE *e); const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e); EVP_PKEY *ENGINE_load_private_key(ENGINE *e, const char *key_id, UI_METHOD *ui_method, void *callback_data); EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id, UI_METHOD *ui_method, void *callback_data); void ENGINE_add_conf_module(void);=head1 DESCRIPTIONThese functions create, manipulate, and use cryptographic modules in theform of B<ENGINE> objects. These objects act as containers forimplementations of cryptographic algorithms, and support areference-counted mechanism to allow them to be dynamically loaded in andout of the running application.The cryptographic functionality that can be provided by an B<ENGINE>implementation includes the following abstractions; RSA_METHOD - for providing alternative RSA implementations DSA_METHOD, DH_METHOD, RAND_METHOD, ECDH_METHOD, ECDSA_METHOD, STORE_METHOD - similarly for other OpenSSL APIs EVP_CIPHER - potentially multiple cipher algorithms (indexed by 'nid') EVP_DIGEST - potentially multiple hash algorithms (indexed by 'nid') key-loading - loading public and/or private EVP_PKEY keys=head2 Reference counting and handlesDue to the modular nature of the ENGINE API, pointers to ENGINEs need to betreated as handles - ie. not only as pointers, but also as references tothe underlying ENGINE object. Ie. one should obtain a new reference whenmaking copies of an ENGINE pointer if the copies will be used (andreleased) independantly.ENGINE objects have two levels of reference-counting to match the way inwhich the objects are used. At the most basic level, each ENGINE pointer isinherently a B<structural> reference - a structural reference is requiredto use the pointer value at all, as this kind of reference is a guaranteethat the structure can not be deallocated until the reference is released.However, a structural reference provides no guarantee that the ENGINE isinitiliased and able to use any of its cryptographicimplementations. Indeed it's quite possible that most ENGINEs will notinitialise at all in typical environments, as ENGINEs are typically used tosupport specialised hardware. To use an ENGINE's functionality, you need aB<functional> reference. This kind of reference can be considered aspecialised form of structural reference, because each functional referenceimplicitly contains a structural reference as well - however to avoiddifficult-to-find programming bugs, it is recommended to treat the twokinds of reference independantly. If you have a functional reference to anENGINE, you have a guarantee that the ENGINE has been initialised ready toperform cryptographic operations and will remain uninitialiseduntil after you have released your reference.I<Structural references>This basic type of reference is used for instantiating new ENGINEs,iterating across OpenSSL's internal linked-list of loadedENGINEs, reading information about an ENGINE, etc. Essentially a structuralreference is sufficient if you only need to query or manipulate the data ofan ENGINE implementation rather than use its functionality.The ENGINE_new() function returns a structural reference to a new (empty)ENGINE object. There are other ENGINE API functions that return structuralreferences such as; ENGINE_by_id(), ENGINE_get_first(), ENGINE_get_last(),ENGINE_get_next(), ENGINE_get_prev(). All structural references should bereleased by a corresponding to call to the ENGINE_free() function - theENGINE object itself will only actually be cleaned up and deallocated whenthe last structural reference is released.It should also be noted that many ENGINE API function calls that accept astructural reference will internally obtain another reference - typicallythis happens whenever the supplied ENGINE will be needed by OpenSSL afterthe function has returned. Eg. the function to add a new ENGINE toOpenSSL's internal list is ENGINE_add() - if this function returns success,then OpenSSL will have stored a new structural reference internally so thecaller is still responsible for freeing their own reference withENGINE_free() when they are finished with it. In a similar way, somefunctions will automatically release the structural reference passed to itif part of the function's job is to do so. Eg. the ENGINE_get_next() andENGINE_get_prev() functions are used for iterating across the internalENGINE list - they will return a new structural reference to the next (orprevious) ENGINE in the list or NULL if at the end (or beginning) of thelist, but in either case the structural reference passed to the function isreleased on behalf of the caller.To clarify a particular function's handling of references, one shouldalways consult that function's documentation "man" page, or failing thatthe openssl/engine.h header file includes some hints.I<Functional references>As mentioned, functional references exist when the cryptographicfunctionality of an ENGINE is required to be available. A functionalreference can be obtained in one of two ways; from an existing structuralreference to the required ENGINE, or by asking OpenSSL for the defaultoperational ENGINE for a given cryptographic purpose.To obtain a functional reference from an existing structural reference,call the ENGINE_init() function. This returns zero if the ENGINE was notalready operational and couldn't be successfully initialised (eg. lack ofsystem drivers, no special hardware attached, etc), otherwise it willreturn non-zero to indicate that the ENGINE is now operational and willhave allocated a new B<functional> reference to the ENGINE. All functionalreferences are released by calling ENGINE_finish() (which removes theimplicit structural reference as well).The second way to get a functional reference is by asking OpenSSL for adefault implementation for a given task, eg. by ENGINE_get_default_RSA(),ENGINE_get_default_cipher_engine(), etc. These are discussed in the nextsection, though they are not usually required by application programmers asthey are used automatically when creating and using the relevantalgorithm-specific types in OpenSSL, such as RSA, DSA, EVP_CIPHER_CTX, etc.=head2 Default implementationsFor each supported abstraction, the ENGINE code maintains an internal tableof state to control which implementations are available for a givenabstraction and which should be used by default. These implementations areregistered in the tables and indexed by an 'nid' value, becauseabstractions like EVP_CIPHER and EVP_DIGEST support many distinctalgorithms and modes, and ENGINEs can support arbitrarily many of them.In the case of other abstractions like RSA, DSA, etc, there is only one"algorithm" so all implementations implicitly register using the same 'nid'index.When a default ENGINE is requested for a given abstraction/algorithm/mode, (eg.when calling RSA_new_method(NULL)), a "get_default" call will be made to theENGINE subsystem to process the corresponding state table and return afunctional reference to an initialised ENGINE whose implementation should beused. If no ENGINE should (or can) be used, it will return NULL and the callerwill operate with a NULL ENGINE handle - this usually equates to using theconventional software implementation. In the latter case, OpenSSL will fromthen on behave the way it used to before the ENGINE API existed.Each state table has a flag to note whether it has processed this"get_default" query since the table was last modified, because to processthis question it must iterate across all the registered ENGINEs in thetable trying to initialise each of them in turn, in case one of them isoperational. If it returns a functional reference to an ENGINE, it willalso cache another reference to speed up processing future queries (withoutneeding to iterate across the table). Likewise, it will cache a NULLresponse if no ENGINE was available so that future queries won't repeat thesame iteration unless the state table changes. This behaviour can also bechanged; if the ENGINE_TABLE_FLAG_NOINIT flag is set (usingENGINE_set_table_flags()), no attempted initialisations will take place,instead the only way for the state table to return a non-NULL ENGINE to the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -