Exemple #1
0
void RC6Decryption::ProcessBlock(const byte *in, byte *out) const
{
	const RC6_WORD *sptr = sTable+sTable.size;
	RC6_WORD a, b, c, d, t, u;

	GetBlockLittleEndian(in, a, b, c, d);

	sptr -= 2;
	c -= sptr[1];
	a -= sptr[0];

	for (unsigned i=0; i < r; i++)
	{
		sptr -= 2;
		t = a; a = d; d = c; c = b; b = t;
		u = rotlFixed(d*(2*d+1), 5);
		t = rotlFixed(b*(2*b+1), 5);
		c = rotrMod(c-sptr[1], t) ^ u;
		a = rotrMod(a-sptr[0], u) ^ t;
	}

	sptr -= 2;
	d -= sTable[1];
	b -= sTable[0];

	PutBlockLittleEndian(out, a, b, c, d);
}
Exemple #2
0
void RC6Encryption::ProcessBlock(const byte *in, byte *out) const
{
	const RC6_WORD *sptr = sTable;
	RC6_WORD a, b, c, d, t, u;

	GetBlockLittleEndian(in, a, b, c, d);
	b += sptr[0];
	d += sptr[1];
	sptr += 2;

	for(unsigned i=0; i<r; i++)
	{
		t = rotlFixed(b*(2*b+1), 5);
		u = rotlFixed(d*(2*d+1), 5);
		a = rotlMod(a^t,u) + sptr[0];
		c = rotlMod(c^u,t) + sptr[1];
		t = a; a = b; b = c; c = d; d = t;
		sptr += 2;
	}

	a += sptr[0];
	c += sptr[1];

	PutBlockLittleEndian(out, a, b, c, d);
}
Exemple #3
0
void CRC2Encryptor::Transform(TDes8& aBlock)
	{
	assert(aBlock.Size() == KRC2BlockBytes);
	
	TUint16 R0, R1, R2, R3;
	GetBlockLittleEndian((TUint8*)&aBlock[0], R0, R1, R2, R3);
	
	TInt i = 0;
	for (; i < 16; i++)
		{
		R0 += (R1 & ~R3) + (R2 & R3) + iK[4*i+0];
		R0 = rotlFixed(R0, 1);

		R1 += (R2 & ~R0) + (R3 & R0) + iK[4*i+1];
		R1 = rotlFixed(R1, 2);

		R2 += (R3 & ~R1) + (R0 & R1) + iK[4*i+2];
		R2 = rotlFixed(R2, 3);

		R3 += (R0 & ~R2) + (R1 & R2) + iK[4*i+3];
		R3 = rotlFixed(R3, 5);

		if (i == 4 || i == 10)
			{
			R0 += iK[R3 & 63];
			R1 += iK[R0 & 63];
			R2 += iK[R1 & 63];
			R3 += iK[R2 & 63];
			}
		}

	PutBlockLittleEndian((TUint8*)&aBlock[0], R0, R1, R2, R3);	
	}
Exemple #4
0
void CRC2Decryptor::Transform(TDes8& aBlock)
	{
	assert(aBlock.Size() == KRC2BlockBytes);

	TUint16 R0, R1, R2, R3;
	GetBlockLittleEndian((TUint8*)&aBlock[0], R0, R1, R2, R3);

	TInt i = 15;
	for (; i >= 0; i--)
		{
		if (i == 4 || i == 10)
			{
			R3 -= iK[R2 & 63];
			R2 -= iK[R1 & 63];
			R1 -= iK[R0 & 63];
			R0 -= iK[R3 & 63];
			}

		R3 = rotrFixed(R3, 5);
		R3 -= (R0 & ~R2) + (R1 & R2) + iK[4*i+3];

		R2 = rotrFixed(R2, 3);
		R2 -= (R3 & ~R1) + (R0 & R1) + iK[4*i+2];

		R1 = rotrFixed(R1, 2);
		R1 -= (R2 & ~R0) + (R3 & R0) + iK[4*i+1];

		R0 = rotrFixed(R0, 1);
		R0 -= (R1 & ~R3) + (R2 & R3) + iK[4*i+0];
		}

	PutBlockLittleEndian((TUint8*)&aBlock[0], R0, R1, R2, R3);
	}
Exemple #5
0
void RijndaelDecryption::ProcessBlock(const UCHAR *inBlock, UCHAR *outBlock) const
{
	ULONG	b0[4], b1[4];

	GetBlockLittleEndian(inBlock, b0[0], b0[1], b0[2], b0[3]);

	b0[0] ^= key[4 * k_len + 24];
	b0[1] ^= key[4 * k_len + 25];
	b0[2] ^= key[4 * k_len + 26];
	b0[3] ^= key[4 * k_len + 27];

	const ULONG *kp = key + 4 * (k_len + 5);

	if(k_len > 6)
	{
		i_nround(b1, b0, kp); i_nround(b0, b1, kp);
	}

	if(k_len > 4)
	{
		i_nround(b1, b0, kp); i_nround(b0, b1, kp);
	}

	i_nround(b1, b0, kp); i_nround(b0, b1, kp);
	i_nround(b1, b0, kp); i_nround(b0, b1, kp);
	i_nround(b1, b0, kp); i_nround(b0, b1, kp);
	i_nround(b1, b0, kp); i_nround(b0, b1, kp);
	i_nround(b1, b0, kp); i_lround(b0, b1, kp);

	PutBlockLittleEndian(outBlock, b0[0], b0[1], b0[2], b0[3]);
}
Exemple #6
0
void RijndaelEncryption::ProcessBlock(const UCHAR *inBlock, UCHAR *outBlock) const
{
	ULONG b0[4], b1[4];

	GetBlockLittleEndian(inBlock, b0[0], b0[1], b0[2], b0[3]);

	b0[0] ^= key[0];
	b0[1] ^= key[1];
	b0[2] ^= key[2];
	b0[3] ^= key[3];

	const ULONG *kp = key + 4;

	if(k_len > 6)
	{
		f_nround(b1, b0, kp); f_nround(b0, b1, kp);
	}

	if(k_len > 4)
	{
		f_nround(b1, b0, kp); f_nround(b0, b1, kp);
	}

	f_nround(b1, b0, kp); f_nround(b0, b1, kp);
	f_nround(b1, b0, kp); f_nround(b0, b1, kp);
	f_nround(b1, b0, kp); f_nround(b0, b1, kp);
	f_nround(b1, b0, kp); f_nround(b0, b1, kp);
	f_nround(b1, b0, kp); f_lround(b0, b1, kp);

	PutBlockLittleEndian(outBlock, b0[0], b0[1], b0[2], b0[3]);
}