using arc4 algorithm of linux kernel crypto subsystem
Arif Hossain
aftnix at gmail.com
Tue Jul 24 06:18:43 EDT 2012
Hi,
I'm trying to use the "arc4" algorithm to to encrypt a arbitrary data
stream from a module. But i'm a little clueless about how should i
approach it.the implementation is in <crypto/arc4.c>
$find . -type f -name '*.[ch]' -exec grep 'EXPORT_SYMBOL' {} \; | grep
'rc4'
returned nothing. So i guess there is no external interface to
static void arc4_crypt(struct crypto_tfm *tfm, u8 *out, const u8 *in).
The register function is defined as
static int __init arc4_init(void)
{
return crypto_register_alg(&arc4_alg);
}
And there is a static instance of struct crypto_alg.
By these hints, I've come to conclusion that, I need a higher level
interface to access this algorithm.
Only function which seems relevant in my case is :
EXPORT_SYMBOL_GPL(crypto_alloc_tfm);
from <crypto/api.c> :
void *crypto_alloc_tfm(const char *alg_name,
const struct crypto_type *frontend, u32 type, u32 mask)
it returns void * which is my first concern.
And also from <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.
But no specific crypto_alloc_* i could find which will provide arc4
algorithm.
Second concern:
struct crypto_type in <include/crypto/algapi.h> is looking horrendous to
instantiate by hand.
And lastly if get a tfm instance, how i use it to do actual encryption?
More information about the Kernelnewbies
mailing list