接口设计
18 Jul 2024
Read time: 5 minute(s)
| 函数原型 | int aic_skcipher_alg_init(struct crypto_skcipher *tfm) |
| 功能说明 | 对称密钥算法的初始化函数 |
| 参数定义 | struct crypto_skcipher *tfm 算法实例指针 |
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | void aic_skcipher_alg_exit(struct crypto_skcipher *tfm) |
| 功能说明 | 对称密钥算法使用完毕,释放相关资源 |
| 参数定义 | struct crypto_skcipher *tfm 算法实例指针 |
| 返回值 | 无 |
| 注意事项 | - |
| 函数原型 | int aic_skcipher_alg_setkey(struct crypto_skcipher *tfm, const u8 *key, unsigned int keylen) |
| 功能说明 | 设置对称密钥算法的密钥 |
| 参数定义 |
|
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | int aic_skcipher_crypt(struct skcipher_request *req, unsigned long flg) |
| 功能说明 | 发起一个对称密钥算法的加解密处理的请求 |
| 参数定义 |
|
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | int aic_akcipher_rsa_alg_init(struct crypto_akcipher *tfm) |
| 功能说明 | RSA 算法初始化 |
| 参数定义 | struct crypto_akcipher *tfm 算法实例的指针 |
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | void aic_akcipher_rsa_alg_exit(struct crypto_akcipher *tfm) |
| 功能说明 | RSA 算法使用完毕,释放相关资源 |
| 参数定义 | struct crypto_akcipher *tfm 算法实例的指针 |
| 返回值 | 无 |
| 注意事项 | - |
| 函数原型 | int aic_akcipher_rsa_set_pub_key(struct crypto_akcipher *tfm, const void *key,unsigned int keylen) |
| 功能说明 | 设置 RSA 算法的公钥 |
| 参数定义 |
|
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | int aic_akcipher_rsa_set_priv_key(struct crypto_akcipher *tfm, const void *key,unsigned int keylen) |
| 功能说明 | 设置 RSA 算法的私钥 |
| 参数定义 |
|
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | int aic_akcipher_rsa_max_size(struct crypto_akcipher *tfm) |
| 功能说明 | 获取当前 RSA 算法的密钥长度 |
| 参数定义 | struct crypto_akcipher *tfm 算法实例指针 |
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | int aic_akcipher_rsa_crypt(struct akcipher_request *req, unsigned long flag) |
| 功能说明 | 发起一个 RSA 算法的加解密请求 |
| 参数定义 | struct akcipher_request *req 请求的指针 flag 算法标记 |
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | int aic_hash_alg_init(struct crypto_tfm *tfm) |
| 功能说明 | HASH 算法的初始化 |
| 参数定义 | struct crypto_tfm *tfm 算法实例的指针 |
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | void aic_hash_alg_exit(struct crypto_tfm *tfm) |
| 功能说明 | HASH 算法使用完毕,释放相关资源 |
| 参数定义 | struct crypto_tfm *tfm 算法实例的指针 |
| 返回值 | 无 |
| 注意事项 | - |
| 函数原型 | int aic_hash_init(struct ahash_request *req) |
| 功能说明 | 初始化一个 HASH 运算的操作 |
| 参数定义 | struct ahash_request *req HASH 运算的请求,具体所使用的算法,根据消息摘要的大小决定 |
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | int aic_hash_update(struct ahash_request *req) |
| 功能说明 | 更新一笔 HASH 运算的数据,用于数据分多次输入的场景 |
| 参数定义 | struct ahash_request *req HASH 运算的请求,数据信息保存在该结构体中 |
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | int aic_hash_final(struct ahash_request *req) |
| 功能说明 | HASH 运算的数据输入结束,获取结果 |
| 参数定义 | struct ahash_request *req HASH 运算的请求,本请求不带数据,只获取结果 |
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | int aic_hash_finup(struct ahash_request *req) |
| 功能说明 | HASH 运算的最后一笔数据,并且获取结果 |
| 参数定义 | struct ahash_request *req HASH 运算的请求,本请求带最后一笔数据,并获取结果 |
| 返回值 |
|
| 注意事项 | - |
| 函数原型 | int aic_hash_digest(struct ahash_request *req) |
| 功能说明 | 针对一笔数据,完成 init 和 finup 的 HASH 运算操作,并获取结果 |
| 参数定义 | struct ahash_request *req HASH 运算的请求,本请求带最后一笔数据,并获取结果 |
| 返回值 |
|
| 注意事项 | - |
Driver 层接口设计
| 函数原型 | rt_err_t drv_aes_init(struct rt_hwcrypto_ctx *ctx) |
|---|---|
| 功能说明 | AES 算法初始化 |
| 参数定义 | struct rt_hwcrypto_ctx *ctx - 上下文实例指针 |
| 返回值 | 0,初始化成功。其它,初始化失败 |
| 注意事项 | - |
| 函数原型 | s32 aes_ecb_crypto(u8 *key, u8 keylen, u8 dir, u8 *in, u8 *out, u32 len) |
|---|---|
| 功能说明 | AES ECB 加解密实现 |
| 参数定义 |
|
| 返回值 | 0,加解密成功。其它,加解密失败。 |
| 注意事项 | - |
| 函数原型 | s32 aes_cbc_crypto(u8 *key, u8 keylen, u8 dir, u8 *iv, u8 *in, u8 *out, u32 len) |
|---|---|
| 功能说明 | AES CBC 加解密实现 |
| 参数定义 |
|
| 返回值 | 0,加解密成功。其它,加解密失败。 |
| 注意事项 | - |
| 函数原型 | rt_err_t drv_sha_init(struct rt_hwcrypto_ctx *ctx) |
|---|---|
| 功能说明 | SHA 算法初始化 |
| 参数定义 | struct rt_hwcrypto_ctx *ctx - 上下文实例指针 |
| 返回值 | 0,初始化成功。其它,初始化失败 |
| 注意事项 | - |
| 函数原型 | rt_err_t drv_sha_start(struct rt_hwcrypto_ctx *ctx) |
|---|---|
| 功能说明 | SHA 算法启动 |
| 参数定义 | struct rt_hwcrypto_ctx *ctx - 上下文实例指针 |
| 返回值 | 0,初始化成功。其它,初始化失败 |
| 注意事项 | - |
| 函数原型 | rt_err_t drv_sha_update(aic_sha_context_t *context, const void *input, uint32_t size) |
|---|---|
| 功能说明 | 更新一笔 SHA 算法数据 |
| 参数定义 |
|
| 返回值 | 0,运算成功。其它,运算失败 |
| 注意事项 | - |
| 函数原型 | rt_err_t drv_sha_finish(struct hwcrypto_hash *ctx, void *output, rt_size_t *out_size) |
|---|---|
| 功能说明 | SHA 算法运算结束,获取结果 |
| 参数定义 |
|
| 返回值 | 0,获取结果成功。其它,获取结果失败 |
| 注意事项 | - |
HAL 层接口设计
HAL 层的函数接口声明存放在 hal_ce.h
中,主要接口有:
s32 hal_crypto_init(void); s32 hal_crypto_deinit(void); void hal_crypto_irq_handler(); s32 hal_crypto_start_symm(struct crypto_task *task); s32 hal_crypto_start_asym(struct crypto_task *task); s32 hal_crypto_start_hash(struct crypto_task *task); u32 hal_crypto_poll_finish(u32 alg_unit); void hal_crypto_pending_clear(u32 alg_unit); u32 hal_crypto_get_err(u32 alg_unit); s32 hal_crypto_bignum_byteswap(u8 *bn, u32 len); s32 hal_crypto_bignum_le2be(u8 *src, u32 slen, u8 *dst, u32 dlen); s32 hal_crypto_bignum_be2le(u8 *src, u32 slen, u8 *dst, u32 dlen);
