gpt4 book ai didi

c - 使用用户空间的 Linux 加密 API 进行 RSA

转载 作者:太空宇宙 更新时间:2023-11-04 04:11:00 71 4
gpt4 key购买 nike

我正在寻找一种从用户空间调用 Linux 内核加密 API 以进行 RSA 加密/解密的方法。 RSA 函数在 linux 内核中实现。

目前,我找到了两种从用户空间调用加密 API 的方法:

不幸的是,cryptodev 不支持像 RSA 这样的非对称算法。

而且我不确定 AF_ALG 是否像 RSA 一样支持 akcipher。 cat/proc/crypto 的结果是:

...
name : rsa
driver : rsa-generic
module : kernel
priority : 100
refcnt : 1
selftest : passed
internal : no
type : akcipher

但是,我尝试绑定(bind)一个 AF_ALG 套接字:

int sockfd = socket(AF_ALG, SOCK_SEQPACKET, 0); 
struct sockaddr_alg sa = {
.salg_family = AF_ALG,
.salg_type = "akcipher",
.salg_name = "rsa"
};

绑定(bind)失败,***错误:绑定(bind)套接字失败 (2):没有这样的文件或目录

我错过了什么吗?还有其他方法可以从用户空间调用加密 API 吗?

最佳答案

来自文档:

The kernel crypto API is accessible from user space. Currently, the following ciphers are accessible:

  • Message digest including keyed message digest (HMAC, CMAC)

  • Symmetric ciphers

  • AEAD ciphers

  • Random Number Generators

这意味着 akcipher 密码系列在用户空间不可用,因此绑定(bind)到它失败并返回 ENOENT。事实上,检查 linux 内核源代码显示,没有 algif_akcipher.c,其中将实现 akcipher 系列的用户空间接口(interface)。

关于c - 使用用户空间的 Linux 加密 API 进行 RSA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57359394/

71 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com