我正在尝试使用“arc4”算法来加密任意数据
来自模块的流。但我有点不知道该怎么办
接近它。实现在 <crypto/arc4.c>
$find . -type f -name '*.[ch]' -exec grep 'EXPORT_SYMBOL' {} \; | grep
'rc4'
什么也没返回。所以我猜没有外部接口(interface)
static void arc4_crypt(struct crypto_tfm *tfm, u8 *out, const u8 *in).
寄存器函数定义为
static int __init arc4_init(void)
{
return crypto_register_alg(&arc4_alg);
}
并且有一个 struct crypto_alg
的静态实例.
通过这些提示,我得出的结论是,我需要更高的级别 访问该算法的接口(interface)。
唯一与我的情况相关的功能是:
EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
来自 <crypto/api.c>
:
void *crypto_alloc_tfm(const char *alg_name,
const struct crypto_type *frontend, u32 type, u32 mask)
它返回void *
这是我首先关心的问题。
也来自<crypt/api.c>
crypto_alloc_tfm() will first attempt to locate an already loaded algorithm. If that fails and the kernel supports dynamically loadable modules, it will then attempt to load a module of the same name or alias. If that fails it will send a query to any loaded crypto manager to construct an algorithm on the fly. A refcount is grabbed on the algorithm which is then associated with the new transform.
The returned transform is of a non-determinate type. Most people should use one of the more specific allocation functions such as crypto_alloc_blkcipher.
但没有具体crypto_alloc_*
我可以找到哪个将提供arc4
算法。
第二个问题:
struct crypto_type
看起来很可怕
手动实例化。
最后,如果得到 tfm
例如,我如何使用它进行实际加密?
最佳答案
对于用户空间程序,您必须使用“CryptoDev for Linux”,它是一个内核模块,使您能够通过/dev/crypto使用加密API。请参阅http://www.logix.cz/michal/devel/cryptodev/ 。 您可以下载示例 http://www.logix.cz/michal/devel/cryptodev/cryptodev-demo1.c .
查看您的内核源文档./kernel/documentation/crypto/。
有关内核代码,请查看:http://www.linuxjournal.com/article/6451?page=0,0
它解释了当某些内核代码需要加密数据时如何使用加密API。
许多内核模块已经使用加密 API,在内核源文件中搜索单词“crypto_”,并在 stackoverflow 上搜索... how to use CryptoAPI in the linux kernel 2.6
关于c - 使用linux内核加密子系统的arc4算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11629005/