Example #1
0
int
main(int argc, char *argv[])
{
        int ch;
        while ((ch = getopt(argc, argv, "dn")) != -1) {
                switch (ch) {
                case 'd':
                        debug = 1;
                        break;
                case 'n':
                        mode32 = 1;
                        break;
                default:
                        abort();
                }
        }

        setup();
        while (1) {
                if (mode32)
                        loop32();
                else
                        loop8();
                if (debug)
                        sleep(1);
        }
}
Example #2
0
rijndaelCtx *
rijndael_set_key(rijndaelCtx *ctx, const uint32_t *in_key, const uint32_t key_len,
				 int encrypt)
{
	uint32_t		i,
				t,
				u,
				v,
				w;
	uint32_t	   *e_key = ctx->e_key;
	uint32_t	   *d_key = ctx->d_key;

	ctx->decrypt = !encrypt;

	ctx->k_len = (key_len + 31) / 32;

	e_key[0] = io_swap(in_key[0]);
	e_key[1] = io_swap(in_key[1]);
	e_key[2] = io_swap(in_key[2]);
	e_key[3] = io_swap(in_key[3]);

	switch (ctx->k_len)
	{
		case 4:
			t = e_key[3];
			for (i = 0; i < 10; ++i)
				loop4(i);
			break;

		case 6:
			e_key[4] = io_swap(in_key[4]);
			t = e_key[5] = io_swap(in_key[5]);
			for (i = 0; i < 8; ++i)
				loop6(i);
			break;

		case 8:
			e_key[4] = io_swap(in_key[4]);
			e_key[5] = io_swap(in_key[5]);
			e_key[6] = io_swap(in_key[6]);
			t = e_key[7] = io_swap(in_key[7]);
			for (i = 0; i < 7; ++i)
				loop8(i);
			break;
	}

	if (!encrypt)
	{
		d_key[0] = e_key[0];
		d_key[1] = e_key[1];
		d_key[2] = e_key[2];
		d_key[3] = e_key[3];

		for (i = 4; i < 4 * ctx->k_len + 24; ++i)
			imix_col(d_key[i], e_key[i]);
	}

	return ctx;
}
Example #3
0
int main(int argc, char *argv[])
{
    loop0();
    loop1();
    loop2();
    loop3();
    loop4();
    loop5();
    loop6();
    loop7();
    loop8();
    loop9();
    loop10();
}
Example #4
0
void rijndael::set_key(const u1byte in_key[], const u4byte key_len)
{
	u4byte  i, t, u, v, w;

	if(!tab_gen)

		gen_tabs();

	k_len = (key_len + 31) / 32;

	e_key[0] = u4byte_in(in_key     ); 
	e_key[1] = u4byte_in(in_key +  4);
	e_key[2] = u4byte_in(in_key +  8); 
	e_key[3] = u4byte_in(in_key + 12);

	switch(k_len)
	{
	case 4: t = e_key[3];
		for(i = 0; i < 10; ++i) 
			loop4(i);
		break;

	case 6: e_key[4] = u4byte_in(in_key + 16); t = e_key[5] = u4byte_in(in_key + 20);
		for(i = 0; i < 8; ++i) 
			loop6(i);
		break;

	case 8: e_key[4] = u4byte_in(in_key + 16); e_key[5] = u4byte_in(in_key + 20);
		e_key[6] = u4byte_in(in_key + 24); t = e_key[7] = u4byte_in(in_key + 28);
		for(i = 0; i < 7; ++i) 
			loop8(i);
		break;
	}

	d_key[0] = e_key[0]; d_key[1] = e_key[1];
	d_key[2] = e_key[2]; d_key[3] = e_key[3];

	for(i = 4; i < 4 * k_len + 24; ++i)
	{
		imix_col(d_key[i], e_key[i]);
	}

	return;
}