在 Linux 内核中对文件使用加密 API
我一直在尝试在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我前段时间也做过类似的事情。唯一的区别是我计算了 ELF 部分的哈希值。
I have done something similar some time ago. The only difference is that I calculated a hash of ELF sections.