0

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 is looking horrendous to instantiate by hand.

And lastly if get a tfm instance, how i use it to do actual encryption?

Aftnix
  • 4,461
  • 6
  • 26
  • 43

1 Answers1

0

For userspace programs you have to use 'CryptoDev for Linux' which is a kernel module that enable you to use the crypto API through /dev/crypto. See http://www.logix.cz/michal/devel/cryptodev/. you can download an example http://www.logix.cz/michal/devel/cryptodev/cryptodev-demo1.c.

Have a look into your kernel source documentation ./kernel/documentation/crypto/.

For kernel code, have a look there : http://www.linuxjournal.com/article/6451?page=0,0

It explains how to use the crypto api when some kernel code needs to encrypt data.

Many kernel modules already use the crypto API, search into your kernel source file for the word "crypto_" and also search on stackoverflow... how to use CryptoAPI in the linux kernel 2.6

Community
  • 1
  • 1
A.G.
  • 1,279
  • 1
  • 11
  • 28
  • Mine is not a user space program. Its a kernel module. The linux journal link is pretty outdated. Its from 2003. – Aftnix Jul 24 '12 at 13:48
  • answers given there talks about digests(The question was about md5/sha1). I'm looking for how i can initiate a rc4 stream cipher.I'm looking through "encryptfs" code. lets see what i can find.. – Aftnix Jul 24 '12 at 14:28