在 Linux 内核中对文件使用加密 API

发布于 2024-12-14 09:13:45 字数 637 浏览 1 评论 0原文

我一直在尝试在linux内核中使用加密API,我需要做的是sha一个正在打开的文件。我正在使用 LSM 来捕获这些文件的打开情况。

到目前为止我所拥有的是使用创建一个 struct crypto_shash

struct crypto_shash *tfm;
struct shash_desc desc;
tfm = crypto_alloc_shash("sha1", 0, CRYPTO_ALG_ASYNC);

,我假设我应该在使用之后初始化它,

desc.tfm = tfm;
desc.flags = 0;

err = crypto_shash_init(&desc);

一切正常,但后来我想使用

crypto_shash_digest(&desc, ??, ??, sha_hash);

并且我意识到它需要一个分散列表作为它的第二个参数和长度该分散列表作为第三个参数。我不明白的是我应该如何将文件加载到分散列表中以便将其提供给加密系统。

我已经阅读了相当多的内容,但到目前为止还无法找到有关将文件内容加载到分散列表中的任何详细信息。因此,任何正确方向的指示都将不胜感激。

谢谢

I have been trying to use the crypto api in the linux kernel, what i need to do is sha a file that is being opened. I am using the LSM to catch those file opens.

What I have so far is creating a struct crypto_shash using

struct crypto_shash *tfm;
struct shash_desc desc;
tfm = crypto_alloc_shash("sha1", 0, CRYPTO_ALG_ASYNC);

and i assume i am supposed to init it after that using

desc.tfm = tfm;
desc.flags = 0;

err = crypto_shash_init(&desc);

that all works fine, but then i want to use

crypto_shash_digest(&desc, ??, ??, sha_hash);

and i realize that it expects a scatterlist as its second argument and the length of that scatter list as the third argument. What i cant figure out is how I am supposed to load the file into a scatterlist in order to give it to the crypto system.

I have done quite a bit of reading but have thus far been unable to find any details about getting a files contents loaded into a scatterlist. So any pointers in the right direction would be appreciated.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余生共白头 2024-12-21 09:13:45

我前段时间也做过类似的事情。唯一的区别是我计算了 ELF 部分的哈希值。

  1. 也许你的 desc.flags 应该是 CRYPTO_TFM_REQ_MAY_SLEEP ,直到你有充分的理由阻止加密操作被阻塞。
  2. 您确定没有将 crypto_shash_digestcrypto_hash_digest?因为 crypto_*s*hash_digest() 接收一个指向数据的指针作为其第三个参数。如果这不适合你,那么你在谈论哪个 linux kenrel 版本?

I have done something similar some time ago. The only difference is that I calculated a hash of ELF sections.

  1. Probably your desc.flags should be CRYPTO_TFM_REQ_MAY_SLEEP until you have really good reason to prevent crypto operation from blocking.
  2. Are you sure you didn't confuse crypto_shash_digest with crypto_hash_digest? Because crypto_*s*hash_digest() receives a pointer to data as its 3rd argument. If it's not true for you, what linux kenrel version are you talking about?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文