arcfour.c

Luke Kenneth Casson Leighton lkcl at switchboard.net
Mon Feb 9 21:48:19 GMT 1998


you do realise that you have just broken ITAR restrictions regarding the
export of encryption software, and so have i?

luke

On Tue, 10 Feb 1998, Valdas Andrulis wrote:

> 
> 
> On Tue, 10 Feb 1998, Yaroslav L. Halchinsky wrote:
> 
> > Dear All!
> > Can anyone help me finding file `arcfour.c`?
> > Thank you!
> > 
> > Yaroslav Halchinsky
> > 
> 
> 
> <<<<
> <<<<<<arcfour.h>>>>>>
> <<<<
> 
> 
> /*
> 
> ARCFOUR cipher (based on a cipher posted on the Usenet in Spring-95).
> This cipher is widely believed and has been tested to be equivalent
> with the RC4 cipher from RSA Data Security, Inc.  (RC4 is a trademark
> of RSA Data Security)
> 
> */
> 
> /*
>  * $Id: arcfour.h,v 1.1.1.1 1996/02/18 21:38:11 ylo Exp $
>  * $Log: arcfour.h,v $
>  * Revision 1.1.1.1  1996/02/18 21:38:11  ylo
>  * 	Imported ssh-1.2.13.
>  *
>  * Revision 1.2  1995/07/13  01:30:25  ylo
>  * 	Added cvs log.
>  *
>  * $Endlog$
>  */
> 
> #ifndef ARCFOUR_H
> #define ARCFOUR_H
> 
> typedef struct
> {
>    unsigned int x;
>    unsigned int y;
>    unsigned char state[256];
> } ArcfourContext;
> 
> /* Initializes the context and sets the key. */
> void arcfour_init(ArcfourContext *ctx, const unsigned char *key, 
> 		  unsigned int keylen);
> 
> /* Returns the next pseudo-random byte from the arcfour (pseudo-random 
>    generator) stream. */
> unsigned int arcfour_byte(ArcfourContext *ctx);
> 
> /* Encrypts data. */
> void arcfour_encrypt(ArcfourContext *ctx, unsigned char *dest, 
> 		     const unsigned char *src, unsigned int len);
> 
> /* Decrypts data. */
> void arcfour_decrypt(ArcfourContext *ctx, unsigned char *dest, 
> 		     const unsigned char *src, unsigned int len);
> 
> #endif /* ARCFOUR_H */
> 
> <<<<
> <<<<<<arcfour.c>>>>>>
> <<<<
> 
> 
> /*
> 
> ARCFOUR cipher (based on a cipher posted on the Usenet in Spring-95).
> This cipher is widely believed and has been tested to be equivalent
> with the RC4 cipher from RSA Data Security, Inc.  (RC4 is a trademark
> of RSA Data Security)
> 
> */
> 
> /*
>  * $Id: arcfour.c,v 1.1.1.1 1996/02/18 21:38:11 ylo Exp $
>  * $Log: arcfour.c,v $
>  * Revision 1.1.1.1  1996/02/18 21:38:11  ylo
>  * 	Imported ssh-1.2.13.
>  *
>  * Revision 1.2  1995/07/13  01:29:59  ylo
>  * 	Added cvs log.
>  *
>  * $Endlog$
>  */
> 
> #include "assert.h"
> #include "arcfour.h"
> 
> /* arcfour added for SAMBA-NTDOMAIN */
> 
> void arcfour(unsigned char data[16], unsigned char data_out[16], unsigned char data_in[16])
> {
>     ArcfourContext ctx1;
>     
>     arcfour_init(&ctx1, data, 16);
>     arcfour_encrypt(&ctx1, data_out, data_in, 16);
> }
> 
> void arcfour_init(ArcfourContext *ctx, const unsigned char *key, 
> 		  unsigned int key_len)
> {
>   unsigned int t, u;
>   unsigned int keyindex;
>   unsigned int stateindex;
>   unsigned char* state;
>   unsigned int counter;
> 
>   assert(key_len > 0);
> 
>   state = &ctx->state[0];
>   ctx->x = 0;
>   ctx->y = 0;
>   for (counter = 0; counter < 256; counter++)
>     state[counter] = counter;
>   keyindex = 0;
>   stateindex = 0;
>   for (counter = 0; counter < 256; counter++)
>     {
>       t = state[counter];
>       stateindex = (stateindex + key[keyindex] + t) & 0xff;
>       u = state[stateindex];
>       state[stateindex] = t;
>       state[counter] = u;
>       if (++keyindex >= key_len)
> 	keyindex = 0;
>     }
> }
> 
> inline unsigned int arcfour_byte(ArcfourContext *ctx)
> {
>   unsigned int x;
>   unsigned int y;
>   unsigned int sx, sy;
>   unsigned char *state;
> 
>   state = ctx->state;
>   x = (ctx->x + 1) & 0xff;
>   sx = state[x];
>   y = (sx + ctx->y) & 0xff;
>   sy = state[y];
>   ctx->x = x;
>   ctx->y = y;
>   state[y] = sx;
>   state[x] = sy;
>   return state[(sx + sy) & 0xff];
> }
> 
> void arcfour_encrypt(ArcfourContext *ctx, unsigned char *dest, 
> 		     const unsigned char *src, unsigned int len)
> {
>   unsigned int i;
>   for (i = 0; i < len; i++)
>     dest[i] = src[i] ^ arcfour_byte(ctx);
> }
> 
> void arcfour_decrypt(ArcfourContext *ctx, unsigned char *dest, 
> 		 const unsigned char *src, unsigned int len)
> {
>   arcfour_encrypt(ctx, dest, src, len);
> }
> 
> 
> 
> 
> VAldas
> 
> 

<a href="mailto:lkcl at samba.anu.edu.au" > Luke Kenneth Casson Leighton  </a>
<a href="http://mailhost.cb1.com/~lkcl"> Samba and Network Development </a>
<a href="http://www.samba.co.uk"       > Samba and Network Consultancy </a>



More information about the samba-ntdom mailing list