auxFormat.c 3.21 KB
Newer Older
Wentao Zhang 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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
#include"auxFormat.h"
void ROUND384_Three(unsigned int *s, unsigned char *c, int lunnum) {
	unsigned int t, t1, t2;
	u32 rci, temp;
	rci = c[0];
	ARC(rci);
	SBOX(s[0], s[3], s[6], s[9]);
	SBOX(s[1], s[4], s[7], s[10]);
	SBOX(s[2], s[5], s[8], s[11]);
	t = 1;
	while (lunnum--) {
		temp = ((u32*) (c + t))[0];
		rci = temp & 0xff;
		ARC(rci);
		SBOX1_ROR(s[0], s[4], s[8], s[10] );
		SBOX2_ROR(s[1], s[5], s[6], s[11]);
		SBOX3_ROR(s[2], s[3], s[7], s[9]);
		rci = (temp & 0xff00) >> 8;
		ARC(rci);
		SBOX1_ROR(s[0], s[5], s[7], s[11]);
		SBOX2_ROR(s[1], s[3], s[8], s[9]);
		SBOX3_ROR(s[2], s[4], s[6], s[10]);
		rci = (temp & 0xff0000) >> 16;
		ARC(rci);
		SBOX1_ROR(s[0], s[3], s[6], s[9]);
		SBOX2_ROR(s[1], s[4], s[7], s[10]);
		SBOX3_ROR(s[2], s[5], s[8], s[11]);
		t += 3;
	}
}

void packU96FormatToThreePacket(u32 *out, u8 *in) {
	u32 temp0[3] = { 0 };
	u32 temp1[3] = { 0 };
	u32 temp2[3] = { 0 };
	temp0[0] = U32BIG(((u32* )in)[0]);
	temp0[1] = U32BIG(((u32*)in)[0]) >> 1;
	temp0[2] = U32BIG(((u32*)in)[0]) >> 2;
	puckU32ToThree_1(temp0[0]);
	puckU32ToThree_1(temp0[1]);
	puckU32ToThree_1(temp0[2]);
	temp1[0] = U32BIG(((u32* )in)[1]);
	temp1[1] = U32BIG(((u32*)in)[1]) >> 1;
	temp1[2] = U32BIG(((u32*)in)[1]) >> 2;
	puckU32ToThree_1(temp1[0]);
	puckU32ToThree_1(temp1[1]);
	puckU32ToThree_1(temp1[2]);
	temp2[0] = U32BIG(((u32* )in)[2]);
	temp2[1] = U32BIG(((u32*)in)[2]) >> 1;
	temp2[2] = U32BIG(((u32*)in)[2]) >> 2;
	puckU32ToThree_1(temp2[0]);
	puckU32ToThree_1(temp2[1]);
	puckU32ToThree_1(temp2[2]);
	out[0] = (temp2[1] << 21) | (temp1[0] << 10) | temp0[2];
	out[1] = (temp2[0] << 21) | (temp1[2] << 11) | temp0[1];
	out[2] = (temp2[2] << 22) | (temp1[1] << 11) | temp0[0];
}
void unpackU96FormatToThreePacket(u8 *out, u32 *in) {
	u32 temp0[3] = { 0 };
	u32 temp1[3] = { 0 };
	u32 temp2[3] = { 0 };
	u32 t[3] = { 0 };
	temp0[0] = in[2] & 0x7ff;
	temp0[1] = in[1] & 0x7ff;
	temp0[2] = in[0] & 0x3ff;
	temp1[0] = (in[0] >> 10) & 0x7ff;
	temp1[1] = (in[2] >> 11) & 0x7ff;
	temp1[2] = (in[1] >> 11) & 0x3ff;
	temp2[0] = in[1] >> 21;
	temp2[1] = in[0] >> 21;
	temp2[2] = in[2] >> 22;
	unpuckU32ToThree_1(temp0[0]);
	unpuckU32ToThree_1(temp0[1]);
	unpuckU32ToThree_1(temp0[2]);
	t[0] = temp0[0] | temp0[1] << 1 | temp0[2] << 2;
	unpuckU32ToThree_1(temp1[0]);
	unpuckU32ToThree_1(temp1[1]);
	unpuckU32ToThree_1(temp1[2]);
	t[1] = temp1[0] | temp1[1] << 1 | temp1[2] << 2;
	unpuckU32ToThree_1(temp2[0]);
	unpuckU32ToThree_1(temp2[1]);
	unpuckU32ToThree_1(temp2[2]);
	t[2] = temp2[0] | temp2[1] << 1 | temp2[2] << 2;
	memcpy(out, t, 12 * sizeof(unsigned char));
}
void packU48FormatToThreePacket(u32 *out, u8 *in) {
	u32 t1 = (u32) U16BIG(*(u16* )(in + 4));
	u32 temp0[3] = { 0 };
	u32 temp1[3] = { 0 };
	temp0[0] = U32BIG(((u32* )in)[0]);
	temp0[1] = U32BIG(((u32*)in)[0]) >> 1;
	temp0[2] = U32BIG(((u32*)in)[0]) >> 2;
	puckU32ToThree_1(temp0[0]);
	puckU32ToThree_1(temp0[1]);
	puckU32ToThree_1(temp0[2]);
	temp1[0] = t1;
	temp1[1] = t1 >> 1;
	temp1[2] = t1 >> 2;
	puckU32ToThree_1(temp1[0]);
	puckU32ToThree_1(temp1[1]);
	puckU32ToThree_1(temp1[2]);
	out[0] = (temp1[0] << 10) | temp0[2];
	out[1] = (temp1[2] << 11) | temp0[1];
	out[2] = (temp1[1] << 11) | temp0[0];
}