mirror of
https://github.com/hashcat/hashcat.git
synced 2025-01-03 12:21:07 +00:00
Updated old RC4 code in Kerberos 5, increased performance
This commit is contained in:
parent
a849313093
commit
87095191d7
@ -23,8 +23,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
u8 S[256];
|
u8 S[256];
|
||||||
|
|
||||||
u8 i;
|
u32 wtf_its_faster;
|
||||||
u8 j;
|
|
||||||
|
|
||||||
} RC4_KEY;
|
} RC4_KEY;
|
||||||
|
|
||||||
@ -39,137 +38,132 @@ static void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
|
|||||||
|
|
||||||
static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
|
static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
|
||||||
{
|
{
|
||||||
u32 i;
|
u32 v = 0x03020100;
|
||||||
|
u32 a = 0x04040404;
|
||||||
|
|
||||||
#pragma unroll 256
|
__local u32 *ptr = (__local u32 *) rc4_key->S;
|
||||||
for (i = 0; i < 256; i += 1) rc4_key->S[i] = i;
|
|
||||||
|
|
||||||
u8 j = 0;
|
#pragma unroll
|
||||||
|
for (u32 i = 0; i < 64; i++)
|
||||||
#pragma unroll 16
|
|
||||||
for (i = 0; i < 256; i += 16)
|
|
||||||
{
|
{
|
||||||
u32 idx = i;
|
*ptr++ = v; v += a;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 j = 0;
|
||||||
|
|
||||||
|
for (u32 i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
u32 idx = i * 16;
|
||||||
|
|
||||||
u32 v;
|
u32 v;
|
||||||
|
|
||||||
v = data[0];
|
v = data[0];
|
||||||
|
|
||||||
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
||||||
|
|
||||||
v = data[1];
|
v = data[1];
|
||||||
|
|
||||||
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
||||||
|
|
||||||
v = data[2];
|
v = data[2];
|
||||||
|
|
||||||
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
||||||
|
|
||||||
v = data[3];
|
v = data[3];
|
||||||
|
|
||||||
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc4_key->i = 0;
|
|
||||||
rc4_key->j = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static u32 rc4_next_4 (__local RC4_KEY *rc4_key, const u32 ct)
|
static u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, const u32 in[4], u32 out[4])
|
||||||
{
|
{
|
||||||
u8 idx;
|
#pragma unroll
|
||||||
|
for (u32 k = 0; k < 4; k++)
|
||||||
|
{
|
||||||
|
u32 xor4 = 0;
|
||||||
|
|
||||||
u32 xor4 = 0;
|
u8 idx;
|
||||||
|
|
||||||
u8 i = rc4_key->i;
|
i += 1;
|
||||||
u8 j = rc4_key->j;
|
j += rc4_key->S[i];
|
||||||
|
|
||||||
i += 1;
|
swap (rc4_key, i, j);
|
||||||
j += rc4_key->S[i];
|
|
||||||
|
|
||||||
swap (rc4_key, i, j);
|
idx = rc4_key->S[i] + rc4_key->S[j];
|
||||||
|
|
||||||
idx = rc4_key->S[i] + rc4_key->S[j];
|
xor4 |= rc4_key->S[idx] << 0;
|
||||||
|
|
||||||
xor4 |= rc4_key->S[idx] << 0;
|
i += 1;
|
||||||
|
j += rc4_key->S[i];
|
||||||
|
|
||||||
i += 1;
|
swap (rc4_key, i, j);
|
||||||
j += rc4_key->S[i];
|
|
||||||
|
|
||||||
swap (rc4_key, i, j);
|
idx = rc4_key->S[i] + rc4_key->S[j];
|
||||||
|
|
||||||
idx = rc4_key->S[i] + rc4_key->S[j];
|
xor4 |= rc4_key->S[idx] << 8;
|
||||||
|
|
||||||
xor4 |= rc4_key->S[idx] << 8;
|
i += 1;
|
||||||
|
j += rc4_key->S[i];
|
||||||
|
|
||||||
i += 1;
|
swap (rc4_key, i, j);
|
||||||
j += rc4_key->S[i];
|
|
||||||
|
|
||||||
swap (rc4_key, i, j);
|
idx = rc4_key->S[i] + rc4_key->S[j];
|
||||||
|
|
||||||
idx = rc4_key->S[i] + rc4_key->S[j];
|
xor4 |= rc4_key->S[idx] << 16;
|
||||||
|
|
||||||
xor4 |= rc4_key->S[idx] << 16;
|
i += 1;
|
||||||
|
j += rc4_key->S[i];
|
||||||
|
|
||||||
i += 1;
|
swap (rc4_key, i, j);
|
||||||
j += rc4_key->S[i];
|
|
||||||
|
|
||||||
swap (rc4_key, i, j);
|
idx = rc4_key->S[i] + rc4_key->S[j];
|
||||||
|
|
||||||
idx = rc4_key->S[i] + rc4_key->S[j];
|
xor4 |= rc4_key->S[idx] << 24;
|
||||||
|
|
||||||
xor4 |= rc4_key->S[idx] << 24;
|
out[k] = in[k] ^ xor4;
|
||||||
|
}
|
||||||
|
|
||||||
rc4_key->i = i;
|
return j;
|
||||||
rc4_key->j = j;
|
|
||||||
|
|
||||||
return ct ^ xor4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int decrypt_and_check (__local RC4_KEY *rc4_key, u32 data[4], u32 timestamp_ct[8])
|
static int decrypt_and_check (__local RC4_KEY *rc4_key, u32 data[4], u32 timestamp_ct[8])
|
||||||
{
|
{
|
||||||
u32 pt;
|
|
||||||
|
|
||||||
rc4_init_16 (rc4_key, data);
|
rc4_init_16 (rc4_key, data);
|
||||||
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[0]);
|
u32 out[4];
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[1]);
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[2]);
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[3]);
|
|
||||||
|
|
||||||
if ((pt & 0xffff0000) != 0x30320000) return 0;
|
u8 j = 0;
|
||||||
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[4]);
|
j = rc4_next_16 (rc4_key, 0, j, timestamp_ct + 0, out);
|
||||||
|
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if ((out[3] & 0xffff0000) != 0x30320000) return 0;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0;
|
|
||||||
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[5]);
|
j = rc4_next_16 (rc4_key, 16, j, timestamp_ct + 4, out);
|
||||||
|
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[0] & 0xff) < '0') || ((out[0] & 0xff) > '9')) return 0; out[0] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[0] & 0xff) < '0') || ((out[0] & 0xff) > '9')) return 0; out[0] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[0] & 0xff) < '0') || ((out[0] & 0xff) > '9')) return 0; out[0] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0;
|
if (((out[0] & 0xff) < '0') || ((out[0] & 0xff) > '9')) return 0;
|
||||||
|
if (((out[1] & 0xff) < '0') || ((out[1] & 0xff) > '9')) return 0; out[1] >>= 8;
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[6]);
|
if (((out[1] & 0xff) < '0') || ((out[1] & 0xff) > '9')) return 0; out[1] >>= 8;
|
||||||
|
if (((out[1] & 0xff) < '0') || ((out[1] & 0xff) > '9')) return 0; out[1] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[1] & 0xff) < '0') || ((out[1] & 0xff) > '9')) return 0;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[2] & 0xff) < '0') || ((out[2] & 0xff) > '9')) return 0; out[2] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[2] & 0xff) < '0') || ((out[2] & 0xff) > '9')) return 0; out[2] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0;
|
if (((out[2] & 0xff) < '0') || ((out[2] & 0xff) > '9')) return 0; out[2] >>= 8;
|
||||||
|
if (((out[2] & 0xff) < '0') || ((out[2] & 0xff) > '9')) return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
u8 S[256];
|
u8 S[256];
|
||||||
|
|
||||||
u8 i;
|
u32 wtf_its_faster;
|
||||||
u8 j;
|
|
||||||
|
|
||||||
} RC4_KEY;
|
} RC4_KEY;
|
||||||
|
|
||||||
@ -37,137 +36,132 @@ static void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
|
|||||||
|
|
||||||
static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
|
static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
|
||||||
{
|
{
|
||||||
u32 i;
|
u32 v = 0x03020100;
|
||||||
|
u32 a = 0x04040404;
|
||||||
|
|
||||||
#pragma unroll 256
|
__local u32 *ptr = (__local u32 *) rc4_key->S;
|
||||||
for (i = 0; i < 256; i += 1) rc4_key->S[i] = i;
|
|
||||||
|
|
||||||
u8 j = 0;
|
#pragma unroll
|
||||||
|
for (u32 i = 0; i < 64; i++)
|
||||||
#pragma unroll 16
|
|
||||||
for (i = 0; i < 256; i += 16)
|
|
||||||
{
|
{
|
||||||
u32 idx = i;
|
*ptr++ = v; v += a;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 j = 0;
|
||||||
|
|
||||||
|
for (u32 i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
u32 idx = i * 16;
|
||||||
|
|
||||||
u32 v;
|
u32 v;
|
||||||
|
|
||||||
v = data[0];
|
v = data[0];
|
||||||
|
|
||||||
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
||||||
|
|
||||||
v = data[1];
|
v = data[1];
|
||||||
|
|
||||||
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
||||||
|
|
||||||
v = data[2];
|
v = data[2];
|
||||||
|
|
||||||
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
||||||
|
|
||||||
v = data[3];
|
v = data[3];
|
||||||
|
|
||||||
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc4_key->i = 0;
|
|
||||||
rc4_key->j = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static u32 rc4_next_4 (__local RC4_KEY *rc4_key, const u32 ct)
|
static u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, const u32 in[4], u32 out[4])
|
||||||
{
|
{
|
||||||
u8 idx;
|
#pragma unroll
|
||||||
|
for (u32 k = 0; k < 4; k++)
|
||||||
|
{
|
||||||
|
u32 xor4 = 0;
|
||||||
|
|
||||||
u32 xor4 = 0;
|
u8 idx;
|
||||||
|
|
||||||
u8 i = rc4_key->i;
|
i += 1;
|
||||||
u8 j = rc4_key->j;
|
j += rc4_key->S[i];
|
||||||
|
|
||||||
i += 1;
|
swap (rc4_key, i, j);
|
||||||
j += rc4_key->S[i];
|
|
||||||
|
|
||||||
swap (rc4_key, i, j);
|
idx = rc4_key->S[i] + rc4_key->S[j];
|
||||||
|
|
||||||
idx = rc4_key->S[i] + rc4_key->S[j];
|
xor4 |= rc4_key->S[idx] << 0;
|
||||||
|
|
||||||
xor4 |= rc4_key->S[idx] << 0;
|
i += 1;
|
||||||
|
j += rc4_key->S[i];
|
||||||
|
|
||||||
i += 1;
|
swap (rc4_key, i, j);
|
||||||
j += rc4_key->S[i];
|
|
||||||
|
|
||||||
swap (rc4_key, i, j);
|
idx = rc4_key->S[i] + rc4_key->S[j];
|
||||||
|
|
||||||
idx = rc4_key->S[i] + rc4_key->S[j];
|
xor4 |= rc4_key->S[idx] << 8;
|
||||||
|
|
||||||
xor4 |= rc4_key->S[idx] << 8;
|
i += 1;
|
||||||
|
j += rc4_key->S[i];
|
||||||
|
|
||||||
i += 1;
|
swap (rc4_key, i, j);
|
||||||
j += rc4_key->S[i];
|
|
||||||
|
|
||||||
swap (rc4_key, i, j);
|
idx = rc4_key->S[i] + rc4_key->S[j];
|
||||||
|
|
||||||
idx = rc4_key->S[i] + rc4_key->S[j];
|
xor4 |= rc4_key->S[idx] << 16;
|
||||||
|
|
||||||
xor4 |= rc4_key->S[idx] << 16;
|
i += 1;
|
||||||
|
j += rc4_key->S[i];
|
||||||
|
|
||||||
i += 1;
|
swap (rc4_key, i, j);
|
||||||
j += rc4_key->S[i];
|
|
||||||
|
|
||||||
swap (rc4_key, i, j);
|
idx = rc4_key->S[i] + rc4_key->S[j];
|
||||||
|
|
||||||
idx = rc4_key->S[i] + rc4_key->S[j];
|
xor4 |= rc4_key->S[idx] << 24;
|
||||||
|
|
||||||
xor4 |= rc4_key->S[idx] << 24;
|
out[k] = in[k] ^ xor4;
|
||||||
|
}
|
||||||
|
|
||||||
rc4_key->i = i;
|
return j;
|
||||||
rc4_key->j = j;
|
|
||||||
|
|
||||||
return ct ^ xor4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int decrypt_and_check (__local RC4_KEY *rc4_key, u32 data[4], u32 timestamp_ct[8])
|
static int decrypt_and_check (__local RC4_KEY *rc4_key, u32 data[4], u32 timestamp_ct[8])
|
||||||
{
|
{
|
||||||
u32 pt;
|
|
||||||
|
|
||||||
rc4_init_16 (rc4_key, data);
|
rc4_init_16 (rc4_key, data);
|
||||||
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[0]);
|
u32 out[4];
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[1]);
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[2]);
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[3]);
|
|
||||||
|
|
||||||
if ((pt & 0xffff0000) != 0x30320000) return 0;
|
u8 j = 0;
|
||||||
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[4]);
|
j = rc4_next_16 (rc4_key, 0, j, timestamp_ct + 0, out);
|
||||||
|
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if ((out[3] & 0xffff0000) != 0x30320000) return 0;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0;
|
|
||||||
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[5]);
|
j = rc4_next_16 (rc4_key, 16, j, timestamp_ct + 4, out);
|
||||||
|
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[0] & 0xff) < '0') || ((out[0] & 0xff) > '9')) return 0; out[0] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[0] & 0xff) < '0') || ((out[0] & 0xff) > '9')) return 0; out[0] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[0] & 0xff) < '0') || ((out[0] & 0xff) > '9')) return 0; out[0] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0;
|
if (((out[0] & 0xff) < '0') || ((out[0] & 0xff) > '9')) return 0;
|
||||||
|
if (((out[1] & 0xff) < '0') || ((out[1] & 0xff) > '9')) return 0; out[1] >>= 8;
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[6]);
|
if (((out[1] & 0xff) < '0') || ((out[1] & 0xff) > '9')) return 0; out[1] >>= 8;
|
||||||
|
if (((out[1] & 0xff) < '0') || ((out[1] & 0xff) > '9')) return 0; out[1] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[1] & 0xff) < '0') || ((out[1] & 0xff) > '9')) return 0;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[2] & 0xff) < '0') || ((out[2] & 0xff) > '9')) return 0; out[2] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[2] & 0xff) < '0') || ((out[2] & 0xff) > '9')) return 0; out[2] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0;
|
if (((out[2] & 0xff) < '0') || ((out[2] & 0xff) > '9')) return 0; out[2] >>= 8;
|
||||||
|
if (((out[2] & 0xff) < '0') || ((out[2] & 0xff) > '9')) return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
u8 S[256];
|
u8 S[256];
|
||||||
|
|
||||||
u8 i;
|
u32 wtf_its_faster;
|
||||||
u8 j;
|
|
||||||
|
|
||||||
} RC4_KEY;
|
} RC4_KEY;
|
||||||
|
|
||||||
@ -37,137 +36,132 @@ static void swap (__local RC4_KEY *rc4_key, const u8 i, const u8 j)
|
|||||||
|
|
||||||
static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
|
static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
|
||||||
{
|
{
|
||||||
u32 i;
|
u32 v = 0x03020100;
|
||||||
|
u32 a = 0x04040404;
|
||||||
|
|
||||||
#pragma unroll 256
|
__local u32 *ptr = (__local u32 *) rc4_key->S;
|
||||||
for (i = 0; i < 256; i += 1) rc4_key->S[i] = i;
|
|
||||||
|
|
||||||
u8 j = 0;
|
#pragma unroll
|
||||||
|
for (u32 i = 0; i < 64; i++)
|
||||||
#pragma unroll 16
|
|
||||||
for (i = 0; i < 256; i += 16)
|
|
||||||
{
|
{
|
||||||
u32 idx = i;
|
*ptr++ = v; v += a;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32 j = 0;
|
||||||
|
|
||||||
|
for (u32 i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
u32 idx = i * 16;
|
||||||
|
|
||||||
u32 v;
|
u32 v;
|
||||||
|
|
||||||
v = data[0];
|
v = data[0];
|
||||||
|
|
||||||
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
||||||
|
|
||||||
v = data[1];
|
v = data[1];
|
||||||
|
|
||||||
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
||||||
|
|
||||||
v = data[2];
|
v = data[2];
|
||||||
|
|
||||||
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
||||||
|
|
||||||
v = data[3];
|
v = data[3];
|
||||||
|
|
||||||
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 0); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 8); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 16); swap (rc4_key, idx, j); idx++;
|
||||||
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
j += rc4_key->S[idx] + (v >> 24); swap (rc4_key, idx, j); idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc4_key->i = 0;
|
|
||||||
rc4_key->j = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static u32 rc4_next_4 (__local RC4_KEY *rc4_key, const u32 ct)
|
static u8 rc4_next_16 (__local RC4_KEY *rc4_key, u8 i, u8 j, const u32 in[4], u32 out[4])
|
||||||
{
|
{
|
||||||
u8 idx;
|
#pragma unroll
|
||||||
|
for (u32 k = 0; k < 4; k++)
|
||||||
|
{
|
||||||
|
u32 xor4 = 0;
|
||||||
|
|
||||||
u32 xor4 = 0;
|
u8 idx;
|
||||||
|
|
||||||
u8 i = rc4_key->i;
|
i += 1;
|
||||||
u8 j = rc4_key->j;
|
j += rc4_key->S[i];
|
||||||
|
|
||||||
i += 1;
|
swap (rc4_key, i, j);
|
||||||
j += rc4_key->S[i];
|
|
||||||
|
|
||||||
swap (rc4_key, i, j);
|
idx = rc4_key->S[i] + rc4_key->S[j];
|
||||||
|
|
||||||
idx = rc4_key->S[i] + rc4_key->S[j];
|
xor4 |= rc4_key->S[idx] << 0;
|
||||||
|
|
||||||
xor4 |= rc4_key->S[idx] << 0;
|
i += 1;
|
||||||
|
j += rc4_key->S[i];
|
||||||
|
|
||||||
i += 1;
|
swap (rc4_key, i, j);
|
||||||
j += rc4_key->S[i];
|
|
||||||
|
|
||||||
swap (rc4_key, i, j);
|
idx = rc4_key->S[i] + rc4_key->S[j];
|
||||||
|
|
||||||
idx = rc4_key->S[i] + rc4_key->S[j];
|
xor4 |= rc4_key->S[idx] << 8;
|
||||||
|
|
||||||
xor4 |= rc4_key->S[idx] << 8;
|
i += 1;
|
||||||
|
j += rc4_key->S[i];
|
||||||
|
|
||||||
i += 1;
|
swap (rc4_key, i, j);
|
||||||
j += rc4_key->S[i];
|
|
||||||
|
|
||||||
swap (rc4_key, i, j);
|
idx = rc4_key->S[i] + rc4_key->S[j];
|
||||||
|
|
||||||
idx = rc4_key->S[i] + rc4_key->S[j];
|
xor4 |= rc4_key->S[idx] << 16;
|
||||||
|
|
||||||
xor4 |= rc4_key->S[idx] << 16;
|
i += 1;
|
||||||
|
j += rc4_key->S[i];
|
||||||
|
|
||||||
i += 1;
|
swap (rc4_key, i, j);
|
||||||
j += rc4_key->S[i];
|
|
||||||
|
|
||||||
swap (rc4_key, i, j);
|
idx = rc4_key->S[i] + rc4_key->S[j];
|
||||||
|
|
||||||
idx = rc4_key->S[i] + rc4_key->S[j];
|
xor4 |= rc4_key->S[idx] << 24;
|
||||||
|
|
||||||
xor4 |= rc4_key->S[idx] << 24;
|
out[k] = in[k] ^ xor4;
|
||||||
|
}
|
||||||
|
|
||||||
rc4_key->i = i;
|
return j;
|
||||||
rc4_key->j = j;
|
|
||||||
|
|
||||||
return ct ^ xor4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int decrypt_and_check (__local RC4_KEY *rc4_key, u32 data[4], u32 timestamp_ct[8])
|
static int decrypt_and_check (__local RC4_KEY *rc4_key, u32 data[4], u32 timestamp_ct[8])
|
||||||
{
|
{
|
||||||
u32 pt;
|
|
||||||
|
|
||||||
rc4_init_16 (rc4_key, data);
|
rc4_init_16 (rc4_key, data);
|
||||||
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[0]);
|
u32 out[4];
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[1]);
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[2]);
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[3]);
|
|
||||||
|
|
||||||
if ((pt & 0xffff0000) != 0x30320000) return 0;
|
u8 j = 0;
|
||||||
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[4]);
|
j = rc4_next_16 (rc4_key, 0, j, timestamp_ct + 0, out);
|
||||||
|
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if ((out[3] & 0xffff0000) != 0x30320000) return 0;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0;
|
|
||||||
|
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[5]);
|
j = rc4_next_16 (rc4_key, 16, j, timestamp_ct + 4, out);
|
||||||
|
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[0] & 0xff) < '0') || ((out[0] & 0xff) > '9')) return 0; out[0] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[0] & 0xff) < '0') || ((out[0] & 0xff) > '9')) return 0; out[0] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[0] & 0xff) < '0') || ((out[0] & 0xff) > '9')) return 0; out[0] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0;
|
if (((out[0] & 0xff) < '0') || ((out[0] & 0xff) > '9')) return 0;
|
||||||
|
if (((out[1] & 0xff) < '0') || ((out[1] & 0xff) > '9')) return 0; out[1] >>= 8;
|
||||||
pt = rc4_next_4 (rc4_key, timestamp_ct[6]);
|
if (((out[1] & 0xff) < '0') || ((out[1] & 0xff) > '9')) return 0; out[1] >>= 8;
|
||||||
|
if (((out[1] & 0xff) < '0') || ((out[1] & 0xff) > '9')) return 0; out[1] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[1] & 0xff) < '0') || ((out[1] & 0xff) > '9')) return 0;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[2] & 0xff) < '0') || ((out[2] & 0xff) > '9')) return 0; out[2] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0; pt >>= 8;
|
if (((out[2] & 0xff) < '0') || ((out[2] & 0xff) > '9')) return 0; out[2] >>= 8;
|
||||||
if (((pt & 0xff) < '0') || ((pt & 0xff) > '9')) return 0;
|
if (((out[2] & 0xff) < '0') || ((out[2] & 0xff) > '9')) return 0; out[2] >>= 8;
|
||||||
|
if (((out[2] & 0xff) < '0') || ((out[2] & 0xff) > '9')) return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user