Esempio n. 1
0
static void F_func(char* In, char* Ki)
{
	static char MR[48];
	Transform(MR, In, E_Table, 48);
	Xor(MR, Ki, 48);
	S_func(In, MR);
	Transform(In, In, P_Table, 32);
}
Esempio n. 2
0
int
test_S()
{
	unsigned char vals[5][16] = {
		{ 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88,
		  0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x00 },
		{ 0xb6, 0x6c, 0xd8, 0x88, 0x7d, 0x38, 0xe8, 0xd7,
		  0x77, 0x65, 0xae, 0xea, 0x0c, 0x9a, 0x7e, 0xfc },
		{ 0x55, 0x9d, 0x8d, 0xd7, 0xbd, 0x06, 0xcb, 0xfe,
		  0x7e, 0x7b, 0x26, 0x25, 0x23, 0x28, 0x0d, 0x39 },
		{ 0x0c, 0x33, 0x22, 0xfe, 0xd5, 0x31, 0xe4, 0x63,
		  0x0d, 0x80, 0xef, 0x5c, 0x5a, 0x81, 0xc5, 0x0b },
		{ 0x23, 0xae, 0x65, 0x63, 0x3f, 0x84, 0x2d, 0x29,
		  0xc5, 0xdf, 0x52, 0x9c, 0x13, 0xf5, 0xac, 0xda }
	};

	unsigned char buf[16];
	int i, ret;

	memcpy(buf, vals[0], 16);

	for (i = 0; i < 4; i++) {
		S_func(buf);
		ret = memcmp(buf, vals[i + 1], 16);
		if (ret != 0) {
			printf("S_func Fail. iter %d, key: \n", i);
			PRINT_BLOCK(buf);
			PRINT_BLOCK(vals[i + 1]);
			return 1;
		}
	}

	for (i = 4; i > 0; i--) {
		Sinv_func(buf);
		ret = memcmp(buf, vals[i - 1], 16);
		if (ret != 0) {
			printf("Sinv_func Fail. iter %d, key: \n", i);
			PRINT_BLOCK(buf);
			PRINT_BLOCK(vals[i - 1]);
			return 1;
		}
	}

	return 0;
}