当前物联网设备对数据的安全性提出了越来越高的要求,而基于硬件的加解密技术越来越丰富。hwcrypto 设置则是一个硬件加解密设备驱动框架。并将crc、rng等作为独立设备注册到框架中,主要实现抽象硬件加解密的驱动和API接口,应用程序可直接使用,简单方便,简化开发流程。
硬件加解密框架目前已经支持 AES/DES/3DES/RC4/SHA1/SHA2/MD5/CRC/RNG/BIGNUM 等加解密相关的接口,每种硬件加解密作为单独设备注册到设备框架。
将上述加解密算法按照不同的类型分成如下几个大类,每一类都有丰富的 API 可供使用。目前已经支持的类型如下(实例应用主要有crc、rng):
循环冗余校验(Cyclic Redundancy Check, CRC)是一种根据网络数据包或计算机文件等数据产生简短固定位数校验码的一种信道编码技术,主要用来检测或校验数据传输或者保存后可能出现的错误。主要利用除法及余数的原理来作错误侦测。CRC设备的访问api接口如下:
接口 | 说明 |
---|---|
os_hwcrypto_crc_create() | 创建 CRC 上下文 |
os_hwcrypto_crc_destroy() | 释放上下文 |
os_hwcrypto_crc_update() | 计算一包数据 |
os_hwcrypto_crc_cfg() | 设置上下文计算数据 |
os_hwcrypto_crc_register() | 注册CRC设备 |
该函数用于创建 CRC 上下文,其根据 CRC 设备的指针,可创建 CRC 上下文,函数原型如下:
struct os_hwcrypto_ctx *os_hwcrypto_crc_create(hwcrypto_crc_mode mode)
参数 | 说明 |
---|---|
mode | CRC 计算模式 |
返回 | 说明 |
NULL | 失败 |
其他 | 设备对象 |
其中的mode模式包括:
typedef enum
{
HWCRYPTO_CRC_CUSTOM, /* Custom CRC mode */
HWCRYPTO_CRC_CRC8, /* poly : 0x07 */
HWCRYPTO_CRC_CRC16, /* poly : 0x8005 */
HWCRYPTO_CRC_CRC32, /* poly : 0x04C11DB7 */
HWCRYPTO_CRC_CCITT, /* poly : 0x1021 */
HWCRYPTO_CRC_DNP, /* poly : 0x3D65 */
} hwcrypto_crc_mode;
该函数用于释放上下文,当不再使用时,可删除该上下文并释放资源,函数原型如下:
void os_hwcrypto_crc_destroy(struct os_hwcrypto_ctx *ctx)
参数 | 说明 |
---|---|
ctx | CRC上下文 |
返回 | 说明 |
无 | 无 |
该函数用于计算CRC值,其根据 CRC 的上下文、输入数据及其长度,可获得 CRC 计算结果,函数原型如下:
os_uint32_t os_hwcrypto_crc_update(struct os_hwcrypto_ctx *ctx,
const os_uint8_t *input,os_size_t length)
参数 | 说明 |
---|---|
ctx | 上下文 |
input | 输入数据 |
length | 输入数据长度 |
返回 | 说明 |
os_uint32_t | 计算结果 |
0 | 失败 |
该函数用于配置CRC,应用程序可根据 CRC 的上下文和配置信息,对CRC上下文进行配置,函数原型如下:
void os_hwcrypto_crc_cfg(struct os_hwcrypto_ctx *ctx, struct hwcrypto_crc_cfg *cfg)
参数 | 说明 |
---|---|
ctx | CRC上下文 |
cfg | 加解密配置参数 |
返回 | 说明 |
无 | 无 |
其中cfg为加解密配置参数,其结构体为:
struct hwcrypto_crc_cfg
{
os_uint32_t last_val; /**< Last CRC value cache */
os_uint32_t poly; /**< CRC polynomial */
os_uint16_t width; /**< CRC value width */
os_uint32_t xorout; /**< Result XOR Value */
os_uint16_t flags; /**< Input or output data reverse. CRC_FLAG_REFIN or CRC_FLAG_REFOUT */
};
该函数用于注册CRC设备,函数原型如下:
os_err_t os_hwcrypto_crc_register(struct os_hwcrypto_device *device, const char *name)
参数 | 说明 |
---|---|
device | hwcrypto设备指针 |
name | 设备名 |
返回 | 说明 |
OS_EOK | 注册成功 |
其他 | 失败 |
随机数发生(Random Numeral Generator,RNG)器所产生的数据,后面的数与前面的数毫无关系。其访问AP接口主要有:
接口 | 说明 |
---|---|
os_hwcrypto_rng_update_ctx() | 生成随机数 |
os_hwcrypto_rng_update() | 获取更新随机数 |
os_hwcrypto_rng_register() | 注册rng设备 |
该函数用于生成随机数,函数原型如下:
os_uint32_t os_hwcrypto_rng_update_ctx(struct os_hwcrypto_ctx *ctx)
参数 | 说明 |
---|---|
ctx | rng上下文 |
返回 | 说明 |
0 | fail |
Others | 随机数 |
该函数用于获取随机数,函数原型如下:
os_uint32_t os_hwcrypto_rng_update(void)
参数 | 说明 |
---|---|
返回 | 说明 |
0 | fail |
Others | succeed |
该函数用于注册rng设备,函数原型如下:
os_err_t os_hwcrypto_rng_register(struct os_hwcrypto_device *device, const char *name)
参数 | 说明 |
---|---|
device | hwcrypto设备指针 |
name | 设备名 |
返回 | 说明 |
OS_EOK | 注册成功 |
其他 | 失败 |
Hash,一般翻译做散列、杂凑,或音译为哈希,是把任意长度的输入(又叫做预映射pre-image)通过散列算法变换成固定长度的输出,该输出就是散列值。访问hash硬件的API接口如下:
接口 | 说明 |
---|---|
os_hwcrypto_hash_create() | 创建 hash 上下文 |
os_hwcrypto_hash_destroy() | 释放上下文 |
os_hwcrypto_hash_finish() | 计算最终 hash 值 |
os_hwcrypto_hash_update() | 处理一包数据 |
os_hwcrypto_hash_cpy() | 复制上下文 |
os_hwcrypto_hash_reset() | 重置上下文 |
os_hwcrypto_hash_set_type() | 设置 hash 算法类型 |
os_hwcrypto_hash_register() | 注册hash设备 |
该函数可根据hash设备指针创建hash上下文,函数原型如下:
struct os_hwcrypto_ctx *os_hwcrypto_hash_create(hwcrypto_type type)
参数 | 说明 |
---|---|
type | hash算法类型 |
返回 | 说明 |
其他 | 设备对象指针 |
NULL | 没有找到设备 |
该函数用于不再使用上下文时,来释放资源、删除(释放)上下文,函数原型如下:
void os_hwcrypto_hash_destroy(struct os_hwcrypto_ctx *ctx)
参数 | 说明 |
---|---|
ctx | hash上下文 |
返回 | 说明 |
无 | 无 |
该函数用于输出最后的 hash 值,函数原型如下:
os_err_t os_hwcrypto_hash_finish(struct os_hwcrypto_ctx *ctx, os_uint8_t *output, os_size_t length)
应用程序根据 hash 的上下文,可以输出最后的 hash 值
参数 | 说明 |
---|---|
ctx | hash上下文 |
output | 存储输出数据指针 |
length | 数据长度 |
返回 | 说明 |
OS_EOK | 计算成功 |
其他 | 失败 |
该函数用于输入一包数据到hash上下文,并计算hash值,函数原型如下:
os_err_t os_hwcrypto_hash_update(struct os_hwcrypto_ctx *ctx, const os_uint8_t *input, os_size_t length)
参数 | 说明 |
---|---|
ctx | hash上下文 |
input | 输入的数据包 |
length | 输入的数据长度 |
返回 | 说明 |
OS_EOK | 计算成功 |
其他 | 失败 |
该函数用于将源hash的上下文复制到目标的hash的上下文,函数原型如下:
os_err_t os_hwcrypto_hash_cpy(struct os_hwcrypto_ctx *des, const struct os_hwcrypto_ctx *src)
参数 | 说明 |
---|---|
des | 目标hash上下文 |
src | 源hash上下文 |
返回 | 说明 |
OS_EOK | 计算成功 |
其他 | 失败 |
该函数根据 hash 的上下文,重置 hash 上下文文本,函数原型如下:
void os_hwcrypto_hash_reset(struct os_hwcrypto_ctx *ctx)
参数 | 说明 |
---|---|
ctx | 上下文 |
返回 | 说明 |
无 | 无 |
该函数用于修改hash算法类型,函数原型如下:
os_err_t os_hwcrypto_hash_set_type(struct os_hwcrypto_ctx *ctx, hwcrypto_type type);
参数 | 说明 |
---|---|
ctx | hash上下文 |
type | hash 算法类型 |
返回 | 说明 |
OS_EOK | 计算成功 |
其他 | 失败 |
该函数用于注册hash设备,函数原型如下:
os_err_t os_hwcrypto_hash_register(struct os_hwcrypto_device *device, const char *name)
参数 | 说明 |
---|---|
device | hwcrypto设备指针 |
name | hash 设备名 |
返回 | 说明 |
OS_EOK | 注册成功 |
其他 | 失败 |
对称加密算法是应用较早的加密算法,技术成熟。在对称加密算法中,数据发信方将明文(原始数据)和加密密钥一起经过特殊加密算法处理后,使其变成复杂的加密密文发送出去。收信方收到密文后,若想解读原文,则需要使用加密用过的密钥及相同算法的逆算法对密文进行解密,才能使其恢复成可读明文。在对称加密算法中,使用的密钥只有一个,发收信双方都使用这个密钥对数据进行加密和解密,要求解密方事先知道加密密钥。
访问 symmetric 算法设备硬件的api接口如下:
接口 | 说明 |
---|---|
os_hwcrypto_symmetric_create() | 创建对称加解密上下文 |
os_hwcrypto_symmetric_destroy() | 释放上下文 |
os_hwcrypto_symmetric_crypt() | 加解密操作 |
os_hwcrypto_symmetric_setkey() | 设置加解密密钥 |
os_hwcrypto_symmetric_getkey() | 获取加解密密钥 |
os_hwcrypto_symmetric_setiv() | 设置对称加解密初始化向量 |
os_hwcrypto_symmetric_getiv() | 获取对称加解密初始化向量 |
os_hwcrypto_symmetric_set_ivoff() | 设置对称加解密初始化向量偏移值 |
os_hwcrypto_symmetric_get_ivoff() | 获取对称加解密初始化向量偏移值 |
os_hwcrypto_symmetric_cpy() | 复制上下文 |
os_hwcrypto_symmetric_reset() | 重置上下文 |
os_hwcrypto_symmetric_set_type() | 设置加解密类型 |
os_hwcrypto_symmetric_register() | 注册对称加解密设备 |
该函数用于创建对称加解密上下文,应用程序根据对称加解密设备指针实现,函数原型如下:
struct os_hwcrypto_ctx *os_hwcrypto_symmetric_create(hwcrypto_type type)
参数 | 说明 |
---|---|
type | 对称加解密算法类型 |
返回 | 说明 |
OS_NULL | 失败 |
其他 | 设备对象 |
该函数用于不再使用上下文时,应用程序进行调用,实现删除该上下文、释放资源,函数原型如下:
void os_hwcrypto_symmetric_destroy(struct os_hwcrypto_ctx *ctx)
参数 | 说明 |
---|---|
ctx | 对称加解密上下文指针 |
返回 | 说明 |
无 | 无 |
该函数根据对称加解密的上下文、加解密模式、输入数据及长度,可以输出最后计算后的值,函数原型如下:
os_err_t os_hwcrypto_symmetric_crypt(struct os_hwcrypto_ctx *ctx, hwcrypto_mode mode, os_size_t length, const os_uint8_t *in, os_uint8_t *out)
参数 | 说明 |
---|---|
ctx | 上下文句柄 |
mode | 加密或者解密 |
length | 数据长度 |
in | 输入数据 |
out | 输出数据 |
返回 | 说明 |
OS_EOK | 计算成功 |
其他 | 失败 |
该函数用于设置加解密密钥,根据对称加解密的上下文、密钥与密钥及长度,设置加解密密钥,函数原型如下:
os_err_t os_hwcrypto_symmetric_setkey(struct os_hwcrypto_ctx *ctx, const os_uint8_t *key, os_uint32_t bitlen)
参数 | 说明 |
---|---|
ctx | 上下文句柄 |
key | 输入密钥 |
bitlen | 密钥长度 |
返回 | 说明 |
OS_EOK | 设置密钥成功 |
其他 | 失败 |
该函数用于获取密钥,应用程序根据对称加解密的上下文、密钥、长度,获取密钥长度,函数原型如下:
int os_hwcrypto_symmetric_getkey(struct os_hwcrypto_ctx *ctx, os_uint8_t *key, os_uint32_t bitlen)
参数 | 说明 |
---|---|
ctx | 目标上下文 |
key | 密钥 |
bitlen | 密钥长度 |
返回 | 说明 |
int | 复制密钥长度 |
其他 | 失败 |
该函数用于设置对称加解密初始化向量,应用程序根据对称加解密的上下文、初始化向量与向量长度,设置对称加解密初始化向量,函数原型如下:
os_err_t os_hwcrypto_symmetric_setiv(struct os_hwcrypto_ctx *ctx, const os_uint8_t *iv, os_size_t len)
参数 | 说明 |
---|---|
ctx | 上下文 |
iv | 初始化向量 |
len | 初始化向量的长度 |
返回 | 说明 |
OS_EOK | 设置成功 |
其他 | 失败 |
该函数用于获取对称加解密初始化向量,根据对称加解密的上下文,获取对称加解密初始化向量,函数原型如下:
int os_hwcrypto_symmetric_getiv(struct os_hwcrypto_ctx *ctx, os_uint8_t *iv, os_size_t len)
参数 | 说明 |
---|---|
ctx | 上下文 |
iv | 将获取初始化向量 |
len | 初始化向量的长度 |
返回 | 说明 |
int | 获取成功的长度 |
其他 | 失败 |
该函数用于设置对称加解密初始化向量偏移,应用程序根据对称加解密的上下文、初始化向量偏移值,设置对称加解密初始化向量的偏移值,函数原型如下:
void os_hwcrypto_symmetric_set_ivoff(struct os_hwcrypto_ctx *ctx, os_int32_t iv_off)
参数 | 说明 |
---|---|
ctx | 对称加解密上下文 |
iv_off | 初始化向量的偏移值 |
返回 | 说明 |
无 | 无 |
该函数用于获取对称加解密初始化向量偏移值,应用程序根据对称加解密的上下文,获取对称加解密初始化向量的偏移值,函数原型如下:
void os_hwcrypto_symmetric_get_ivoff(struct os_hwcrypto_ctx *ctx, os_int32_t *iv_off)
参数 | 说明 |
---|---|
ctx | 上下文 |
iv_off | 初始化向量的偏移指针 |
返回 | 说明 |
无 | 无 |
该函数用于复制对称加解密上下文,应用程序根据源对称加解密的上下文,复制到目的上下文中,函数原型如下:
os_err_t os_hwcrypto_symmetric_cpy(struct os_hwcrypto_ctx *des, const struct os_hwcrypto_ctx *src);
参数 | 说明 |
---|---|
des | 目标上下文 |
src | 源上下文 |
返回 | 说明 |
OS_EOK | 设置成功 |
其他 | 失败 |
该函数用于重置对称加解密上下文,应用程序根据对称加解密的上下文,重置上下文,函数原型如下:
void os_hwcrypto_symmetric_reset(struct os_hwcrypto_ctx *ctx)
参数 | 说明 |
---|---|
ctx | 上下文 |
返回 | 说明 |
无 | 无 |
该函数用于设置加解密类型,应用程序根据对称加解密的上下文,设置加密或者解密,函数原型如下:
os_err_t os_hwcrypto_symmetric_set_type(struct os_hwcrypto_ctx *ctx, hwcrypto_type type)
参数 | 说明 |
---|---|
ctx | 上下文 |
type | 加解密类型 |
返回 | 说明 |
OS_EOK | 设置成功 |
其他 | 失败 |
该函数用于注册symmetric设备,函数原型如下:
os_err_t os_hwcrypto_symmetric_register(struct os_hwcrypto_device *device, const char *name)
参数 | 说明 |
---|---|
device | hwcrypto设备指针 |
name | 设备名 |
返回 | 说明 |
OS_EOK | 注册成功 |
其他 | 失败 |
gcm 消息认证可以提供对消息的加密和完整性校验,也能够对其他附加消息的真实性进行检验。
接口 | 说明 |
---|---|
os_hwcrypto_gcm_create() | 创建上下文 |
os_hwcrypto_gcm_destroy() | 释放上下文 |
os_hwcrypto_gcm_start() | 传入附加值 |
os_hwcrypto_gcm_finish() | 生成消息认证码 |
os_hwcrypto_gcm_crypt() | 进行加解密 |
os_hwcrypto_gcm_setkey() | 设置密钥 |
os_hwcrypto_gcm_getkey() | 获取密钥 |
os_hwcrypto_gcm_setiv() | 设置初始化向量 |
os_hwcrypto_gcm_getiv() | 获取初始化向量 |
os_hwcrypto_gcm_set_ivoff() | 设置初始化向量偏移 |
os_hwcrypto_gcm_get_ivoff() | 获取初始化向量偏移 |
os_hwcrypto_gcm_cpy() | 复制上下文 |
os_hwcrypto_gcm_reset() | 重置上下文 |
os_hwcrypto_gcm_register() | 注册gcm设备 |
该函数根据 gcm 消息认证的指针,创建gcm上下文,函数原型如下:
struct os_hwcrypto_ctx *os_hwcrypto_gcm_create(hwcrypto_type crypt_type)
参数 | 说明 |
---|---|
crypt_type | 加解密算法类型 |
返回 | 说明 |
NULL | 创建失败 |
其他 | gcm上下文指针 |
该函数用于删除gcm上下文,函数原型如下:
void os_hwcrypto_gcm_destroy(struct os_hwcrypto_ctx *ctx)
参数 | 说明 |
---|---|
ctx | gcm上下文指针 |
返回 | 说明 |
无 | 无 |
该函数用于传入附加消息,函数原型如下:
os_err_t os_hwcrypto_gcm_start(struct os_hwcrypto_ctx *ctx, const os_uint8_t *add, os_size_t add_len)
参数 | 说明 |
---|---|
ctx | gcm上下文 |
add | 附加消息 |
add_len | 附加消息长度 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于生成消息认证码,用作完整性与真实性检验认证,函数原型如下:
os_err_t os_hwcrypto_gcm_finish(struct os_hwcrypto_ctx *ctx, const os_uint8_t *tag, os_size_t tag_len)
参数 | 说明 |
---|---|
ctx | gcm上下文 |
tag | 消息认证码 |
tag_len | 消息认证长度 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数根据 gcm 的上下文、加解密模式对输入数据进行加密,函数原型如下:
os_err_t os_hwcrypto_gcm_crypt(struct os_hwcrypto_ctx *ctx, hwcrypto_mode mode,
os_size_t length, const os_uint8_t *in, os_uint8_t *out)
参数 | 说明 |
---|---|
ctx | gcm上下文 |
mode | 加解密模式 |
length | 输入数据长度 |
in | 输出数据 |
out | 输出数据 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于设置密钥,函数原型如下:
os_err_t os_hwcrypto_gcm_setkey(struct os_hwcrypto_ctx *ctx,const os_uint8_t *key, os_uint32_t bitlen)
参数 | 说明 |
---|---|
ctx | gcm上下文 |
key | 密钥 |
bitlen | 密钥长度 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于获取密钥,函数原型如下:
os_err_t os_hwcrypto_gcm_getkey(struct os_hwcrypto_ctx *ctx,os_uint8_t *key, os_uint32_t bitlen)
参数 | 说明 |
---|---|
ctx | gcm上下文 |
key | 密钥 |
bitlen | 密钥长度 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于设置初始化向量,函数原型如下:
os_err_t os_hwcrypto_gcm_setiv(struct os_hwcrypto_ctx *ctx,const os_uint8_t *iv, os_size_t len)
参数 | 说明 |
---|---|
ctx | gcm上下文 |
iv | 初始化向量 |
len | 初始化向量长度 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于获取初始化向量,函数原型如下:
os_err_t os_hwcrypto_gcm_getiv(struct os_hwcrypto_ctx *ctx,os_uint8_t *iv, os_size_t len)
参数 | 说明 |
---|---|
ctx | gcm上下文 |
iv | 初始化向量 |
len | 初始化向量长度 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于设置初始化向量偏移,函数原型如下:
void os_hwcrypto_gcm_set_ivoff(struct os_hwcrypto_ctx *ctx, os_int32_t iv_off)
参数 | 说明 |
---|---|
ctx | gcm上下文 |
iv_off | 初始化向量偏移 |
返回 | 说明 |
无 | 无 |
该函数用于获取初始化向量偏移,函数原型如下:
void os_hwcrypto_gcm_get_ivoff(struct os_hwcrypto_ctx *ctx, os_int32_t *iv_off)
参数 | 说明 |
---|---|
ctx | gcm上下文 |
iv_off | 初始化向量偏移 |
返回 | 说明 |
无 | 无 |
该函数用于复制gcm上下文,函数原型如下:
os_err_t os_hwcrypto_gcm_cpy(struct os_hwcrypto_ctx *des,const struct os_hwcrypto_ctx *src)
参数 | 说明 |
---|---|
des | 目标gcm上下文 |
src | 源gcm上下文 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于重置gcm上下文,函数原型如下:
void os_hwcrypto_gcm_reset(struct os_hwcrypto_ctx *ctx)
参数 | 说明 |
---|---|
ctx | gcm上下文 |
返回 | 说明 |
无 | 无 |
该函数用于注册gcm设备,函数原型如下:
os_err_t os_hwcrypto_gcm_register(struct os_hwcrypto_device *device, const char *name)
参数 | 说明 |
---|---|
device | hwcrypto设备指针 |
name | 设备名 |
返回 | 说明 |
OS_EOK | 注册成功 |
其他 | 失败 |
由于编程语言提供的基本数值数据类型表示的数值范围有限,不能满足较大规模的高精度数值计算,因此需要利用其他方法实现高精度数值的计算。
访问大数设备的api接口如下所示:
参数 | 说明 |
---|---|
os_hwcrypto_bignum_init() | 初始化大数对象 |
os_hwcrypto_bignum_free() | 释放大数 |
os_hwcrypto_bignum_get_len() | 获取大数长度 |
os_hwcrypto_bignum_export_bin() | 以大端模式输出二进制 |
os_hwcrypto_bignum_import_bin() | 以大端模式输入二进制 |
os_hwcrypto_bignum_add() | 大数相加 |
os_hwcrypto_bignum_sub() | 大数相减 |
os_hwcrypto_bignum_mul() | 大数相乘 |
os_hwcrypto_bignum_mulmod() | 大数乘积取模 |
os_hwcrypto_bignum_exptmod() | 大数幂运算取模 |
os_hwcrypto_bignum_register() | 注册大数设备 |
该函数用于初始化大数对象,应用程序根据大数的上下文,初始化大数对象,函数原型如下:
void os_hwcrypto_bignum_init(struct hw_bignum_mpi *n)
参数 | 说明 |
---|---|
n | 初始化大数对象 |
返回 | 说明 |
无 | 无 |
该函数用于释放大数对象,函数原型如下:
void os_hwcrypto_bignum_free(struct hw_bignum_mpi *n)
参数 | 说明 |
---|---|
n | 大数对象 |
返回 | 说明 |
无 | 无 |
该函数用于获取大数的长度,函数原型如下:
int os_hwcrypto_bignum_get_len(const struct hw_bignum_mpi *n)
参数 | 说明 |
---|---|
n | 将要获取长度的大数对象 |
返回 | 说明 |
int | 返回大数的长度 |
其他 | 失败 |
该函数根据大数的对象,以大端的模式输出二进制数,返回复制的长度,函数原型如下:
int os_hwcrypto_bignum_export_bin(struct hw_bignum_mpi *n, os_uint8_t *buf, int len)
参数 | 说明 |
---|---|
n | 大数对象 |
buf | 将要输出数据 |
len | 数据长度 |
返回 | 说明 |
int | 返回复制的长度 |
其他 | 失败 |
该函数根据大数的指针,以大端的模式输入二进制数,函数原型如下:
os_err_t os_hwcrypto_bignum_import_bin(struct hw_bignum_mpi *n, os_uint8_t *buf, int len)
参数 | 说明 |
---|---|
n | 大数对象 |
buf | 输入数据 |
len | 数据长度 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于将两个大数对象进行相加,结果赋值给第一个参数x,,函数原型如下:
os_err_t os_hwcrypto_bignum_add(struct hw_bignum_mpi *x,
const struct hw_bignum_mpi *a,
const struct hw_bignum_mpi *b)
参数 | 说明 |
---|---|
x | 输出结果 |
a | 输入数据 |
b | 输入数据 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于两个大数对象进行相减,结果赋值给第一个参数x,函数原型如下:
os_err_t os_hwcrypto_bignum_sub(struct hw_bignum_mpi *x,
const struct hw_bignum_mpi *a,
const struct hw_bignum_mpi *b)
参数 | 说明 |
---|---|
x | 输出结果 |
a | 输入数据 |
b | 输入数据 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于将两个大数对象进行相乘,结果赋值给第一个参数x,函数原型如下:
os_err_t os_hwcrypto_bignum_mul(struct hw_bignum_mpi *x,
const struct hw_bignum_mpi *a,
const struct hw_bignum_mpi *b)
参数 | 说明 |
---|---|
x | 输出结果 |
a | 输入数据 |
b | 输入数据 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于将大数对象进行乘积取模,结果赋值给第一个参数x,函数原型如下:
os_err_t os_hwcrypto_bignum_mulmod(struct hw_bignum_mpi *x,
const struct hw_bignum_mpi *a,
const struct hw_bignum_mpi *b,
const struct hw_bignum_mpi *c)
参数 | 说明 |
---|---|
x | 输出结果 |
a | 输入数据 |
b | 输入数据 |
c | 输入数据 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于将大数对象进行指数取模,结果赋值给第一个参数x,函数原型如下:
os_err_t os_hwcrypto_bignum_exptmod(struct hw_bignum_mpi *x,
const struct hw_bignum_mpi *a,
const struct hw_bignum_mpi *b,
const struct hw_bignum_mpi *c)
参数 | 说明 |
---|---|
x | 输出结果 |
a | 输入数据 |
b | 输入数据 |
c | 输入数据 |
返回 | 说明 |
OS_EOK | 成功 |
其他 | 失败 |
该函数用于注册大数设备,函数原型如下:
os_err_t os_hwcrypto_bignum_register(struct os_hwcrypto_device *device, const char *name)
参数 | 说明 |
---|---|
device | hwcrypto设备指针 |
name | 设备名 |
返回 | 说明 |
OS_EOK | 注册成功 |
其他 | 失败 |