网上OpenSSL engine的例子不多,OpenSSL 1.1.1的例子就更少了。我在这儿提供两个engine的例子。第一个是最简单的一个框架。第二个是RSA的一个框架。
最简单的一个OpenSSL engine
(来源: https://www.openssl.org/blog/blog/2015/10/08/engine-building-lesson-1-a-minimum-useless-engine/)
#include <stdio.h>
#include <openssl/engine.h>
static const char *engine_id = "silly";
static const char *engine_name = "A silly engine for demonstration purposes";
static int bind(ENGINE *e, const char *id)
{
int ret = 0;
if (!ENGINE_set_id(e, engine_id)) {
fprintf(stderr, "ENGINE_set_id failed\n");
goto end;
}
if (!ENGINE_set_name(e, engine_name)) {
printf("ENGINE_set_name failed\n");
goto end;
}
ret = 1;
end:
return ret;
}
IMPLEMENT_DYNAMIC_BIND_FN(bind)
IMPLEMENT_DYNAMIC_CHECK_FN()
IMPLEMENT_DYNAMIC_BIND_FN:定义完成引擎的注册
ENGINE_set_id:Set engine id
ENGINE