# [rc5] Some thoughts on finding the key

Rémi Guyomarch rguyom at mail.dotcom.fr
Sat Oct 25 13:03:02 EDT 1997

```Jeff Woods wrote:
>
> At 09:45 PM 10/23/97 -0500, you wrote:
>
> >The client only compares the first 8 bytes of the decrypted text to
> >the known plaintext.  The algorithm encrypts/decrypts in multiples of
> >8 bytes, so there's no benefit to doing a smaller comparison.
>
> I thought this was RC5-32/12/??, or 32-bit wordsize.   It SHOULD decrypt in
> FOUR byte chunks, no?  Or did I miss something in reading the RFC?  Of
> course, you're the expert....

-----------------------
6.  Description of RC5 Block Cipher

This section describes the RC5 block cipher by explaining the steps
required to perform an encryption of a single input block.  The
decryption process is the reverse of these steps so it will not be
explained.  The RC5 cipher is parameterized by a version number, V, a
round count, R, and a word size in bits, W.  This description
corresponds to original version of RC5 (V = 16 decimal) and covers
any positive value for R and the values 16, 32, and 64 for W.

The inputs to this process are the expanded key table, S, the number
of rounds, R, the input buffer pointer, in, and the output buffer
pointer, out.
[...]
void RC5_Block_Encrypt (S, R, in, out)
RC5_WORD    *S;
int  R;
char    *in;
char    *out;
{
int  i;
RC5_WORD    A, B;

A  =  in & 0xFF;
A += (in & 0xFF) << 8;
A += (in & 0xFF) << 16;
A += (in & 0xFF) << 24;
B  =  in & 0xFF;
B += (in & 0xFF) << 8;
B += (in & 0xFF) << 16;
B += (in & 0xFF) << 24;

A = A + S;
B = B + S;
for (i = 1 ; i <= R ; i++) {
A = A ^ B;
A = ROTL(A, B, W) + S[2*i];
B = B ^ A;
B = ROTL(B, A, W) + S[(2*i)+1];
}

out = (A >>  0) & 0xFF;
out = (A >>  8) & 0xFF;
out = (A >> 16) & 0xFF;
out = (A >> 24) & 0xFF;
out = (B >>  0) & 0xFF;
out = (B >>  8) & 0xFF;
out = (B >> 16) & 0xFF;
out = (B >> 24) & 0xFF;
return;
} /* End of RC5_Block_Encrypt */
-----------------------

>  I was more concerned with the algorithm to
> compare those 4 or 8 byte chunks to "The " and "The unkn"....   Compares
> are usually the SLOWEST things one can do in computing other than floating
> point emulation, and since Cyberian's clients are faster than ours, I was
> thinking of this as the most likely area for optimization.   I assume the
> coders have run a profiler on this thing to find out where most of the time
> is spent?

In the main decryption routine, there's only two compares (per key), and
the second one is executed only if the first one is true. But due to the
RC5 algorithm, we must decrypt 8 bytes at a time, and not 4 bytes.

About Cyberian beeing faster that Distributed.net, you should
double-check the client speed pages of Cyberian and D.N., you will see
that we're faster on most CPUs, and we're on pair on the others.

--
Rémi

----
To unsubscribe, send email to majordomo at llamas.net with 'unsubscribe rc5' in the body.

```