Re: TEA
From: Tim Smith (reply_in_group_at_mouse-potato.com)
Date: 01/08/04
- Next message: Roger Schlafly: "Re: ANNOUNCE: SHA-224 in Digest::SHA"
- Previous message: Paul Rubin: "Re: ANNOUNCE: SHA-224 in Digest::SHA"
- In reply to: mike3: "Re: TEA"
- Next in thread: Jean-Luc Cooke: "Re: TEA"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
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
- Next message: Roger Schlafly: "Re: ANNOUNCE: SHA-224 in Digest::SHA"
- Previous message: Paul Rubin: "Re: ANNOUNCE: SHA-224 in Digest::SHA"
- In reply to: mike3: "Re: TEA"
- Next in thread: Jean-Luc Cooke: "Re: TEA"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|