1
0
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:
jsteube 2015-12-30 21:53:01 +01:00
parent a849313093
commit 87095191d7
3 changed files with 228 additions and 246 deletions

View File

@ -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,17 +38,22 @@ 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;
@ -81,19 +85,16 @@ static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
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])
{
#pragma unroll
for (u32 k = 0; k < 4; k++)
{ {
u8 idx;
u32 xor4 = 0; u32 xor4 = 0;
u8 i = rc4_key->i; u8 idx;
u8 j = rc4_key->j;
i += 1; i += 1;
j += rc4_key->S[i]; j += rc4_key->S[i];
@ -131,45 +132,38 @@ static u32 rc4_next_4 (__local RC4_KEY *rc4_key, const u32 ct)
xor4 |= rc4_key->S[idx] << 24; xor4 |= rc4_key->S[idx] << 24;
rc4_key->i = i; out[k] = in[k] ^ xor4;
rc4_key->j = j; }
return ct ^ xor4; return j;
} }
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;
} }

View File

@ -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,17 +36,22 @@ 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;
@ -79,19 +83,16 @@ static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
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])
{
#pragma unroll
for (u32 k = 0; k < 4; k++)
{ {
u8 idx;
u32 xor4 = 0; u32 xor4 = 0;
u8 i = rc4_key->i; u8 idx;
u8 j = rc4_key->j;
i += 1; i += 1;
j += rc4_key->S[i]; j += rc4_key->S[i];
@ -129,45 +130,38 @@ static u32 rc4_next_4 (__local RC4_KEY *rc4_key, const u32 ct)
xor4 |= rc4_key->S[idx] << 24; xor4 |= rc4_key->S[idx] << 24;
rc4_key->i = i; out[k] = in[k] ^ xor4;
rc4_key->j = j; }
return ct ^ xor4; return j;
} }
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;
} }

View File

@ -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,17 +36,22 @@ 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;
@ -79,19 +83,16 @@ static void rc4_init_16 (__local RC4_KEY *rc4_key, const u32 data[4])
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])
{
#pragma unroll
for (u32 k = 0; k < 4; k++)
{ {
u8 idx;
u32 xor4 = 0; u32 xor4 = 0;
u8 i = rc4_key->i; u8 idx;
u8 j = rc4_key->j;
i += 1; i += 1;
j += rc4_key->S[i]; j += rc4_key->S[i];
@ -129,45 +130,38 @@ static u32 rc4_next_4 (__local RC4_KEY *rc4_key, const u32 ct)
xor4 |= rc4_key->S[idx] << 24; xor4 |= rc4_key->S[idx] << 24;
rc4_key->i = i; out[k] = in[k] ^ xor4;
rc4_key->j = j; }
return ct ^ xor4; return j;
} }
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;
} }