rijndael256.c 792 Bytes
Newer Older
lwc-tester committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "rijndael256.h"

word8 rk[MAXROUNDS+1][4][MAXBC];

void rijndael256KeySched (const unsigned char *key_state)
{
	size_t i;
	size_t j;
	word8 k[4][MAXKC];
	for (j = 0; j < MAXKC; j++)
	{
		for (i = 0; i < 4; i++)
		{
			k[i][j] = key_state[j * 4 + i];
		}
	}

	rijndaelKeySched(k, rk);
}

void rijndael256Encrypt (unsigned char *state_inout, const uint8_t  domain)
{
	size_t i;
	size_t j;
	word8 a[4][MAXBC];
	for (j = 0; j < MAXBC; j++)
	{
		for (i = 0; i < 4; i++)
		{
			a[i][j] = state_inout[j * 4 + i];
		}
	}

	rijndaelEncrypt(a, rk, domain);

	for (j = 0; j < MAXBC; j++)
	{
		for (i = 0; i < 4; i++)
		{
			state_inout[j * 4 + i] = a[i][j];
		}
	}	
}