/*
 *  FIPS-197 compliant AES implementation
 *
 *  Copyright (C) 2001-2003  Christophe Devine
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU 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
 */

#include "aes.h"

#include <string.h>
#include <stdio.h>

/*
 * Rijndael Monte Carlo Test: ECB mode
 * source: NIST - rijndael-vals.zip
 */

static void xor(unsigned char *key2, unsigned char *key1, unsigned char *xorval)
{
	int i;
	for (i = 0; i < 32; i++)
		key2[i] = key1[i] ^ xorval[i];
}

int main( void )
{
	int m, i;
	aes_context ctx1;
	aes_context ctx2;
	unsigned char buf[16];
	unsigned char out1[16];
	unsigned char out2[16];
	unsigned char xorval[32];
	unsigned char key1[32];
	unsigned char key2[32];

	memset( buf, 0, 16 );
	memset( key1, 0xff, 16 );
	memset( xorval, 0x1, 16 );
	memcpy( key2, key1, 16 );

	for (i = 0; i < 1024000; i += 16)
	{
		memcpy(key1, (char *)&i, sizeof(i));

		aes_set_key( &ctx1, key1, 128 );

		xor(key2, key1, xorval);

		aes_set_key( &ctx2, key2, 128 );

		aes_encrypt( &ctx1, buf, out1 );
		aes_encrypt( &ctx2, buf, out2 );

		for (m = 0; m < 16; m++)
		{
			printf("%c", out1[m] ^ out2[m]);
		}
	}
    return( 0 );
}

