I need this function below for a Rjindael encrypting.
I need to call a function which takes a uint* and byte* as parameter to calculate the ney key. How can I do this? I stick on this since hours.
public static int RijndaelKeySetupEnc(int nr, uint* rk /*4*(Nr + 1)*/, byte* cipherKey, int keyBits)
{
var i = 0;
uint temp;
rk[0] = GeTuint(cipherKey);
rk[1] = GeTuint(cipherKey + 4);
rk[2] = GeTuint(cipherKey + 8);
rk[3] = GeTuint(cipherKey + 12);
if (keyBits == 128)
{
for (; ; )
{
temp = rk[3];
rk[4] = rk[0] ^
(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
(Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
(Te4[temp & 0xff] & 0x0000ff00) ^
(Te4[temp >> 24] & 0x000000ff) ^
Rcon[i];
rk[5] = rk[1] ^ rk[4];
rk[6] = rk[2] ^ rk[5];
rk[7] = rk[3] ^ rk[6];
if (++i == nr)
{
return nr;
}
rk += 4;
}
}
return 0;
//rk[4] = GeTuint(cipherKey + 16);
//rk[5] = GeTuint(cipherKey + 20);
//if (keyBits == 192)
//{
// for (; ; )
// {
// temp = rk[5];
// rk[6] = rk[0] ^
// (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
// (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
// (Te4[temp & 0xff] & 0x0000ff00) ^
// (Te4[temp >> 24] & 0x000000ff) ^
// Rcon[i];
// rk[7] = rk[1] ^ rk[6];
// rk[8] = rk[2] ^ rk[7];
// rk[9] = rk[3] ^ rk[8];
// if (++i == 8)
// {
// return 12;
// }
// rk[10] = rk[4] ^ rk[9];
// rk[11] = rk[5] ^ rk[10];
// rk += 6;
// }
//}
//rk[6] = GeTuint(cipherKey + 24);
//rk[7] = GeTuint(cipherKey + 28);
//if (keyBits != 256) return 0;
//for (; ; )
//{
// temp = rk[7];
// rk[8] = rk[0] ^
// (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
// (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
// (Te4[temp & 0xff] & 0x0000ff00) ^
// (Te4[temp >> 24] & 0x000000ff) ^
// Rcon[i];
// rk[9] = rk[1] ^ rk[8];
// rk[10] = rk[2] ^ rk[9];
// rk[11] = rk[3] ^ rk[10];
// if (++i == 7)
// {
// return 14;
// }
// temp = rk[11];
// rk[12] = rk[4] ^
// (Te4[temp >> 24] & 0xff000000) ^
// (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
// (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
// (Te4[temp & 0xff] & 0x000000ff);
// rk[13] = rk[5] ^ rk[12];
// rk[14] = rk[6] ^ rk[13];
// rk[15] = rk[7] ^ rk[14];
// rk += 8;
//}
}
How can I convert my byte[] and uint to byte* and uint* ?
In C the Call function is like that but on c# it do not work.
KeyTransform(SKPrimeHash,SKPrimeHash);
//====================================================
void KeyTransform(unsigned char *pIn, unsigned char *pOut)
{
AES_128_Transform(3,transKey,pIn,pOut);
}
//=======================================================
void AES_128_Transform(int Nr, unsigned char *key, unsigned char *plainText, unsigned char *cipherText)
{
u32 rk[4*(AES_128_ROUNDS + 1)];
int i;
rijndaelKeySetupEncTransform(Nr,rk, key, 128);
rijndaelEncrypt(rk, Nr, plainText, cipherText);
for (i = 0; i < (4 * (AES_128_ROUNDS + 1)); i++) rk[i] = 0;
}
User contributions licensed under CC BY-SA 3.0