Mailing List Archive

[PATCH] RSA RC4
I wrote a implementation of RSA RC4 for the libgcrypt. I hope the
implementation is usefull and bug free :)

There are some security problems with RSA RC4
http://www.wisdom.weizmann.ac.il/~itsik/RC4/rc4.html

But RSA RC4 (was) used in a lot of software!

BTW.
What do you think about a Modul for IBM MARS? It was an AES Final Candidate
and after the XSL problem of Rijndael it could be interessting to use it

cipher/ChangeLog

2002-12-06 Ruediger Sonderfeld <cplusplushelp@gmx.net>

* rc4.c: New
* rc4.h: New
* Makefile.am (EXTRA_PROGRAMS): Add rc4.c and rc4.h
* cipher.c (setup_cipher_table): load rc4 modul

src/ChangeLog

2002-12-06 Ruediger Sonderfeld <cplusplushelp@gmx.net>

* gcrypt.h: Added rc4 number

Index: cipher/Makefile.am
===================================================================
RCS file: /cvs/gnupg/libgcrypt/cipher/Makefile.am,v
retrieving revision 1.67
diff -r1.67 Makefile.am
70c70,71
< construct.c
---
> construct.c \
> rc4.c rc4.h
Index: cipher/cipher.c
===================================================================
RCS file: /cvs/gnupg/libgcrypt/cipher/cipher.c,v
retrieving revision 1.47
diff -r1.47 cipher.c
29a30
> #include "rc4.h"
37c38,39
< #define TABLE_SIZE 14
---
> #define TABLE_SIZE 15
133c135,146
< i = 0;
---
> i = 0;
> cipher_table[i].algo = GCRY_CIPHER_RC4;
> cipher_table[i].name = _gcry_rc4_get_info( cipher_table[i].algo,
> &cipher_table[i].keylen,
> &cipher_table[i].blocksize,
> &cipher_table[i].contextsize,
> &cipher_table[i].setkey,
> &cipher_table[i].stencrypt,
> &cipher_table[i].stdecrypt );
> if( !cipher_table[i].name )
> BUG();
> i++;
Index: src/gcrypt.h
===================================================================
RCS file: /cvs/gnupg/libgcrypt/src/gcrypt.h,v
retrieving revision 1.64
diff -r1.64 gcrypt.h
40c40
< #define GCRYPT_VERSION "1.1.10"
---
> #define GCRYPT_VERSION "1.1.7"
485c485,487
< GCRY_CIPHER_DES = 302
---
> GCRY_CIPHER_DES = 302,
> GCRY_CIPHER_RC4 = 303

rc4.c
/* rc4.h - RSA Security RC4 (Ron's Code #4)
* Copyright (C) 2002 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
* Libgcrypt is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* Libgcrypt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
* This implementation is based on the RC4 Description from
* http://www.ncat.edu/~grogans/main.htm
*
* It is written by Ruediger Sonderfeld <cplusplushelp@gmx.net>
*/

#include <config.h>
#include <string.h>
#include "types.h"
#include "g10lib.h"
#include "dynload.h"
#include "rc4.h"

#define CIPHER_ALGO_RC4 303

typedef struct {
byte sbox[256];
} RC4_context;

static void
burn_stack (int bytes)
{
char buf[64];

memset (buf, 0, sizeof buf);
bytes -= sizeof buf;
if (bytes > 0)
burn_stack (bytes);
}

static void
swap_bytes (byte *a, byte *b)
{
byte tmp=*b;
*b=*a;
*a=tmp;
}

/* Perform the key setup. */
static int
do_rc4_setkey (RC4_context *ctx, const byte *key, const unsigned keylen)
{
u32 i,j; /*iterators*/
byte k[256];/*key*/
for(i=0; i<=255 ; ++i) {
ctx->sbox[i]=i; /*fill sbox*/
k[i]=key[i%keylen]; /*fill key*/
}

for(i=0; i<=255 ; ++i) {
j = ( ctx->sbox[i] + k[i] + j ) % 256;
swap_bytes(ctx->sbox+i,ctx->sbox+j);
}
}

static int
rc4_setkey (RC4_context *ctx, const byte *key, unsigned int keylen)
{
int rc = do_rc4_setkey (ctx, key, keylen);
burn_stack (/*[TODO] ...*/1);
return rc;
}

static void
do_rc4_stcrypt (const RC4_context *ctx, byte *out, const byte *in, unsigned
int length)
{
u32 i=0,j=0,l,t=0; /*iterators*/
byte sbox[256];
memcpy(sbox,ctx->sbox,256);
for(; t<length ; ++t) {
i=(i + 1) % 256;
j=(j + sbox[i]) % 256;
swap_bytes(sbox+i,sbox+j);
l=(ctx->sbox[i] + ctx->sbox[j]) % 256;
out[t] = in[t] ^ ctx->sbox[l];
}
}

static void
rc4_stcrypt (const RC4_context *ctx, byte *out, const byte *in, unsigned int
length)
{
do_rc4_stcrypt (ctx, out, in, length);
burn_stack (/*[TODO] ...*/1);
}

const char *
_gcry_rc4_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize,
int (**r_setkey)( void *c, byte *key, unsigned keylen ),
void (**r_stencrypt)( void *c, byte *outbuf, byte *inbuf,
unsigned ),
void (**r_stdecrypt)( void *c, byte *outbuf, byte *inbuf,
unsigned )
)
{
*keylen = 2048; /*max!*/
*blocksize = 1;
*contextsize = sizeof(RC4_context);

*(int (**)(RC4_context*, const byte*, unsigned))r_setkey
= rc4_setkey;
*(void (**)(const RC4_context*, byte*, const byte*, unsigned))r_stencrypt
= rc4_stcrypt;
*(void (**)(const RC4_context*, byte*, const byte*, unsigned))r_stdecrypt
= rc4_stcrypt;

if(algo==CIPHER_ALGO_RC4)
return "RC4";
return NULL;
}

rc4.h
/* rc4.h - RSA Security RC4 (Ron's Code #4)
* Copyright (C) 2002 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
* Libgcrypt is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* Libgcrypt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
* This implementation is based on the RC4 Description from
* http://www.ncat.edu/~grogans/main.htm
*
* It is written by Ruediger Sonderfeld <cplusplushelp@gmx.net>
*/
#ifndef G10_RC4_H
#define G10_RC4_H

#include "types.h"

const char *
_gcry_rc4_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize,
int (**setkeyf)( void *c, byte *key, unsigned keylen ),
void (**stencryptf)( void *c, byte *outbuf, byte *inbuf,
unsigned ),
void (**stdecryptf)( void *c, byte *outbuf, byte *inbuf,
unsigned )
);

#endif /*G10_RC4_H*/
Re: [PATCH] RSA RC4 [ In reply to ]
ups, the rc4.c code was a little bit old here is the newest version :)

I didn't know if I'm allowed to use inline because it is a very new C feature
(but very useful)

/* rc4.c - RSA Security RC4 (Ron's Code #4)
* Copyright (C) 2002 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
* Libgcrypt is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser general Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* Libgcrypt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
* This implementation is based on the RC4 Description from
* http://www.ncat.edu/~grogans/main.htm
*
* It is written by Ruediger Sonderfeld <cplusplushelp@gmx.net>
*/

#include <config.h>
#include <string.h>
#include "types.h"
#include "g10lib.h"
#include "dynload.h"
#include "rc4.h"

#define CIPHER_ALGO_RC4 303

static void
burn_stack (int bytes)
{
char buf[64];

memset (buf, 0, sizeof buf);
bytes -= sizeof buf;
if (bytes > 0)
burn_stack (bytes);
}

static /*inline*/ void
swap_bytes (byte *a, byte *b)
{
byte tmp=*b;
*b=*a;
*a=tmp;
}

/* Perform the key setup. */
static int
do_rc4_setkey (RC4_context *ctx, const byte *key, const unsigned keylen)
{
u32 i,j; /*iterators*/
byte k[256];/*key*/
for(i=0; i<=255 ; ++i) {
ctx->sbox[i]=i; /*fill sbox*/
k[i]=key[i%keylen]; /*fill key*/
}

for(i=0; i<=255 ; ++i) {
j = ( ctx->sbox[i] + k[i] + j ) % 256;
swap_bytes(ctx->sbox+i,ctx->sbox+j);
}
return 0;
}

static int
rc4_setkey (RC4_context *ctx, const byte *key, unsigned int keylen)
{
int rc = do_rc4_setkey (ctx, key, keylen);
burn_stack (2*sizeof(u32)+256);
return rc;
}

static void
do_rc4_stcrypt (const RC4_context *ctx, byte *out, const byte *in, unsigned
int length)
{
u32 i=0,j=0,l,t=0; /*iterators*/
byte sbox[256];
memcpy(sbox,ctx->sbox,256);
for(; t<length ; ++t) {
i=(i + 1) % 256;
j=(j + sbox[i]) % 256;
swap_bytes(sbox+i,sbox+j);
l=(ctx->sbox[i] + ctx->sbox[j]) % 256;
out[t] = in[t] ^ ctx->sbox[l];
}
}

static void
rc4_stcrypt (const RC4_context *ctx, byte *out, const byte *in, unsigned int
length)
{
do_rc4_stcrypt (ctx, out, in, length);
burn_stack (256+4*sizeof(u32));
}

const char *
_gcry_rc4_get_info( int algo, size_t *keylen,
size_t *blocksize, size_t *contextsize,
int (**r_setkey)( void *c, byte *key, unsigned keylen ),
void (**r_stencrypt)( void *c, byte *outbuf, byte *inbuf,
unsigned ),
void (**r_stdecrypt)( void *c, byte *outbuf, byte *inbuf,
unsigned )
)
{
*keylen = 2048; /*max!*/
*blocksize = 1;
*contextsize = sizeof(RC4_context);

*(int (**)(RC4_context*, const byte*, unsigned))r_setkey
= rc4_setkey;
*(void (**)(const RC4_context*, byte*, const byte*, unsigned))r_stencrypt
= rc4_stcrypt;
*(void (**)(const RC4_context*, byte*, const byte*, unsigned))r_stdecrypt
= rc4_stcrypt;

if(algo==CIPHER_ALGO_RC4)
return "RC4";
return NULL;
}
Re: [PATCH] RSA RC4 [ In reply to ]
On Fri Dec 06 2002; 23:04, Rüdiger Sonderfeld wrote:

> I wrote a implementation of RSA RC4 for the libgcrypt. I hope the
> implementation is usefull and bug free :)

What's wrong with arcfour.c which is already part of Libgcrypt?


Timo

--
"Ich habe das Interesse an meiner eigenen Frage verloren." -- John Cage
Re: [PATCH] RSA RC4 [ In reply to ]
On Saturday, 7. December 2002 00:16, you wrote:
> On Fri Dec 06 2002; 23:04, Rüdiger Sonderfeld wrote:
> > I wrote a implementation of RSA RC4 for the libgcrypt. I hope the
> > implementation is usefull and bug free :)
>
> What's wrong with arcfour.c which is already part of Libgcrypt?

ups :) I thought arcfour is a different algo :)

okay thx
Re: [PATCH] RSA RC4 [ In reply to ]
On Sat, Dec 07, 2002 at 12:23:26AM +0100, Rüdiger Sonderfeld wrote:
> On Saturday, 7. December 2002 00:16, you wrote:
> > On Fri Dec 06 2002; 23:04, Rüdiger Sonderfeld wrote:
> > > I wrote a implementation of RSA RC4 for the libgcrypt. I hope the
> > > implementation is usefull and bug free :)

> > What's wrong with arcfour.c which is already part of Libgcrypt?

> ups :) I thought arcfour is a different algo :)

The "hint" is in the name...

It's "A"RC4... Alleged RC4. From the time is was alleged to
have been leaked/stolen/reimplimented. It was alleged because it wasn't
their code but it did 100% of what their code did. If it walks like a
duck and it quacks like a duck and it smells like a duck it must be
an alleged duck (when intellectual property gets involved).

:-)

> okay thx

> _______________________________________________
> Gcrypt-devel mailing list
> Gcrypt-devel@gnupg.org
> http://lists.gnupg.org/mailman/listinfo/gcrypt-devel

Mike
--
Michael H. Warfield | (770) 985-6132 | mhw@WittsEnd.com
/\/\|=mhw=|\/\/ | (678) 463-0932 | http://www.wittsend.com/mhw/
NIC whois: MHW9 | An optimist believes we live in the best of all
PGP Key: 0xDF1DD471 | possible worlds. A pessimist is sure of it!
Re: [PATCH] RSA RC4 [ In reply to ]
"Michael H. Warfield" <mhw@wittsend.com> writes:

> On Sat, Dec 07, 2002 at 12:23:26AM +0100, Rüdiger Sonderfeld wrote:
>> On Saturday, 7. December 2002 00:16, you wrote:
>> > On Fri Dec 06 2002; 23:04, Rüdiger Sonderfeld wrote:
>> > > I wrote a implementation of RSA RC4 for the libgcrypt. I hope the
>> > > implementation is usefull and bug free :)
>
>> > What's wrong with arcfour.c which is already part of Libgcrypt?
>
>> ups :) I thought arcfour is a different algo :)
>
> The "hint" is in the name...
>
> It's "A"RC4... Alleged RC4. From the time is was alleged to
> have been leaked/stolen/reimplimented. It was alleged because it wasn't
> their code but it did 100% of what their code did. If it walks like a
> duck and it quacks like a duck and it smells like a duck it must be
> an alleged duck (when intellectual property gets involved).

I can't help but feeling that this is silly. At least adding a
comment, or even better an enum type mapping RC4 to ARCFOUR would
prevent the confusion.
Re: [PATCH] RSA RC4 [ In reply to ]
On Wed, Dec 11, 2002 at 04:40:20AM +0100, Simon Josefsson wrote:
> "Michael H. Warfield" <mhw@wittsend.com> writes:

> > On Sat, Dec 07, 2002 at 12:23:26AM +0100, Rüdiger Sonderfeld wrote:
> >> On Saturday, 7. December 2002 00:16, you wrote:
> >> > On Fri Dec 06 2002; 23:04, Rüdiger Sonderfeld wrote:
> >> > > I wrote a implementation of RSA RC4 for the libgcrypt. I hope the
> >> > > implementation is usefull and bug free :)
> >
> >> > What's wrong with arcfour.c which is already part of Libgcrypt?
> >
> >> ups :) I thought arcfour is a different algo :)
> >
> > The "hint" is in the name...
> >
> > It's "A"RC4... Alleged RC4. From the time is was alleged to
> > have been leaked/stolen/reimplimented. It was alleged because it wasn't
> > their code but it did 100% of what their code did. If it walks like a
> > duck and it quacks like a duck and it smells like a duck it must be
> > an alleged duck (when intellectual property gets involved).

> I can't help but feeling that this is silly. At least adding a
> comment, or even better an enum type mapping RC4 to ARCFOUR would
> prevent the confusion.

Probably true. The RC4 vs ARC4 vs ARCFOUR debate goes back to
the early appearance of a public "RC4" and RSA's claim that it really
wasn't RC4 and then their claim that is was copyrighted and then their
claim that it was trade secret (or maybe it was the other way around).
Somewhere in there, someone changed the name to ARC4, I think, to avoid
some claims of Trademark infringement. Yup, it's caused a lot of
confusion for a lot of people. Yup, much of it could have been avoided.
I don't know about the "an enum type mapping RC4 to ARCFOUR" but
when intellectual property rights issues get involved if things weren't
so pathetic, I would agree that they would be silly. At least the
damn thing wasn't patented like IDEA.

Mike
--
Michael H. Warfield | (770) 985-6132 | mhw@WittsEnd.com
/\/\|=mhw=|\/\/ | (678) 463-0932 | http://www.wittsend.com/mhw/
NIC whois: MHW9 | An optimist believes we live in the best of all
PGP Key: 0xDF1DD471 | possible worlds. A pessimist is sure of it!
Re: [PATCH] RSA RC4 [ In reply to ]
On Wednesday, 11. December 2002 14:49, you wrote:
> Probably true. The RC4 vs ARC4 vs ARCFOUR debate goes back to
> the early appearance of a public "RC4" and RSA's claim that it really
> wasn't RC4 and then their claim that is was copyrighted and then their
> claim that it was trade secret (or maybe it was the other way around).
> Somewhere in there, someone changed the name to ARC4, I think, to avoid
> some claims of Trademark infringement. Yup, it's caused a lot of
> confusion for a lot of people. Yup, much of it could have been avoided.
> I don't know about the "an enum type mapping RC4 to ARCFOUR" but
> when intellectual property rights issues get involved if things weren't
> so pathetic, I would agree that they would be silly. At least the
> damn thing wasn't patented like IDEA.

I don't think that RSA will blame the libgcrypt developers for using the name
RC4.

But what is about a IBM MARS Modul for the libgcrypt? I wrote a modul (at the
moment I'm debugging it and checking the implementation)
Re: [PATCH] RSA RC4 [ In reply to ]
Rüdiger Sonderfeld <cplusplushelp@gmx.net> writes:

> I don't think that RSA will blame the libgcrypt developers for using
> the name RC4.

It's their trademark, so they have every right to do so.

Better play safe, IMHO.
Re: [PATCH] RSA RC4 [ In reply to ]
Florian Weimer <fw@deneb.enyo.de> writes:

> Rüdiger Sonderfeld <cplusplushelp@gmx.net> writes:
>
>> I don't think that RSA will blame the libgcrypt developers for using
>> the name RC4.
>
> It's their trademark, so they have every right to do so.

Libgcrypt might call it "a RC4 implementation", which at least
according to <http://www.gnu.org/prep/standards_5.html> would be
legal.
Re: [PATCH] RSA RC4 [ In reply to ]
On Wed, 11 Dec 2002 22:05:46 +0100, Rüdiger Sonderfeld said:

> But what is about a IBM MARS Modul for the libgcrypt? I wrote a modul (at the

MARS is patented and I see no use for it. BTW, we require legal
papers before we can put any substantial amount of your code into
libgcrypt.


Salam-Shalom,

Werner
Re: [PATCH] RSA RC4 [ In reply to ]
Simon Josefsson <jas@extundo.com> writes:

>>> I don't think that RSA will blame the libgcrypt developers for using
>>> the name RC4.
>>
>> It's their trademark, so they have every right to do so.
>
> Libgcrypt might call it "a RC4 implementation", which at least
> according to <http://www.gnu.org/prep/standards_5.html> would be
> legal.

In this case, I'm not sure. RC4 is probably still considered a trade
secret by RSA (the company), and I don't think you can easily claim
that your code implements RC4.

Of course, in the meantime, RSA indirectly admitted that the code
which was posted to Usenet a couple of years ago. Recently, Papers
started talking about "the RC4 algorithm" instead of "the alleged RC4
algorithm", but I don't think much has changed, at least formally.
Re: [PATCH] RSA RC4 [ In reply to ]
On Thu, 12 Dec 2002 12:37:00 +0100, Florian Weimer said:

> In this case, I'm not sure. RC4 is probably still considered a trade
> secret by RSA (the company), and I don't think you can easily claim
> that your code implements RC4.

There is another reason that the name arcfour is sufficient: Other
free tools use that name (e.g. ssh used to have rc4 support, still?)
and one can expect that someone going to use a cryptographic algorithm
with difficile properties should know about the name and trademark
issue.


Salam-Shalom,

Werner
Re: [PATCH] RSA RC4 [ In reply to ]
Hi,

On Thu, Dec 12, 2002 at 02:45:03PM +0100, Werner Koch wrote:
> > In this case, I'm not sure. RC4 is probably still considered a trade
> > secret by RSA (the company), and I don't think you can easily claim
> > that your code implements RC4.
>
> There is another reason that the name arcfour is sufficient: Other
> free tools use that name (e.g. ssh used to have rc4 support, still?)
> ...

the ssh protocol version 2 supports Arcfour and the openssh implementation
provides Arcfour among 3DES, CAST128 and Blowfish.

Cheers,
Hans
--
pub 1024D/513AEFD9 1999-12-18 Hans-Joerg Hoexer
<Hans-Joerg.Hoexer@yerbouti.franken.de>
Key fingerprint = 83D2 436A 0D3C 34A9 E0FF 4C33 35F6 617C 513A EFD9
Re: [PATCH] RSA RC4 [ In reply to ]
On Thursday, 12. December 2002 10:57, you wrote:
> MARS is patented and I see no use for it. BTW, we require legal
> papers before we can put any substantial amount of your code into
> libgcrypt.

MARS is now available worldwide under a royalty-free license from Tivoli.

http://www.research.ibm.com/security/mars.html
http://www.tivoli.com/news/press/pressreleases/en/2000/mars.html

IBM MARS is AFAIK also available in the Linux Kernel. I will ask IBM for any
detailed information.
Re: [PATCH] RSA RC4 [ In reply to ]
Rüdiger Sonderfeld <cplusplushelp@gmx.net> writes:

> On Thursday, 12. December 2002 10:57, you wrote:
>> MARS is patented and I see no use for it. BTW, we require legal
>> papers before we can put any substantial amount of your code into
>> libgcrypt.
>
> MARS is now available worldwide under a royalty-free license from Tivoli.
>
> http://www.research.ibm.com/security/mars.html
> http://www.tivoli.com/news/press/pressreleases/en/2000/mars.html

Could you post a link to the license, please?
Re: [PATCH] RSA RC4 [ In reply to ]
On Thursday, 12. December 2002 18:51, you wrote:
> Could you post a link to the license, please?

IBM didn't send me an answer to my requests about MARS

:(