accessing arcfour sboxes

Simon Josefsson jas@extundo.com
Wed, 24 Sep 2003 00:48:18 +0200


I have an application that uses arcfour, and need to be able to
extract (and set) the (sbox, i, j) tuple.  I tried to implement this
in libgcrypt, and noticed the cipher-specific _ctl functions has been
removed, so it does not seem possible to reach each low-level cipher
via gcry_cipher_ctl() any longer, which I miss.  The cipher struct now
looks like:

/* Module specification structure for ciphers.  */
typedef struct gcry_cipher_spec
{
  const char *name;
  const char **aliases;
  gcry_cipher_oid_spec_t *oids;
  size_t blocksize;
  size_t keylen;
  size_t contextsize;
  gcry_cipher_setkey_t setkey;
  gcry_cipher_encrypt_t encrypt;
  gcry_cipher_decrypt_t decrypt;
  gcry_cipher_stencrypt_t stencrypt;
  gcry_cipher_stdecrypt_t stdecrypt;
} gcry_cipher_spec_t;

Where the two last entries correspond to stream en/de-cryption (btw,
why does a stream cipher need different encryption/decryption calls?).

Would it be possible to add a 'gcry_cipher_ctl_t ctl', or something,
to that struct, and in the arcfour.c define this to a function that
extract/set the (sbox, i, j)?  The gcry_cipher_ctl_t function should
be modeled after gcry_cipher_ctl():

/* Perform various operations on the cipher object H. */
gcry_error_t gcry_cipher_ctl (gcry_cipher_hd_t h, int cmd, void *buffer,
			     size_t buflen);

So it is able to support various low-level cipher specific stuff.

What do you think of the general idea?

Is there any other way to communicate, from the application, directly
to each low-level cipher object in libgcrypt, that I missed?

Thanks.