简体   繁体   English

在用户空间中使用内核功能

[英]Use Kernel functions in userspace

I am currently trying to use the functions of 我目前正在尝试使用以下功能

/usr/src/linux/crypto/aes_generic.c 

in a userspace program I want to encode allocated memory and use the ecnrypt function of the above file. 在用户空间程序中,我想对分配的内存进行编码,并使用上述文件的ecnrypt函数。

how can i use these kernel functions in a userspace program? 如何在用户空间程序中使用这些内核函数?

I tried to include the needed kernel headers in my userspace program with 我试图在用户空间程序中包含所需的内核标头

-I /usr/src/linux/include/

but i dindt get far as I get the error that asm/irqflags.h, file or directory not found. 但是我发现我找不到asm / irqflags.h,文件或目录的错误。

here's the include 这是包含

#include <asm-generic/irqflags.h> 

I do not have an asm directory and other two headers with the above stated error got included fine with asm-generic as directory 我没有一个asm目录,其他两个带有上述错误的标头已包含在asm-generic作为目录中

Thanks in advance 提前致谢

There is User-space interface for Crypto API . 加密API用户空间接口 So you can use AF_ALG interface to access kernel crypto API (after version 2.6.38 of the Linux kernel). 因此,您可以使用AF_ALG接口访问内核加密API(在Linux内核的2.6.38版本之后)。

Here are some working examples in cryptsetup source code. 这是cryptsetup源代码中的一些工作示例。

The Cryptodev-linux module allows you to access the Linux kernel cryptographic drivers from userspace via /dev/crypto . Cryptodev-linux模块允许您通过/dev/crypto从用户空间访问Linux内核加密驱动程序。 Examples can be found eg here . 例子可以在这里找到。 The advantage is you can benefit from its possibly used hardware acceleration. 好处是您可以从其可能使用的硬件加速中受益。

Otherwise you need to use one of many derivatives of the AES library to be linked against your user application. 否则,您需要使用AES库的许多派生之一来链接到您的用户应用程序。 See here for a list. 请参阅此处以获取列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM