OpenSSL Engine数据结构定义在crypto/engine/eng_int.h文件中。
/*
* This is a structure for storing implementations of various crypto
* algorithms and functions.
*/
struct engine_st {
const char *id; //Engine标识
const char *name; //Engine名字
const RSA_METHOD *rsa_meth; //RSA方法集合
const DSA_METHOD *dsa_meth; //DSA方法集合
const DH_METHOD *dh_meth; //DH方法集合
const EC_KEY_METHOD *ec_meth; //ECDH方法集合
const RAND_METHOD *rand_meth; //随机数方法集合
/* Cipher handling is via this callback */
/*对称算法选取函数。硬件一般会支持多种对称算法,
该回调函数用来从用户实现的多个对称算法中根据某种条件(一般是算法nid)来选择其中的一种.*/
ENGINE_CIPHERS_PTR ciphers;
/* Digest handling is via this callback */
/*摘要算法选取函数。
该回调函数用来从用户实现的多个摘要算法中根据某种条件(一般是算法nid)来选择其中的一种*/
ENGINE_DIGESTS_PTR digests;
/* Public key handling via this callback */
/*公钥算法选取函数*/
ENGINE_PKEY_METHS_PTR pkey_meths;
/* ASN1 public key handling via this callback */
ENGINE_PKEY_ASN1_METHS_PTR pkey_asn1_meths;
ENGINE_GEN_INT_FUNC_PTR destroy; //销毁引擎函数
ENGINE_GEN_INT_FUNC_PTR init; //初始化引擎函数
ENGINE_GEN_INT_FUNC_PTR finish; //完成回调函数
//控制函数,可通过控制函数传入不同的命令,实现登录密码设备、修改口令等操作。
ENGINE_CTRL_FUNC_PTR ctrl;
ENGINE_LOAD_KEY_PTR load_privkey; //加载私钥函数
ENGINE_LOAD_KEY_PTR load_pubkey; //加载公钥函数
ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert;
const ENGINE_CMD_DEFN *cmd_defns;
int flags;
/* reference count on the structure itself */
int struct_ref;
/*
* reference count on usability of the engine type. NB: This controls the
* loading and initialisation of any functionality required by this
* engine, whereas the previous count is simply to cope with
* (de)allocation of this structure. Hence, running_ref <= struct_ref at
* all times.
*/
int funct_ref;
/* A place to store per-ENGINE data */
CRYPTO_EX_DATA ex_data; //扩展数据结构,可用来存放用户数据
/* Used to maintain the linked-list of engines. */
/*用于构建Engine链表,openssl中的硬件Engine可能不止一个*/
struct engine_st *prev;
struct engine_st *next;
};