kunpengaccel
KAE引擎使用示例代码
更新时间:2021/01/18 GMT+08:00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <stdio.h>
#include <stdlib.h>
/* OpenSSL headers */
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/engine.h>
int main(int argc, char **argv)
{
/* Initializing OpenSSL */
SSL_load_error_strings();
ERR_load_BIO_strings();
OpenSSL_add_all_algorithms();
/*You can use ENGINE_by_id Function to get the handle of the Huawei Accelerator Engine*/
ENGINE *e = ENGINE_by_id("kae");
/*使能加速引擎异步功能,可选配置,设置为“0”表示不使能,设置为“1”表示使能,默认使能异步功能*/
ENGINE_ctrl_cmd_string(e, "KAE_CMD_ENABLE_ASYNC", "1", 0)
ENGINE_init(e);
/*指定引擎用于RSA加解密, 如果初始时使用ENGINE_set_default_RSA(ENGINE *e);则无需传入e*/
RSA *rsa = RSA_new_method(e);
/*The user code*/
……
ENGINE_free(e);
}
|
用户还可以在初始化阶段指定crypto相应算法使用KAE引擎,其他算法不需要使用KAE引擎,这样对已有的代码修改量将更小,只需要在初始化的某个阶段设置一下即可。
1 2 3 4 5 | int ENGINE_set_default_RSA(ENGINE *e);
int ENGINE_set_default_DH(ENGINE *e);
int ENGINE_set_default_ciphers(ENGINE *e);
int ENGINE_set_default_digests(ENGINE *e);
int ENGINE_set_default(ENGINE *e, unsigned int flags);
|
更多使用API方法请访问OpenSSL官网,链接如下:
https://www.openssl.org/docs/man1.1.0/man3/ENGINE_set_default_ciphers.html
父主题: 加速引擎的应用
