非对称密码算法定义¶
-
struct akcipher_request¶
公钥密码请求
定义:
struct akcipher_request {
struct crypto_async_request base;
struct scatterlist *src;
struct scatterlist *dst;
unsigned int src_len;
unsigned int dst_len;
void *__ctx[] ;
};
成员
base
异步加密请求的通用属性
src
源数据
dst
目标数据
src_len
输入缓冲区的大小
dst_len
dst 缓冲区的大小。它需要至少与预期的结果一样大,具体取决于操作。 操作完成后,它将使用结果的实际大小进行更新。 如果发生错误,其中 dst sgl 大小不足,它将更新为操作所需的大小。
__ctx
私有上下文数据的开始
-
struct akcipher_alg¶
通用公钥密码算法
定义:
struct akcipher_alg {
int (*encrypt)(struct akcipher_request *req);
int (*decrypt)(struct akcipher_request *req);
int (*set_pub_key)(struct crypto_akcipher *tfm, const void *key, unsigned int keylen);
int (*set_priv_key)(struct crypto_akcipher *tfm, const void *key, unsigned int keylen);
unsigned int (*max_size)(struct crypto_akcipher *tfm);
int (*init)(struct crypto_akcipher *tfm);
void (*exit)(struct crypto_akcipher *tfm);
struct crypto_alg base;
};
成员
encrypt
函数执行由公钥算法定义的加密操作。 如果发生错误,其中 dst_len 不足,req->dst_len 将更新为操作所需的大小
decrypt
函数执行由公钥算法定义的解密操作。 如果发生错误,其中 dst_len 不足,req->dst_len 将更新为操作所需的大小
set_pub_key
函数调用算法特定的设置公钥函数,该函数知道如何解码和解释 BER 编码的公钥和参数
set_priv_key
函数调用算法特定的设置私钥函数,该函数知道如何解码和解释 BER 编码的私钥和参数
max_size
函数返回给定密钥所需的目标缓冲区大小。
init
初始化加密转换对象。 此函数用于初始化加密转换对象。 此函数仅在实例化时调用一次,就在转换上下文分配之后。 如果加密硬件有一些特殊的软件处理要求,此函数应检查转换的精确要求,并将任何软件回退放在适当的位置。
exit
取消初始化加密转换对象。 这是 init 的对应项,用于删除在 init 中设置的各种更改。
base
通用加密 API 算法数据结构
非对称密码 API¶
公钥密码 API 与 CRYPTO_ALG_TYPE_AKCIPHER 类型的算法一起使用(在 /proc/crypto 中列为“akcipher”类型)
-
struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type, u32 mask)¶
分配 AKCIPHER tfm 句柄
参数
const char *alg_name
是公钥算法的 cra_name / name 或 cra_driver_name / 驱动程序名称,例如“rsa”
u32 type
指定算法的类型
u32 mask
指定算法的掩码
描述
为公钥算法分配一个句柄。 返回的 struct crypto_akcipher 是公钥操作的任何后续 API 调用所需的句柄。
返回
- 成功时分配的句柄; 如果 IS_ERR() 为真
出错,
PTR_ERR()
返回错误代码。
-
void crypto_free_akcipher(struct crypto_akcipher *tfm)¶
释放 AKCIPHER tfm 句柄
参数
struct crypto_akcipher *tfm
使用
crypto_alloc_akcipher()
分配的 AKCIPHER tfm 句柄
描述
如果 tfm 是 NULL 或错误指针,此函数不执行任何操作。
-
unsigned int crypto_akcipher_maxsize(struct crypto_akcipher *tfm)¶
获取输出缓冲区的长度
参数
struct crypto_akcipher *tfm
使用
crypto_alloc_akcipher()
分配的 AKCIPHER tfm 句柄
描述
函数返回给定密钥所需的目标缓冲区大小。 函数假定密钥已在转换中设置。 如果在没有 setkey 或 setkey 失败的情况下调用此函数,您将最终得到 NULL 指针解引用。
-
int crypto_akcipher_encrypt(struct akcipher_request *req)¶
调用公钥加密操作
参数
struct akcipher_request *req
非对称密钥请求
描述
函数为给定的公钥算法调用特定的公钥加密操作
返回
成功时为零; 出错时为错误代码
-
int crypto_akcipher_decrypt(struct akcipher_request *req)¶
调用公钥解密操作
参数
struct akcipher_request *req
非对称密钥请求
描述
函数为给定的公钥算法调用特定的公钥解密操作
返回
成功时为零; 出错时为错误代码
-
int crypto_akcipher_set_pub_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen)¶
调用设置公钥操作
参数
struct crypto_akcipher *tfm
tfm 句柄
const void *key
BER 编码的公钥、算法 OID、paramlen、BER 编码的参数
unsigned int keylen
密钥的长度(不包括其他数据)
描述
函数调用算法特定的设置密钥函数,该函数知道如何解码和解释编码的密钥和参数
返回
成功时为零; 出错时为错误代码
-
int crypto_akcipher_set_priv_key(struct crypto_akcipher *tfm, const void *key, unsigned int keylen)¶
调用设置私钥操作
参数
struct crypto_akcipher *tfm
tfm 句柄
const void *key
BER 编码的私钥、算法 OID、paramlen、BER 编码的参数
unsigned int keylen
密钥的长度(不包括其他数据)
描述
函数调用算法特定的设置密钥函数,该函数知道如何解码和解释编码的密钥和参数
返回
成功时为零; 出错时为错误代码
非对称密码请求句柄¶
-
struct akcipher_request *akcipher_request_alloc(struct crypto_akcipher *tfm, gfp_t gfp)¶
分配公钥请求
参数
struct crypto_akcipher *tfm
使用
crypto_alloc_akcipher()
分配的 AKCIPHER tfm 句柄gfp_t gfp
分配标志
返回
成功时分配的句柄,出错时为 NULL。
-
void akcipher_request_free(struct akcipher_request *req)¶
清零并释放公钥请求
参数
struct akcipher_request *req
要释放的请求
-
void akcipher_request_set_callback(struct akcipher_request *req, u32 flgs, crypto_completion_t cmpl, void *data)¶
设置异步回调。
参数
struct akcipher_request *req
将为其设置回调的请求
u32 flgs
指定实例,如果操作可能积压
crypto_completion_t cmpl
将被调用的回调
void *data
调用者使用的私有数据
描述
当给定请求的异步操作完成时,将调用回调。
-
void akcipher_request_set_crypt(struct akcipher_request *req, struct scatterlist *src, struct scatterlist *dst, unsigned int src_len, unsigned int dst_len)¶
设置请求参数
参数
struct akcipher_request *req
公钥请求
struct scatterlist *src
指向输入散列表的指针
struct scatterlist *dst
指向输出散列表的指针
unsigned int src_len
要处理的 src 输入散列表的大小
unsigned int dst_len
dst 输出散列表的大小
描述
设置加密操作所需的参数