mirror of
https://github.com/hashcat/hashcat
synced 2024-11-02 20:39:22 +01:00
Update support for RSA/DSA/EC/OPENSSH Private Keys
This commit is contained in:
parent
152fefe65f
commit
e00cae4c5c
@ -771,262 +771,6 @@ DECLSPEC void md5_update_global_utf16le_swap (md5_ctx_t *ctx, GLOBAL_AS const u3
|
||||
md5_update_64 (ctx, w0, w1, w2, w3, (len - pos1) * 2);
|
||||
}
|
||||
|
||||
DECLSPEC void md5_update_local (md5_ctx_t *ctx, LOCAL_AS const u32 *w, const int len)
|
||||
{
|
||||
u32 w0[4];
|
||||
u32 w1[4];
|
||||
u32 w2[4];
|
||||
u32 w3[4];
|
||||
|
||||
int pos1;
|
||||
int pos4;
|
||||
|
||||
for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16)
|
||||
{
|
||||
w0[0] = w[pos4 + 0];
|
||||
w0[1] = w[pos4 + 1];
|
||||
w0[2] = w[pos4 + 2];
|
||||
w0[3] = w[pos4 + 3];
|
||||
w1[0] = w[pos4 + 4];
|
||||
w1[1] = w[pos4 + 5];
|
||||
w1[2] = w[pos4 + 6];
|
||||
w1[3] = w[pos4 + 7];
|
||||
w2[0] = w[pos4 + 8];
|
||||
w2[1] = w[pos4 + 9];
|
||||
w2[2] = w[pos4 + 10];
|
||||
w2[3] = w[pos4 + 11];
|
||||
w3[0] = w[pos4 + 12];
|
||||
w3[1] = w[pos4 + 13];
|
||||
w3[2] = w[pos4 + 14];
|
||||
w3[3] = w[pos4 + 15];
|
||||
|
||||
md5_update_64 (ctx, w0, w1, w2, w3, 64);
|
||||
}
|
||||
|
||||
w0[0] = w[pos4 + 0];
|
||||
w0[1] = w[pos4 + 1];
|
||||
w0[2] = w[pos4 + 2];
|
||||
w0[3] = w[pos4 + 3];
|
||||
w1[0] = w[pos4 + 4];
|
||||
w1[1] = w[pos4 + 5];
|
||||
w1[2] = w[pos4 + 6];
|
||||
w1[3] = w[pos4 + 7];
|
||||
w2[0] = w[pos4 + 8];
|
||||
w2[1] = w[pos4 + 9];
|
||||
w2[2] = w[pos4 + 10];
|
||||
w2[3] = w[pos4 + 11];
|
||||
w3[0] = w[pos4 + 12];
|
||||
w3[1] = w[pos4 + 13];
|
||||
w3[2] = w[pos4 + 14];
|
||||
w3[3] = w[pos4 + 15];
|
||||
|
||||
md5_update_64 (ctx, w0, w1, w2, w3, len - pos1);
|
||||
}
|
||||
|
||||
DECLSPEC void md5_update_local_swap (md5_ctx_t *ctx, LOCAL_AS const u32 *w, const int len)
|
||||
{
|
||||
u32 w0[4];
|
||||
u32 w1[4];
|
||||
u32 w2[4];
|
||||
u32 w3[4];
|
||||
|
||||
int pos1;
|
||||
int pos4;
|
||||
|
||||
for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16)
|
||||
{
|
||||
w0[0] = w[pos4 + 0];
|
||||
w0[1] = w[pos4 + 1];
|
||||
w0[2] = w[pos4 + 2];
|
||||
w0[3] = w[pos4 + 3];
|
||||
w1[0] = w[pos4 + 4];
|
||||
w1[1] = w[pos4 + 5];
|
||||
w1[2] = w[pos4 + 6];
|
||||
w1[3] = w[pos4 + 7];
|
||||
w2[0] = w[pos4 + 8];
|
||||
w2[1] = w[pos4 + 9];
|
||||
w2[2] = w[pos4 + 10];
|
||||
w2[3] = w[pos4 + 11];
|
||||
w3[0] = w[pos4 + 12];
|
||||
w3[1] = w[pos4 + 13];
|
||||
w3[2] = w[pos4 + 14];
|
||||
w3[3] = w[pos4 + 15];
|
||||
|
||||
w0[0] = hc_swap32_S (w0[0]);
|
||||
w0[1] = hc_swap32_S (w0[1]);
|
||||
w0[2] = hc_swap32_S (w0[2]);
|
||||
w0[3] = hc_swap32_S (w0[3]);
|
||||
w1[0] = hc_swap32_S (w1[0]);
|
||||
w1[1] = hc_swap32_S (w1[1]);
|
||||
w1[2] = hc_swap32_S (w1[2]);
|
||||
w1[3] = hc_swap32_S (w1[3]);
|
||||
w2[0] = hc_swap32_S (w2[0]);
|
||||
w2[1] = hc_swap32_S (w2[1]);
|
||||
w2[2] = hc_swap32_S (w2[2]);
|
||||
w2[3] = hc_swap32_S (w2[3]);
|
||||
w3[0] = hc_swap32_S (w3[0]);
|
||||
w3[1] = hc_swap32_S (w3[1]);
|
||||
w3[2] = hc_swap32_S (w3[2]);
|
||||
w3[3] = hc_swap32_S (w3[3]);
|
||||
|
||||
md5_update_64 (ctx, w0, w1, w2, w3, 64);
|
||||
}
|
||||
|
||||
w0[0] = w[pos4 + 0];
|
||||
w0[1] = w[pos4 + 1];
|
||||
w0[2] = w[pos4 + 2];
|
||||
w0[3] = w[pos4 + 3];
|
||||
w1[0] = w[pos4 + 4];
|
||||
w1[1] = w[pos4 + 5];
|
||||
w1[2] = w[pos4 + 6];
|
||||
w1[3] = w[pos4 + 7];
|
||||
w2[0] = w[pos4 + 8];
|
||||
w2[1] = w[pos4 + 9];
|
||||
w2[2] = w[pos4 + 10];
|
||||
w2[3] = w[pos4 + 11];
|
||||
w3[0] = w[pos4 + 12];
|
||||
w3[1] = w[pos4 + 13];
|
||||
w3[2] = w[pos4 + 14];
|
||||
w3[3] = w[pos4 + 15];
|
||||
|
||||
w0[0] = hc_swap32_S (w0[0]);
|
||||
w0[1] = hc_swap32_S (w0[1]);
|
||||
w0[2] = hc_swap32_S (w0[2]);
|
||||
w0[3] = hc_swap32_S (w0[3]);
|
||||
w1[0] = hc_swap32_S (w1[0]);
|
||||
w1[1] = hc_swap32_S (w1[1]);
|
||||
w1[2] = hc_swap32_S (w1[2]);
|
||||
w1[3] = hc_swap32_S (w1[3]);
|
||||
w2[0] = hc_swap32_S (w2[0]);
|
||||
w2[1] = hc_swap32_S (w2[1]);
|
||||
w2[2] = hc_swap32_S (w2[2]);
|
||||
w2[3] = hc_swap32_S (w2[3]);
|
||||
w3[0] = hc_swap32_S (w3[0]);
|
||||
w3[1] = hc_swap32_S (w3[1]);
|
||||
w3[2] = hc_swap32_S (w3[2]);
|
||||
w3[3] = hc_swap32_S (w3[3]);
|
||||
|
||||
md5_update_64 (ctx, w0, w1, w2, w3, len - pos1);
|
||||
}
|
||||
|
||||
DECLSPEC void md5_update_local_utf16le (md5_ctx_t *ctx, LOCAL_AS const u32 *w, const int len)
|
||||
{
|
||||
u32 w0[4];
|
||||
u32 w1[4];
|
||||
u32 w2[4];
|
||||
u32 w3[4];
|
||||
|
||||
int pos1;
|
||||
int pos4;
|
||||
|
||||
for (pos1 = 0, pos4 = 0; pos1 < len - 32; pos1 += 32, pos4 += 8)
|
||||
{
|
||||
w0[0] = w[pos4 + 0];
|
||||
w0[1] = w[pos4 + 1];
|
||||
w0[2] = w[pos4 + 2];
|
||||
w0[3] = w[pos4 + 3];
|
||||
w1[0] = w[pos4 + 4];
|
||||
w1[1] = w[pos4 + 5];
|
||||
w1[2] = w[pos4 + 6];
|
||||
w1[3] = w[pos4 + 7];
|
||||
|
||||
make_utf16le_S (w1, w2, w3);
|
||||
make_utf16le_S (w0, w0, w1);
|
||||
|
||||
md5_update_64 (ctx, w0, w1, w2, w3, 32 * 2);
|
||||
}
|
||||
|
||||
w0[0] = w[pos4 + 0];
|
||||
w0[1] = w[pos4 + 1];
|
||||
w0[2] = w[pos4 + 2];
|
||||
w0[3] = w[pos4 + 3];
|
||||
w1[0] = w[pos4 + 4];
|
||||
w1[1] = w[pos4 + 5];
|
||||
w1[2] = w[pos4 + 6];
|
||||
w1[3] = w[pos4 + 7];
|
||||
|
||||
make_utf16le_S (w1, w2, w3);
|
||||
make_utf16le_S (w0, w0, w1);
|
||||
|
||||
md5_update_64 (ctx, w0, w1, w2, w3, (len - pos1) * 2);
|
||||
}
|
||||
|
||||
DECLSPEC void md5_update_local_utf16le_swap (md5_ctx_t *ctx, LOCAL_AS const u32 *w, const int len)
|
||||
{
|
||||
u32 w0[4];
|
||||
u32 w1[4];
|
||||
u32 w2[4];
|
||||
u32 w3[4];
|
||||
|
||||
int pos1;
|
||||
int pos4;
|
||||
|
||||
for (pos1 = 0, pos4 = 0; pos1 < len - 32; pos1 += 32, pos4 += 8)
|
||||
{
|
||||
w0[0] = w[pos4 + 0];
|
||||
w0[1] = w[pos4 + 1];
|
||||
w0[2] = w[pos4 + 2];
|
||||
w0[3] = w[pos4 + 3];
|
||||
w1[0] = w[pos4 + 4];
|
||||
w1[1] = w[pos4 + 5];
|
||||
w1[2] = w[pos4 + 6];
|
||||
w1[3] = w[pos4 + 7];
|
||||
|
||||
make_utf16le_S (w1, w2, w3);
|
||||
make_utf16le_S (w0, w0, w1);
|
||||
|
||||
w0[0] = hc_swap32_S (w0[0]);
|
||||
w0[1] = hc_swap32_S (w0[1]);
|
||||
w0[2] = hc_swap32_S (w0[2]);
|
||||
w0[3] = hc_swap32_S (w0[3]);
|
||||
w1[0] = hc_swap32_S (w1[0]);
|
||||
w1[1] = hc_swap32_S (w1[1]);
|
||||
w1[2] = hc_swap32_S (w1[2]);
|
||||
w1[3] = hc_swap32_S (w1[3]);
|
||||
w2[0] = hc_swap32_S (w2[0]);
|
||||
w2[1] = hc_swap32_S (w2[1]);
|
||||
w2[2] = hc_swap32_S (w2[2]);
|
||||
w2[3] = hc_swap32_S (w2[3]);
|
||||
w3[0] = hc_swap32_S (w3[0]);
|
||||
w3[1] = hc_swap32_S (w3[1]);
|
||||
w3[2] = hc_swap32_S (w3[2]);
|
||||
w3[3] = hc_swap32_S (w3[3]);
|
||||
|
||||
md5_update_64 (ctx, w0, w1, w2, w3, 32 * 2);
|
||||
}
|
||||
|
||||
w0[0] = w[pos4 + 0];
|
||||
w0[1] = w[pos4 + 1];
|
||||
w0[2] = w[pos4 + 2];
|
||||
w0[3] = w[pos4 + 3];
|
||||
w1[0] = w[pos4 + 4];
|
||||
w1[1] = w[pos4 + 5];
|
||||
w1[2] = w[pos4 + 6];
|
||||
w1[3] = w[pos4 + 7];
|
||||
|
||||
make_utf16le_S (w1, w2, w3);
|
||||
make_utf16le_S (w0, w0, w1);
|
||||
|
||||
w0[0] = hc_swap32_S (w0[0]);
|
||||
w0[1] = hc_swap32_S (w0[1]);
|
||||
w0[2] = hc_swap32_S (w0[2]);
|
||||
w0[3] = hc_swap32_S (w0[3]);
|
||||
w1[0] = hc_swap32_S (w1[0]);
|
||||
w1[1] = hc_swap32_S (w1[1]);
|
||||
w1[2] = hc_swap32_S (w1[2]);
|
||||
w1[3] = hc_swap32_S (w1[3]);
|
||||
w2[0] = hc_swap32_S (w2[0]);
|
||||
w2[1] = hc_swap32_S (w2[1]);
|
||||
w2[2] = hc_swap32_S (w2[2]);
|
||||
w2[3] = hc_swap32_S (w2[3]);
|
||||
w3[0] = hc_swap32_S (w3[0]);
|
||||
w3[1] = hc_swap32_S (w3[1]);
|
||||
w3[2] = hc_swap32_S (w3[2]);
|
||||
w3[3] = hc_swap32_S (w3[3]);
|
||||
|
||||
md5_update_64 (ctx, w0, w1, w2, w3, (len - pos1) * 2);
|
||||
}
|
||||
|
||||
DECLSPEC void md5_final (md5_ctx_t *ctx)
|
||||
{
|
||||
MAYBE_VOLATILE const int pos = ctx->len & 63;
|
||||
@ -1742,58 +1486,6 @@ DECLSPEC void md5_update_vector (md5_ctx_vector_t *ctx, const u32x *w, const int
|
||||
md5_update_vector_64 (ctx, w0, w1, w2, w3, len - pos1);
|
||||
}
|
||||
|
||||
DECLSPEC void md5_update_vector_from_scalar (md5_ctx_vector_t *ctx, const u32 *w, const int len)
|
||||
{
|
||||
u32x w0[4];
|
||||
u32x w1[4];
|
||||
u32x w2[4];
|
||||
u32x w3[4];
|
||||
|
||||
int pos1;
|
||||
int pos4;
|
||||
|
||||
for (pos1 = 0, pos4 = 0; pos1 < len - 64; pos1 += 64, pos4 += 16)
|
||||
{
|
||||
w0[0] = w[pos4 + 0];
|
||||
w0[1] = w[pos4 + 1];
|
||||
w0[2] = w[pos4 + 2];
|
||||
w0[3] = w[pos4 + 3];
|
||||
w1[0] = w[pos4 + 4];
|
||||
w1[1] = w[pos4 + 5];
|
||||
w1[2] = w[pos4 + 6];
|
||||
w1[3] = w[pos4 + 7];
|
||||
w2[0] = w[pos4 + 8];
|
||||
w2[1] = w[pos4 + 9];
|
||||
w2[2] = w[pos4 + 10];
|
||||
w2[3] = w[pos4 + 11];
|
||||
w3[0] = w[pos4 + 12];
|
||||
w3[1] = w[pos4 + 13];
|
||||
w3[2] = w[pos4 + 14];
|
||||
w3[3] = w[pos4 + 15];
|
||||
|
||||
md5_update_vector_64 (ctx, w0, w1, w2, w3, 64);
|
||||
}
|
||||
|
||||
w0[0] = w[pos4 + 0];
|
||||
w0[1] = w[pos4 + 1];
|
||||
w0[2] = w[pos4 + 2];
|
||||
w0[3] = w[pos4 + 3];
|
||||
w1[0] = w[pos4 + 4];
|
||||
w1[1] = w[pos4 + 5];
|
||||
w1[2] = w[pos4 + 6];
|
||||
w1[3] = w[pos4 + 7];
|
||||
w2[0] = w[pos4 + 8];
|
||||
w2[1] = w[pos4 + 9];
|
||||
w2[2] = w[pos4 + 10];
|
||||
w2[3] = w[pos4 + 11];
|
||||
w3[0] = w[pos4 + 12];
|
||||
w3[1] = w[pos4 + 13];
|
||||
w3[2] = w[pos4 + 14];
|
||||
w3[3] = w[pos4 + 15];
|
||||
|
||||
md5_update_vector_64 (ctx, w0, w1, w2, w3, len - pos1);
|
||||
}
|
||||
|
||||
DECLSPEC void md5_update_vector_swap (md5_ctx_vector_t *ctx, const u32x *w, const int len)
|
||||
{
|
||||
u32x w0[4];
|
||||
|
@ -100,10 +100,6 @@ DECLSPEC void md5_update_global (md5_ctx_t *ctx, GLOBAL_AS const u32 *w, const i
|
||||
DECLSPEC void md5_update_global_swap (md5_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
|
||||
DECLSPEC void md5_update_global_utf16le (md5_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
|
||||
DECLSPEC void md5_update_global_utf16le_swap (md5_ctx_t *ctx, GLOBAL_AS const u32 *w, const int len);
|
||||
DECLSPEC void md5_update_local (md5_ctx_t *ctx, LOCAL_AS const u32 *w, const int len);
|
||||
DECLSPEC void md5_update_local_swap (md5_ctx_t *ctx, LOCAL_AS const u32 *w, const int len);
|
||||
DECLSPEC void md5_update_local_utf16le (md5_ctx_t *ctx, LOCAL_AS const u32 *w, const int len);
|
||||
DECLSPEC void md5_update_local_utf16le_swap (md5_ctx_t *ctx, LOCAL_AS const u32 *w, const int len);
|
||||
DECLSPEC void md5_final (md5_ctx_t *ctx);
|
||||
DECLSPEC void md5_hmac_init_64 (md5_hmac_ctx_t *ctx, const u32 *w0, const u32 *w1, const u32 *w2, const u32 *w3);
|
||||
DECLSPEC void md5_hmac_init (md5_hmac_ctx_t *ctx, const u32 *w, const int len);
|
||||
@ -125,7 +121,6 @@ DECLSPEC void md5_init_vector (md5_ctx_vector_t *ctx);
|
||||
DECLSPEC void md5_init_vector_from_scalar (md5_ctx_vector_t *ctx, md5_ctx_t *ctx0);
|
||||
DECLSPEC void md5_update_vector_64 (md5_ctx_vector_t *ctx, u32x *w0, u32x *w1, u32x *w2, u32x *w3, const int len);
|
||||
DECLSPEC void md5_update_vector (md5_ctx_vector_t *ctx, const u32x *w, const int len);
|
||||
DECLSPEC void md5_update_vector_from_scalar (md5_ctx_vector_t *ctx, const u32 *w, const int len);
|
||||
DECLSPEC void md5_update_vector_swap (md5_ctx_vector_t *ctx, const u32x *w, const int len);
|
||||
DECLSPEC void md5_update_vector_utf16le (md5_ctx_vector_t *ctx, const u32x *w, const int len);
|
||||
DECLSPEC void md5_update_vector_utf16le_swap (md5_ctx_vector_t *ctx, const u32x *w, const int len);
|
||||
|
@ -1,190 +0,0 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#include "inc_types.h"
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_pem_common.h"
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_hash_md5.cl"
|
||||
#endif
|
||||
|
||||
DECLSPEC void generate_key (u32 *salt_buf, u32 *pw, size_t pw_len, u32 *key)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("salt_buf:");
|
||||
for (u32 i = 0; i < 16; i++) printf(" 0x%08x", salt_buf[i]);
|
||||
printf("\n");
|
||||
printf("pw:");
|
||||
for (u32 i = 0; i < 16; i++) printf(" 0x%08x", pw[i]);
|
||||
printf("\n");
|
||||
printf("pw_len: %lu\n", pw_len);
|
||||
#endif
|
||||
|
||||
u32 md_buf[16] = { 0 };
|
||||
md5_ctx_t md_ctx;
|
||||
|
||||
md5_init (&md_ctx);
|
||||
md5_update (&md_ctx, pw, pw_len);
|
||||
md5_update (&md_ctx, salt_buf, HC_PEM_SALT_LENGTH);
|
||||
md5_final (&md_ctx);
|
||||
|
||||
key[0] = md_ctx.h[0];
|
||||
|
||||
#if KEY_LENGTH > 4
|
||||
key[1] = md_ctx.h[1];
|
||||
#endif
|
||||
|
||||
#if KEY_LENGTH > 8
|
||||
key[2] = md_ctx.h[2];
|
||||
#endif
|
||||
|
||||
#if KEY_LENGTH > 12
|
||||
key[3] = md_ctx.h[3];
|
||||
#endif
|
||||
|
||||
#if KEY_LENGTH > 16
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < HC_PEM_MD_LENGTH / 4; i++)
|
||||
{
|
||||
md_buf[i] = md_ctx.h[i];
|
||||
}
|
||||
|
||||
md5_init (&md_ctx);
|
||||
md5_update (&md_ctx, md_buf, HC_PEM_MD_LENGTH);
|
||||
md5_update (&md_ctx, pw, pw_len);
|
||||
md5_update (&md_ctx, salt_buf, HC_PEM_SALT_LENGTH);
|
||||
md5_final (&md_ctx);
|
||||
|
||||
key[4] = md_ctx.h[0];
|
||||
#endif // KEY_LENGTH > 16
|
||||
|
||||
#if KEY_LENGTH > 20
|
||||
key[5] = md_ctx.h[1];
|
||||
#endif
|
||||
|
||||
#if KEY_LENGTH > 24
|
||||
key[6] = md_ctx.h[2];
|
||||
#endif
|
||||
|
||||
#if KEY_LENGTH > 28
|
||||
key[7] = md_ctx.h[3];
|
||||
#endif
|
||||
|
||||
#if KEY_LENGTH > 32
|
||||
#error Only supports up to KEY_LENGTH == 32 at present. Extend generate_key!
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("key:");
|
||||
for (u32 i = 0; i < KEY_LENGTH / 4; i++) printf(" 0x%08x", key[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
}
|
||||
|
||||
DECLSPEC void generate_key_vector (u32 *salt_buf, u32x *pw, size_t pw_len, u32x *key)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("salt_buf:");
|
||||
for (u32 i = 0; i < 16; i++) printf(" 0x%08x", salt_buf[i]);
|
||||
printf("\n");
|
||||
for (u32 v = 0; v < VECT_SIZE; v++)
|
||||
{
|
||||
printf("pw[%u]:", v);
|
||||
for (u32 i = 0; i < 16; i++) printf(" 0x%08x", VECTOR_ELEMENT(pw[i], v));
|
||||
printf("\n");
|
||||
}
|
||||
printf("pw_len: %lu\n", pw_len);
|
||||
#endif
|
||||
|
||||
u32x md_buf[16] = { 0 };
|
||||
md5_ctx_vector_t md_ctx;
|
||||
|
||||
md5_init_vector (&md_ctx);
|
||||
md5_update_vector (&md_ctx, pw, pw_len);
|
||||
md5_update_vector_from_scalar (&md_ctx, salt_buf, HC_PEM_SALT_LENGTH);
|
||||
md5_final_vector (&md_ctx);
|
||||
|
||||
key[0] = md_ctx.h[0];
|
||||
|
||||
#if KEY_LENGTH > 4
|
||||
key[1] = md_ctx.h[1];
|
||||
#endif
|
||||
|
||||
#if KEY_LENGTH > 8
|
||||
key[2] = md_ctx.h[2];
|
||||
#endif
|
||||
|
||||
#if KEY_LENGTH > 12
|
||||
key[3] = md_ctx.h[3];
|
||||
#endif
|
||||
|
||||
#if KEY_LENGTH > 16
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < HC_PEM_MD_LENGTH / 4; i++)
|
||||
{
|
||||
md_buf[i] = md_ctx.h[i];
|
||||
}
|
||||
|
||||
md5_init_vector (&md_ctx);
|
||||
md5_update_vector (&md_ctx, md_buf, HC_PEM_MD_LENGTH);
|
||||
md5_update_vector (&md_ctx, pw, pw_len);
|
||||
md5_update_vector_from_scalar (&md_ctx, salt_buf, HC_PEM_SALT_LENGTH);
|
||||
md5_final_vector (&md_ctx);
|
||||
|
||||
key[4] = md_ctx.h[0];
|
||||
#endif // KEY_LENGTH > 16
|
||||
|
||||
#if KEY_LENGTH > 20
|
||||
key[5] = md_ctx.h[1];
|
||||
#endif
|
||||
|
||||
#if KEY_LENGTH > 24
|
||||
key[6] = md_ctx.h[2];
|
||||
#endif
|
||||
|
||||
#if KEY_LENGTH > 28
|
||||
key[7] = md_ctx.h[3];
|
||||
#endif
|
||||
|
||||
#if KEY_LENGTH > 32
|
||||
#error Only supports up to KEY_LENGTH == 32 at present. Extend generate_key!
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
for (u32 v = 0; v < VECT_SIZE; v++)
|
||||
{
|
||||
printf("key[%u]:", v);
|
||||
for (u32 i = 0; i < KEY_LENGTH / 4; i++) printf(" 0x%08x", VECTOR_ELEMENT(key[i], v));
|
||||
printf("\n");
|
||||
}
|
||||
#endif // DEBUG
|
||||
}
|
||||
|
||||
DECLSPEC void prep_buffers(u32 *salt_buf, u32 *salt_iv, u32 *first_block, PSEUDO_SHM_TYPE u32 *data, GLOBAL_AS const pem_t *esalt)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < HC_PEM_SALT_LENGTH / 4; i++)
|
||||
{
|
||||
salt_buf[i] = esalt->salt_iv[i];
|
||||
}
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
salt_iv[i] = esalt->salt_iv[i];
|
||||
first_block[i] = data[i];
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#ifndef _INC_PEM_COMMON_H
|
||||
#define _INC_PEM_COMMON_H
|
||||
|
||||
#define HC_PEM_SALT_LENGTH 8
|
||||
#define HC_PEM_MD_LENGTH 16
|
||||
|
||||
#define HC_PEM_MAX_BLOCK_SIZE 16
|
||||
#define HC_PEM_MAX_KEY_LENGTH 32
|
||||
#define HC_PEM_MAX_DATA_LENGTH 12288
|
||||
|
||||
typedef struct pem
|
||||
{
|
||||
void *chosen_cipher;
|
||||
u32 salt_iv[HC_PEM_MAX_BLOCK_SIZE / 4];
|
||||
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
size_t data_len;
|
||||
} pem_t;
|
||||
|
||||
#ifdef REAL_SHM
|
||||
#define PSEUDO_SHM_TYPE LOCAL_AS
|
||||
#else
|
||||
#define PSEUDO_SHM_TYPE
|
||||
#endif
|
||||
|
||||
DECLSPEC void generate_key (u32 *salt_buf, u32 *pw, size_t pw_len, u32 *key);
|
||||
DECLSPEC void generate_key_vector (u32 *salt_buf, u32x *pw, size_t pw_len, u32x *key);
|
||||
DECLSPEC void prep_buffers (u32 *salt_buf, u32 *salt_iv, u32 *first_block, PSEUDO_SHM_TYPE u32 *data, GLOBAL_AS const pem_t *esalt);
|
||||
|
||||
#endif // _INC_PEM_COMMON_H
|
@ -3,43 +3,37 @@
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#define BLOCK_SIZE 8
|
||||
#define KEY_LENGTH 24
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_rp.h"
|
||||
#include "inc_rp.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_des.cl"
|
||||
#include "inc_pem_common.cl"
|
||||
#endif // KERNEL_STATIC
|
||||
#endif
|
||||
|
||||
KERNEL_FQ void m22911_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
typedef struct pem
|
||||
{
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22911_mxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 data_len;
|
||||
data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
for (u32 i = lid; i <= data_len / 4; i += lsz)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
LOCAL_VK u32 s_SPtrans[8][64];
|
||||
LOCAL_VK u32 s_skb[8][64];
|
||||
|
||||
@ -68,171 +62,378 @@ KERNEL_FQ void m22911_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
|
||||
#else
|
||||
|
||||
const size_t data_len = esalt_bufs[digests_offset].data_len;
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < data_len / 4; i++)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
|
||||
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
|
||||
|
||||
#endif // REAL_SHM
|
||||
#endif
|
||||
|
||||
u32 salt_buf[16] = { 0 };
|
||||
u32 salt_iv[BLOCK_SIZE / 4], first_block[BLOCK_SIZE / 4];
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
prep_buffers(salt_buf, salt_iv, first_block, data, &esalt_bufs[digests_offset]);
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
COPY_PW (pws[gid]);
|
||||
|
||||
u32 s[2];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
|
||||
u32 first_data[2];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[2];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
|
||||
u32 enc[2];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
|
||||
|
||||
pw_t tmp = PASTE_PW;
|
||||
|
||||
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
|
||||
|
||||
generate_key (salt_buf, tmp.i, tmp.pw_len, key);
|
||||
md5_ctx_t ctx;
|
||||
|
||||
u32 asn1_ok = 0, padding_ok = 0, plaintext_length, plaintext[BLOCK_SIZE / 4];
|
||||
u32 ciphertext[BLOCK_SIZE / 4], iv[BLOCK_SIZE / 4];
|
||||
u32 K0[16], K1[16], K2[16], K3[16], K4[16], K5[16];
|
||||
md5_init (&ctx);
|
||||
|
||||
_des_crypt_keysetup (key[0], key[1], K0, K1, s_skb);
|
||||
_des_crypt_keysetup (key[2], key[3], K2, K3, s_skb);
|
||||
_des_crypt_keysetup (key[4], key[5], K4, K5, s_skb);
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
u32 p1[BLOCK_SIZE / 4], p2[BLOCK_SIZE / 4];
|
||||
u32 t[16];
|
||||
|
||||
_des_crypt_decrypt (p1, first_block, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (plaintext, p2, K0, K1, s_SPtrans);
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
plaintext[i] ^= salt_iv[i];
|
||||
}
|
||||
md5_final (&ctx);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("First plaintext block:");
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
u32 ukey[6];
|
||||
|
||||
if (data_len < 128)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0x00ff80ff) == 0x00020030;
|
||||
plaintext_length = ((plaintext[0] & 0x00007f00) >> 8) + 2;
|
||||
}
|
||||
else if (data_len < 256)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0xff00ffff) == 0x02008130;
|
||||
plaintext_length = ((plaintext[0] & 0x00ff0000) >> 16) + 3;
|
||||
}
|
||||
else if (data_len < 65536)
|
||||
{
|
||||
asn1_ok = ((plaintext[0] & 0x0000ffff) == 0x00008230) && ((plaintext[1] & 0x000000ff) == 0x00000002);
|
||||
plaintext_length = ((plaintext[0] & 0xff000000) >> 24) + ((plaintext[0] & 0x00ff0000) >> 8) + 4;
|
||||
}
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
#ifdef DEBUG
|
||||
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
|
||||
#endif // DEBUG
|
||||
md5_init (&ctx);
|
||||
|
||||
if (asn1_ok == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
iv[i] = first_block[i];
|
||||
}
|
||||
ctx.len = 16;
|
||||
|
||||
for (u32 i = BLOCK_SIZE / 4; i < data_len / 4; i += BLOCK_SIZE / 4)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
ciphertext[j] = data[i + j];
|
||||
}
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
_des_crypt_decrypt (p1, ciphertext, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (plaintext, p2, K0, K1, s_SPtrans);
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
plaintext[j] ^= iv[j];
|
||||
iv[j] = ciphertext[j];
|
||||
}
|
||||
md5_final (&ctx);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Plaintext block %u:", i / (BLOCK_SIZE / 4));
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++) printf(" 0x%08x", plaintext[j]);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
|
||||
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
|
||||
u8 *pt_bytes = (u8 *) plaintext;
|
||||
// DES
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Padding byte: 0x%02x\n", padding_count);
|
||||
#endif
|
||||
u32 K0[16];
|
||||
u32 K1[16];
|
||||
u32 K2[16];
|
||||
u32 K3[16];
|
||||
u32 K4[16];
|
||||
u32 K5[16];
|
||||
|
||||
if (padding_count > BLOCK_SIZE || padding_count == 0)
|
||||
{
|
||||
// That *can't* be right
|
||||
padding_ok = 0;
|
||||
} else {
|
||||
padding_ok = 1;
|
||||
}
|
||||
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
|
||||
_des_crypt_keysetup (ukey[2], ukey[3], K2, K3, s_skb);
|
||||
_des_crypt_keysetup (ukey[4], ukey[5], K4, K5, s_skb);
|
||||
|
||||
for (u32 i = 0; i < padding_count; i++)
|
||||
{
|
||||
if (pt_bytes[BLOCK_SIZE - 1 - i] != padding_count)
|
||||
{
|
||||
padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
plaintext_length++;
|
||||
}
|
||||
u32 dec[2];
|
||||
|
||||
#ifdef DEBUG
|
||||
if (padding_ok == 1) printf("Padding checks out\n");
|
||||
if (plaintext_length == data_len) printf("ASN.1 sequence length checks out\n");
|
||||
#endif
|
||||
// first check the padding
|
||||
|
||||
if (asn1_ok == 1 && padding_ok == 1 && plaintext_length == data_len)
|
||||
{
|
||||
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
|
||||
{
|
||||
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset, gid, il_pos, 0, 0);
|
||||
}
|
||||
}
|
||||
u32 p1[2];
|
||||
u32 p2[2];
|
||||
|
||||
_des_crypt_decrypt (p1, enc, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (dec, p2, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
|
||||
const int paddingv = pkcs_padding_bs8 (dec, 8);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
_des_crypt_decrypt (p1, first_data, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (dec, p2, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
|
||||
const int real_len = (data_len - 8) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22911_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_SPtrans[8][64];
|
||||
LOCAL_VK u32 s_skb[8][64];
|
||||
|
||||
for (u32 i = lid; i < 64; i += lsz)
|
||||
{
|
||||
s_SPtrans[0][i] = c_SPtrans[0][i];
|
||||
s_SPtrans[1][i] = c_SPtrans[1][i];
|
||||
s_SPtrans[2][i] = c_SPtrans[2][i];
|
||||
s_SPtrans[3][i] = c_SPtrans[3][i];
|
||||
s_SPtrans[4][i] = c_SPtrans[4][i];
|
||||
s_SPtrans[5][i] = c_SPtrans[5][i];
|
||||
s_SPtrans[6][i] = c_SPtrans[6][i];
|
||||
s_SPtrans[7][i] = c_SPtrans[7][i];
|
||||
|
||||
s_skb[0][i] = c_skb[0][i];
|
||||
s_skb[1][i] = c_skb[1][i];
|
||||
s_skb[2][i] = c_skb[2][i];
|
||||
s_skb[3][i] = c_skb[3][i];
|
||||
s_skb[4][i] = c_skb[4][i];
|
||||
s_skb[5][i] = c_skb[5][i];
|
||||
s_skb[6][i] = c_skb[6][i];
|
||||
s_skb[7][i] = c_skb[7][i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
|
||||
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
|
||||
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
COPY_PW (pws[gid]);
|
||||
|
||||
u32 s[2];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
|
||||
u32 first_data[2];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[2];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
|
||||
u32 enc[2];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
pw_t tmp = PASTE_PW;
|
||||
|
||||
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
|
||||
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[6];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
|
||||
// DES
|
||||
|
||||
u32 K0[16];
|
||||
u32 K1[16];
|
||||
u32 K2[16];
|
||||
u32 K3[16];
|
||||
u32 K4[16];
|
||||
u32 K5[16];
|
||||
|
||||
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
|
||||
_des_crypt_keysetup (ukey[2], ukey[3], K2, K3, s_skb);
|
||||
_des_crypt_keysetup (ukey[4], ukey[5], K4, K5, s_skb);
|
||||
|
||||
u32 dec[2];
|
||||
|
||||
// first check the padding
|
||||
|
||||
u32 p1[2];
|
||||
u32 p2[2];
|
||||
|
||||
_des_crypt_decrypt (p1, enc, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (dec, p2, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
|
||||
const int paddingv = pkcs_padding_bs8 (dec, 8);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
_des_crypt_decrypt (p1, first_data, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (dec, p2, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
|
||||
const int real_len = (data_len - 8) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
@ -3,42 +3,35 @@
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#define BLOCK_SIZE 8
|
||||
#define KEY_LENGTH 24
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_des.cl"
|
||||
#include "inc_pem_common.cl"
|
||||
#endif // KERNEL_STATIC
|
||||
#endif
|
||||
|
||||
KERNEL_FQ void m22911_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
typedef struct pem
|
||||
{
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22911_mxx (KERN_ATTR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 data_len;
|
||||
data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
for (u32 i = lid; i <= data_len / 4; i += lsz)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
LOCAL_VK u32 s_SPtrans[8][64];
|
||||
LOCAL_VK u32 s_skb[8][64];
|
||||
|
||||
@ -67,35 +60,54 @@ KERNEL_FQ void m22911_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
|
||||
#else
|
||||
|
||||
const size_t data_len = esalt_bufs[digests_offset].data_len;
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < data_len / 4; i++)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
|
||||
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
|
||||
|
||||
#endif // REAL_SHM
|
||||
#endif
|
||||
|
||||
u32 salt_buf[16] = { 0 };
|
||||
u32 salt_iv[BLOCK_SIZE / 4], first_block[BLOCK_SIZE / 4];
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
prep_buffers(salt_buf, salt_iv, first_block, data, &esalt_bufs[digests_offset]);
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32 w[16] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
const u32 search[4] =
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[2];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
|
||||
u32 first_data[2];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[2];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
|
||||
u32 enc[2];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
@ -103,159 +115,319 @@ KERNEL_FQ void m22911_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
const u32 comb_len = combs_buf[il_pos].pw_len;
|
||||
u32 c[64];
|
||||
md5_ctx_t ctx;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
c[i] = combs_buf[il_pos].i[i];
|
||||
}
|
||||
md5_init (&ctx);
|
||||
|
||||
switch_buffer_by_offset_1x64_be_S (c, pw_len);
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
c[i] |= w[i];
|
||||
}
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
|
||||
u32 t[16];
|
||||
|
||||
generate_key (salt_buf, c, pw_len + comb_len, key);
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
u32 asn1_ok = 0, padding_ok = 0, plaintext_length, plaintext[BLOCK_SIZE / 4];
|
||||
u32 ciphertext[BLOCK_SIZE / 4], iv[BLOCK_SIZE / 4];
|
||||
u32 K0[16], K1[16], K2[16], K3[16], K4[16], K5[16];
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
_des_crypt_keysetup (key[0], key[1], K0, K1, s_skb);
|
||||
_des_crypt_keysetup (key[2], key[3], K2, K3, s_skb);
|
||||
_des_crypt_keysetup (key[4], key[5], K4, K5, s_skb);
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 p1[BLOCK_SIZE / 4], p2[BLOCK_SIZE / 4];
|
||||
u32 ukey[6];
|
||||
|
||||
_des_crypt_decrypt (p1, first_block, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (plaintext, p2, K0, K1, s_SPtrans);
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
plaintext[i] ^= salt_iv[i];
|
||||
}
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("First plaintext block:");
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
ctx.len = 16;
|
||||
|
||||
if (data_len < 128)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0x00ff80ff) == 0x00020030;
|
||||
plaintext_length = ((plaintext[0] & 0x00007f00) >> 8) + 2;
|
||||
}
|
||||
else if (data_len < 256)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0xff00ffff) == 0x02008130;
|
||||
plaintext_length = ((plaintext[0] & 0x00ff0000) >> 16) + 3;
|
||||
}
|
||||
else if (data_len < 65536)
|
||||
{
|
||||
asn1_ok = ((plaintext[0] & 0x0000ffff) == 0x00008230) && ((plaintext[1] & 0x000000ff) == 0x00000002);
|
||||
plaintext_length = ((plaintext[0] & 0xff000000) >> 24) + ((plaintext[0] & 0x00ff0000) >> 8) + 4;
|
||||
}
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
|
||||
#endif // DEBUG
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
if (asn1_ok == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
iv[i] = first_block[i];
|
||||
}
|
||||
md5_final (&ctx);
|
||||
|
||||
for (u32 i = BLOCK_SIZE / 4; i < data_len / 4; i += BLOCK_SIZE / 4)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
ciphertext[j] = data[i + j];
|
||||
}
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
|
||||
_des_crypt_decrypt (p1, ciphertext, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (plaintext, p2, K0, K1, s_SPtrans);
|
||||
// DES
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
plaintext[j] ^= iv[j];
|
||||
iv[j] = ciphertext[j];
|
||||
}
|
||||
u32 K0[16];
|
||||
u32 K1[16];
|
||||
u32 K2[16];
|
||||
u32 K3[16];
|
||||
u32 K4[16];
|
||||
u32 K5[16];
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Plaintext block %u:", i / (BLOCK_SIZE / 4));
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++) printf(" 0x%08x", plaintext[j]);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
|
||||
_des_crypt_keysetup (ukey[2], ukey[3], K2, K3, s_skb);
|
||||
_des_crypt_keysetup (ukey[4], ukey[5], K4, K5, s_skb);
|
||||
|
||||
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
|
||||
u8 *pt_bytes = (u8 *) plaintext;
|
||||
u32 dec[2];
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Padding byte: 0x%02x\n", padding_count);
|
||||
#endif
|
||||
// first check the padding
|
||||
|
||||
if (padding_count > BLOCK_SIZE || padding_count == 0)
|
||||
{
|
||||
// That *can't* be right
|
||||
padding_ok = 0;
|
||||
} else {
|
||||
padding_ok = 1;
|
||||
}
|
||||
u32 p1[2];
|
||||
u32 p2[2];
|
||||
|
||||
for (u32 i = 0; i < padding_count; i++)
|
||||
{
|
||||
if (pt_bytes[BLOCK_SIZE - 1 - i] != padding_count)
|
||||
{
|
||||
padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
plaintext_length++;
|
||||
}
|
||||
_des_crypt_decrypt (p1, enc, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (dec, p2, K0, K1, s_SPtrans);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (padding_ok == 1) printf("Padding checks out\n");
|
||||
if (plaintext_length == data_len) printf("ASN.1 sequence length checks out\n");
|
||||
#endif
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
|
||||
if (asn1_ok == 1 && padding_ok == 1 && plaintext_length == data_len)
|
||||
{
|
||||
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
|
||||
{
|
||||
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset, gid, il_pos, 0, 0);
|
||||
}
|
||||
}
|
||||
const int paddingv = pkcs_padding_bs8 (dec, 8);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
_des_crypt_decrypt (p1, first_data, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (dec, p2, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
|
||||
const int real_len = (data_len - 8) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22911_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_SPtrans[8][64];
|
||||
LOCAL_VK u32 s_skb[8][64];
|
||||
|
||||
for (u32 i = lid; i < 64; i += lsz)
|
||||
{
|
||||
s_SPtrans[0][i] = c_SPtrans[0][i];
|
||||
s_SPtrans[1][i] = c_SPtrans[1][i];
|
||||
s_SPtrans[2][i] = c_SPtrans[2][i];
|
||||
s_SPtrans[3][i] = c_SPtrans[3][i];
|
||||
s_SPtrans[4][i] = c_SPtrans[4][i];
|
||||
s_SPtrans[5][i] = c_SPtrans[5][i];
|
||||
s_SPtrans[6][i] = c_SPtrans[6][i];
|
||||
s_SPtrans[7][i] = c_SPtrans[7][i];
|
||||
|
||||
s_skb[0][i] = c_skb[0][i];
|
||||
s_skb[1][i] = c_skb[1][i];
|
||||
s_skb[2][i] = c_skb[2][i];
|
||||
s_skb[3][i] = c_skb[3][i];
|
||||
s_skb[4][i] = c_skb[4][i];
|
||||
s_skb[5][i] = c_skb[5][i];
|
||||
s_skb[6][i] = c_skb[6][i];
|
||||
s_skb[7][i] = c_skb[7][i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
|
||||
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
|
||||
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[2];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
|
||||
u32 first_data[2];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[2];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
|
||||
u32 enc[2];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[6];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
|
||||
// DES
|
||||
|
||||
u32 K0[16];
|
||||
u32 K1[16];
|
||||
u32 K2[16];
|
||||
u32 K3[16];
|
||||
u32 K4[16];
|
||||
u32 K5[16];
|
||||
|
||||
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
|
||||
_des_crypt_keysetup (ukey[2], ukey[3], K2, K3, s_skb);
|
||||
_des_crypt_keysetup (ukey[4], ukey[5], K4, K5, s_skb);
|
||||
|
||||
u32 dec[2];
|
||||
|
||||
// first check the padding
|
||||
|
||||
u32 p1[2];
|
||||
u32 p2[2];
|
||||
|
||||
_des_crypt_decrypt (p1, enc, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (dec, p2, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
|
||||
const int paddingv = pkcs_padding_bs8 (dec, 8);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
_des_crypt_decrypt (p1, first_data, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (dec, p2, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
|
||||
const int real_len = (data_len - 8) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
@ -3,45 +3,35 @@
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#define NEW_SIMD_CODE
|
||||
|
||||
#define BLOCK_SIZE 8
|
||||
#define KEY_LENGTH 24
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_simd.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_des.cl"
|
||||
#include "inc_pem_common.cl"
|
||||
#endif // KERNEL_STATIC
|
||||
#endif
|
||||
|
||||
KERNEL_FQ void m22911_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
typedef struct pem
|
||||
{
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22911_mxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 data_len;
|
||||
data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
for (u32 i = lid; i <= data_len / 4; i += lsz)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
LOCAL_VK u32 s_SPtrans[8][64];
|
||||
LOCAL_VK u32 s_skb[8][64];
|
||||
|
||||
@ -70,184 +60,408 @@ KERNEL_FQ void m22911_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
|
||||
#else
|
||||
|
||||
const size_t data_len = esalt_bufs[digests_offset].data_len;
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < data_len / 4; i++)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
|
||||
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
|
||||
|
||||
#endif // REAL_SHM
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[2];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
|
||||
u32 first_data[2];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[2];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
|
||||
u32 enc[2];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32 salt_buf[16] = { 0 };
|
||||
u32 salt_iv[BLOCK_SIZE / 4], first_block[BLOCK_SIZE / 4];
|
||||
|
||||
prep_buffers(salt_buf, salt_iv, first_block, data, &esalt_bufs[digests_offset]);
|
||||
|
||||
u32x w[16] = { 0 };
|
||||
u32x w[64] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
u32x w0l = w[0];
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
|
||||
{
|
||||
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
|
||||
|
||||
const u32x w0 = w0l | w0r;
|
||||
|
||||
w[0] = w0;
|
||||
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[6];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
|
||||
// DES
|
||||
|
||||
u32 K0[16];
|
||||
u32 K1[16];
|
||||
u32 K2[16];
|
||||
u32 K3[16];
|
||||
u32 K4[16];
|
||||
u32 K5[16];
|
||||
|
||||
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
|
||||
_des_crypt_keysetup (ukey[2], ukey[3], K2, K3, s_skb);
|
||||
_des_crypt_keysetup (ukey[4], ukey[5], K4, K5, s_skb);
|
||||
|
||||
u32 dec[2];
|
||||
|
||||
// first check the padding
|
||||
|
||||
u32 p1[2];
|
||||
u32 p2[2];
|
||||
|
||||
_des_crypt_decrypt (p1, enc, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (dec, p2, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
|
||||
const int paddingv = pkcs_padding_bs8 (dec, 8);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
_des_crypt_decrypt (p1, first_data, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (dec, p2, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
|
||||
const int real_len = (data_len - 8) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22911_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_SPtrans[8][64];
|
||||
LOCAL_VK u32 s_skb[8][64];
|
||||
|
||||
for (u32 i = lid; i < 64; i += lsz)
|
||||
{
|
||||
s_SPtrans[0][i] = c_SPtrans[0][i];
|
||||
s_SPtrans[1][i] = c_SPtrans[1][i];
|
||||
s_SPtrans[2][i] = c_SPtrans[2][i];
|
||||
s_SPtrans[3][i] = c_SPtrans[3][i];
|
||||
s_SPtrans[4][i] = c_SPtrans[4][i];
|
||||
s_SPtrans[5][i] = c_SPtrans[5][i];
|
||||
s_SPtrans[6][i] = c_SPtrans[6][i];
|
||||
s_SPtrans[7][i] = c_SPtrans[7][i];
|
||||
|
||||
s_skb[0][i] = c_skb[0][i];
|
||||
s_skb[1][i] = c_skb[1][i];
|
||||
s_skb[2][i] = c_skb[2][i];
|
||||
s_skb[3][i] = c_skb[3][i];
|
||||
s_skb[4][i] = c_skb[4][i];
|
||||
s_skb[5][i] = c_skb[5][i];
|
||||
s_skb[6][i] = c_skb[6][i];
|
||||
s_skb[7][i] = c_skb[7][i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
|
||||
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
|
||||
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[2];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
|
||||
u32 first_data[2];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[2];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
|
||||
u32 enc[2];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32x w[64] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
u32x w0l = w[0];
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
|
||||
{
|
||||
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
|
||||
|
||||
const u32x w0 = w0l | w0r;
|
||||
|
||||
w[0] = w0;
|
||||
|
||||
u32x key[HC_PEM_MAX_KEY_LENGTH / 4];
|
||||
md5_ctx_t ctx;
|
||||
|
||||
generate_key_vector (salt_buf, w, pw_len, key);
|
||||
md5_init (&ctx);
|
||||
|
||||
for (u32 v_pos = 0; v_pos < VECT_SIZE; v_pos++)
|
||||
{
|
||||
u32 asn1_ok = 0, padding_ok = 0, plaintext_length, plaintext[BLOCK_SIZE / 4];
|
||||
u32 ciphertext[BLOCK_SIZE / 4], iv[BLOCK_SIZE / 4];
|
||||
u32 K0[16], K1[16], K2[16], K3[16], K4[16], K5[16];
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
_des_crypt_keysetup (VECTOR_ELEMENT(key[0], v_pos), VECTOR_ELEMENT(key[1], v_pos), K0, K1, s_skb);
|
||||
_des_crypt_keysetup (VECTOR_ELEMENT(key[2], v_pos), VECTOR_ELEMENT(key[3], v_pos), K2, K3, s_skb);
|
||||
_des_crypt_keysetup (VECTOR_ELEMENT(key[4], v_pos), VECTOR_ELEMENT(key[5], v_pos), K4, K5, s_skb);
|
||||
u32 t[16];
|
||||
|
||||
u32 p1[BLOCK_SIZE / 4], p2[BLOCK_SIZE / 4];
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
_des_crypt_decrypt (p1, first_block, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (plaintext, p2, K0, K1, s_SPtrans);
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
plaintext[i] ^= salt_iv[i];
|
||||
}
|
||||
u32 ukey[6];
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("First plaintext block:");
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
if (data_len < 128)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0x00ff80ff) == 0x00020030;
|
||||
plaintext_length = ((plaintext[0] & 0x00007f00) >> 8) + 2;
|
||||
}
|
||||
else if (data_len < 256)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0xff00ffff) == 0x02008130;
|
||||
plaintext_length = ((plaintext[0] & 0x00ff0000) >> 16) + 3;
|
||||
}
|
||||
else if (data_len < 65536)
|
||||
{
|
||||
asn1_ok = ((plaintext[0] & 0x0000ffff) == 0x00008230) && ((plaintext[1] & 0x000000ff) == 0x00000002);
|
||||
plaintext_length = ((plaintext[0] & 0xff000000) >> 24) + ((plaintext[0] & 0x00ff0000) >> 8) + 4;
|
||||
}
|
||||
md5_init (&ctx);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
|
||||
#endif // DEBUG
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
if (asn1_ok == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ctx.len = 16;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
iv[i] = first_block[i];
|
||||
}
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
for (u32 i = BLOCK_SIZE / 4; i < data_len / 4; i += BLOCK_SIZE / 4)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
ciphertext[j] = data[i + j];
|
||||
}
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
_des_crypt_decrypt (p1, ciphertext, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (plaintext, p2, K0, K1, s_SPtrans);
|
||||
md5_final (&ctx);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
plaintext[j] ^= iv[j];
|
||||
iv[j] = ciphertext[j];
|
||||
}
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Plaintext block %u:", i / (BLOCK_SIZE / 4));
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++) printf(" 0x%08x", plaintext[j]);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
// DES
|
||||
|
||||
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
|
||||
u8 *pt_bytes = (u8 *) plaintext;
|
||||
u32 K0[16];
|
||||
u32 K1[16];
|
||||
u32 K2[16];
|
||||
u32 K3[16];
|
||||
u32 K4[16];
|
||||
u32 K5[16];
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Padding byte: 0x%02x\n", padding_count);
|
||||
#endif
|
||||
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
|
||||
_des_crypt_keysetup (ukey[2], ukey[3], K2, K3, s_skb);
|
||||
_des_crypt_keysetup (ukey[4], ukey[5], K4, K5, s_skb);
|
||||
|
||||
if (padding_count > BLOCK_SIZE || padding_count == 0)
|
||||
{
|
||||
// That *can't* be right
|
||||
padding_ok = 0;
|
||||
} else {
|
||||
padding_ok = 1;
|
||||
}
|
||||
u32 dec[2];
|
||||
|
||||
for (u32 i = 0; i < padding_count; i++)
|
||||
{
|
||||
if (pt_bytes[BLOCK_SIZE - 1 - i] != padding_count)
|
||||
{
|
||||
padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
plaintext_length++;
|
||||
}
|
||||
// first check the padding
|
||||
|
||||
#ifdef DEBUG
|
||||
if (padding_ok == 1) printf("Padding checks out\n");
|
||||
if (plaintext_length == data_len) printf("ASN.1 sequence length checks out\n");
|
||||
#endif
|
||||
u32 p1[2];
|
||||
u32 p2[2];
|
||||
|
||||
if (asn1_ok == 1 && padding_ok == 1 && plaintext_length == data_len)
|
||||
{
|
||||
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
|
||||
{
|
||||
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset, gid, il_pos + v_pos, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
_des_crypt_decrypt (p1, enc, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (dec, p2, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
|
||||
const int paddingv = pkcs_padding_bs8 (dec, 8);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
_des_crypt_decrypt (p1, first_data, K4, K5, s_SPtrans);
|
||||
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
|
||||
_des_crypt_decrypt (dec, p2, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
|
||||
const int real_len = (data_len - 8) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
@ -3,43 +3,37 @@
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#define BLOCK_SIZE 8
|
||||
#define KEY_LENGTH 8
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_rp.h"
|
||||
#include "inc_rp.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_des.cl"
|
||||
#include "inc_pem_common.cl"
|
||||
#endif // KERNEL_STATIC
|
||||
#endif
|
||||
|
||||
KERNEL_FQ void m22921_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
typedef struct pem
|
||||
{
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22921_mxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 data_len;
|
||||
data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
for (u32 i = lid; i <= data_len / 4; i += lsz)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
LOCAL_VK u32 s_SPtrans[8][64];
|
||||
LOCAL_VK u32 s_skb[8][64];
|
||||
|
||||
@ -68,28 +62,56 @@ KERNEL_FQ void m22921_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
|
||||
#else
|
||||
|
||||
const size_t data_len = esalt_bufs[digests_offset].data_len;
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < data_len / 4; i++)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
|
||||
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
|
||||
|
||||
#endif // REAL_SHM
|
||||
#endif
|
||||
|
||||
u32 salt_buf[16] = { 0 };
|
||||
u32 salt_iv[BLOCK_SIZE / 4], first_block[BLOCK_SIZE / 4];
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
prep_buffers(salt_buf, salt_iv, first_block, data, &esalt_bufs[digests_offset]);
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
COPY_PW(pws[gid]);
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
COPY_PW (pws[gid]);
|
||||
|
||||
u32 s[2];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
|
||||
u32 first_data[2];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[2];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
|
||||
u32 enc[2];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
@ -97,133 +119,255 @@ KERNEL_FQ void m22921_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
|
||||
|
||||
pw_t tmp = PASTE_PW;
|
||||
|
||||
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
|
||||
|
||||
generate_key (salt_buf, tmp.i, tmp.pw_len, key);
|
||||
md5_ctx_t ctx;
|
||||
|
||||
u32 asn1_ok = 0, padding_ok = 0, plaintext_length, plaintext[BLOCK_SIZE / 4];
|
||||
u32 ciphertext[BLOCK_SIZE / 4], iv[BLOCK_SIZE / 4];
|
||||
u32 K0[16], K1[16];
|
||||
md5_init (&ctx);
|
||||
|
||||
_des_crypt_keysetup (key[0], key[1], K0, K1, s_skb);
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
_des_crypt_decrypt (plaintext, first_block, K0, K1, s_SPtrans);
|
||||
u32 t[16];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
plaintext[i] ^= salt_iv[i];
|
||||
}
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("First plaintext block:");
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
if (data_len < 128)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0x00ff80ff) == 0x00020030;
|
||||
plaintext_length = ((plaintext[0] & 0x00007f00) >> 8) + 2;
|
||||
}
|
||||
else if (data_len < 256)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0xff00ffff) == 0x02008130;
|
||||
plaintext_length = ((plaintext[0] & 0x00ff0000) >> 16) + 3;
|
||||
}
|
||||
else if (data_len < 65536)
|
||||
{
|
||||
asn1_ok = ((plaintext[0] & 0x0000ffff) == 0x00008230) && ((plaintext[1] & 0x000000ff) == 0x00000002);
|
||||
plaintext_length = ((plaintext[0] & 0xff000000) >> 24) + ((plaintext[0] & 0x00ff0000) >> 8) + 4;
|
||||
}
|
||||
md5_final (&ctx);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
|
||||
#endif // DEBUG
|
||||
u32 ukey[2];
|
||||
|
||||
if (asn1_ok == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
iv[i] = first_block[i];
|
||||
}
|
||||
// DES
|
||||
|
||||
for (u32 i = BLOCK_SIZE / 4; i < data_len / 4; i += BLOCK_SIZE / 4)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
ciphertext[j] = data[i + j];
|
||||
}
|
||||
u32 K0[16];
|
||||
u32 K1[16];
|
||||
|
||||
_des_crypt_decrypt (plaintext, ciphertext, K0, K1, s_SPtrans);
|
||||
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
plaintext[j] ^= iv[j];
|
||||
iv[j] = ciphertext[j];
|
||||
}
|
||||
u32 dec[2];
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Plaintext block %u:", i / (BLOCK_SIZE / 4));
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++) printf(" 0x%08x", plaintext[j]);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
// first check the padding
|
||||
|
||||
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
|
||||
u8 *pt_bytes = (u8 *) plaintext;
|
||||
_des_crypt_decrypt (dec, enc, K0, K1, s_SPtrans);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Padding byte: 0x%02x\n", padding_count);
|
||||
#endif
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
|
||||
if (padding_count > BLOCK_SIZE || padding_count == 0)
|
||||
{
|
||||
// That *can't* be right
|
||||
padding_ok = 0;
|
||||
} else {
|
||||
padding_ok = 1;
|
||||
}
|
||||
const int paddingv = pkcs_padding_bs8 (dec, 8);
|
||||
|
||||
for (u32 i = 0; i < padding_count; i++)
|
||||
{
|
||||
if (pt_bytes[BLOCK_SIZE - 1 - i] != padding_count)
|
||||
{
|
||||
padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
plaintext_length++;
|
||||
}
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (padding_ok == 1) printf("Padding checks out\n");
|
||||
if (plaintext_length == data_len) printf("ASN.1 sequence length checks out\n");
|
||||
#endif
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
if (asn1_ok == 1 && padding_ok == 1 && plaintext_length == data_len)
|
||||
{
|
||||
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
|
||||
{
|
||||
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset, gid, il_pos, 0, 0);
|
||||
}
|
||||
}
|
||||
_des_crypt_decrypt (dec, first_data, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
|
||||
const int real_len = (data_len - 8) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22921_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_SPtrans[8][64];
|
||||
LOCAL_VK u32 s_skb[8][64];
|
||||
|
||||
for (u32 i = lid; i < 64; i += lsz)
|
||||
{
|
||||
s_SPtrans[0][i] = c_SPtrans[0][i];
|
||||
s_SPtrans[1][i] = c_SPtrans[1][i];
|
||||
s_SPtrans[2][i] = c_SPtrans[2][i];
|
||||
s_SPtrans[3][i] = c_SPtrans[3][i];
|
||||
s_SPtrans[4][i] = c_SPtrans[4][i];
|
||||
s_SPtrans[5][i] = c_SPtrans[5][i];
|
||||
s_SPtrans[6][i] = c_SPtrans[6][i];
|
||||
s_SPtrans[7][i] = c_SPtrans[7][i];
|
||||
|
||||
s_skb[0][i] = c_skb[0][i];
|
||||
s_skb[1][i] = c_skb[1][i];
|
||||
s_skb[2][i] = c_skb[2][i];
|
||||
s_skb[3][i] = c_skb[3][i];
|
||||
s_skb[4][i] = c_skb[4][i];
|
||||
s_skb[5][i] = c_skb[5][i];
|
||||
s_skb[6][i] = c_skb[6][i];
|
||||
s_skb[7][i] = c_skb[7][i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
|
||||
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
|
||||
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
COPY_PW (pws[gid]);
|
||||
|
||||
u32 s[2];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
|
||||
u32 first_data[2];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[2];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
|
||||
u32 enc[2];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
pw_t tmp = PASTE_PW;
|
||||
|
||||
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
|
||||
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[2];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
|
||||
// DES
|
||||
|
||||
u32 K0[16];
|
||||
u32 K1[16];
|
||||
|
||||
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
|
||||
|
||||
u32 dec[2];
|
||||
|
||||
// first check the padding
|
||||
|
||||
_des_crypt_decrypt (dec, enc, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
|
||||
const int paddingv = pkcs_padding_bs8 (dec, 8);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
_des_crypt_decrypt (dec, first_data, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
|
||||
const int real_len = (data_len - 8) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
@ -3,42 +3,35 @@
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#define BLOCK_SIZE 8
|
||||
#define KEY_LENGTH 8
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_des.cl"
|
||||
#include "inc_pem_common.cl"
|
||||
#endif // KERNEL_STATIC
|
||||
#endif
|
||||
|
||||
KERNEL_FQ void m22921_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
typedef struct pem
|
||||
{
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22921_mxx (KERN_ATTR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 data_len;
|
||||
data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
for (u32 i = lid; i <= data_len / 4; i += lsz)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
LOCAL_VK u32 s_SPtrans[8][64];
|
||||
LOCAL_VK u32 s_skb[8][64];
|
||||
|
||||
@ -67,35 +60,54 @@ KERNEL_FQ void m22921_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
|
||||
#else
|
||||
|
||||
const size_t data_len = esalt_bufs[digests_offset].data_len;
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < data_len / 4; i++)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
|
||||
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
|
||||
|
||||
#endif // REAL_SHM
|
||||
#endif
|
||||
|
||||
u32 salt_buf[16] = { 0 };
|
||||
u32 salt_iv[BLOCK_SIZE / 4], first_block[BLOCK_SIZE / 4];
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
prep_buffers(salt_buf, salt_iv, first_block, data, &esalt_bufs[digests_offset]);
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32 w[16] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
const u32 search[4] =
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[2];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
|
||||
u32 first_data[2];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[2];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
|
||||
u32 enc[2];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
@ -103,150 +115,249 @@ KERNEL_FQ void m22921_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
const u32 comb_len = combs_buf[il_pos].pw_len;
|
||||
u32 c[64];
|
||||
md5_ctx_t ctx;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
c[i] = combs_buf[il_pos].i[i];
|
||||
}
|
||||
md5_init (&ctx);
|
||||
|
||||
switch_buffer_by_offset_1x64_be_S (c, pw_len);
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
c[i] |= w[i];
|
||||
}
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
|
||||
u32 t[16];
|
||||
|
||||
generate_key (salt_buf, c, pw_len + comb_len, key);
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
u32 asn1_ok = 0, padding_ok = 0, plaintext_length, plaintext[BLOCK_SIZE / 4];
|
||||
u32 ciphertext[BLOCK_SIZE / 4], iv[BLOCK_SIZE / 4];
|
||||
u32 K0[16], K1[16];
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
_des_crypt_keysetup (key[0], key[1], K0, K1, s_skb);
|
||||
md5_final (&ctx);
|
||||
|
||||
_des_crypt_decrypt (plaintext, first_block, K0, K1, s_SPtrans);
|
||||
u32 ukey[2];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
plaintext[i] ^= salt_iv[i];
|
||||
}
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("First plaintext block:");
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
// DES
|
||||
|
||||
if (data_len < 128)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0x00ff80ff) == 0x00020030;
|
||||
plaintext_length = ((plaintext[0] & 0x00007f00) >> 8) + 2;
|
||||
}
|
||||
else if (data_len < 256)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0xff00ffff) == 0x02008130;
|
||||
plaintext_length = ((plaintext[0] & 0x00ff0000) >> 16) + 3;
|
||||
}
|
||||
else if (data_len < 65536)
|
||||
{
|
||||
asn1_ok = ((plaintext[0] & 0x0000ffff) == 0x00008230) && ((plaintext[1] & 0x000000ff) == 0x00000002);
|
||||
plaintext_length = ((plaintext[0] & 0xff000000) >> 24) + ((plaintext[0] & 0x00ff0000) >> 8) + 4;
|
||||
}
|
||||
u32 K0[16];
|
||||
u32 K1[16];
|
||||
|
||||
#ifdef DEBUG
|
||||
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
|
||||
#endif // DEBUG
|
||||
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
|
||||
|
||||
if (asn1_ok == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
u32 dec[2];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
iv[i] = first_block[i];
|
||||
}
|
||||
// first check the padding
|
||||
|
||||
for (u32 i = BLOCK_SIZE / 4; i < data_len / 4; i += BLOCK_SIZE / 4)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
ciphertext[j] = data[i + j];
|
||||
}
|
||||
_des_crypt_decrypt (dec, enc, K0, K1, s_SPtrans);
|
||||
|
||||
_des_crypt_decrypt (plaintext, ciphertext, K0, K1, s_SPtrans);
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
plaintext[j] ^= iv[j];
|
||||
iv[j] = ciphertext[j];
|
||||
}
|
||||
const int paddingv = pkcs_padding_bs8 (dec, 8);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Plaintext block %u:", i / (BLOCK_SIZE / 4));
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++) printf(" 0x%08x", plaintext[j]);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
|
||||
u8 *pt_bytes = (u8 *) plaintext;
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Padding byte: 0x%02x\n", padding_count);
|
||||
#endif
|
||||
_des_crypt_decrypt (dec, first_data, K0, K1, s_SPtrans);
|
||||
|
||||
if (padding_count > BLOCK_SIZE || padding_count == 0)
|
||||
{
|
||||
// That *can't* be right
|
||||
padding_ok = 0;
|
||||
} else {
|
||||
padding_ok = 1;
|
||||
}
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
|
||||
for (u32 i = 0; i < padding_count; i++)
|
||||
{
|
||||
if (pt_bytes[BLOCK_SIZE - 1 - i] != padding_count)
|
||||
{
|
||||
padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
plaintext_length++;
|
||||
}
|
||||
const int real_len = (data_len - 8) + paddingv;
|
||||
|
||||
#ifdef DEBUG
|
||||
if (padding_ok == 1) printf("Padding checks out\n");
|
||||
if (plaintext_length == data_len) printf("ASN.1 sequence length checks out\n");
|
||||
#endif
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 1 && padding_ok == 1 && plaintext_length == data_len)
|
||||
{
|
||||
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
|
||||
{
|
||||
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset, gid, il_pos, 0, 0);
|
||||
}
|
||||
}
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22921_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_SPtrans[8][64];
|
||||
LOCAL_VK u32 s_skb[8][64];
|
||||
|
||||
for (u32 i = lid; i < 64; i += lsz)
|
||||
{
|
||||
s_SPtrans[0][i] = c_SPtrans[0][i];
|
||||
s_SPtrans[1][i] = c_SPtrans[1][i];
|
||||
s_SPtrans[2][i] = c_SPtrans[2][i];
|
||||
s_SPtrans[3][i] = c_SPtrans[3][i];
|
||||
s_SPtrans[4][i] = c_SPtrans[4][i];
|
||||
s_SPtrans[5][i] = c_SPtrans[5][i];
|
||||
s_SPtrans[6][i] = c_SPtrans[6][i];
|
||||
s_SPtrans[7][i] = c_SPtrans[7][i];
|
||||
|
||||
s_skb[0][i] = c_skb[0][i];
|
||||
s_skb[1][i] = c_skb[1][i];
|
||||
s_skb[2][i] = c_skb[2][i];
|
||||
s_skb[3][i] = c_skb[3][i];
|
||||
s_skb[4][i] = c_skb[4][i];
|
||||
s_skb[5][i] = c_skb[5][i];
|
||||
s_skb[6][i] = c_skb[6][i];
|
||||
s_skb[7][i] = c_skb[7][i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
|
||||
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
|
||||
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[2];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
|
||||
u32 first_data[2];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[2];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
|
||||
u32 enc[2];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[2];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
|
||||
// DES
|
||||
|
||||
u32 K0[16];
|
||||
u32 K1[16];
|
||||
|
||||
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
|
||||
|
||||
u32 dec[2];
|
||||
|
||||
// first check the padding
|
||||
|
||||
_des_crypt_decrypt (dec, enc, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
|
||||
const int paddingv = pkcs_padding_bs8 (dec, 8);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
_des_crypt_decrypt (dec, first_data, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
|
||||
const int real_len = (data_len - 8) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
@ -3,45 +3,35 @@
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#define NEW_SIMD_CODE
|
||||
|
||||
#define BLOCK_SIZE 8
|
||||
#define KEY_LENGTH 8
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_simd.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_des.cl"
|
||||
#include "inc_pem_common.cl"
|
||||
#endif // KERNEL_STATIC
|
||||
#endif
|
||||
|
||||
KERNEL_FQ void m22921_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
typedef struct pem
|
||||
{
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22921_mxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 data_len;
|
||||
data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
for (u32 i = lid; i <= data_len / 4; i += lsz)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
LOCAL_VK u32 s_SPtrans[8][64];
|
||||
LOCAL_VK u32 s_skb[8][64];
|
||||
|
||||
@ -70,175 +60,343 @@ KERNEL_FQ void m22921_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
|
||||
#else
|
||||
|
||||
const size_t data_len = esalt_bufs[digests_offset].data_len;
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < data_len / 4; i++)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
|
||||
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
|
||||
|
||||
#endif // REAL_SHM
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[2];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
|
||||
u32 first_data[2];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[2];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
|
||||
u32 enc[2];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32 salt_buf[16] = { 0 };
|
||||
u32 salt_iv[BLOCK_SIZE / 4], first_block[BLOCK_SIZE / 4];
|
||||
|
||||
prep_buffers(salt_buf, salt_iv, first_block, data, &esalt_bufs[digests_offset]);
|
||||
|
||||
u32x w[16] = { 0 };
|
||||
u32x w[64] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
u32x w0l = w[0];
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
|
||||
{
|
||||
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
|
||||
|
||||
const u32x w0 = w0l | w0r;
|
||||
|
||||
w[0] = w0;
|
||||
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[2];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
|
||||
// DES
|
||||
|
||||
u32 K0[16];
|
||||
u32 K1[16];
|
||||
|
||||
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
|
||||
|
||||
u32 dec[2];
|
||||
|
||||
// first check the padding
|
||||
|
||||
_des_crypt_decrypt (dec, enc, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
|
||||
const int paddingv = pkcs_padding_bs8 (dec, 8);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
_des_crypt_decrypt (dec, first_data, K0, K1, s_SPtrans);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
|
||||
const int real_len = (data_len - 8) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
KERNEL_FQ void m22921_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_SPtrans[8][64];
|
||||
LOCAL_VK u32 s_skb[8][64];
|
||||
|
||||
for (u32 i = lid; i < 64; i += lsz)
|
||||
{
|
||||
s_SPtrans[0][i] = c_SPtrans[0][i];
|
||||
s_SPtrans[1][i] = c_SPtrans[1][i];
|
||||
s_SPtrans[2][i] = c_SPtrans[2][i];
|
||||
s_SPtrans[3][i] = c_SPtrans[3][i];
|
||||
s_SPtrans[4][i] = c_SPtrans[4][i];
|
||||
s_SPtrans[5][i] = c_SPtrans[5][i];
|
||||
s_SPtrans[6][i] = c_SPtrans[6][i];
|
||||
s_SPtrans[7][i] = c_SPtrans[7][i];
|
||||
|
||||
s_skb[0][i] = c_skb[0][i];
|
||||
s_skb[1][i] = c_skb[1][i];
|
||||
s_skb[2][i] = c_skb[2][i];
|
||||
s_skb[3][i] = c_skb[3][i];
|
||||
s_skb[4][i] = c_skb[4][i];
|
||||
s_skb[5][i] = c_skb[5][i];
|
||||
s_skb[6][i] = c_skb[6][i];
|
||||
s_skb[7][i] = c_skb[7][i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a (*s_SPtrans)[64] = c_SPtrans;
|
||||
CONSTANT_AS u32a (*s_skb)[64] = c_skb;
|
||||
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[2];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
|
||||
u32 first_data[2];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[2];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
|
||||
u32 enc[2];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32x w[64] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
u32x w0l = w[0];
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
|
||||
{
|
||||
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
|
||||
|
||||
const u32x w0 = w0l | w0r;
|
||||
|
||||
w[0] = w0;
|
||||
|
||||
u32x key[HC_PEM_MAX_KEY_LENGTH / 4];
|
||||
md5_ctx_t ctx;
|
||||
|
||||
generate_key_vector (salt_buf, w, pw_len, key);
|
||||
md5_init (&ctx);
|
||||
|
||||
for (u32 v_pos = 0; v_pos < VECT_SIZE; v_pos++)
|
||||
{
|
||||
u32 asn1_ok = 0, padding_ok = 0, plaintext_length, plaintext[BLOCK_SIZE / 4];
|
||||
u32 ciphertext[BLOCK_SIZE / 4], iv[BLOCK_SIZE / 4];
|
||||
u32 K0[16], K1[16];
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
_des_crypt_keysetup (VECTOR_ELEMENT(key[0], v_pos), VECTOR_ELEMENT(key[1], v_pos), K0, K1, s_skb);
|
||||
u32 t[16];
|
||||
|
||||
_des_crypt_decrypt (plaintext, first_block, K0, K1, s_SPtrans);
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
plaintext[i] ^= salt_iv[i];
|
||||
}
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("First plaintext block:");
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
md5_final (&ctx);
|
||||
|
||||
if (data_len < 128)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0x00ff80ff) == 0x00020030;
|
||||
plaintext_length = ((plaintext[0] & 0x00007f00) >> 8) + 2;
|
||||
}
|
||||
else if (data_len < 256)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0xff00ffff) == 0x02008130;
|
||||
plaintext_length = ((plaintext[0] & 0x00ff0000) >> 16) + 3;
|
||||
}
|
||||
else if (data_len < 65536)
|
||||
{
|
||||
asn1_ok = ((plaintext[0] & 0x0000ffff) == 0x00008230) && ((plaintext[1] & 0x000000ff) == 0x00000002);
|
||||
plaintext_length = ((plaintext[0] & 0xff000000) >> 24) + ((plaintext[0] & 0x00ff0000) >> 8) + 4;
|
||||
}
|
||||
u32 ukey[2];
|
||||
|
||||
#ifdef DEBUG
|
||||
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
|
||||
#endif // DEBUG
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
|
||||
if (asn1_ok == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// DES
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
iv[i] = first_block[i];
|
||||
}
|
||||
u32 K0[16];
|
||||
u32 K1[16];
|
||||
|
||||
for (u32 i = BLOCK_SIZE / 4; i < data_len / 4; i += BLOCK_SIZE / 4)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
ciphertext[j] = data[i + j];
|
||||
}
|
||||
_des_crypt_keysetup (ukey[0], ukey[1], K0, K1, s_skb);
|
||||
|
||||
_des_crypt_decrypt (plaintext, ciphertext, K0, K1, s_SPtrans);
|
||||
u32 dec[2];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
plaintext[j] ^= iv[j];
|
||||
iv[j] = ciphertext[j];
|
||||
}
|
||||
// first check the padding
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Plaintext block %u:", i / (BLOCK_SIZE / 4));
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++) printf(" 0x%08x", plaintext[j]);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
_des_crypt_decrypt (dec, enc, K0, K1, s_SPtrans);
|
||||
|
||||
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
|
||||
u8 *pt_bytes = (u8 *) plaintext;
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Padding byte: 0x%02x\n", padding_count);
|
||||
#endif
|
||||
const int paddingv = pkcs_padding_bs8 (dec, 8);
|
||||
|
||||
if (padding_count > BLOCK_SIZE || padding_count == 0)
|
||||
{
|
||||
// That *can't* be right
|
||||
padding_ok = 0;
|
||||
} else {
|
||||
padding_ok = 1;
|
||||
}
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
for (u32 i = 0; i < padding_count; i++)
|
||||
{
|
||||
if (pt_bytes[BLOCK_SIZE - 1 - i] != padding_count)
|
||||
{
|
||||
padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
plaintext_length++;
|
||||
}
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
#ifdef DEBUG
|
||||
if (padding_ok == 1) printf("Padding checks out\n");
|
||||
if (plaintext_length == data_len) printf("ASN.1 sequence length checks out\n");
|
||||
#endif
|
||||
_des_crypt_decrypt (dec, first_data, K0, K1, s_SPtrans);
|
||||
|
||||
if (asn1_ok == 1 && padding_ok == 1 && plaintext_length == data_len)
|
||||
{
|
||||
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
|
||||
{
|
||||
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset, gid, il_pos + v_pos, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
|
||||
const int real_len = (data_len - 8) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
@ -3,43 +3,41 @@
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#define BLOCK_SIZE 16
|
||||
#define KEY_LENGTH 16
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_rp.h"
|
||||
#include "inc_rp.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_aes.cl"
|
||||
#include "inc_pem_common.cl"
|
||||
#endif // KERNEL_STATIC
|
||||
#endif
|
||||
|
||||
KERNEL_FQ void m22931_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
typedef struct pem
|
||||
{
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22931_mxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 data_len;
|
||||
data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
for (u32 i = lid; i <= data_len / 4; i += lsz)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
@ -71,16 +69,212 @@ KERNEL_FQ void m22931_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
|
||||
#else
|
||||
|
||||
const size_t data_len = esalt_bufs[digests_offset].data_len;
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
CONSTANT_AS u32a *s_td3 = td3;
|
||||
CONSTANT_AS u32a *s_td4 = td4;
|
||||
|
||||
CONSTANT_AS u32a *s_te0 = te0;
|
||||
CONSTANT_AS u32a *s_te1 = te1;
|
||||
CONSTANT_AS u32a *s_te2 = te2;
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < data_len / 4; i++)
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
COPY_PW (pws[gid]);
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
pw_t tmp = PASTE_PW;
|
||||
|
||||
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
|
||||
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[4];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
|
||||
u32 ks[44];
|
||||
|
||||
AES128_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
u32 dec[4];
|
||||
|
||||
// first check the padding
|
||||
|
||||
aes128_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes128_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22931_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
LOCAL_VK u32 s_td3[256];
|
||||
LOCAL_VK u32 s_td4[256];
|
||||
|
||||
LOCAL_VK u32 s_te0[256];
|
||||
LOCAL_VK u32 s_te1[256];
|
||||
LOCAL_VK u32 s_te2[256];
|
||||
LOCAL_VK u32 s_te3[256];
|
||||
LOCAL_VK u32 s_te4[256];
|
||||
|
||||
for (u32 i = lid; i < 256; i += lsz)
|
||||
{
|
||||
s_td0[i] = td0[i];
|
||||
s_td1[i] = td1[i];
|
||||
s_td2[i] = td2[i];
|
||||
s_td3[i] = td3[i];
|
||||
s_td4[i] = td4[i];
|
||||
|
||||
s_te0[i] = te0[i];
|
||||
s_te1[i] = te1[i];
|
||||
s_te2[i] = te2[i];
|
||||
s_te3[i] = te3[i];
|
||||
s_te4[i] = te4[i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
@ -94,148 +288,154 @@ KERNEL_FQ void m22931_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#endif // REAL_SHM
|
||||
#endif
|
||||
|
||||
u32 salt_buf[16] = { 0 };
|
||||
u32 salt_iv[BLOCK_SIZE / 4], first_block[BLOCK_SIZE / 4];
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
prep_buffers(salt_buf, salt_iv, first_block, data, &esalt_bufs[digests_offset]);
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
COPY_PW (pws[gid]);
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
|
||||
|
||||
pw_t tmp = PASTE_PW;
|
||||
|
||||
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
|
||||
|
||||
generate_key (salt_buf, tmp.i, tmp.pw_len, key);
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[4];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
|
||||
u32 asn1_ok = 0, padding_ok = 0, plaintext_length, plaintext[BLOCK_SIZE / 4];
|
||||
u32 ciphertext[BLOCK_SIZE / 4], iv[BLOCK_SIZE / 4];
|
||||
u32 ks[44];
|
||||
|
||||
aes128_set_decrypt_key (ks, key, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
AES128_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
aes128_decrypt (ks, first_block, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
u32 dec[4];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
plaintext[i] ^= salt_iv[i];
|
||||
}
|
||||
// first check the padding
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("First plaintext block:");
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
aes128_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
if (data_len < 128)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0x00ff80ff) == 0x00020030;
|
||||
plaintext_length = ((plaintext[0] & 0x00007f00) >> 8) + 2;
|
||||
}
|
||||
else if (data_len < 256)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0xff00ffff) == 0x02008130;
|
||||
plaintext_length = ((plaintext[0] & 0x00ff0000) >> 16) + 3;
|
||||
}
|
||||
else if (data_len < 65536)
|
||||
{
|
||||
asn1_ok = ((plaintext[0] & 0x0000ffff) == 0x00008230) && ((plaintext[1] & 0x000000ff) == 0x00000002);
|
||||
plaintext_length = ((plaintext[0] & 0xff000000) >> 24) + ((plaintext[0] & 0x00ff0000) >> 8) + 4;
|
||||
}
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
#ifdef DEBUG
|
||||
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
|
||||
#endif // DEBUG
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (asn1_ok == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
iv[i] = first_block[i];
|
||||
}
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
for (u32 i = BLOCK_SIZE / 4; i < data_len / 4; i += BLOCK_SIZE / 4)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
ciphertext[j] = data[i + j];
|
||||
}
|
||||
aes128_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
aes128_decrypt (ks, ciphertext, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
plaintext[j] ^= iv[j];
|
||||
iv[j] = ciphertext[j];
|
||||
}
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Plaintext block %u:", i / (BLOCK_SIZE / 4));
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++) printf(" 0x%08x", plaintext[j]);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
|
||||
u8 *pt_bytes = (u8 *) plaintext;
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Padding byte: 0x%02x\n", padding_count);
|
||||
#endif
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
if (padding_count > BLOCK_SIZE || padding_count == 0)
|
||||
{
|
||||
// That *can't* be right
|
||||
padding_ok = 0;
|
||||
} else {
|
||||
padding_ok = 1;
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < padding_count; i++)
|
||||
{
|
||||
if (pt_bytes[BLOCK_SIZE - 1 - i] != padding_count)
|
||||
{
|
||||
padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
plaintext_length++;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (padding_ok == 1) printf("Padding checks out\n");
|
||||
if (plaintext_length == data_len) printf("ASN.1 sequence length checks out\n");
|
||||
#endif
|
||||
|
||||
if (asn1_ok == 1 && padding_ok == 1 && plaintext_length == data_len)
|
||||
{
|
||||
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
|
||||
{
|
||||
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset, gid, il_pos, 0, 0);
|
||||
}
|
||||
}
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
@ -3,42 +3,39 @@
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#define BLOCK_SIZE 16
|
||||
#define KEY_LENGTH 16
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_aes.cl"
|
||||
#include "inc_pem_common.cl"
|
||||
#endif // KERNEL_STATIC
|
||||
#endif
|
||||
|
||||
KERNEL_FQ void m22931_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
typedef struct pem
|
||||
{
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22931_mxx (KERN_ATTR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 data_len;
|
||||
data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
for (u32 i = lid; i <= data_len / 4; i += lsz)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
@ -70,16 +67,208 @@ KERNEL_FQ void m22931_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
|
||||
#else
|
||||
|
||||
const size_t data_len = esalt_bufs[digests_offset].data_len;
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
CONSTANT_AS u32a *s_td3 = td3;
|
||||
CONSTANT_AS u32a *s_td4 = td4;
|
||||
|
||||
CONSTANT_AS u32a *s_te0 = te0;
|
||||
CONSTANT_AS u32a *s_te1 = te1;
|
||||
CONSTANT_AS u32a *s_te2 = te2;
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < data_len / 4; i++)
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[4];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
|
||||
u32 ks[44];
|
||||
|
||||
AES128_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
u32 dec[4];
|
||||
|
||||
// first check the padding
|
||||
|
||||
aes128_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes128_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22931_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
LOCAL_VK u32 s_td3[256];
|
||||
LOCAL_VK u32 s_td4[256];
|
||||
|
||||
LOCAL_VK u32 s_te0[256];
|
||||
LOCAL_VK u32 s_te1[256];
|
||||
LOCAL_VK u32 s_te2[256];
|
||||
LOCAL_VK u32 s_te3[256];
|
||||
LOCAL_VK u32 s_te4[256];
|
||||
|
||||
for (u32 i = lid; i < 256; i += lsz)
|
||||
{
|
||||
s_td0[i] = td0[i];
|
||||
s_td1[i] = td1[i];
|
||||
s_td2[i] = td2[i];
|
||||
s_td3[i] = td3[i];
|
||||
s_td4[i] = td4[i];
|
||||
|
||||
s_te0[i] = te0[i];
|
||||
s_te1[i] = te1[i];
|
||||
s_te2[i] = te2[i];
|
||||
s_te3[i] = te3[i];
|
||||
s_te4[i] = te4[i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
@ -93,21 +282,59 @@ KERNEL_FQ void m22931_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#endif // REAL_SHM
|
||||
#endif
|
||||
|
||||
u32 salt_buf[16] = { 0 };
|
||||
u32 salt_iv[BLOCK_SIZE / 4], first_block[BLOCK_SIZE / 4];
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
prep_buffers(salt_buf, salt_iv, first_block, data, &esalt_bufs[digests_offset]);
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32 w[16] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
const u32 search[4] =
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
@ -115,150 +342,90 @@ KERNEL_FQ void m22931_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
const u32 comb_len = combs_buf[il_pos].pw_len;
|
||||
u32 c[64];
|
||||
md5_ctx_t ctx;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
c[i] = combs_buf[il_pos].i[i];
|
||||
}
|
||||
md5_init (&ctx);
|
||||
|
||||
switch_buffer_by_offset_1x64_be_S (c, pw_len);
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
c[i] |= w[i];
|
||||
}
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
|
||||
u32 t[16];
|
||||
|
||||
generate_key (salt_buf, c, pw_len + comb_len, key);
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[4];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
|
||||
u32 asn1_ok = 0, padding_ok = 0, plaintext_length, plaintext[BLOCK_SIZE / 4];
|
||||
u32 ciphertext[BLOCK_SIZE / 4], iv[BLOCK_SIZE / 4];
|
||||
u32 ks[44];
|
||||
|
||||
aes128_set_decrypt_key (ks, key, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
AES128_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
aes128_decrypt (ks, first_block, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
u32 dec[4];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
plaintext[i] ^= salt_iv[i];
|
||||
}
|
||||
// first check the padding
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("First plaintext block:");
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
aes128_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
if (data_len < 128)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0x00ff80ff) == 0x00020030;
|
||||
plaintext_length = ((plaintext[0] & 0x00007f00) >> 8) + 2;
|
||||
}
|
||||
else if (data_len < 256)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0xff00ffff) == 0x02008130;
|
||||
plaintext_length = ((plaintext[0] & 0x00ff0000) >> 16) + 3;
|
||||
}
|
||||
else if (data_len < 65536)
|
||||
{
|
||||
asn1_ok = ((plaintext[0] & 0x0000ffff) == 0x00008230) && ((plaintext[1] & 0x000000ff) == 0x00000002);
|
||||
plaintext_length = ((plaintext[0] & 0xff000000) >> 24) + ((plaintext[0] & 0x00ff0000) >> 8) + 4;
|
||||
}
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
#ifdef DEBUG
|
||||
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
|
||||
#endif // DEBUG
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (asn1_ok == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
iv[i] = first_block[i];
|
||||
}
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
for (u32 i = BLOCK_SIZE / 4; i < data_len / 4; i += BLOCK_SIZE / 4)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
ciphertext[j] = data[i + j];
|
||||
}
|
||||
aes128_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
aes128_decrypt (ks, ciphertext, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
plaintext[j] ^= iv[j];
|
||||
iv[j] = ciphertext[j];
|
||||
}
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Plaintext block %u:", i / (BLOCK_SIZE / 4));
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++) printf(" 0x%08x", plaintext[j]);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
|
||||
u8 *pt_bytes = (u8 *) plaintext;
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Padding byte: 0x%02x\n", padding_count);
|
||||
#endif
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
if (padding_count > BLOCK_SIZE || padding_count == 0)
|
||||
{
|
||||
// That *can't* be right
|
||||
padding_ok = 0;
|
||||
} else {
|
||||
padding_ok = 1;
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < padding_count; i++)
|
||||
{
|
||||
if (pt_bytes[BLOCK_SIZE - 1 - i] != padding_count)
|
||||
{
|
||||
padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
plaintext_length++;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (padding_ok == 1) printf("Padding checks out\n");
|
||||
if (plaintext_length == data_len) printf("ASN.1 sequence length checks out\n");
|
||||
#endif
|
||||
|
||||
if (asn1_ok == 1 && padding_ok == 1 && plaintext_length == data_len)
|
||||
{
|
||||
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
|
||||
{
|
||||
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset, gid, il_pos, 0, 0);
|
||||
}
|
||||
}
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
@ -3,45 +3,39 @@
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#define NEW_SIMD_CODE
|
||||
|
||||
#define BLOCK_SIZE 16
|
||||
#define KEY_LENGTH 16
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_simd.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_aes.cl"
|
||||
#include "inc_pem_common.cl"
|
||||
#endif // KERNEL_STATIC
|
||||
#endif
|
||||
|
||||
KERNEL_FQ void m22931_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
typedef struct pem
|
||||
{
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22931_mxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 data_len;
|
||||
data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
for (u32 i = lid; i <= data_len / 4; i += lsz)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
@ -73,17 +67,228 @@ KERNEL_FQ void m22931_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
|
||||
#else
|
||||
|
||||
const size_t data_len = esalt_bufs[digests_offset].data_len;
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
CONSTANT_AS u32a *s_td3 = td3;
|
||||
CONSTANT_AS u32a *s_td4 = td4;
|
||||
|
||||
CONSTANT_AS u32a *s_te0 = te0;
|
||||
CONSTANT_AS u32a *s_te1 = te1;
|
||||
CONSTANT_AS u32a *s_te2 = te2;
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < data_len / 4; i++)
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32x w[64] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
u32x w0l = w[0];
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
|
||||
{
|
||||
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
|
||||
|
||||
const u32x w0 = w0l | w0r;
|
||||
|
||||
w[0] = w0;
|
||||
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[4];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
|
||||
u32 ks[44];
|
||||
|
||||
AES128_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
u32 dec[4];
|
||||
|
||||
// first check the padding
|
||||
|
||||
aes128_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes128_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22931_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
LOCAL_VK u32 s_td3[256];
|
||||
LOCAL_VK u32 s_td4[256];
|
||||
|
||||
LOCAL_VK u32 s_te0[256];
|
||||
LOCAL_VK u32 s_te1[256];
|
||||
LOCAL_VK u32 s_te2[256];
|
||||
LOCAL_VK u32 s_te3[256];
|
||||
LOCAL_VK u32 s_te4[256];
|
||||
|
||||
for (u32 i = lid; i < 256; i += lsz)
|
||||
{
|
||||
s_td0[i] = td0[i];
|
||||
s_td1[i] = td1[i];
|
||||
s_td2[i] = td2[i];
|
||||
s_td3[i] = td3[i];
|
||||
s_td4[i] = td4[i];
|
||||
|
||||
s_te0[i] = te0[i];
|
||||
s_te1[i] = te1[i];
|
||||
s_te2[i] = te2[i];
|
||||
s_te3[i] = te3[i];
|
||||
s_te4[i] = te4[i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
@ -96,170 +301,169 @@ KERNEL_FQ void m22931_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#endif // REAL_SHM
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32 salt_buf[16] = { 0 };
|
||||
u32 salt_iv[BLOCK_SIZE / 4], first_block[BLOCK_SIZE / 4];
|
||||
|
||||
prep_buffers(salt_buf, salt_iv, first_block, data, &esalt_bufs[digests_offset]);
|
||||
|
||||
u32x w[16] = { 0 };
|
||||
u32x w[64] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
|
||||
u32x w0l = w[0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
u32x w0l = w[0];
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
|
||||
{
|
||||
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
|
||||
|
||||
const u32x w0 = w0l | w0r;
|
||||
|
||||
w[0] = w0;
|
||||
|
||||
u32x keys[KEY_LENGTH / 4];
|
||||
md5_ctx_t ctx;
|
||||
|
||||
generate_key_vector (salt_buf, w, pw_len, keys);
|
||||
md5_init (&ctx);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 v_pos = 0; v_pos < VECT_SIZE; v_pos++)
|
||||
{
|
||||
u32 asn1_ok = 0, padding_ok = 0, plaintext_length, plaintext[BLOCK_SIZE / 4];
|
||||
u32 ciphertext[BLOCK_SIZE / 4], iv[BLOCK_SIZE / 4];
|
||||
u32 ks[44];
|
||||
u32 key[KEY_LENGTH / 4];
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
for (u32 i = 0; i < KEY_LENGTH; i++)
|
||||
{
|
||||
key[i] = VECTOR_ELEMENT(keys[i], v_pos);
|
||||
}
|
||||
u32 t[16];
|
||||
|
||||
aes128_set_decrypt_key (ks, key, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
aes128_decrypt (ks, first_block, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
plaintext[i] ^= salt_iv[i];
|
||||
}
|
||||
md5_final (&ctx);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("First plaintext block:");
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
u32 ukey[4];
|
||||
|
||||
if (data_len < 128)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0x00ff80ff) == 0x00020030;
|
||||
plaintext_length = ((plaintext[0] & 0x00007f00) >> 8) + 2;
|
||||
}
|
||||
else if (data_len < 256)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0xff00ffff) == 0x02008130;
|
||||
plaintext_length = ((plaintext[0] & 0x00ff0000) >> 16) + 3;
|
||||
}
|
||||
else if (data_len < 65536)
|
||||
{
|
||||
asn1_ok = ((plaintext[0] & 0x0000ffff) == 0x00008230) && ((plaintext[1] & 0x000000ff) == 0x00000002);
|
||||
plaintext_length = ((plaintext[0] & 0xff000000) >> 24) + ((plaintext[0] & 0x00ff0000) >> 8) + 4;
|
||||
}
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
#ifdef DEBUG
|
||||
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
|
||||
#endif // DEBUG
|
||||
// AES
|
||||
|
||||
if (asn1_ok == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
iv[i] = first_block[i];
|
||||
}
|
||||
u32 ks[44];
|
||||
|
||||
for (u32 i = BLOCK_SIZE / 4; i < data_len / 4; i += BLOCK_SIZE / 4)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
ciphertext[j] = data[i + j];
|
||||
}
|
||||
AES128_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
aes128_decrypt (ks, ciphertext, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
u32 dec[4];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
plaintext[j] ^= iv[j];
|
||||
iv[j] = ciphertext[j];
|
||||
}
|
||||
// first check the padding
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Plaintext block %u:", i / (BLOCK_SIZE / 4));
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++) printf(" 0x%08x", plaintext[j]);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
aes128_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
|
||||
u8 *pt_bytes = (u8 *) plaintext;
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Padding byte: 0x%02x\n", padding_count);
|
||||
#endif
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (padding_count > BLOCK_SIZE || padding_count == 0)
|
||||
{
|
||||
// That *can't* be right
|
||||
padding_ok = 0;
|
||||
} else {
|
||||
padding_ok = 1;
|
||||
}
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
for (u32 i = 0; i < padding_count; i++)
|
||||
{
|
||||
if (pt_bytes[BLOCK_SIZE - 1 - i] != padding_count)
|
||||
{
|
||||
padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
plaintext_length++;
|
||||
}
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
#ifdef DEBUG
|
||||
if (padding_ok == 1) printf("Padding checks out\n");
|
||||
if (plaintext_length == data_len) printf("ASN.1 sequence length checks out\n");
|
||||
#endif
|
||||
aes128_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
if (asn1_ok == 1 && padding_ok == 1 && plaintext_length == data_len)
|
||||
{
|
||||
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
|
||||
{
|
||||
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset, gid, il_pos + v_pos, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
481
OpenCL/m22941_a0-pure.cl
Normal file
481
OpenCL/m22941_a0-pure.cl
Normal file
@ -0,0 +1,481 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_rp.h"
|
||||
#include "inc_rp.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_aes.cl"
|
||||
#endif
|
||||
|
||||
typedef struct pem
|
||||
{
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22941_mxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
LOCAL_VK u32 s_td3[256];
|
||||
LOCAL_VK u32 s_td4[256];
|
||||
|
||||
LOCAL_VK u32 s_te0[256];
|
||||
LOCAL_VK u32 s_te1[256];
|
||||
LOCAL_VK u32 s_te2[256];
|
||||
LOCAL_VK u32 s_te3[256];
|
||||
LOCAL_VK u32 s_te4[256];
|
||||
|
||||
for (u32 i = lid; i < 256; i += lsz)
|
||||
{
|
||||
s_td0[i] = td0[i];
|
||||
s_td1[i] = td1[i];
|
||||
s_td2[i] = td2[i];
|
||||
s_td3[i] = td3[i];
|
||||
s_td4[i] = td4[i];
|
||||
|
||||
s_te0[i] = te0[i];
|
||||
s_te1[i] = te1[i];
|
||||
s_te2[i] = te2[i];
|
||||
s_te3[i] = te3[i];
|
||||
s_te4[i] = te4[i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
CONSTANT_AS u32a *s_td3 = td3;
|
||||
CONSTANT_AS u32a *s_td4 = td4;
|
||||
|
||||
CONSTANT_AS u32a *s_te0 = te0;
|
||||
CONSTANT_AS u32a *s_te1 = te1;
|
||||
CONSTANT_AS u32a *s_te2 = te2;
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
COPY_PW (pws[gid]);
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
pw_t tmp = PASTE_PW;
|
||||
|
||||
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
|
||||
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[6];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
ukey[4] = hc_swap32_S (ukey[4]);
|
||||
ukey[5] = hc_swap32_S (ukey[5]);
|
||||
|
||||
u32 ks[52];
|
||||
|
||||
AES192_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
u32 dec[4];
|
||||
|
||||
// first check the padding
|
||||
|
||||
aes192_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes192_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22941_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
LOCAL_VK u32 s_td3[256];
|
||||
LOCAL_VK u32 s_td4[256];
|
||||
|
||||
LOCAL_VK u32 s_te0[256];
|
||||
LOCAL_VK u32 s_te1[256];
|
||||
LOCAL_VK u32 s_te2[256];
|
||||
LOCAL_VK u32 s_te3[256];
|
||||
LOCAL_VK u32 s_te4[256];
|
||||
|
||||
for (u32 i = lid; i < 256; i += lsz)
|
||||
{
|
||||
s_td0[i] = td0[i];
|
||||
s_td1[i] = td1[i];
|
||||
s_td2[i] = td2[i];
|
||||
s_td3[i] = td3[i];
|
||||
s_td4[i] = td4[i];
|
||||
|
||||
s_te0[i] = te0[i];
|
||||
s_te1[i] = te1[i];
|
||||
s_te2[i] = te2[i];
|
||||
s_te3[i] = te3[i];
|
||||
s_te4[i] = te4[i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
CONSTANT_AS u32a *s_td3 = td3;
|
||||
CONSTANT_AS u32a *s_td4 = td4;
|
||||
|
||||
CONSTANT_AS u32a *s_te0 = te0;
|
||||
CONSTANT_AS u32a *s_te1 = te1;
|
||||
CONSTANT_AS u32a *s_te2 = te2;
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
COPY_PW (pws[gid]);
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
pw_t tmp = PASTE_PW;
|
||||
|
||||
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
|
||||
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[6];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
ukey[4] = hc_swap32_S (ukey[4]);
|
||||
ukey[5] = hc_swap32_S (ukey[5]);
|
||||
|
||||
u32 ks[52];
|
||||
|
||||
AES192_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
u32 dec[4];
|
||||
|
||||
// first check the padding
|
||||
|
||||
aes192_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes192_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
475
OpenCL/m22941_a1-pure.cl
Normal file
475
OpenCL/m22941_a1-pure.cl
Normal file
@ -0,0 +1,475 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_aes.cl"
|
||||
#endif
|
||||
|
||||
typedef struct pem
|
||||
{
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22941_mxx (KERN_ATTR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
LOCAL_VK u32 s_td3[256];
|
||||
LOCAL_VK u32 s_td4[256];
|
||||
|
||||
LOCAL_VK u32 s_te0[256];
|
||||
LOCAL_VK u32 s_te1[256];
|
||||
LOCAL_VK u32 s_te2[256];
|
||||
LOCAL_VK u32 s_te3[256];
|
||||
LOCAL_VK u32 s_te4[256];
|
||||
|
||||
for (u32 i = lid; i < 256; i += lsz)
|
||||
{
|
||||
s_td0[i] = td0[i];
|
||||
s_td1[i] = td1[i];
|
||||
s_td2[i] = td2[i];
|
||||
s_td3[i] = td3[i];
|
||||
s_td4[i] = td4[i];
|
||||
|
||||
s_te0[i] = te0[i];
|
||||
s_te1[i] = te1[i];
|
||||
s_te2[i] = te2[i];
|
||||
s_te3[i] = te3[i];
|
||||
s_te4[i] = te4[i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
CONSTANT_AS u32a *s_td3 = td3;
|
||||
CONSTANT_AS u32a *s_td4 = td4;
|
||||
|
||||
CONSTANT_AS u32a *s_te0 = te0;
|
||||
CONSTANT_AS u32a *s_te1 = te1;
|
||||
CONSTANT_AS u32a *s_te2 = te2;
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[6];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
ukey[4] = hc_swap32_S (ukey[4]);
|
||||
ukey[5] = hc_swap32_S (ukey[5]);
|
||||
|
||||
u32 ks[52];
|
||||
|
||||
AES192_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
u32 dec[4];
|
||||
|
||||
// first check the padding
|
||||
|
||||
aes192_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes192_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22941_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
LOCAL_VK u32 s_td3[256];
|
||||
LOCAL_VK u32 s_td4[256];
|
||||
|
||||
LOCAL_VK u32 s_te0[256];
|
||||
LOCAL_VK u32 s_te1[256];
|
||||
LOCAL_VK u32 s_te2[256];
|
||||
LOCAL_VK u32 s_te3[256];
|
||||
LOCAL_VK u32 s_te4[256];
|
||||
|
||||
for (u32 i = lid; i < 256; i += lsz)
|
||||
{
|
||||
s_td0[i] = td0[i];
|
||||
s_td1[i] = td1[i];
|
||||
s_td2[i] = td2[i];
|
||||
s_td3[i] = td3[i];
|
||||
s_td4[i] = td4[i];
|
||||
|
||||
s_te0[i] = te0[i];
|
||||
s_te1[i] = te1[i];
|
||||
s_te2[i] = te2[i];
|
||||
s_te3[i] = te3[i];
|
||||
s_te4[i] = te4[i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
CONSTANT_AS u32a *s_td3 = td3;
|
||||
CONSTANT_AS u32a *s_td4 = td4;
|
||||
|
||||
CONSTANT_AS u32a *s_te0 = te0;
|
||||
CONSTANT_AS u32a *s_te1 = te1;
|
||||
CONSTANT_AS u32a *s_te2 = te2;
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[6];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
ukey[4] = hc_swap32_S (ukey[4]);
|
||||
ukey[5] = hc_swap32_S (ukey[5]);
|
||||
|
||||
u32 ks[52];
|
||||
|
||||
AES192_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
u32 dec[4];
|
||||
|
||||
// first check the padding
|
||||
|
||||
aes192_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes192_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
509
OpenCL/m22941_a3-pure.cl
Normal file
509
OpenCL/m22941_a3-pure.cl
Normal file
@ -0,0 +1,509 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_aes.cl"
|
||||
#endif
|
||||
|
||||
typedef struct pem
|
||||
{
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22941_mxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
LOCAL_VK u32 s_td3[256];
|
||||
LOCAL_VK u32 s_td4[256];
|
||||
|
||||
LOCAL_VK u32 s_te0[256];
|
||||
LOCAL_VK u32 s_te1[256];
|
||||
LOCAL_VK u32 s_te2[256];
|
||||
LOCAL_VK u32 s_te3[256];
|
||||
LOCAL_VK u32 s_te4[256];
|
||||
|
||||
for (u32 i = lid; i < 256; i += lsz)
|
||||
{
|
||||
s_td0[i] = td0[i];
|
||||
s_td1[i] = td1[i];
|
||||
s_td2[i] = td2[i];
|
||||
s_td3[i] = td3[i];
|
||||
s_td4[i] = td4[i];
|
||||
|
||||
s_te0[i] = te0[i];
|
||||
s_te1[i] = te1[i];
|
||||
s_te2[i] = te2[i];
|
||||
s_te3[i] = te3[i];
|
||||
s_te4[i] = te4[i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
CONSTANT_AS u32a *s_td3 = td3;
|
||||
CONSTANT_AS u32a *s_td4 = td4;
|
||||
|
||||
CONSTANT_AS u32a *s_te0 = te0;
|
||||
CONSTANT_AS u32a *s_te1 = te1;
|
||||
CONSTANT_AS u32a *s_te2 = te2;
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32x w[64] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
u32x w0l = w[0];
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
|
||||
{
|
||||
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
|
||||
|
||||
const u32x w0 = w0l | w0r;
|
||||
|
||||
w[0] = w0;
|
||||
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[6];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
ukey[4] = hc_swap32_S (ukey[4]);
|
||||
ukey[5] = hc_swap32_S (ukey[5]);
|
||||
|
||||
u32 ks[52];
|
||||
|
||||
AES192_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
u32 dec[4];
|
||||
|
||||
// first check the padding
|
||||
|
||||
aes192_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes192_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22941_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
LOCAL_VK u32 s_td3[256];
|
||||
LOCAL_VK u32 s_td4[256];
|
||||
|
||||
LOCAL_VK u32 s_te0[256];
|
||||
LOCAL_VK u32 s_te1[256];
|
||||
LOCAL_VK u32 s_te2[256];
|
||||
LOCAL_VK u32 s_te3[256];
|
||||
LOCAL_VK u32 s_te4[256];
|
||||
|
||||
for (u32 i = lid; i < 256; i += lsz)
|
||||
{
|
||||
s_td0[i] = td0[i];
|
||||
s_td1[i] = td1[i];
|
||||
s_td2[i] = td2[i];
|
||||
s_td3[i] = td3[i];
|
||||
s_td4[i] = td4[i];
|
||||
|
||||
s_te0[i] = te0[i];
|
||||
s_te1[i] = te1[i];
|
||||
s_te2[i] = te2[i];
|
||||
s_te3[i] = te3[i];
|
||||
s_te4[i] = te4[i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
CONSTANT_AS u32a *s_td3 = td3;
|
||||
CONSTANT_AS u32a *s_td4 = td4;
|
||||
|
||||
CONSTANT_AS u32a *s_te0 = te0;
|
||||
CONSTANT_AS u32a *s_te1 = te1;
|
||||
CONSTANT_AS u32a *s_te2 = te2;
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32x w[64] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
u32x w0l = w[0];
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
|
||||
{
|
||||
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
|
||||
|
||||
const u32x w0 = w0l | w0r;
|
||||
|
||||
w[0] = w0;
|
||||
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[6];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
ukey[4] = hc_swap32_S (ukey[4]);
|
||||
ukey[5] = hc_swap32_S (ukey[5]);
|
||||
|
||||
u32 ks[52];
|
||||
|
||||
AES192_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
u32 dec[4];
|
||||
|
||||
// first check the padding
|
||||
|
||||
aes192_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes192_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
@ -3,43 +3,41 @@
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#define BLOCK_SIZE 16
|
||||
#define KEY_LENGTH 32
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_rp.h"
|
||||
#include "inc_rp.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_aes.cl"
|
||||
#include "inc_pem_common.cl"
|
||||
#endif // KERNEL_STATIC
|
||||
#endif
|
||||
|
||||
KERNEL_FQ void m22951_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
typedef struct pem
|
||||
{
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22951_mxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 data_len;
|
||||
data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
for (u32 i = lid; i <= data_len / 4; i += lsz)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
@ -71,16 +69,236 @@ KERNEL_FQ void m22951_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
|
||||
#else
|
||||
|
||||
const size_t data_len = esalt_bufs[digests_offset].data_len;
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
CONSTANT_AS u32a *s_td3 = td3;
|
||||
CONSTANT_AS u32a *s_td4 = td4;
|
||||
|
||||
CONSTANT_AS u32a *s_te0 = te0;
|
||||
CONSTANT_AS u32a *s_te1 = te1;
|
||||
CONSTANT_AS u32a *s_te2 = te2;
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < data_len / 4; i++)
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
COPY_PW (pws[gid]);
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
pw_t tmp = PASTE_PW;
|
||||
|
||||
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
|
||||
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[8];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
ukey[6] = ctx.h[2];
|
||||
ukey[7] = ctx.h[3];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
ukey[4] = hc_swap32_S (ukey[4]);
|
||||
ukey[5] = hc_swap32_S (ukey[5]);
|
||||
ukey[6] = hc_swap32_S (ukey[6]);
|
||||
ukey[7] = hc_swap32_S (ukey[7]);
|
||||
|
||||
u32 ks[60];
|
||||
|
||||
AES256_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
u32 dec[4];
|
||||
|
||||
// first check the padding
|
||||
|
||||
aes256_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes256_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22951_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
LOCAL_VK u32 s_td3[256];
|
||||
LOCAL_VK u32 s_td4[256];
|
||||
|
||||
LOCAL_VK u32 s_te0[256];
|
||||
LOCAL_VK u32 s_te1[256];
|
||||
LOCAL_VK u32 s_te2[256];
|
||||
LOCAL_VK u32 s_te3[256];
|
||||
LOCAL_VK u32 s_te4[256];
|
||||
|
||||
for (u32 i = lid; i < 256; i += lsz)
|
||||
{
|
||||
s_td0[i] = td0[i];
|
||||
s_td1[i] = td1[i];
|
||||
s_td2[i] = td2[i];
|
||||
s_td3[i] = td3[i];
|
||||
s_td4[i] = td4[i];
|
||||
|
||||
s_te0[i] = te0[i];
|
||||
s_te1[i] = te1[i];
|
||||
s_te2[i] = te2[i];
|
||||
s_te3[i] = te3[i];
|
||||
s_te4[i] = te4[i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
@ -94,148 +312,178 @@ KERNEL_FQ void m22951_sxx (KERN_ATTR_RULES_ESALT (pem_t))
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#endif // REAL_SHM
|
||||
#endif
|
||||
|
||||
u32 salt_buf[16] = { 0 };
|
||||
u32 salt_iv[BLOCK_SIZE / 4], first_block[BLOCK_SIZE / 4];
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
prep_buffers(salt_buf, salt_iv, first_block, data, &esalt_bufs[digests_offset]);
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
COPY_PW (pws[gid]);
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
|
||||
|
||||
pw_t tmp = PASTE_PW;
|
||||
|
||||
tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len);
|
||||
|
||||
generate_key (salt_buf, tmp.i, tmp.pw_len, key);
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[8];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update (&ctx, tmp.i, tmp.pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
ukey[6] = ctx.h[2];
|
||||
ukey[7] = ctx.h[3];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
ukey[4] = hc_swap32_S (ukey[4]);
|
||||
ukey[5] = hc_swap32_S (ukey[5]);
|
||||
ukey[6] = hc_swap32_S (ukey[6]);
|
||||
ukey[7] = hc_swap32_S (ukey[7]);
|
||||
|
||||
u32 asn1_ok = 0, padding_ok = 0, plaintext_length, plaintext[BLOCK_SIZE / 4];
|
||||
u32 ciphertext[BLOCK_SIZE / 4], iv[BLOCK_SIZE / 4];
|
||||
u32 ks[60];
|
||||
|
||||
aes256_set_decrypt_key (ks, key, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
AES256_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
aes256_decrypt (ks, first_block, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
u32 dec[4];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
plaintext[i] ^= salt_iv[i];
|
||||
}
|
||||
// first check the padding
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("First plaintext block:");
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
aes256_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
if (data_len < 128)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0x00ff80ff) == 0x00020030;
|
||||
plaintext_length = ((plaintext[0] & 0x00007f00) >> 8) + 2;
|
||||
}
|
||||
else if (data_len < 256)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0xff00ffff) == 0x02008130;
|
||||
plaintext_length = ((plaintext[0] & 0x00ff0000) >> 16) + 3;
|
||||
}
|
||||
else if (data_len < 65536)
|
||||
{
|
||||
asn1_ok = ((plaintext[0] & 0x0000ffff) == 0x00008230) && ((plaintext[1] & 0x000000ff) == 0x00000002);
|
||||
plaintext_length = ((plaintext[0] & 0xff000000) >> 24) + ((plaintext[0] & 0x00ff0000) >> 8) + 4;
|
||||
}
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
#ifdef DEBUG
|
||||
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
|
||||
#endif // DEBUG
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (asn1_ok == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
iv[i] = first_block[i];
|
||||
}
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
for (u32 i = BLOCK_SIZE / 4; i < data_len / 4; i += BLOCK_SIZE / 4)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
ciphertext[j] = data[i + j];
|
||||
}
|
||||
aes256_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
aes256_decrypt (ks, ciphertext, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
plaintext[j] ^= iv[j];
|
||||
iv[j] = ciphertext[j];
|
||||
}
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Plaintext block %u:", i / (BLOCK_SIZE / 4));
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++) printf(" 0x%08x", plaintext[j]);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
|
||||
u8 *pt_bytes = (u8 *) plaintext;
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Padding byte: 0x%02x\n", padding_count);
|
||||
#endif
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
if (padding_count > BLOCK_SIZE || padding_count == 0)
|
||||
{
|
||||
// That *can't* be right
|
||||
padding_ok = 0;
|
||||
} else {
|
||||
padding_ok = 1;
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < padding_count; i++)
|
||||
{
|
||||
if (pt_bytes[BLOCK_SIZE - 1 - i] != padding_count)
|
||||
{
|
||||
padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
plaintext_length++;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (padding_ok == 1) printf("Padding checks out\n");
|
||||
if (plaintext_length == data_len) printf("ASN.1 sequence length checks out\n");
|
||||
#endif
|
||||
|
||||
if (asn1_ok == 1 && padding_ok == 1 && plaintext_length == data_len)
|
||||
{
|
||||
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
|
||||
{
|
||||
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset, gid, il_pos, 0, 0);
|
||||
}
|
||||
}
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
@ -3,42 +3,39 @@
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#define BLOCK_SIZE 16
|
||||
#define KEY_LENGTH 32
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_aes.cl"
|
||||
#include "inc_pem_common.cl"
|
||||
#endif // KERNEL_STATIC
|
||||
#endif
|
||||
|
||||
KERNEL_FQ void m22951_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
typedef struct pem
|
||||
{
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22951_mxx (KERN_ATTR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 data_len;
|
||||
data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
for (u32 i = lid; i <= data_len / 4; i += lsz)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
@ -70,16 +67,234 @@ KERNEL_FQ void m22951_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
|
||||
#else
|
||||
|
||||
const size_t data_len = esalt_bufs[digests_offset].data_len;
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
CONSTANT_AS u32a *s_td3 = td3;
|
||||
CONSTANT_AS u32a *s_td4 = td4;
|
||||
|
||||
CONSTANT_AS u32a *s_te0 = te0;
|
||||
CONSTANT_AS u32a *s_te1 = te1;
|
||||
CONSTANT_AS u32a *s_te2 = te2;
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < data_len / 4; i++)
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[8];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
ukey[6] = ctx.h[2];
|
||||
ukey[7] = ctx.h[3];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
ukey[4] = hc_swap32_S (ukey[4]);
|
||||
ukey[5] = hc_swap32_S (ukey[5]);
|
||||
ukey[6] = hc_swap32_S (ukey[6]);
|
||||
ukey[7] = hc_swap32_S (ukey[7]);
|
||||
|
||||
u32 ks[60];
|
||||
|
||||
AES256_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
u32 dec[4];
|
||||
|
||||
// first check the padding
|
||||
|
||||
aes256_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes256_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22951_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
LOCAL_VK u32 s_td3[256];
|
||||
LOCAL_VK u32 s_td4[256];
|
||||
|
||||
LOCAL_VK u32 s_te0[256];
|
||||
LOCAL_VK u32 s_te1[256];
|
||||
LOCAL_VK u32 s_te2[256];
|
||||
LOCAL_VK u32 s_te3[256];
|
||||
LOCAL_VK u32 s_te4[256];
|
||||
|
||||
for (u32 i = lid; i < 256; i += lsz)
|
||||
{
|
||||
s_td0[i] = td0[i];
|
||||
s_td1[i] = td1[i];
|
||||
s_td2[i] = td2[i];
|
||||
s_td3[i] = td3[i];
|
||||
s_td4[i] = td4[i];
|
||||
|
||||
s_te0[i] = te0[i];
|
||||
s_te1[i] = te1[i];
|
||||
s_te2[i] = te2[i];
|
||||
s_te3[i] = te3[i];
|
||||
s_te4[i] = te4[i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
@ -93,21 +308,59 @@ KERNEL_FQ void m22951_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#endif // REAL_SHM
|
||||
#endif
|
||||
|
||||
u32 salt_buf[16] = { 0 };
|
||||
u32 salt_iv[BLOCK_SIZE / 4], first_block[BLOCK_SIZE / 4];
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
prep_buffers(salt_buf, salt_iv, first_block, data, &esalt_bufs[digests_offset]);
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32 w[16] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
const u32 search[4] =
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
@ -115,150 +368,116 @@ KERNEL_FQ void m22951_sxx (KERN_ATTR_ESALT (pem_t))
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
||||
{
|
||||
const u32 comb_len = combs_buf[il_pos].pw_len;
|
||||
u32 c[64];
|
||||
md5_ctx_t ctx;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
c[i] = combs_buf[il_pos].i[i];
|
||||
}
|
||||
md5_init (&ctx);
|
||||
|
||||
switch_buffer_by_offset_1x64_be_S (c, pw_len);
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
c[i] |= w[i];
|
||||
}
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
|
||||
u32 t[16];
|
||||
|
||||
generate_key (salt_buf, c, pw_len + comb_len, key);
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[8];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update_global (&ctx, pws[gid].i, pws[gid].pw_len);
|
||||
|
||||
md5_update_global (&ctx, combs_buf[il_pos].i, combs_buf[il_pos].pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
ukey[6] = ctx.h[2];
|
||||
ukey[7] = ctx.h[3];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
ukey[4] = hc_swap32_S (ukey[4]);
|
||||
ukey[5] = hc_swap32_S (ukey[5]);
|
||||
ukey[6] = hc_swap32_S (ukey[6]);
|
||||
ukey[7] = hc_swap32_S (ukey[7]);
|
||||
|
||||
u32 asn1_ok = 0, padding_ok = 0, plaintext_length, plaintext[BLOCK_SIZE / 4];
|
||||
u32 ciphertext[BLOCK_SIZE / 4], iv[BLOCK_SIZE / 4];
|
||||
u32 ks[60];
|
||||
|
||||
aes256_set_decrypt_key (ks, key, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
AES256_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
aes256_decrypt (ks, first_block, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
u32 dec[4];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
plaintext[i] ^= salt_iv[i];
|
||||
}
|
||||
// first check the padding
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("First plaintext block:");
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
aes256_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
if (data_len < 128)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0x00ff80ff) == 0x00020030;
|
||||
plaintext_length = ((plaintext[0] & 0x00007f00) >> 8) + 2;
|
||||
}
|
||||
else if (data_len < 256)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0xff00ffff) == 0x02008130;
|
||||
plaintext_length = ((plaintext[0] & 0x00ff0000) >> 16) + 3;
|
||||
}
|
||||
else if (data_len < 65536)
|
||||
{
|
||||
asn1_ok = ((plaintext[0] & 0x0000ffff) == 0x00008230) && ((plaintext[1] & 0x000000ff) == 0x00000002);
|
||||
plaintext_length = ((plaintext[0] & 0xff000000) >> 24) + ((plaintext[0] & 0x00ff0000) >> 8) + 4;
|
||||
}
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
#ifdef DEBUG
|
||||
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
|
||||
#endif // DEBUG
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (asn1_ok == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
iv[i] = first_block[i];
|
||||
}
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
for (u32 i = BLOCK_SIZE / 4; i < data_len / 4; i += BLOCK_SIZE / 4)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
ciphertext[j] = data[i + j];
|
||||
}
|
||||
aes256_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
aes256_decrypt (ks, ciphertext, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
plaintext[j] ^= iv[j];
|
||||
iv[j] = ciphertext[j];
|
||||
}
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Plaintext block %u:", i / (BLOCK_SIZE / 4));
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++) printf(" 0x%08x", plaintext[j]);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
|
||||
u8 *pt_bytes = (u8 *) plaintext;
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Padding byte: 0x%02x\n", padding_count);
|
||||
#endif
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
if (padding_count > BLOCK_SIZE || padding_count == 0)
|
||||
{
|
||||
// That *can't* be right
|
||||
padding_ok = 0;
|
||||
} else {
|
||||
padding_ok = 1;
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < padding_count; i++)
|
||||
{
|
||||
if (pt_bytes[BLOCK_SIZE - 1 - i] != padding_count)
|
||||
{
|
||||
padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
plaintext_length++;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (padding_ok == 1) printf("Padding checks out\n");
|
||||
if (plaintext_length == data_len) printf("ASN.1 sequence length checks out\n");
|
||||
#endif
|
||||
|
||||
if (asn1_ok == 1 && padding_ok == 1 && plaintext_length == data_len)
|
||||
{
|
||||
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
|
||||
{
|
||||
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset, gid, il_pos, 0, 0);
|
||||
}
|
||||
}
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
@ -3,45 +3,39 @@
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#define NEW_SIMD_CODE
|
||||
|
||||
#define BLOCK_SIZE 16
|
||||
#define KEY_LENGTH 32
|
||||
//#define NEW_SIMD_CODE
|
||||
|
||||
#ifdef KERNEL_STATIC
|
||||
#include "inc_vendor.h"
|
||||
#include "inc_types.h"
|
||||
#include "inc_platform.cl"
|
||||
#include "inc_common.cl"
|
||||
#include "inc_simd.cl"
|
||||
#include "inc_scalar.cl"
|
||||
#include "inc_hash_md5.cl"
|
||||
#include "inc_cipher_aes.cl"
|
||||
#include "inc_pem_common.cl"
|
||||
#endif // KERNEL_STATIC
|
||||
#endif
|
||||
|
||||
KERNEL_FQ void m22951_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
typedef struct pem
|
||||
{
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
u32 data_buf[16384];
|
||||
int data_len;
|
||||
|
||||
int cipher;
|
||||
|
||||
} pem_t;
|
||||
|
||||
KERNEL_FQ void m22951_mxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 data_len;
|
||||
data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
|
||||
for (u32 i = lid; i <= data_len / 4; i += lsz)
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
}
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
@ -73,17 +67,252 @@ KERNEL_FQ void m22951_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
|
||||
#else
|
||||
|
||||
const size_t data_len = esalt_bufs[digests_offset].data_len;
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
CONSTANT_AS u32a *s_td3 = td3;
|
||||
CONSTANT_AS u32a *s_td4 = td4;
|
||||
|
||||
CONSTANT_AS u32a *s_te0 = te0;
|
||||
CONSTANT_AS u32a *s_te1 = te1;
|
||||
CONSTANT_AS u32a *s_te2 = te2;
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < data_len / 4; i++)
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
data[i] = esalt_bufs[digests_offset].data[i];
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32x w[64] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
u32x w0l = w[0];
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
|
||||
{
|
||||
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
|
||||
|
||||
const u32x w0 = w0l | w0r;
|
||||
|
||||
w[0] = w0;
|
||||
|
||||
md5_ctx_t ctx;
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
u32 t[16];
|
||||
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
u32 ukey[8];
|
||||
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
md5_init (&ctx);
|
||||
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
ctx.len = 16;
|
||||
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
md5_final (&ctx);
|
||||
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
ukey[6] = ctx.h[2];
|
||||
ukey[7] = ctx.h[3];
|
||||
|
||||
// AES
|
||||
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
ukey[4] = hc_swap32_S (ukey[4]);
|
||||
ukey[5] = hc_swap32_S (ukey[5]);
|
||||
ukey[6] = hc_swap32_S (ukey[6]);
|
||||
ukey[7] = hc_swap32_S (ukey[7]);
|
||||
|
||||
u32 ks[60];
|
||||
|
||||
AES256_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
u32 dec[4];
|
||||
|
||||
// first check the padding
|
||||
|
||||
aes256_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes256_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_M_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
||||
KERNEL_FQ void m22951_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
{
|
||||
const u64 gid = get_global_id (0);
|
||||
const u64 lid = get_local_id (0);
|
||||
const u64 lsz = get_local_size (0);
|
||||
|
||||
/**
|
||||
* aes shared
|
||||
*/
|
||||
|
||||
#ifdef REAL_SHM
|
||||
|
||||
LOCAL_VK u32 s_td0[256];
|
||||
LOCAL_VK u32 s_td1[256];
|
||||
LOCAL_VK u32 s_td2[256];
|
||||
LOCAL_VK u32 s_td3[256];
|
||||
LOCAL_VK u32 s_td4[256];
|
||||
|
||||
LOCAL_VK u32 s_te0[256];
|
||||
LOCAL_VK u32 s_te1[256];
|
||||
LOCAL_VK u32 s_te2[256];
|
||||
LOCAL_VK u32 s_te3[256];
|
||||
LOCAL_VK u32 s_te4[256];
|
||||
|
||||
for (u32 i = lid; i < 256; i += lsz)
|
||||
{
|
||||
s_td0[i] = td0[i];
|
||||
s_td1[i] = td1[i];
|
||||
s_td2[i] = td2[i];
|
||||
s_td3[i] = td3[i];
|
||||
s_td4[i] = td4[i];
|
||||
|
||||
s_te0[i] = te0[i];
|
||||
s_te1[i] = te1[i];
|
||||
s_te2[i] = te2[i];
|
||||
s_te3[i] = te3[i];
|
||||
s_te4[i] = te4[i];
|
||||
}
|
||||
|
||||
SYNC_THREADS ();
|
||||
|
||||
#else
|
||||
|
||||
CONSTANT_AS u32a *s_td0 = td0;
|
||||
CONSTANT_AS u32a *s_td1 = td1;
|
||||
CONSTANT_AS u32a *s_td2 = td2;
|
||||
@ -96,167 +325,193 @@ KERNEL_FQ void m22951_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
|
||||
CONSTANT_AS u32a *s_te3 = te3;
|
||||
CONSTANT_AS u32a *s_te4 = te4;
|
||||
|
||||
#endif // REAL_SHM
|
||||
#endif
|
||||
|
||||
if (gid >= gid_max) return;
|
||||
|
||||
/**
|
||||
* digest
|
||||
*/
|
||||
|
||||
const u32 search[4] =
|
||||
{
|
||||
digests_buf[digests_offset].digest_buf[0],
|
||||
digests_buf[digests_offset].digest_buf[1],
|
||||
digests_buf[digests_offset].digest_buf[2],
|
||||
digests_buf[digests_offset].digest_buf[3]
|
||||
};
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
u32 s[4];
|
||||
|
||||
s[0] = salt_bufs[salt_pos].salt_buf[0];
|
||||
s[1] = salt_bufs[salt_pos].salt_buf[1];
|
||||
s[2] = salt_bufs[salt_pos].salt_buf[2];
|
||||
s[3] = salt_bufs[salt_pos].salt_buf[3];
|
||||
|
||||
u32 first_data[4];
|
||||
|
||||
first_data[0] = esalt_bufs[digests_offset].data_buf[0];
|
||||
first_data[1] = esalt_bufs[digests_offset].data_buf[1];
|
||||
first_data[2] = esalt_bufs[digests_offset].data_buf[2];
|
||||
first_data[3] = esalt_bufs[digests_offset].data_buf[3];
|
||||
|
||||
const int data_len = esalt_bufs[digests_offset].data_len;
|
||||
|
||||
const int last_pad_pos = data_len - 1;
|
||||
|
||||
const int last_pad_elem = last_pad_pos / 4;
|
||||
|
||||
u32 iv[4];
|
||||
|
||||
iv[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 7];
|
||||
iv[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 6];
|
||||
iv[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 5];
|
||||
iv[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 4];
|
||||
|
||||
u32 enc[4];
|
||||
|
||||
enc[0] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 3];
|
||||
enc[1] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 2];
|
||||
enc[2] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 1];
|
||||
enc[3] = esalt_bufs[digests_offset].data_buf[last_pad_elem - 0];
|
||||
|
||||
/**
|
||||
* base
|
||||
*/
|
||||
|
||||
const u32 pw_len = pws[gid].pw_len;
|
||||
|
||||
u32 salt_buf[16] = { 0 };
|
||||
u32 salt_iv[BLOCK_SIZE / 4], first_block[BLOCK_SIZE / 4];
|
||||
|
||||
prep_buffers(salt_buf, salt_iv, first_block, data, &esalt_bufs[digests_offset]);
|
||||
|
||||
u32x w[16] = { 0 };
|
||||
u32x w[64] = { 0 };
|
||||
|
||||
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
|
||||
{
|
||||
w[idx] = pws[gid].i[idx];
|
||||
}
|
||||
|
||||
u32x w0l = w[0];
|
||||
|
||||
/**
|
||||
* loop
|
||||
*/
|
||||
|
||||
u32x w0l = w[0];
|
||||
|
||||
for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
|
||||
{
|
||||
const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
|
||||
|
||||
const u32x w0 = w0l | w0r;
|
||||
|
||||
w[0] = w0;
|
||||
|
||||
u32x keys[HC_PEM_MAX_KEY_LENGTH / 4];
|
||||
md5_ctx_t ctx;
|
||||
|
||||
generate_key_vector (salt_buf, w, pw_len, keys);
|
||||
md5_init (&ctx);
|
||||
|
||||
for (u32 v_pos = 0; v_pos < VECT_SIZE; v_pos++)
|
||||
{
|
||||
u32 asn1_ok = 0, padding_ok = 0, plaintext_length, plaintext[BLOCK_SIZE / 4];
|
||||
u32 ciphertext[BLOCK_SIZE / 4], iv[BLOCK_SIZE / 4];
|
||||
u32 ks[60];
|
||||
u32 key[KEY_LENGTH / 4];
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
for (u32 i = 0; i < KEY_LENGTH; i++)
|
||||
{
|
||||
key[i] = VECTOR_ELEMENT(keys[i], v_pos);
|
||||
}
|
||||
u32 t[16];
|
||||
|
||||
aes256_set_decrypt_key (ks, key, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
t[ 0] = s[0];
|
||||
t[ 1] = s[1];
|
||||
t[ 2] = 0;
|
||||
t[ 3] = 0;
|
||||
t[ 4] = 0;
|
||||
t[ 5] = 0;
|
||||
t[ 6] = 0;
|
||||
t[ 7] = 0;
|
||||
t[ 8] = 0;
|
||||
t[ 9] = 0;
|
||||
t[10] = 0;
|
||||
t[11] = 0;
|
||||
t[12] = 0;
|
||||
t[13] = 0;
|
||||
t[14] = 0;
|
||||
t[15] = 0;
|
||||
|
||||
aes256_decrypt (ks, first_block, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
plaintext[i] ^= salt_iv[i];
|
||||
}
|
||||
md5_final (&ctx);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("First plaintext block:");
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
|
||||
printf("\n");
|
||||
#endif // DEBUG
|
||||
u32 ukey[8];
|
||||
|
||||
if (data_len < 128)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0x00ff80ff) == 0x00020030;
|
||||
plaintext_length = ((plaintext[0] & 0x00007f00) >> 8) + 2;
|
||||
}
|
||||
else if (data_len < 256)
|
||||
{
|
||||
asn1_ok = (plaintext[0] & 0xff00ffff) == 0x02008130;
|
||||
plaintext_length = ((plaintext[0] & 0x00ff0000) >> 16) + 3;
|
||||
}
|
||||
else if (data_len < 65536)
|
||||
{
|
||||
asn1_ok = ((plaintext[0] & 0x0000ffff) == 0x00008230) && ((plaintext[1] & 0x000000ff) == 0x00000002);
|
||||
plaintext_length = ((plaintext[0] & 0xff000000) >> 24) + ((plaintext[0] & 0x00ff0000) >> 8) + 4;
|
||||
}
|
||||
ukey[0] = ctx.h[0];
|
||||
ukey[1] = ctx.h[1];
|
||||
ukey[2] = ctx.h[2];
|
||||
ukey[3] = ctx.h[3];
|
||||
|
||||
#ifdef DEBUG
|
||||
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
|
||||
#endif // DEBUG
|
||||
md5_init (&ctx);
|
||||
|
||||
if (asn1_ok == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ctx.w0[0] = ukey[0];
|
||||
ctx.w0[1] = ukey[1];
|
||||
ctx.w0[2] = ukey[2];
|
||||
ctx.w0[3] = ukey[3];
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
|
||||
{
|
||||
iv[i] = first_block[i];
|
||||
}
|
||||
ctx.len = 16;
|
||||
|
||||
for (u32 i = BLOCK_SIZE / 4; i < data_len / 4; i += BLOCK_SIZE / 4)
|
||||
{
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
ciphertext[j] = data[i + j];
|
||||
}
|
||||
md5_update (&ctx, w, pw_len);
|
||||
|
||||
aes256_decrypt (ks, ciphertext, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
md5_update (&ctx, t, 8);
|
||||
|
||||
#ifdef _unroll
|
||||
#pragma unroll
|
||||
#endif
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
|
||||
{
|
||||
plaintext[j] ^= iv[j];
|
||||
iv[j] = ciphertext[j];
|
||||
}
|
||||
md5_final (&ctx);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Plaintext block %u:", i / (BLOCK_SIZE / 4));
|
||||
for (u32 j = 0; j < BLOCK_SIZE / 4; j++) printf(" 0x%08x", plaintext[j]);
|
||||
printf("\n");
|
||||
#endif
|
||||
}
|
||||
ukey[4] = ctx.h[0];
|
||||
ukey[5] = ctx.h[1];
|
||||
ukey[6] = ctx.h[2];
|
||||
ukey[7] = ctx.h[3];
|
||||
|
||||
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
|
||||
u8 *pt_bytes = (u8 *) plaintext;
|
||||
// AES
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("Padding byte: 0x%02x\n", padding_count);
|
||||
#endif
|
||||
ukey[0] = hc_swap32_S (ukey[0]);
|
||||
ukey[1] = hc_swap32_S (ukey[1]);
|
||||
ukey[2] = hc_swap32_S (ukey[2]);
|
||||
ukey[3] = hc_swap32_S (ukey[3]);
|
||||
ukey[4] = hc_swap32_S (ukey[4]);
|
||||
ukey[5] = hc_swap32_S (ukey[5]);
|
||||
ukey[6] = hc_swap32_S (ukey[6]);
|
||||
ukey[7] = hc_swap32_S (ukey[7]);
|
||||
|
||||
if (padding_count > BLOCK_SIZE || padding_count == 0)
|
||||
{
|
||||
// That *can't* be right
|
||||
padding_ok = 0;
|
||||
} else {
|
||||
padding_ok = 1;
|
||||
}
|
||||
u32 ks[60];
|
||||
|
||||
for (u32 i = 0; i < padding_count; i++)
|
||||
{
|
||||
if (pt_bytes[BLOCK_SIZE - 1 - i] != padding_count)
|
||||
{
|
||||
padding_ok = 0;
|
||||
break;
|
||||
}
|
||||
plaintext_length++;
|
||||
}
|
||||
AES256_set_decrypt_key (ks, ukey, s_te0, s_te1, s_te2, s_te3, s_td0, s_td1, s_td2, s_td3);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (padding_ok == 1) printf("Padding checks out\n");
|
||||
if (plaintext_length == data_len) printf("ASN.1 sequence length checks out\n");
|
||||
#endif
|
||||
u32 dec[4];
|
||||
|
||||
if (asn1_ok == 1 && padding_ok == 1 && plaintext_length == data_len)
|
||||
{
|
||||
if (atomic_inc (&hashes_shown[digests_offset]) == 0)
|
||||
{
|
||||
mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset, gid, il_pos + v_pos, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
// first check the padding
|
||||
|
||||
aes256_decrypt (ks, enc, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= iv[0];
|
||||
dec[1] ^= iv[1];
|
||||
dec[2] ^= iv[2];
|
||||
dec[3] ^= iv[3];
|
||||
|
||||
const int paddingv = pkcs_padding_bs16 (dec, 16);
|
||||
|
||||
if (paddingv == -1) continue;
|
||||
|
||||
// second check (naive code) ASN.1 structure
|
||||
|
||||
aes256_decrypt (ks, first_data, dec, s_td0, s_td1, s_td2, s_td3, s_td4);
|
||||
|
||||
dec[0] ^= s[0];
|
||||
dec[1] ^= s[1];
|
||||
dec[2] ^= s[2];
|
||||
dec[3] ^= s[3];
|
||||
|
||||
const int real_len = (data_len - 16) + paddingv;
|
||||
|
||||
const int asn1_ok = asn1_detect (dec, real_len);
|
||||
|
||||
if (asn1_ok == 0) continue;
|
||||
|
||||
const u32 r0 = search[0];
|
||||
const u32 r1 = search[1];
|
||||
const u32 r2 = search[2];
|
||||
const u32 r3 = search[3];
|
||||
|
||||
COMPARE_S_SCALAR (r0, r1, r2, r3);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,11 @@
|
||||
* changes v6.1.1 -> v6.x.x
|
||||
|
||||
##
|
||||
## Algorithms
|
||||
##
|
||||
|
||||
- Added hash-mode: RSA/DSA/EC/OPENSSH Private Keys
|
||||
|
||||
* changes v6.1.0 -> v6.1.1
|
||||
|
||||
##
|
||||
@ -97,7 +103,6 @@
|
||||
- Added hash-mode: Open Document Format (ODF) 1.1 (SHA-1, Blowfish)
|
||||
- Added hash-mode: Open Document Format (ODF) 1.2 (SHA-256, AES)
|
||||
- Added hash-mode: Oracle Transportation Management (SHA256)
|
||||
- Added hash-mode: PKCS#1 key
|
||||
- Added hash-mode: PKZIP archive encryption
|
||||
- Added hash-mode: PKZIP Master Key
|
||||
- Added hash-mode: Python passlib pbkdf2-sha1
|
||||
|
@ -273,6 +273,7 @@ NVIDIA GPUs require "NVIDIA Driver" (440.64 or later) and "CUDA Toolkit" (9.0 or
|
||||
- Apple Keychain
|
||||
- Apple Secure Notes
|
||||
- JKS Java Key Store Private Keys (SHA1)
|
||||
- RSA/DSA/EC/OPENSSH Private Keys
|
||||
- 1Password, agilekeychain
|
||||
- 1Password, cloudkeychain
|
||||
- Password Safe v2
|
||||
@ -327,7 +328,6 @@ NVIDIA GPUs require "NVIDIA Driver" (440.64 or later) and "CUDA Toolkit" (9.0 or
|
||||
- Django (SHA-1)
|
||||
- Web2py pbkdf2-sha512
|
||||
- TOTP (HMAC-SHA1)
|
||||
- PKCS#1 key
|
||||
|
||||
##
|
||||
## Attack-Modes
|
||||
|
@ -1,524 +0,0 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "types.h"
|
||||
#include "modules.h"
|
||||
#include "bitops.h"
|
||||
#include "convert.h"
|
||||
#include "shared.h"
|
||||
#include "memory.h"
|
||||
|
||||
#define HC_PEM_SALT_LENGTH 8
|
||||
#define HC_PEM_MAX_BLOCK_SIZE 16
|
||||
#define HC_PEM_MAX_KEY_LENGTH 32
|
||||
#define HC_PEM_MAX_DATA_LENGTH 12288
|
||||
|
||||
// The longest OpenSSL cipher name I can find is 24 characters, so add on seven
|
||||
// more characters for luck and one for the \0 gives us 32.
|
||||
#define HC_PEM_MAX_CIPHER_NAME_LENGTH 32
|
||||
|
||||
static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL;
|
||||
static const u32 DGST_POS0 = 0;
|
||||
static const u32 DGST_POS1 = 1;
|
||||
static const u32 DGST_POS2 = 2;
|
||||
static const u32 DGST_POS3 = 3;
|
||||
static const u32 DGST_SIZE = DGST_SIZE_4_4;
|
||||
static const u32 HASH_CATEGORY = HASH_CATEGORY_DOCUMENTS;
|
||||
static const char *HASH_NAME = "PEM encrypted private key";
|
||||
static const u64 KERN_TYPE = 22911; // Kernel used for the benchmark esalt; will likely be overridden in production
|
||||
static const u32 OPTI_TYPE = OPTI_TYPE_ZERO_BYTE;
|
||||
static const u64 OPTS_TYPE = OPTS_TYPE_PT_GENERATE_LE
|
||||
| OPTS_TYPE_BINARY_HASHFILE;
|
||||
static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED;
|
||||
static const char *ST_PASS = "hashcat";
|
||||
static const char *ST_HASH = NULL; // Benchmark / self-test hash provided in module_benchmark_esalt
|
||||
|
||||
u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; }
|
||||
u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; }
|
||||
u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; }
|
||||
u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; }
|
||||
u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; }
|
||||
u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; }
|
||||
u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; }
|
||||
const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; }
|
||||
u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; }
|
||||
u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; }
|
||||
u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; }
|
||||
u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; }
|
||||
const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; }
|
||||
const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; }
|
||||
|
||||
typedef enum hc_pem_cipher_type
|
||||
{
|
||||
HC_PEM_CIPHER_TYPE_3DES = 1,
|
||||
HC_PEM_CIPHER_TYPE_DES = 2,
|
||||
HC_PEM_CIPHER_TYPE_AES128 = 3,
|
||||
HC_PEM_CIPHER_TYPE_AES192 = 4,
|
||||
HC_PEM_CIPHER_TYPE_AES256 = 5,
|
||||
} hc_pem_cipher_type_t;
|
||||
|
||||
typedef enum hc_pem_cipher_mode
|
||||
{
|
||||
HC_PEM_CIPHER_MODE_CBC = 1,
|
||||
} hc_pem_cipher_mode_t;
|
||||
|
||||
typedef struct pem_cipher
|
||||
{
|
||||
char *name;
|
||||
|
||||
u32 block_size;
|
||||
u32 key_length;
|
||||
u32 cipher_type;
|
||||
u32 cipher_mode;
|
||||
} hc_pem_cipher_t;
|
||||
|
||||
static hc_pem_cipher_t pem_ciphers[] = {
|
||||
{"des-ede3-cbc", 8, 24, HC_PEM_CIPHER_TYPE_3DES, HC_PEM_CIPHER_MODE_CBC},
|
||||
{"des-cbc", 8, 8, HC_PEM_CIPHER_TYPE_DES, HC_PEM_CIPHER_MODE_CBC},
|
||||
{"aes-128-cbc", 16, 16, HC_PEM_CIPHER_TYPE_AES128, HC_PEM_CIPHER_MODE_CBC},
|
||||
{"aes-192-cbc", 16, 24, HC_PEM_CIPHER_TYPE_AES192, HC_PEM_CIPHER_MODE_CBC},
|
||||
{"aes-256-cbc", 16, 32, HC_PEM_CIPHER_TYPE_AES256, HC_PEM_CIPHER_MODE_CBC},
|
||||
{NULL, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
typedef struct pem
|
||||
{
|
||||
hc_pem_cipher_t *chosen_cipher;
|
||||
|
||||
u32 salt_iv[HC_PEM_MAX_BLOCK_SIZE / 4];
|
||||
|
||||
u32 data[HC_PEM_MAX_DATA_LENGTH / 4];
|
||||
size_t data_len;
|
||||
} pem_t;
|
||||
|
||||
typedef struct pem_tmp
|
||||
{
|
||||
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
|
||||
} pem_tmp_t;
|
||||
|
||||
|
||||
u32 module_pw_max (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYBE_UNUSED const user_options_t * user_options, MAYBE_UNUSED const user_options_extra_t * user_options_extra)
|
||||
{
|
||||
const u32 pw_max = 64;
|
||||
|
||||
return pw_max;
|
||||
}
|
||||
|
||||
bool module_outfile_check_disable (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYBE_UNUSED const user_options_t * user_options, MAYBE_UNUSED const user_options_extra_t * user_options_extra)
|
||||
{
|
||||
const bool outfile_check_disable = true;
|
||||
|
||||
return outfile_check_disable;
|
||||
}
|
||||
|
||||
int module_hash_binary_count (MAYBE_UNUSED const hashes_t * hashes)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYBE_UNUSED const user_options_t * user_options, MAYBE_UNUSED const user_options_extra_t * user_options_extra, hashes_t * hashes)
|
||||
{
|
||||
hash_t *hashes_buf = hashes->hashes_buf;
|
||||
hash_t *hash = &hashes_buf[0];
|
||||
|
||||
memset (hash->salt, 0, sizeof (salt_t));
|
||||
memset (hash->esalt, 0, sizeof (pem_t));
|
||||
|
||||
return module_hash_decode (hashconfig, hash->digest, hash->salt, hash->esalt, hash->hook_salt, hash->hash_info, hashes->hashfile, strlen (hashes->hashfile));
|
||||
}
|
||||
|
||||
static int peminator (char *buf, char *type, char **start, size_t * len)
|
||||
{
|
||||
char start_header[256], end_header[256];
|
||||
|
||||
snprintf (start_header, 256, "-----BEGIN %s-----", type);
|
||||
snprintf (end_header, 256, "-----END %s-----", type);
|
||||
|
||||
char *start_point = buf;
|
||||
|
||||
while (start_point != NULL)
|
||||
{
|
||||
if ((start_point = strstr (start_point, start_header)) == NULL)
|
||||
return -1;
|
||||
|
||||
if (start_point != buf && start_point[-1] != '\n')
|
||||
continue;
|
||||
|
||||
if (start_point[strlen (start_header)] == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
char *end_point = start_point;
|
||||
|
||||
while (end_point != NULL)
|
||||
{
|
||||
if ((end_point = strstr (end_point, end_header)) == NULL)
|
||||
return -1;
|
||||
|
||||
if (end_point[-1] == '\n' && (end_point[strlen (end_header)] == '\n' || end_point[strlen (end_header)] == '\0'))
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
end_point++;
|
||||
}
|
||||
}
|
||||
|
||||
*start = start_point + strlen (start_header) + 1;
|
||||
*len = end_point - *start;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_dek_info (char *line, char *cipher_name, u8 * salt)
|
||||
{
|
||||
line += strlen ("DEK-Info: ");
|
||||
|
||||
u8 i = 0;
|
||||
int salty = -1;
|
||||
|
||||
for (; *line != '\0'; line++)
|
||||
{
|
||||
if (salty >= 0)
|
||||
{
|
||||
if (i++ % 2 == 0)
|
||||
{
|
||||
if (line[1] == '\0')
|
||||
{
|
||||
return PARSER_SALT_LENGTH;
|
||||
}
|
||||
|
||||
salt[salty++] = hex_to_u8 ((u8 *) line);
|
||||
|
||||
if (salty > HC_PEM_MAX_BLOCK_SIZE)
|
||||
{
|
||||
return PARSER_SALT_LENGTH;
|
||||
}
|
||||
}
|
||||
else if (line[1] == '\0')
|
||||
{
|
||||
if (salty < HC_PEM_SALT_LENGTH)
|
||||
{
|
||||
// Malformed salt, not long enough for PKCS5's liking
|
||||
return PARSER_SALT_LENGTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (*line == ',')
|
||||
{
|
||||
cipher_name[i] = '\0';
|
||||
salty = 0;
|
||||
i = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
cipher_name[i++] = *line;
|
||||
if (i >= HC_PEM_MAX_CIPHER_NAME_LENGTH)
|
||||
{
|
||||
return PARSER_CIPHER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return PARSER_SALT_VALUE;
|
||||
}
|
||||
|
||||
static int parse_pem_key_data (char *buf, char *cipher_name, u8 * salt, u8 * data, size_t * data_len)
|
||||
{
|
||||
char *pemdata;
|
||||
size_t pemdata_len;
|
||||
|
||||
if (peminator (buf, "RSA PRIVATE KEY", &pemdata, &pemdata_len) < 0)
|
||||
{
|
||||
if (peminator (buf, "DSA PRIVATE KEY", &pemdata, &pemdata_len) < 0)
|
||||
{
|
||||
if (peminator (buf, "EC PRIVATE KEY", &pemdata, &pemdata_len) < 0)
|
||||
{
|
||||
if (peminator (buf, "PRIVATE KEY", &pemdata, &pemdata_len) < 0)
|
||||
{
|
||||
return PARSER_HASH_FILE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
u8 in_header = 1, *b64data;
|
||||
char line[256];
|
||||
size_t pd_idx = 0, l_idx = 0, b64_idx = 0;
|
||||
|
||||
b64data = hcmalloc (pemdata_len);
|
||||
|
||||
for (pd_idx = 0; pd_idx < pemdata_len; pd_idx++)
|
||||
{
|
||||
if (in_header)
|
||||
{
|
||||
if (pemdata[pd_idx] == '\n')
|
||||
{
|
||||
if (l_idx == 0)
|
||||
{
|
||||
// Empty line!
|
||||
in_header = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
line[l_idx] = '\0';
|
||||
|
||||
if (strstr (line, "DEK-Info: ") == line)
|
||||
{
|
||||
int err;
|
||||
|
||||
if ((err = parse_dek_info (line, cipher_name, salt)) < 0)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
l_idx = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
line[l_idx++] = pemdata[pd_idx];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pemdata[pd_idx] != '\n')
|
||||
b64data[b64_idx++] = pemdata[pd_idx];
|
||||
}
|
||||
}
|
||||
|
||||
if (b64_idx * 6 / 8 > HC_PEM_MAX_DATA_LENGTH)
|
||||
{
|
||||
return PARSER_TOKEN_LENGTH;
|
||||
}
|
||||
|
||||
*data_len = base64_decode (base64_to_int, b64data, b64_idx, data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int module_hash_decode (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYBE_UNUSED void *digest_buf, salt_t * salt, void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t * hash_info, const char *line_buf, MAYBE_UNUSED const int line_len)
|
||||
{
|
||||
pem_t *pem = (pem_t *) esalt_buf;
|
||||
|
||||
HCFILE fp;
|
||||
struct stat fileinfo;
|
||||
u8 *filebuf;
|
||||
|
||||
if (stat (line_buf, &fileinfo) < 0)
|
||||
return 0;
|
||||
|
||||
if (hc_fopen (&fp, line_buf, "rb") == false)
|
||||
return 0;
|
||||
|
||||
filebuf = hcmalloc (fileinfo.st_size + 1);
|
||||
|
||||
if (hc_fread (filebuf, 1, fileinfo.st_size, &fp) < (size_t) fileinfo.st_size)
|
||||
{
|
||||
hc_fclose (&fp);
|
||||
hcfree (filebuf);
|
||||
|
||||
return PARSER_FILE_SIZE;
|
||||
}
|
||||
|
||||
hc_fclose (&fp);
|
||||
|
||||
filebuf[fileinfo.st_size] = '\0';
|
||||
|
||||
char cipher_name[HC_PEM_MAX_CIPHER_NAME_LENGTH] = { 0 };
|
||||
u8 saltbytes[MAX(HC_PEM_SALT_LENGTH, HC_PEM_MAX_BLOCK_SIZE)];
|
||||
int err;
|
||||
|
||||
if ((err = parse_pem_key_data ((char *) filebuf, cipher_name, saltbytes, (u8 *) pem->data, &pem->data_len)) < 0)
|
||||
{
|
||||
hcfree (filebuf);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
u32 *saltwords = (u32 *) saltbytes;
|
||||
|
||||
for (u32 i = 0; i < HC_PEM_SALT_LENGTH / 4; i++)
|
||||
{
|
||||
pem->salt_iv[i] = saltwords[i];
|
||||
}
|
||||
|
||||
hc_pem_cipher_t *candidate_cipher = pem_ciphers, *chosen_cipher = NULL;
|
||||
|
||||
while (candidate_cipher->name)
|
||||
{
|
||||
if (strcasecmp (cipher_name, candidate_cipher->name) == 0)
|
||||
{
|
||||
chosen_cipher = candidate_cipher;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
candidate_cipher++;
|
||||
}
|
||||
}
|
||||
|
||||
if (chosen_cipher == NULL)
|
||||
{
|
||||
hcfree (filebuf);
|
||||
|
||||
return PARSER_CIPHER;
|
||||
}
|
||||
|
||||
if (chosen_cipher->block_size > HC_PEM_MAX_BLOCK_SIZE)
|
||||
{
|
||||
hcfree (filebuf);
|
||||
|
||||
return PARSER_BLOCK_SIZE;
|
||||
}
|
||||
|
||||
if (pem->data_len % chosen_cipher->block_size)
|
||||
{
|
||||
hcfree (filebuf);
|
||||
|
||||
return PARSER_HASH_LENGTH;
|
||||
}
|
||||
|
||||
if (chosen_cipher->key_length > HC_PEM_MAX_KEY_LENGTH)
|
||||
{
|
||||
// Nope nope nopety nope
|
||||
return PARSER_KEY_SIZE;
|
||||
}
|
||||
|
||||
pem->chosen_cipher = chosen_cipher;
|
||||
|
||||
memcpy (salt->salt_buf, pem->salt_iv, MIN (HC_PEM_SALT_LENGTH, 64 * 4));
|
||||
salt->salt_iter = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void *module_benchmark_esalt (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
|
||||
{
|
||||
pem_t *pem = (pem_t *) hcmalloc (sizeof (pem_t));
|
||||
|
||||
pem->chosen_cipher = &pem_ciphers[0];
|
||||
hex_decode ((u8 *) "7CC48DB27D461D30", 16, (u8 *) pem->salt_iv);
|
||||
pem->data_len = base64_decode (base64_to_int, (u8 *) "ysVmp6tkcZXRqHyy3YMk5zd4bsT9D97kFcDIKkD2g5o/OBgc0pGQ/iSwJm/V+A2IkwgQlwvLW1OfKkAWdjcSFNKhmiWApVQB", 96, (u8 *) pem->data);
|
||||
|
||||
return pem;
|
||||
}
|
||||
|
||||
salt_t *module_benchmark_salt (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
|
||||
{
|
||||
salt_t *salt = (salt_t *) hcmalloc (sizeof (salt_t));
|
||||
|
||||
salt->salt_iter = 1;
|
||||
hex_decode ((u8 *) "7CC48DB27D461D30", 16, (u8 *) salt->salt_buf);
|
||||
|
||||
return salt;
|
||||
}
|
||||
|
||||
u64 module_kern_type_dynamic (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t * salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t * hash_info)
|
||||
{
|
||||
const pem_t *pem = (const pem_t *) esalt_buf;
|
||||
|
||||
u64 kern_type = 22900;
|
||||
|
||||
kern_type += pem->chosen_cipher->cipher_type * 10;
|
||||
kern_type += pem->chosen_cipher->cipher_mode;
|
||||
|
||||
return kern_type;
|
||||
}
|
||||
|
||||
u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYBE_UNUSED const user_options_t * user_options, MAYBE_UNUSED const user_options_extra_t * user_options_extra)
|
||||
{
|
||||
const u64 esalt_size = (const u64) sizeof (pem_t);
|
||||
|
||||
return esalt_size;
|
||||
}
|
||||
|
||||
char *module_jit_build_options (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYBE_UNUSED const user_options_t * user_options, MAYBE_UNUSED const user_options_extra_t * user_options_extra, MAYBE_UNUSED const hashes_t * hashes, MAYBE_UNUSED const hc_device_param_t * device_param)
|
||||
{
|
||||
char *jit_build_options = NULL;
|
||||
|
||||
hc_asprintf (&jit_build_options, "-D _unroll");
|
||||
|
||||
return jit_build_options;
|
||||
}
|
||||
|
||||
void module_init (module_ctx_t * module_ctx)
|
||||
{
|
||||
module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT;
|
||||
module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT;
|
||||
|
||||
module_ctx->module_attack_exec = module_attack_exec;
|
||||
module_ctx->module_benchmark_esalt = module_benchmark_esalt;
|
||||
module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT;
|
||||
module_ctx->module_benchmark_mask = MODULE_DEFAULT;
|
||||
module_ctx->module_benchmark_salt = module_benchmark_salt;
|
||||
module_ctx->module_build_plain_postprocess = MODULE_DEFAULT;
|
||||
module_ctx->module_deep_comp_kernel = MODULE_DEFAULT;
|
||||
module_ctx->module_dgst_pos0 = module_dgst_pos0;
|
||||
module_ctx->module_dgst_pos1 = module_dgst_pos1;
|
||||
module_ctx->module_dgst_pos2 = module_dgst_pos2;
|
||||
module_ctx->module_dgst_pos3 = module_dgst_pos3;
|
||||
module_ctx->module_dgst_size = module_dgst_size;
|
||||
module_ctx->module_dictstat_disable = MODULE_DEFAULT;
|
||||
module_ctx->module_esalt_size = module_esalt_size;
|
||||
module_ctx->module_extra_buffer_size = MODULE_DEFAULT;
|
||||
module_ctx->module_extra_tmp_size = MODULE_DEFAULT;
|
||||
module_ctx->module_forced_outfile_format = MODULE_DEFAULT;
|
||||
module_ctx->module_hash_binary_count = module_hash_binary_count;
|
||||
module_ctx->module_hash_binary_parse = module_hash_binary_parse;
|
||||
module_ctx->module_hash_binary_save = MODULE_DEFAULT;
|
||||
module_ctx->module_hash_decode_potfile = MODULE_DEFAULT;
|
||||
module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT;
|
||||
module_ctx->module_hash_decode = module_hash_decode;
|
||||
module_ctx->module_hash_encode_status = MODULE_DEFAULT;
|
||||
module_ctx->module_hash_encode_potfile = MODULE_DEFAULT;
|
||||
module_ctx->module_hash_encode = MODULE_DEFAULT;
|
||||
module_ctx->module_hash_init_selftest = MODULE_DEFAULT;
|
||||
module_ctx->module_hash_mode = MODULE_DEFAULT;
|
||||
module_ctx->module_hash_category = module_hash_category;
|
||||
module_ctx->module_hash_name = module_hash_name;
|
||||
module_ctx->module_hashes_count_min = MODULE_DEFAULT;
|
||||
module_ctx->module_hashes_count_max = MODULE_DEFAULT;
|
||||
module_ctx->module_hlfmt_disable = MODULE_DEFAULT;
|
||||
module_ctx->module_hook12 = MODULE_DEFAULT;
|
||||
module_ctx->module_hook23 = MODULE_DEFAULT;
|
||||
module_ctx->module_hook_salt_size = MODULE_DEFAULT;
|
||||
module_ctx->module_hook_size = MODULE_DEFAULT;
|
||||
module_ctx->module_jit_build_options = module_jit_build_options;
|
||||
module_ctx->module_jit_cache_disable = MODULE_DEFAULT;
|
||||
module_ctx->module_kernel_accel_max = MODULE_DEFAULT;
|
||||
module_ctx->module_kernel_accel_min = MODULE_DEFAULT;
|
||||
module_ctx->module_kernel_loops_max = MODULE_DEFAULT;
|
||||
module_ctx->module_kernel_loops_min = MODULE_DEFAULT;
|
||||
module_ctx->module_kernel_threads_max = MODULE_DEFAULT;
|
||||
module_ctx->module_kernel_threads_min = MODULE_DEFAULT;
|
||||
module_ctx->module_kern_type = module_kern_type;
|
||||
module_ctx->module_kern_type_dynamic = module_kern_type_dynamic;
|
||||
module_ctx->module_opti_type = module_opti_type;
|
||||
module_ctx->module_opts_type = module_opts_type;
|
||||
module_ctx->module_outfile_check_disable = module_outfile_check_disable;
|
||||
module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT;
|
||||
module_ctx->module_potfile_custom_check = MODULE_DEFAULT;
|
||||
module_ctx->module_potfile_disable = MODULE_DEFAULT;
|
||||
module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT;
|
||||
module_ctx->module_pwdump_column = MODULE_DEFAULT;
|
||||
module_ctx->module_pw_max = module_pw_max;
|
||||
module_ctx->module_pw_min = MODULE_DEFAULT;
|
||||
module_ctx->module_salt_max = MODULE_DEFAULT;
|
||||
module_ctx->module_salt_min = MODULE_DEFAULT;
|
||||
module_ctx->module_salt_type = module_salt_type;
|
||||
module_ctx->module_separator = MODULE_DEFAULT;
|
||||
module_ctx->module_st_hash = module_st_hash;
|
||||
module_ctx->module_st_pass = module_st_pass;
|
||||
module_ctx->module_tmp_size = MODULE_DEFAULT;
|
||||
module_ctx->module_unstable_warning = MODULE_DEFAULT;
|
||||
module_ctx->module_warmup_disable = MODULE_DEFAULT;
|
||||
}
|
159
tools/test_modules/m22911.pm
Normal file
159
tools/test_modules/m22911.pm
Normal file
@ -0,0 +1,159 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
##
|
||||
## Author......: See docs/credits.txt
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Crypt::CBC;
|
||||
use Digest::MD5 qw (md5);
|
||||
|
||||
sub module_constraints { [[0, 256], [16, 16], [-1, -1], [-1, -1], [-1, -1]] }
|
||||
|
||||
sub generate_key
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
my $bytes = shift;
|
||||
|
||||
my $salt8 = substr ($salt, 0, 8);
|
||||
|
||||
my $out = md5 ($word . $salt8);
|
||||
|
||||
$out .= md5 ($out . $word . $salt8);
|
||||
|
||||
return substr ($out, 0, 24);
|
||||
}
|
||||
|
||||
sub module_generate_hash
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
my $cid = shift // 0;
|
||||
my $data = shift;
|
||||
|
||||
my $salt_bin = pack ("H*", $salt);
|
||||
my $data_bin;
|
||||
|
||||
my $key = generate_key ($word, $salt_bin);
|
||||
|
||||
my $is_decrypt = defined ($data);
|
||||
|
||||
if ($is_decrypt == 1)
|
||||
{
|
||||
$data_bin = pack ("H*", $data);
|
||||
|
||||
my $aes = Crypt::CBC->new ({
|
||||
cipher => "Crypt::DES_EDE3",
|
||||
key => $key,
|
||||
iv => $salt_bin,
|
||||
keysize => 24,
|
||||
literal_key => 1,
|
||||
header => "none",
|
||||
padding => "standard",
|
||||
});
|
||||
|
||||
my $dec_bin = $aes->decrypt ($data_bin);
|
||||
|
||||
## This is a ridiculous check of successfull decryption
|
||||
## There are no useable asn1 parsers for perl available
|
||||
## We have to rely on a combination of padding check and pattern matching
|
||||
## The (minimum) 16 bit should be good enough for a unit test
|
||||
|
||||
if (length ($dec_bin) < length ($data_bin))
|
||||
{
|
||||
if (substr ($dec_bin, 0, 1) eq "\x30")
|
||||
{
|
||||
$data_bin = $dec_bin;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$data_bin = pack ("H*",
|
||||
"308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100b7a2" .
|
||||
"e4c254c8174219e60d9cce96737a906797b8edb86af8f055f60db7bd298b0d31d7ce97ebeae393d5" .
|
||||
"0e6da5215b58dcd72f4d3cac9e79b6ccaed7da47d2bd04f6a767f5ab7dc0f58beb6298c1e2358ed6" .
|
||||
"d3ef441f2326ac5db0027e08ae6c7724ff9a2a220a07e97319b6eff5cd653c7ab8b6ea9f9e89a40a" .
|
||||
"b856f036acfd39b1e5926964a024de35052de6d3423fe763569f48869c834750b28f09cecdddb54a" .
|
||||
"5526a2c5159d22d24606a2af6c6f47a5d9c04c454896192b8e7b82cf6f6934a23d3495059cb7e43b" .
|
||||
"98a20bd5b5782e15d93c8b289838c0a1df82ee429f0708d97aa40d6e75ec57ff12a2714871f241a8" .
|
||||
"6f6d8d3472b084aeb748da33e2d50203010001028201004afab8dadc1122e5fb7b225dbf4051005f" .
|
||||
"4bdcf84620019589541ff633ea89b6dbf958fb62ae9226bfeac34c639b3e18077bd935792ba63d5e" .
|
||||
"352ec2b5be93be57f37a21097f2f06857bceed601ff2041a417f2177b81afb246fd079040af96512" .
|
||||
"34ca24a1456ac11641c7e319114cff23f59bcc1bfa769a0e9fcdeab98429973e10caf303f2bcb065" .
|
||||
"f22c1cc259556de8377431237da7082cf03ce8da9530be398022f0171d468d92fcabbe776a5e9cf2" .
|
||||
"045642868406fd03ab735a70bfec3a951bb3c7a1de0fb3ff63cef23897e4fc3f9c5edf62fd45d058" .
|
||||
"fedc7d2fb22ec928984a061053a7138ce0417b5512579a92be0775104c0bc911f68a5e8ede298102" .
|
||||
"818100e4e17e2c752dbf1ad1025a074dc5f9c3c5989d23c84594313373d3e4ed0c0ddd74429ab026" .
|
||||
"535c5e77549d888835bc94f069ebc5e77fdbd2ddf4c8be6cf777799a6d8d18e2b8cecfc13ab26df8" .
|
||||
"b71ca3d94c2193c294042fb1025fdab38ba7aaeafebd8dd1f9d78ee67100693e99255dad6b964ebf" .
|
||||
"b7401a03b67d412fabb33502818100cd65067097e307643df1fc8214db1dd7d09342ef01417a2620" .
|
||||
"adad87352a58b8fcf07521289da3851623d8d045935fab7ecccc52ba0b86adcb92da76255e00289b" .
|
||||
"af9aacd936201861b0021249f4ab5e6020db823af7171aef0bbbd02dc94d2489fc0b68500bd1b7d2" .
|
||||
"81ed69fe4a44384161fe906e49bc91e0362b446ec2c521028180497662d40c2c49b966ba758100a2" .
|
||||
"799f2f8de369f7bef568b1560cfdde63cf13745c685fff7d2419a1fd83aeade1698cf87956d6a78e" .
|
||||
"2f55482e683c4ea7432ec1b545e365e9e15f676ada98578b166334bcadce4a56cddd2cd85141d5fd" .
|
||||
"0e2cdace36b30d613ea1bc2f2aed9cccf4e4536443d334cfb180680eabb73f80c1bd0281803f30fc" .
|
||||
"b93951a4dd875d62e5968b0f746d7c51147d5b6abc3e4390e6cf4997005af993dfbec23923e1fae7" .
|
||||
"62b47531f2ee510defc9c3700d1a5bb510b2506856160801db79fc78056850a16285145c80edac4e" .
|
||||
"3c93ed9f532f067a2303633273b26c340a44ce4e1873107c3da6f9ac616e643ad0aecdcad14a9cff" .
|
||||
"d4cf0ae76102818100b82528a3dfc595cf9c6a025998491e3b4849c71aa8d1222ddb14af7f82fbe5" .
|
||||
"169ec3ba18ec28d5a9501e95bc9da72cea99e4cdfdf898f40bec6b28f838243d2f39d7226e0873ed" .
|
||||
"ee752bcae07639a4bd0eb31be1718c456391630b83ad0e9bf3fa18a645007e64fe59af467ea021f9" .
|
||||
"e9a0dd759b21cd0b93333a73116abcaa2a"
|
||||
);
|
||||
}
|
||||
|
||||
my $aes = Crypt::CBC->new ({
|
||||
cipher => "Crypt::DES_EDE3",
|
||||
key => $key,
|
||||
iv => $salt_bin,
|
||||
keysize => 24,
|
||||
literal_key => 1,
|
||||
header => "none",
|
||||
padding => "standard",
|
||||
});
|
||||
|
||||
my $enc_bin = $aes->encrypt ($data_bin);
|
||||
|
||||
my $hash = sprintf ('$sshng$%d$%d$%s$%d$%s', $cid, length ($salt_bin), unpack ("H*", $salt_bin), length ($enc_bin), unpack ("H*", $enc_bin));
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
sub module_verify_hash
|
||||
{
|
||||
my $line = shift;
|
||||
|
||||
my $idx = index ($line, ':');
|
||||
|
||||
return unless $idx >= 0;
|
||||
|
||||
my $hash = substr ($line, 0, $idx);
|
||||
my $word = substr ($line, $idx + 1);
|
||||
|
||||
return unless substr ($hash, 0, 7) eq '$sshng$';
|
||||
|
||||
my (undef, $signature, $cid, undef, $salt, undef, $data) = split '\$', $hash;
|
||||
|
||||
return unless defined $signature;
|
||||
return unless defined $cid;
|
||||
return unless defined $salt;
|
||||
return unless defined $data;
|
||||
|
||||
return unless ($signature eq 'sshng');
|
||||
|
||||
return unless ($cid == 0);
|
||||
|
||||
my $word_packed = pack_if_HEX_notation ($word);
|
||||
|
||||
my $new_hash = module_generate_hash ($word_packed, $salt, $cid, $data);
|
||||
|
||||
return ($new_hash, $word);
|
||||
}
|
||||
|
||||
1;
|
157
tools/test_modules/m22921.pm
Normal file
157
tools/test_modules/m22921.pm
Normal file
@ -0,0 +1,157 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
##
|
||||
## Author......: See docs/credits.txt
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Crypt::CBC;
|
||||
use Digest::MD5 qw (md5);
|
||||
|
||||
sub module_constraints { [[0, 256], [16, 16], [-1, -1], [-1, -1], [-1, -1]] }
|
||||
|
||||
sub generate_key
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
my $bytes = shift;
|
||||
|
||||
my $salt8 = substr ($salt, 0, 8);
|
||||
|
||||
my $out = md5 ($word . $salt8);
|
||||
|
||||
return substr ($out, 0, 8);
|
||||
}
|
||||
|
||||
sub module_generate_hash
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
my $cid = shift // 6;
|
||||
my $data = shift;
|
||||
|
||||
my $salt_bin = pack ("H*", $salt);
|
||||
my $data_bin;
|
||||
|
||||
my $key = generate_key ($word, $salt_bin);
|
||||
|
||||
my $is_decrypt = defined ($data);
|
||||
|
||||
if ($is_decrypt == 1)
|
||||
{
|
||||
$data_bin = pack ("H*", $data);
|
||||
|
||||
my $aes = Crypt::CBC->new ({
|
||||
cipher => "Crypt::DES",
|
||||
key => $key,
|
||||
iv => $salt_bin,
|
||||
keysize => 8,
|
||||
literal_key => 1,
|
||||
header => "none",
|
||||
padding => "standard",
|
||||
});
|
||||
|
||||
my $dec_bin = $aes->decrypt ($data_bin);
|
||||
|
||||
## This is a ridiculous check of successfull decryption
|
||||
## There are no useable asn1 parsers for perl available
|
||||
## We have to rely on a combination of padding check and pattern matching
|
||||
## The (minimum) 16 bit should be good enough for a unit test
|
||||
|
||||
if (length ($dec_bin) < length ($data_bin))
|
||||
{
|
||||
if (substr ($dec_bin, 0, 1) eq "\x30")
|
||||
{
|
||||
$data_bin = $dec_bin;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$data_bin = pack ("H*",
|
||||
"308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100b7a2" .
|
||||
"e4c254c8174219e60d9cce96737a906797b8edb86af8f055f60db7bd298b0d31d7ce97ebeae393d5" .
|
||||
"0e6da5215b58dcd72f4d3cac9e79b6ccaed7da47d2bd04f6a767f5ab7dc0f58beb6298c1e2358ed6" .
|
||||
"d3ef441f2326ac5db0027e08ae6c7724ff9a2a220a07e97319b6eff5cd653c7ab8b6ea9f9e89a40a" .
|
||||
"b856f036acfd39b1e5926964a024de35052de6d3423fe763569f48869c834750b28f09cecdddb54a" .
|
||||
"5526a2c5159d22d24606a2af6c6f47a5d9c04c454896192b8e7b82cf6f6934a23d3495059cb7e43b" .
|
||||
"98a20bd5b5782e15d93c8b289838c0a1df82ee429f0708d97aa40d6e75ec57ff12a2714871f241a8" .
|
||||
"6f6d8d3472b084aeb748da33e2d50203010001028201004afab8dadc1122e5fb7b225dbf4051005f" .
|
||||
"4bdcf84620019589541ff633ea89b6dbf958fb62ae9226bfeac34c639b3e18077bd935792ba63d5e" .
|
||||
"352ec2b5be93be57f37a21097f2f06857bceed601ff2041a417f2177b81afb246fd079040af96512" .
|
||||
"34ca24a1456ac11641c7e319114cff23f59bcc1bfa769a0e9fcdeab98429973e10caf303f2bcb065" .
|
||||
"f22c1cc259556de8377431237da7082cf03ce8da9530be398022f0171d468d92fcabbe776a5e9cf2" .
|
||||
"045642868406fd03ab735a70bfec3a951bb3c7a1de0fb3ff63cef23897e4fc3f9c5edf62fd45d058" .
|
||||
"fedc7d2fb22ec928984a061053a7138ce0417b5512579a92be0775104c0bc911f68a5e8ede298102" .
|
||||
"818100e4e17e2c752dbf1ad1025a074dc5f9c3c5989d23c84594313373d3e4ed0c0ddd74429ab026" .
|
||||
"535c5e77549d888835bc94f069ebc5e77fdbd2ddf4c8be6cf777799a6d8d18e2b8cecfc13ab26df8" .
|
||||
"b71ca3d94c2193c294042fb1025fdab38ba7aaeafebd8dd1f9d78ee67100693e99255dad6b964ebf" .
|
||||
"b7401a03b67d412fabb33502818100cd65067097e307643df1fc8214db1dd7d09342ef01417a2620" .
|
||||
"adad87352a58b8fcf07521289da3851623d8d045935fab7ecccc52ba0b86adcb92da76255e00289b" .
|
||||
"af9aacd936201861b0021249f4ab5e6020db823af7171aef0bbbd02dc94d2489fc0b68500bd1b7d2" .
|
||||
"81ed69fe4a44384161fe906e49bc91e0362b446ec2c521028180497662d40c2c49b966ba758100a2" .
|
||||
"799f2f8de369f7bef568b1560cfdde63cf13745c685fff7d2419a1fd83aeade1698cf87956d6a78e" .
|
||||
"2f55482e683c4ea7432ec1b545e365e9e15f676ada98578b166334bcadce4a56cddd2cd85141d5fd" .
|
||||
"0e2cdace36b30d613ea1bc2f2aed9cccf4e4536443d334cfb180680eabb73f80c1bd0281803f30fc" .
|
||||
"b93951a4dd875d62e5968b0f746d7c51147d5b6abc3e4390e6cf4997005af993dfbec23923e1fae7" .
|
||||
"62b47531f2ee510defc9c3700d1a5bb510b2506856160801db79fc78056850a16285145c80edac4e" .
|
||||
"3c93ed9f532f067a2303633273b26c340a44ce4e1873107c3da6f9ac616e643ad0aecdcad14a9cff" .
|
||||
"d4cf0ae76102818100b82528a3dfc595cf9c6a025998491e3b4849c71aa8d1222ddb14af7f82fbe5" .
|
||||
"169ec3ba18ec28d5a9501e95bc9da72cea99e4cdfdf898f40bec6b28f838243d2f39d7226e0873ed" .
|
||||
"ee752bcae07639a4bd0eb31be1718c456391630b83ad0e9bf3fa18a645007e64fe59af467ea021f9" .
|
||||
"e9a0dd759b21cd0b93333a73116abcaa2a"
|
||||
);
|
||||
}
|
||||
|
||||
my $aes = Crypt::CBC->new ({
|
||||
cipher => "Crypt::DES",
|
||||
key => $key,
|
||||
iv => $salt_bin,
|
||||
keysize => 8,
|
||||
literal_key => 1,
|
||||
header => "none",
|
||||
padding => "standard",
|
||||
});
|
||||
|
||||
my $enc_bin = $aes->encrypt ($data_bin);
|
||||
|
||||
my $hash = sprintf ('$sshng$%d$%d$%s$%d$%s', $cid, length ($salt_bin), unpack ("H*", $salt_bin), length ($enc_bin), unpack ("H*", $enc_bin));
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
sub module_verify_hash
|
||||
{
|
||||
my $line = shift;
|
||||
|
||||
my $idx = index ($line, ':');
|
||||
|
||||
return unless $idx >= 0;
|
||||
|
||||
my $hash = substr ($line, 0, $idx);
|
||||
my $word = substr ($line, $idx + 1);
|
||||
|
||||
return unless substr ($hash, 0, 7) eq '$sshng$';
|
||||
|
||||
my (undef, $signature, $cid, undef, $salt, undef, $data) = split '\$', $hash;
|
||||
|
||||
return unless defined $signature;
|
||||
return unless defined $cid;
|
||||
return unless defined $salt;
|
||||
return unless defined $data;
|
||||
|
||||
return unless ($signature eq 'sshng');
|
||||
|
||||
return unless ($cid == 6);
|
||||
|
||||
my $word_packed = pack_if_HEX_notation ($word);
|
||||
|
||||
my $new_hash = module_generate_hash ($word_packed, $salt, $cid, $data);
|
||||
|
||||
return ($new_hash, $word);
|
||||
}
|
||||
|
||||
1;
|
157
tools/test_modules/m22931.pm
Normal file
157
tools/test_modules/m22931.pm
Normal file
@ -0,0 +1,157 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
##
|
||||
## Author......: See docs/credits.txt
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Crypt::CBC;
|
||||
use Digest::MD5 qw (md5);
|
||||
|
||||
sub module_constraints { [[0, 256], [32, 32], [-1, -1], [-1, -1], [-1, -1]] }
|
||||
|
||||
sub generate_key
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
my $bytes = shift;
|
||||
|
||||
my $salt8 = substr ($salt, 0, 8);
|
||||
|
||||
my $out = md5 ($word . $salt8);
|
||||
|
||||
return substr ($out, 0, 16);
|
||||
}
|
||||
|
||||
sub module_generate_hash
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
my $cid = shift // 1;
|
||||
my $data = shift;
|
||||
|
||||
my $salt_bin = pack ("H*", $salt);
|
||||
my $data_bin;
|
||||
|
||||
my $key = generate_key ($word, $salt_bin);
|
||||
|
||||
my $is_decrypt = defined ($data);
|
||||
|
||||
if ($is_decrypt == 1)
|
||||
{
|
||||
$data_bin = pack ("H*", $data);
|
||||
|
||||
my $aes = Crypt::CBC->new ({
|
||||
cipher => "Crypt::Rijndael",
|
||||
key => $key,
|
||||
iv => $salt_bin,
|
||||
keysize => 16,
|
||||
literal_key => 1,
|
||||
header => "none",
|
||||
padding => "standard",
|
||||
});
|
||||
|
||||
my $dec_bin = $aes->decrypt ($data_bin);
|
||||
|
||||
## This is a ridiculous check of successfull decryption
|
||||
## There are no useable asn1 parsers for perl available
|
||||
## We have to rely on a combination of padding check and pattern matching
|
||||
## The (minimum) 16 bit should be good enough for a unit test
|
||||
|
||||
if (length ($dec_bin) < length ($data_bin))
|
||||
{
|
||||
if (substr ($dec_bin, 0, 1) eq "\x30")
|
||||
{
|
||||
$data_bin = $dec_bin;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$data_bin = pack ("H*",
|
||||
"308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100b7a2" .
|
||||
"e4c254c8174219e60d9cce96737a906797b8edb86af8f055f60db7bd298b0d31d7ce97ebeae393d5" .
|
||||
"0e6da5215b58dcd72f4d3cac9e79b6ccaed7da47d2bd04f6a767f5ab7dc0f58beb6298c1e2358ed6" .
|
||||
"d3ef441f2326ac5db0027e08ae6c7724ff9a2a220a07e97319b6eff5cd653c7ab8b6ea9f9e89a40a" .
|
||||
"b856f036acfd39b1e5926964a024de35052de6d3423fe763569f48869c834750b28f09cecdddb54a" .
|
||||
"5526a2c5159d22d24606a2af6c6f47a5d9c04c454896192b8e7b82cf6f6934a23d3495059cb7e43b" .
|
||||
"98a20bd5b5782e15d93c8b289838c0a1df82ee429f0708d97aa40d6e75ec57ff12a2714871f241a8" .
|
||||
"6f6d8d3472b084aeb748da33e2d50203010001028201004afab8dadc1122e5fb7b225dbf4051005f" .
|
||||
"4bdcf84620019589541ff633ea89b6dbf958fb62ae9226bfeac34c639b3e18077bd935792ba63d5e" .
|
||||
"352ec2b5be93be57f37a21097f2f06857bceed601ff2041a417f2177b81afb246fd079040af96512" .
|
||||
"34ca24a1456ac11641c7e319114cff23f59bcc1bfa769a0e9fcdeab98429973e10caf303f2bcb065" .
|
||||
"f22c1cc259556de8377431237da7082cf03ce8da9530be398022f0171d468d92fcabbe776a5e9cf2" .
|
||||
"045642868406fd03ab735a70bfec3a951bb3c7a1de0fb3ff63cef23897e4fc3f9c5edf62fd45d058" .
|
||||
"fedc7d2fb22ec928984a061053a7138ce0417b5512579a92be0775104c0bc911f68a5e8ede298102" .
|
||||
"818100e4e17e2c752dbf1ad1025a074dc5f9c3c5989d23c84594313373d3e4ed0c0ddd74429ab026" .
|
||||
"535c5e77549d888835bc94f069ebc5e77fdbd2ddf4c8be6cf777799a6d8d18e2b8cecfc13ab26df8" .
|
||||
"b71ca3d94c2193c294042fb1025fdab38ba7aaeafebd8dd1f9d78ee67100693e99255dad6b964ebf" .
|
||||
"b7401a03b67d412fabb33502818100cd65067097e307643df1fc8214db1dd7d09342ef01417a2620" .
|
||||
"adad87352a58b8fcf07521289da3851623d8d045935fab7ecccc52ba0b86adcb92da76255e00289b" .
|
||||
"af9aacd936201861b0021249f4ab5e6020db823af7171aef0bbbd02dc94d2489fc0b68500bd1b7d2" .
|
||||
"81ed69fe4a44384161fe906e49bc91e0362b446ec2c521028180497662d40c2c49b966ba758100a2" .
|
||||
"799f2f8de369f7bef568b1560cfdde63cf13745c685fff7d2419a1fd83aeade1698cf87956d6a78e" .
|
||||
"2f55482e683c4ea7432ec1b545e365e9e15f676ada98578b166334bcadce4a56cddd2cd85141d5fd" .
|
||||
"0e2cdace36b30d613ea1bc2f2aed9cccf4e4536443d334cfb180680eabb73f80c1bd0281803f30fc" .
|
||||
"b93951a4dd875d62e5968b0f746d7c51147d5b6abc3e4390e6cf4997005af993dfbec23923e1fae7" .
|
||||
"62b47531f2ee510defc9c3700d1a5bb510b2506856160801db79fc78056850a16285145c80edac4e" .
|
||||
"3c93ed9f532f067a2303633273b26c340a44ce4e1873107c3da6f9ac616e643ad0aecdcad14a9cff" .
|
||||
"d4cf0ae76102818100b82528a3dfc595cf9c6a025998491e3b4849c71aa8d1222ddb14af7f82fbe5" .
|
||||
"169ec3ba18ec28d5a9501e95bc9da72cea99e4cdfdf898f40bec6b28f838243d2f39d7226e0873ed" .
|
||||
"ee752bcae07639a4bd0eb31be1718c456391630b83ad0e9bf3fa18a645007e64fe59af467ea021f9" .
|
||||
"e9a0dd759b21cd0b93333a73116abcaa2a"
|
||||
);
|
||||
}
|
||||
|
||||
my $aes = Crypt::CBC->new ({
|
||||
cipher => "Crypt::Rijndael",
|
||||
key => $key,
|
||||
iv => $salt_bin,
|
||||
keysize => 16,
|
||||
literal_key => 1,
|
||||
header => "none",
|
||||
padding => "standard",
|
||||
});
|
||||
|
||||
my $enc_bin = $aes->encrypt ($data_bin);
|
||||
|
||||
my $hash = sprintf ('$sshng$%d$%d$%s$%d$%s', $cid, length ($salt_bin), unpack ("H*", $salt_bin), length ($enc_bin), unpack ("H*", $enc_bin));
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
sub module_verify_hash
|
||||
{
|
||||
my $line = shift;
|
||||
|
||||
my $idx = index ($line, ':');
|
||||
|
||||
return unless $idx >= 0;
|
||||
|
||||
my $hash = substr ($line, 0, $idx);
|
||||
my $word = substr ($line, $idx + 1);
|
||||
|
||||
return unless substr ($hash, 0, 7) eq '$sshng$';
|
||||
|
||||
my (undef, $signature, $cid, undef, $salt, undef, $data) = split '\$', $hash;
|
||||
|
||||
return unless defined $signature;
|
||||
return unless defined $cid;
|
||||
return unless defined $salt;
|
||||
return unless defined $data;
|
||||
|
||||
return unless ($signature eq 'sshng');
|
||||
|
||||
return unless (($cid == 1) || ($cid == 3));
|
||||
|
||||
my $word_packed = pack_if_HEX_notation ($word);
|
||||
|
||||
my $new_hash = module_generate_hash ($word_packed, $salt, $cid, $data);
|
||||
|
||||
return ($new_hash, $word);
|
||||
}
|
||||
|
||||
1;
|
159
tools/test_modules/m22941.pm
Normal file
159
tools/test_modules/m22941.pm
Normal file
@ -0,0 +1,159 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
##
|
||||
## Author......: See docs/credits.txt
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Crypt::CBC;
|
||||
use Digest::MD5 qw (md5);
|
||||
|
||||
sub module_constraints { [[0, 256], [32, 32], [-1, -1], [-1, -1], [-1, -1]] }
|
||||
|
||||
sub generate_key
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
my $bytes = shift;
|
||||
|
||||
my $salt8 = substr ($salt, 0, 8);
|
||||
|
||||
my $out = md5 ($word . $salt8);
|
||||
|
||||
$out .= md5 ($out . $word . $salt8);
|
||||
|
||||
return substr ($out, 0, 24);
|
||||
}
|
||||
|
||||
sub module_generate_hash
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
my $cid = shift // 4;
|
||||
my $data = shift;
|
||||
|
||||
my $salt_bin = pack ("H*", $salt);
|
||||
my $data_bin;
|
||||
|
||||
my $key = generate_key ($word, $salt_bin);
|
||||
|
||||
my $is_decrypt = defined ($data);
|
||||
|
||||
if ($is_decrypt == 1)
|
||||
{
|
||||
$data_bin = pack ("H*", $data);
|
||||
|
||||
my $aes = Crypt::CBC->new ({
|
||||
cipher => "Crypt::Rijndael",
|
||||
key => $key,
|
||||
iv => $salt_bin,
|
||||
keysize => 24,
|
||||
literal_key => 1,
|
||||
header => "none",
|
||||
padding => "standard",
|
||||
});
|
||||
|
||||
my $dec_bin = $aes->decrypt ($data_bin);
|
||||
|
||||
## This is a ridiculous check of successfull decryption
|
||||
## There are no useable asn1 parsers for perl available
|
||||
## We have to rely on a combination of padding check and pattern matching
|
||||
## The (minimum) 16 bit should be good enough for a unit test
|
||||
|
||||
if (length ($dec_bin) < length ($data_bin))
|
||||
{
|
||||
if (substr ($dec_bin, 0, 1) eq "\x30")
|
||||
{
|
||||
$data_bin = $dec_bin;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$data_bin = pack ("H*",
|
||||
"308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100b7a2" .
|
||||
"e4c254c8174219e60d9cce96737a906797b8edb86af8f055f60db7bd298b0d31d7ce97ebeae393d5" .
|
||||
"0e6da5215b58dcd72f4d3cac9e79b6ccaed7da47d2bd04f6a767f5ab7dc0f58beb6298c1e2358ed6" .
|
||||
"d3ef441f2326ac5db0027e08ae6c7724ff9a2a220a07e97319b6eff5cd653c7ab8b6ea9f9e89a40a" .
|
||||
"b856f036acfd39b1e5926964a024de35052de6d3423fe763569f48869c834750b28f09cecdddb54a" .
|
||||
"5526a2c5159d22d24606a2af6c6f47a5d9c04c454896192b8e7b82cf6f6934a23d3495059cb7e43b" .
|
||||
"98a20bd5b5782e15d93c8b289838c0a1df82ee429f0708d97aa40d6e75ec57ff12a2714871f241a8" .
|
||||
"6f6d8d3472b084aeb748da33e2d50203010001028201004afab8dadc1122e5fb7b225dbf4051005f" .
|
||||
"4bdcf84620019589541ff633ea89b6dbf958fb62ae9226bfeac34c639b3e18077bd935792ba63d5e" .
|
||||
"352ec2b5be93be57f37a21097f2f06857bceed601ff2041a417f2177b81afb246fd079040af96512" .
|
||||
"34ca24a1456ac11641c7e319114cff23f59bcc1bfa769a0e9fcdeab98429973e10caf303f2bcb065" .
|
||||
"f22c1cc259556de8377431237da7082cf03ce8da9530be398022f0171d468d92fcabbe776a5e9cf2" .
|
||||
"045642868406fd03ab735a70bfec3a951bb3c7a1de0fb3ff63cef23897e4fc3f9c5edf62fd45d058" .
|
||||
"fedc7d2fb22ec928984a061053a7138ce0417b5512579a92be0775104c0bc911f68a5e8ede298102" .
|
||||
"818100e4e17e2c752dbf1ad1025a074dc5f9c3c5989d23c84594313373d3e4ed0c0ddd74429ab026" .
|
||||
"535c5e77549d888835bc94f069ebc5e77fdbd2ddf4c8be6cf777799a6d8d18e2b8cecfc13ab26df8" .
|
||||
"b71ca3d94c2193c294042fb1025fdab38ba7aaeafebd8dd1f9d78ee67100693e99255dad6b964ebf" .
|
||||
"b7401a03b67d412fabb33502818100cd65067097e307643df1fc8214db1dd7d09342ef01417a2620" .
|
||||
"adad87352a58b8fcf07521289da3851623d8d045935fab7ecccc52ba0b86adcb92da76255e00289b" .
|
||||
"af9aacd936201861b0021249f4ab5e6020db823af7171aef0bbbd02dc94d2489fc0b68500bd1b7d2" .
|
||||
"81ed69fe4a44384161fe906e49bc91e0362b446ec2c521028180497662d40c2c49b966ba758100a2" .
|
||||
"799f2f8de369f7bef568b1560cfdde63cf13745c685fff7d2419a1fd83aeade1698cf87956d6a78e" .
|
||||
"2f55482e683c4ea7432ec1b545e365e9e15f676ada98578b166334bcadce4a56cddd2cd85141d5fd" .
|
||||
"0e2cdace36b30d613ea1bc2f2aed9cccf4e4536443d334cfb180680eabb73f80c1bd0281803f30fc" .
|
||||
"b93951a4dd875d62e5968b0f746d7c51147d5b6abc3e4390e6cf4997005af993dfbec23923e1fae7" .
|
||||
"62b47531f2ee510defc9c3700d1a5bb510b2506856160801db79fc78056850a16285145c80edac4e" .
|
||||
"3c93ed9f532f067a2303633273b26c340a44ce4e1873107c3da6f9ac616e643ad0aecdcad14a9cff" .
|
||||
"d4cf0ae76102818100b82528a3dfc595cf9c6a025998491e3b4849c71aa8d1222ddb14af7f82fbe5" .
|
||||
"169ec3ba18ec28d5a9501e95bc9da72cea99e4cdfdf898f40bec6b28f838243d2f39d7226e0873ed" .
|
||||
"ee752bcae07639a4bd0eb31be1718c456391630b83ad0e9bf3fa18a645007e64fe59af467ea021f9" .
|
||||
"e9a0dd759b21cd0b93333a73116abcaa2a"
|
||||
);
|
||||
}
|
||||
|
||||
my $aes = Crypt::CBC->new ({
|
||||
cipher => "Crypt::Rijndael",
|
||||
key => $key,
|
||||
iv => $salt_bin,
|
||||
keysize => 24,
|
||||
literal_key => 1,
|
||||
header => "none",
|
||||
padding => "standard",
|
||||
});
|
||||
|
||||
my $enc_bin = $aes->encrypt ($data_bin);
|
||||
|
||||
my $hash = sprintf ('$sshng$%d$%d$%s$%d$%s', $cid, length ($salt_bin), unpack ("H*", $salt_bin), length ($enc_bin), unpack ("H*", $enc_bin));
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
sub module_verify_hash
|
||||
{
|
||||
my $line = shift;
|
||||
|
||||
my $idx = index ($line, ':');
|
||||
|
||||
return unless $idx >= 0;
|
||||
|
||||
my $hash = substr ($line, 0, $idx);
|
||||
my $word = substr ($line, $idx + 1);
|
||||
|
||||
return unless substr ($hash, 0, 7) eq '$sshng$';
|
||||
|
||||
my (undef, $signature, $cid, undef, $salt, undef, $data) = split '\$', $hash;
|
||||
|
||||
return unless defined $signature;
|
||||
return unless defined $cid;
|
||||
return unless defined $salt;
|
||||
return unless defined $data;
|
||||
|
||||
return unless ($signature eq 'sshng');
|
||||
|
||||
return unless ($cid == 4);
|
||||
|
||||
my $word_packed = pack_if_HEX_notation ($word);
|
||||
|
||||
my $new_hash = module_generate_hash ($word_packed, $salt, $cid, $data);
|
||||
|
||||
return ($new_hash, $word);
|
||||
}
|
||||
|
||||
1;
|
159
tools/test_modules/m22951.pm
Normal file
159
tools/test_modules/m22951.pm
Normal file
@ -0,0 +1,159 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
##
|
||||
## Author......: See docs/credits.txt
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Crypt::CBC;
|
||||
use Digest::MD5 qw (md5);
|
||||
|
||||
sub module_constraints { [[0, 256], [32, 32], [-1, -1], [-1, -1], [-1, -1]] }
|
||||
|
||||
sub generate_key
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
my $bytes = shift;
|
||||
|
||||
my $salt8 = substr ($salt, 0, 8);
|
||||
|
||||
my $out = md5 ($word . $salt8);
|
||||
|
||||
$out .= md5 ($out . $word . $salt8);
|
||||
|
||||
return substr ($out, 0, 32);
|
||||
}
|
||||
|
||||
sub module_generate_hash
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
my $cid = shift // 5;
|
||||
my $data = shift;
|
||||
|
||||
my $salt_bin = pack ("H*", $salt);
|
||||
my $data_bin;
|
||||
|
||||
my $key = generate_key ($word, $salt_bin);
|
||||
|
||||
my $is_decrypt = defined ($data);
|
||||
|
||||
if ($is_decrypt == 1)
|
||||
{
|
||||
$data_bin = pack ("H*", $data);
|
||||
|
||||
my $aes = Crypt::CBC->new ({
|
||||
cipher => "Crypt::Rijndael",
|
||||
key => $key,
|
||||
iv => $salt_bin,
|
||||
keysize => 32,
|
||||
literal_key => 1,
|
||||
header => "none",
|
||||
padding => "standard",
|
||||
});
|
||||
|
||||
my $dec_bin = $aes->decrypt ($data_bin);
|
||||
|
||||
## This is a ridiculous check of successfull decryption
|
||||
## There are no useable asn1 parsers for perl available
|
||||
## We have to rely on a combination of padding check and pattern matching
|
||||
## The (minimum) 16 bit should be good enough for a unit test
|
||||
|
||||
if (length ($dec_bin) < length ($data_bin))
|
||||
{
|
||||
if (substr ($dec_bin, 0, 1) eq "\x30")
|
||||
{
|
||||
$data_bin = $dec_bin;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$data_bin = pack ("H*",
|
||||
"308204bd020100300d06092a864886f70d0101010500048204a7308204a30201000282010100b7a2" .
|
||||
"e4c254c8174219e60d9cce96737a906797b8edb86af8f055f60db7bd298b0d31d7ce97ebeae393d5" .
|
||||
"0e6da5215b58dcd72f4d3cac9e79b6ccaed7da47d2bd04f6a767f5ab7dc0f58beb6298c1e2358ed6" .
|
||||
"d3ef441f2326ac5db0027e08ae6c7724ff9a2a220a07e97319b6eff5cd653c7ab8b6ea9f9e89a40a" .
|
||||
"b856f036acfd39b1e5926964a024de35052de6d3423fe763569f48869c834750b28f09cecdddb54a" .
|
||||
"5526a2c5159d22d24606a2af6c6f47a5d9c04c454896192b8e7b82cf6f6934a23d3495059cb7e43b" .
|
||||
"98a20bd5b5782e15d93c8b289838c0a1df82ee429f0708d97aa40d6e75ec57ff12a2714871f241a8" .
|
||||
"6f6d8d3472b084aeb748da33e2d50203010001028201004afab8dadc1122e5fb7b225dbf4051005f" .
|
||||
"4bdcf84620019589541ff633ea89b6dbf958fb62ae9226bfeac34c639b3e18077bd935792ba63d5e" .
|
||||
"352ec2b5be93be57f37a21097f2f06857bceed601ff2041a417f2177b81afb246fd079040af96512" .
|
||||
"34ca24a1456ac11641c7e319114cff23f59bcc1bfa769a0e9fcdeab98429973e10caf303f2bcb065" .
|
||||
"f22c1cc259556de8377431237da7082cf03ce8da9530be398022f0171d468d92fcabbe776a5e9cf2" .
|
||||
"045642868406fd03ab735a70bfec3a951bb3c7a1de0fb3ff63cef23897e4fc3f9c5edf62fd45d058" .
|
||||
"fedc7d2fb22ec928984a061053a7138ce0417b5512579a92be0775104c0bc911f68a5e8ede298102" .
|
||||
"818100e4e17e2c752dbf1ad1025a074dc5f9c3c5989d23c84594313373d3e4ed0c0ddd74429ab026" .
|
||||
"535c5e77549d888835bc94f069ebc5e77fdbd2ddf4c8be6cf777799a6d8d18e2b8cecfc13ab26df8" .
|
||||
"b71ca3d94c2193c294042fb1025fdab38ba7aaeafebd8dd1f9d78ee67100693e99255dad6b964ebf" .
|
||||
"b7401a03b67d412fabb33502818100cd65067097e307643df1fc8214db1dd7d09342ef01417a2620" .
|
||||
"adad87352a58b8fcf07521289da3851623d8d045935fab7ecccc52ba0b86adcb92da76255e00289b" .
|
||||
"af9aacd936201861b0021249f4ab5e6020db823af7171aef0bbbd02dc94d2489fc0b68500bd1b7d2" .
|
||||
"81ed69fe4a44384161fe906e49bc91e0362b446ec2c521028180497662d40c2c49b966ba758100a2" .
|
||||
"799f2f8de369f7bef568b1560cfdde63cf13745c685fff7d2419a1fd83aeade1698cf87956d6a78e" .
|
||||
"2f55482e683c4ea7432ec1b545e365e9e15f676ada98578b166334bcadce4a56cddd2cd85141d5fd" .
|
||||
"0e2cdace36b30d613ea1bc2f2aed9cccf4e4536443d334cfb180680eabb73f80c1bd0281803f30fc" .
|
||||
"b93951a4dd875d62e5968b0f746d7c51147d5b6abc3e4390e6cf4997005af993dfbec23923e1fae7" .
|
||||
"62b47531f2ee510defc9c3700d1a5bb510b2506856160801db79fc78056850a16285145c80edac4e" .
|
||||
"3c93ed9f532f067a2303633273b26c340a44ce4e1873107c3da6f9ac616e643ad0aecdcad14a9cff" .
|
||||
"d4cf0ae76102818100b82528a3dfc595cf9c6a025998491e3b4849c71aa8d1222ddb14af7f82fbe5" .
|
||||
"169ec3ba18ec28d5a9501e95bc9da72cea99e4cdfdf898f40bec6b28f838243d2f39d7226e0873ed" .
|
||||
"ee752bcae07639a4bd0eb31be1718c456391630b83ad0e9bf3fa18a645007e64fe59af467ea021f9" .
|
||||
"e9a0dd759b21cd0b93333a73116abcaa2a"
|
||||
);
|
||||
}
|
||||
|
||||
my $aes = Crypt::CBC->new ({
|
||||
cipher => "Crypt::Rijndael",
|
||||
key => $key,
|
||||
iv => $salt_bin,
|
||||
keysize => 32,
|
||||
literal_key => 1,
|
||||
header => "none",
|
||||
padding => "standard",
|
||||
});
|
||||
|
||||
my $enc_bin = $aes->encrypt ($data_bin);
|
||||
|
||||
my $hash = sprintf ('$sshng$%d$%d$%s$%d$%s', $cid, length ($salt_bin), unpack ("H*", $salt_bin), length ($enc_bin), unpack ("H*", $enc_bin));
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
sub module_verify_hash
|
||||
{
|
||||
my $line = shift;
|
||||
|
||||
my $idx = index ($line, ':');
|
||||
|
||||
return unless $idx >= 0;
|
||||
|
||||
my $hash = substr ($line, 0, $idx);
|
||||
my $word = substr ($line, $idx + 1);
|
||||
|
||||
return unless substr ($hash, 0, 7) eq '$sshng$';
|
||||
|
||||
my (undef, $signature, $cid, undef, $salt, undef, $data) = split '\$', $hash;
|
||||
|
||||
return unless defined $signature;
|
||||
return unless defined $cid;
|
||||
return unless defined $salt;
|
||||
return unless defined $data;
|
||||
|
||||
return unless ($signature eq 'sshng');
|
||||
|
||||
return unless ($cid == 5);
|
||||
|
||||
my $word_packed = pack_if_HEX_notation ($word);
|
||||
|
||||
my $new_hash = module_generate_hash ($word_packed, $salt, $cid, $data);
|
||||
|
||||
return ($new_hash, $word);
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in New Issue
Block a user