Re: TEA

From: Tim Smith (reply_in_group_at_mouse-potato.com)
Date: 01/08/04


Date: Thu, 08 Jan 2004 07:26:03 GMT

In article <1d54b7e4.0401051125.52246de8@posting.google.com>, mike3 wrote:
> Another thing: AES is HIGHLY complicated. That's why I don't use it
> (Other people use it, and I'm sure it's good (that's why they would
> have it as a standard), but it's too complex). Another thing: is RSA

AES is not complicated. It is one of the few things I've ever found to be
easy to implement using just the standard as a reference. If you go for
clarity over speed, it is actually really simple. Here is the main loop
of a Perl implementation, for example:

    # @state is the 16 byte state array
    # @W is the key schedule
    # @aes_S is the S boxes

    foreach my $round (1..$Nr-1)
    {
        # apply the S boxes
        @state = map {$aes_S[$_]} @state;

        # do the row shifting
        @state[1,2,3,5,6,7,9,10,11,13,14,15] =
            @state[5,10,15,9,14,3,13,2,7,1,6,11];

        # do the column mixing
        splice @state, 0, 4, aes_mixcolums(@state[0,1,2,3]);
        splice @state, 4, 4, aes_mixcolums(@state[4,5,6,7]);
        splice @state, 8, 4, aes_mixcolums(@state[8,9,10,11]);
        splice @state, 12, 4, aes_mixcolums(@state[12,13,14,15]);

        # xor in the key material
        $state[$_] ^= $W[$_+16*$round] for 0..15;
    }

Here is the aes_mixcolumns functions (remember, I said this is for clarity,
not speed!):

    sub aes_mixcolums
    {
        my @in = @_;
        my @out;
        push @out, aes_fmul(2,$in[0]) ^ aes_fmul(3,$in[1]) ^ $in[2] ^ $in[3];
        push @out, $in[0] ^ aes_fmul(2,$in[1]) ^ aes_fmul(3,$in[2]) ^ $in[3];
        push @out, $in[0] ^ $in[1] ^ aes_fmul(2,$in[2]) ^ aes_fmul(3,$in[3]);
        push @out, aes_fmul(3,$in[0]) ^ $in[1] ^ $in[2] ^ aes_fmul(2,$in[3]);
        return @out;
    }

Here is the aes_fmul function that uses (clarity, not speed!):

    sub aes_fmul
    {
        my $a = shift;
        my $b = shift;
        my $c = 0;
        while ( $a != 0 )
        {
            $c ^= $b if $a & 1;
            $a >>= 1;
            $b <<= 1;
            $b ^= 0x11b if $b & 0x100;
        }
        return $c;
    }

Optimizing can make it complicated (and several optimizations are apparent
when one looks at the above), but the algorithm itself is not complicated.

-- 
--Tim Smith


Relevant Pages

  • Re: Cohens paper on byte order
    ... > Why not make manufacturer t's depiction look like this: ... between different hardware. ... and as such is NOT in the proper domain of AES. ... > for this in the AES standard. ...
    (sci.crypt)
  • Re: Cohens paper on byte order
    ... Nothing in the whole standard appears to me to try to talk ... > are external to the FIPS but which are used to test the validity of AES ... valid although obscure reasons, ...
    (sci.crypt)
  • Re: Cohens paper on byte order
    ... A normal user (a programmer working with a common ... the program of the recipient. ... transmission of the AES block. ... defined 'standard' functions for doing the conversion ...
    (sci.crypt)
  • Re: AES with SslStream
    ... I can't remember which version of Windows is supposed to get that support, ... my understanding is that the AES types are still ... Aes The Advanced Encryption Standard algorithm. ...
    (microsoft.public.dotnet.security)
  • Re: Cohens paper on byte order
    ... > Anyone who implements FIPS-197 in software using the standard exactly as ... > every other 'perfect' version of AES. ... Let there be two implementations E1 and E2. ...
    (sci.crypt)