Merge pull request #2363 from mpalmer/pkcs1

Module to decrypt PEM-encoded encrypted private keys (#74)
This commit is contained in:
Jens Steube
2020-08-03 16:54:06 +02:00
committed by GitHub
19 changed files with 4078 additions and 0 deletions
+308
View File
@@ -771,6 +771,262 @@ 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;
@@ -1486,6 +1742,58 @@ 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];
+5
View File
@@ -100,6 +100,10 @@ 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);
@@ -121,6 +125,7 @@ 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);
+190
View File
@@ -0,0 +1,190 @@
/**
* 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];
}
}
+35
View File
@@ -0,0 +1,35 @@
/**
* 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
+238
View File
@@ -0,0 +1,238 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define BLOCK_SIZE 8
#define KEY_LENGTH 24
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_rp.cl"
#include "inc_cipher_des.cl"
#include "inc_pem_common.cl"
#endif // KERNEL_STATIC
KERNEL_FQ void m22911_sxx (KERN_ATTR_RULES_ESALT (pem_t))
{
/**
* base
*/
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];
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
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
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]);
COPY_PW (pws[gid]);
/**
* 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);
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];
_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);
u32 p1[BLOCK_SIZE / 4], p2[BLOCK_SIZE / 4];
_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);
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
plaintext[i] ^= salt_iv[i];
}
#ifdef DEBUG
printf("First plaintext block:");
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
printf("\n");
#endif // DEBUG
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;
}
#ifdef DEBUG
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
#endif // DEBUG
if (asn1_ok == 0)
{
continue;
}
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
iv[i] = first_block[i];
}
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 (p1, ciphertext, K4, K5, s_SPtrans);
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
_des_crypt_decrypt (plaintext, p2, K0, K1, s_SPtrans);
#ifdef _unroll
#pragma unroll
#endif
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
{
plaintext[j] ^= iv[j];
iv[j] = ciphertext[j];
}
#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
}
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
u8 *pt_bytes = (u8 *) plaintext;
#ifdef DEBUG
printf("Padding byte: 0x%02x\n", padding_count);
#endif
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);
}
}
}
}
+261
View File
@@ -0,0 +1,261 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define BLOCK_SIZE 8
#define KEY_LENGTH 24
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_cipher_des.cl"
#include "inc_pem_common.cl"
#endif // KERNEL_STATIC
KERNEL_FQ void m22911_sxx (KERN_ATTR_ESALT (pem_t))
{
/**
* base
*/
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];
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
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
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]);
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)
{
w[idx] = pws[gid].i[idx];
}
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
const u32 comb_len = combs_buf[il_pos].pw_len;
u32 c[64];
#ifdef _unroll
#pragma unroll
#endif
for (int i = 0; i < 16; i++)
{
c[i] = combs_buf[il_pos].i[i];
}
switch_buffer_by_offset_1x64_be_S (c, pw_len);
#ifdef _unroll
#pragma unroll
#endif
for (int i = 0; i < 16; i++)
{
c[i] |= w[i];
}
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
generate_key (salt_buf, c, pw_len + comb_len, key);
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];
_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);
u32 p1[BLOCK_SIZE / 4], p2[BLOCK_SIZE / 4];
_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);
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
plaintext[i] ^= salt_iv[i];
}
#ifdef DEBUG
printf("First plaintext block:");
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
printf("\n");
#endif // DEBUG
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;
}
#ifdef DEBUG
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
#endif // DEBUG
if (asn1_ok == 0)
{
continue;
}
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
iv[i] = first_block[i];
}
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 (p1, ciphertext, K4, K5, s_SPtrans);
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
_des_crypt_decrypt (plaintext, p2, K0, K1, s_SPtrans);
#ifdef _unroll
#pragma unroll
#endif
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
{
plaintext[j] ^= iv[j];
iv[j] = ciphertext[j];
}
#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
}
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
u8 *pt_bytes = (u8 *) plaintext;
#ifdef DEBUG
printf("Padding byte: 0x%02x\n", padding_count);
#endif
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);
}
}
}
}
+253
View File
@@ -0,0 +1,253 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define NEW_SIMD_CODE
#define BLOCK_SIZE 8
#define KEY_LENGTH 24
#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_cipher_des.cl"
#include "inc_pem_common.cl"
#endif // KERNEL_STATIC
KERNEL_FQ void m22911_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
{
/**
* base
*/
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];
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
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
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 };
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
{
w[idx] = pws[gid].i[idx];
}
u32x w0l = w[0];
/**
* loop
*/
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];
generate_key_vector (salt_buf, w, pw_len, key);
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];
_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 p1[BLOCK_SIZE / 4], p2[BLOCK_SIZE / 4];
_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);
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
plaintext[i] ^= salt_iv[i];
}
#ifdef DEBUG
printf("First plaintext block:");
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
printf("\n");
#endif // DEBUG
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;
}
#ifdef DEBUG
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
#endif // DEBUG
if (asn1_ok == 0)
{
continue;
}
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
iv[i] = first_block[i];
}
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 (p1, ciphertext, K4, K5, s_SPtrans);
_des_crypt_encrypt (p2, p1, K2, K3, s_SPtrans);
_des_crypt_decrypt (plaintext, p2, K0, K1, s_SPtrans);
#ifdef _unroll
#pragma unroll
#endif
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
{
plaintext[j] ^= iv[j];
iv[j] = ciphertext[j];
}
#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
}
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
u8 *pt_bytes = (u8 *) plaintext;
#ifdef DEBUG
printf("Padding byte: 0x%02x\n", padding_count);
#endif
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 + v_pos, 0, 0);
}
}
}
}
}
+229
View File
@@ -0,0 +1,229 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define BLOCK_SIZE 8
#define KEY_LENGTH 8
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_rp.cl"
#include "inc_cipher_des.cl"
#include "inc_pem_common.cl"
#endif // KERNEL_STATIC
KERNEL_FQ void m22921_sxx (KERN_ATTR_RULES_ESALT (pem_t))
{
/**
* base
*/
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];
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
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
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]);
COPY_PW(pws[gid]);
/**
* 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);
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];
_des_crypt_keysetup (key[0], key[1], K0, K1, s_skb);
_des_crypt_decrypt (plaintext, first_block, K0, K1, s_SPtrans);
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
plaintext[i] ^= salt_iv[i];
}
#ifdef DEBUG
printf("First plaintext block:");
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
printf("\n");
#endif // DEBUG
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;
}
#ifdef DEBUG
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
#endif // DEBUG
if (asn1_ok == 0)
{
continue;
}
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
iv[i] = first_block[i];
}
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 (plaintext, ciphertext, K0, K1, s_SPtrans);
#ifdef _unroll
#pragma unroll
#endif
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
{
plaintext[j] ^= iv[j];
iv[j] = ciphertext[j];
}
#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
}
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
u8 *pt_bytes = (u8 *) plaintext;
#ifdef DEBUG
printf("Padding byte: 0x%02x\n", padding_count);
#endif
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);
}
}
}
}
+252
View File
@@ -0,0 +1,252 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define BLOCK_SIZE 8
#define KEY_LENGTH 8
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_cipher_des.cl"
#include "inc_pem_common.cl"
#endif // KERNEL_STATIC
KERNEL_FQ void m22921_sxx (KERN_ATTR_ESALT (pem_t))
{
/**
* base
*/
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];
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
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
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]);
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)
{
w[idx] = pws[gid].i[idx];
}
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
const u32 comb_len = combs_buf[il_pos].pw_len;
u32 c[64];
#ifdef _unroll
#pragma unroll
#endif
for (int i = 0; i < 16; i++)
{
c[i] = combs_buf[il_pos].i[i];
}
switch_buffer_by_offset_1x64_be_S (c, pw_len);
#ifdef _unroll
#pragma unroll
#endif
for (int i = 0; i < 16; i++)
{
c[i] |= w[i];
}
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
generate_key (salt_buf, c, pw_len + comb_len, key);
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];
_des_crypt_keysetup (key[0], key[1], K0, K1, s_skb);
_des_crypt_decrypt (plaintext, first_block, K0, K1, s_SPtrans);
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
plaintext[i] ^= salt_iv[i];
}
#ifdef DEBUG
printf("First plaintext block:");
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
printf("\n");
#endif // DEBUG
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;
}
#ifdef DEBUG
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
#endif // DEBUG
if (asn1_ok == 0)
{
continue;
}
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
iv[i] = first_block[i];
}
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 (plaintext, ciphertext, K0, K1, s_SPtrans);
#ifdef _unroll
#pragma unroll
#endif
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
{
plaintext[j] ^= iv[j];
iv[j] = ciphertext[j];
}
#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
}
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
u8 *pt_bytes = (u8 *) plaintext;
#ifdef DEBUG
printf("Padding byte: 0x%02x\n", padding_count);
#endif
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);
}
}
}
}
+244
View File
@@ -0,0 +1,244 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define NEW_SIMD_CODE
#define BLOCK_SIZE 8
#define KEY_LENGTH 8
#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_cipher_des.cl"
#include "inc_pem_common.cl"
#endif // KERNEL_STATIC
KERNEL_FQ void m22921_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
{
/**
* base
*/
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];
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
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
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 };
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
{
w[idx] = pws[gid].i[idx];
}
u32x w0l = w[0];
/**
* loop
*/
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];
generate_key_vector (salt_buf, w, pw_len, key);
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];
_des_crypt_keysetup (VECTOR_ELEMENT(key[0], v_pos), VECTOR_ELEMENT(key[1], v_pos), K0, K1, s_skb);
_des_crypt_decrypt (plaintext, first_block, K0, K1, s_SPtrans);
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
plaintext[i] ^= salt_iv[i];
}
#ifdef DEBUG
printf("First plaintext block:");
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
printf("\n");
#endif // DEBUG
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;
}
#ifdef DEBUG
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
#endif // DEBUG
if (asn1_ok == 0)
{
continue;
}
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
iv[i] = first_block[i];
}
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 (plaintext, ciphertext, K0, K1, s_SPtrans);
#ifdef _unroll
#pragma unroll
#endif
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
{
plaintext[j] ^= iv[j];
iv[j] = ciphertext[j];
}
#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
}
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
u8 *pt_bytes = (u8 *) plaintext;
#ifdef DEBUG
printf("Padding byte: 0x%02x\n", padding_count);
#endif
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 + v_pos, 0, 0);
}
}
}
}
}
+241
View File
@@ -0,0 +1,241 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define BLOCK_SIZE 16
#define KEY_LENGTH 16
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_rp.cl"
#include "inc_cipher_aes.cl"
#include "inc_pem_common.cl"
#endif // KERNEL_STATIC
KERNEL_FQ void m22931_sxx (KERN_ATTR_RULES_ESALT (pem_t))
{
/**
* base
*/
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_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
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_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 // REAL_SHM
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]);
COPY_PW (pws[gid]);
/**
* 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);
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_decrypt (ks, first_block, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
plaintext[i] ^= salt_iv[i];
}
#ifdef DEBUG
printf("First plaintext block:");
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
printf("\n");
#endif // DEBUG
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;
}
#ifdef DEBUG
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
#endif // DEBUG
if (asn1_ok == 0)
{
continue;
}
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
iv[i] = first_block[i];
}
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, ciphertext, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
#ifdef _unroll
#pragma unroll
#endif
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
{
plaintext[j] ^= iv[j];
iv[j] = ciphertext[j];
}
#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
}
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
u8 *pt_bytes = (u8 *) plaintext;
#ifdef DEBUG
printf("Padding byte: 0x%02x\n", padding_count);
#endif
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);
}
}
}
}
+264
View File
@@ -0,0 +1,264 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define BLOCK_SIZE 16
#define KEY_LENGTH 16
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_cipher_aes.cl"
#include "inc_pem_common.cl"
#endif // KERNEL_STATIC
KERNEL_FQ void m22931_sxx (KERN_ATTR_ESALT (pem_t))
{
/**
* base
*/
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_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
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_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 // REAL_SHM
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]);
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)
{
w[idx] = pws[gid].i[idx];
}
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
const u32 comb_len = combs_buf[il_pos].pw_len;
u32 c[64];
#ifdef _unroll
#pragma unroll
#endif
for (int i = 0; i < 16; i++)
{
c[i] = combs_buf[il_pos].i[i];
}
switch_buffer_by_offset_1x64_be_S (c, pw_len);
#ifdef _unroll
#pragma unroll
#endif
for (int i = 0; i < 16; i++)
{
c[i] |= w[i];
}
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
generate_key (salt_buf, c, pw_len + comb_len, key);
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_decrypt (ks, first_block, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
plaintext[i] ^= salt_iv[i];
}
#ifdef DEBUG
printf("First plaintext block:");
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
printf("\n");
#endif // DEBUG
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;
}
#ifdef DEBUG
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
#endif // DEBUG
if (asn1_ok == 0)
{
continue;
}
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
iv[i] = first_block[i];
}
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, ciphertext, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
#ifdef _unroll
#pragma unroll
#endif
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
{
plaintext[j] ^= iv[j];
iv[j] = ciphertext[j];
}
#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
}
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
u8 *pt_bytes = (u8 *) plaintext;
#ifdef DEBUG
printf("Padding byte: 0x%02x\n", padding_count);
#endif
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);
}
}
}
}
+265
View File
@@ -0,0 +1,265 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define NEW_SIMD_CODE
#define BLOCK_SIZE 16
#define KEY_LENGTH 16
#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_cipher_aes.cl"
#include "inc_pem_common.cl"
#endif // KERNEL_STATIC
KERNEL_FQ void m22931_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
{
/**
* base
*/
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_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
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_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 // REAL_SHM
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 };
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
{
w[idx] = pws[gid].i[idx];
}
u32x w0l = w[0];
/**
* loop
*/
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];
generate_key_vector (salt_buf, w, pw_len, keys);
#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];
for (u32 i = 0; i < KEY_LENGTH; i++)
{
key[i] = VECTOR_ELEMENT(keys[i], v_pos);
}
aes128_set_decrypt_key (ks, key, 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);
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
plaintext[i] ^= salt_iv[i];
}
#ifdef DEBUG
printf("First plaintext block:");
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
printf("\n");
#endif // DEBUG
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;
}
#ifdef DEBUG
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
#endif // DEBUG
if (asn1_ok == 0)
{
continue;
}
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
iv[i] = first_block[i];
}
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, ciphertext, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
#ifdef _unroll
#pragma unroll
#endif
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
{
plaintext[j] ^= iv[j];
iv[j] = ciphertext[j];
}
#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
}
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
u8 *pt_bytes = (u8 *) plaintext;
#ifdef DEBUG
printf("Padding byte: 0x%02x\n", padding_count);
#endif
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 + v_pos, 0, 0);
}
}
}
}
}
+241
View File
@@ -0,0 +1,241 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define BLOCK_SIZE 16
#define KEY_LENGTH 32
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_rp.cl"
#include "inc_cipher_aes.cl"
#include "inc_pem_common.cl"
#endif // KERNEL_STATIC
KERNEL_FQ void m22951_sxx (KERN_ATTR_RULES_ESALT (pem_t))
{
/**
* base
*/
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_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
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_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 // REAL_SHM
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]);
COPY_PW (pws[gid]);
/**
* 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);
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_decrypt (ks, first_block, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
plaintext[i] ^= salt_iv[i];
}
#ifdef DEBUG
printf("First plaintext block:");
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
printf("\n");
#endif // DEBUG
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;
}
#ifdef DEBUG
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
#endif // DEBUG
if (asn1_ok == 0)
{
continue;
}
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
iv[i] = first_block[i];
}
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, ciphertext, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
#ifdef _unroll
#pragma unroll
#endif
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
{
plaintext[j] ^= iv[j];
iv[j] = ciphertext[j];
}
#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
}
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
u8 *pt_bytes = (u8 *) plaintext;
#ifdef DEBUG
printf("Padding byte: 0x%02x\n", padding_count);
#endif
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);
}
}
}
}
+264
View File
@@ -0,0 +1,264 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define BLOCK_SIZE 16
#define KEY_LENGTH 32
#ifdef KERNEL_STATIC
#include "inc_vendor.h"
#include "inc_types.h"
#include "inc_platform.cl"
#include "inc_common.cl"
#include "inc_cipher_aes.cl"
#include "inc_pem_common.cl"
#endif // KERNEL_STATIC
KERNEL_FQ void m22951_sxx (KERN_ATTR_ESALT (pem_t))
{
/**
* base
*/
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_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
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_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 // REAL_SHM
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]);
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)
{
w[idx] = pws[gid].i[idx];
}
/**
* loop
*/
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
{
const u32 comb_len = combs_buf[il_pos].pw_len;
u32 c[64];
#ifdef _unroll
#pragma unroll
#endif
for (int i = 0; i < 16; i++)
{
c[i] = combs_buf[il_pos].i[i];
}
switch_buffer_by_offset_1x64_be_S (c, pw_len);
#ifdef _unroll
#pragma unroll
#endif
for (int i = 0; i < 16; i++)
{
c[i] |= w[i];
}
u32 key[HC_PEM_MAX_KEY_LENGTH / 4];
generate_key (salt_buf, c, pw_len + comb_len, key);
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_decrypt (ks, first_block, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
plaintext[i] ^= salt_iv[i];
}
#ifdef DEBUG
printf("First plaintext block:");
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
printf("\n");
#endif // DEBUG
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;
}
#ifdef DEBUG
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
#endif // DEBUG
if (asn1_ok == 0)
{
continue;
}
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
iv[i] = first_block[i];
}
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, ciphertext, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
#ifdef _unroll
#pragma unroll
#endif
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
{
plaintext[j] ^= iv[j];
iv[j] = ciphertext[j];
}
#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
}
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
u8 *pt_bytes = (u8 *) plaintext;
#ifdef DEBUG
printf("Padding byte: 0x%02x\n", padding_count);
#endif
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);
}
}
}
}
+262
View File
@@ -0,0 +1,262 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#define NEW_SIMD_CODE
#define BLOCK_SIZE 16
#define KEY_LENGTH 32
#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_cipher_aes.cl"
#include "inc_pem_common.cl"
#endif // KERNEL_STATIC
KERNEL_FQ void m22951_sxx (KERN_ATTR_VECTOR_ESALT (pem_t))
{
/**
* base
*/
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_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
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_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 // REAL_SHM
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 };
for (u32 i = 0, idx = 0; i < pw_len; i += 4, idx += 1)
{
w[idx] = pws[gid].i[idx];
}
u32x w0l = w[0];
/**
* loop
*/
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];
generate_key_vector (salt_buf, w, pw_len, keys);
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];
for (u32 i = 0; i < KEY_LENGTH; i++)
{
key[i] = VECTOR_ELEMENT(keys[i], v_pos);
}
aes256_set_decrypt_key (ks, key, 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);
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
plaintext[i] ^= salt_iv[i];
}
#ifdef DEBUG
printf("First plaintext block:");
for (u32 i = 0; i < BLOCK_SIZE / 4; i++) printf(" 0x%08x", plaintext[i]);
printf("\n");
#endif // DEBUG
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;
}
#ifdef DEBUG
if (asn1_ok == 1) printf("Passed ASN.1 sanity check\n");
#endif // DEBUG
if (asn1_ok == 0)
{
continue;
}
#ifdef _unroll
#pragma unroll
#endif
for (u32 i = 0; i < BLOCK_SIZE / 4; i++)
{
iv[i] = first_block[i];
}
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, ciphertext, plaintext, s_td0, s_td1, s_td2, s_td3, s_td4);
#ifdef _unroll
#pragma unroll
#endif
for (u32 j = 0; j < BLOCK_SIZE / 4; j++)
{
plaintext[j] ^= iv[j];
iv[j] = ciphertext[j];
}
#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
}
u32 padding_count = (plaintext[BLOCK_SIZE / 4 - 1] & 0xff000000) >> 24;
u8 *pt_bytes = (u8 *) plaintext;
#ifdef DEBUG
printf("Padding byte: 0x%02x\n", padding_count);
#endif
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 + v_pos, 0, 0);
}
}
}
}
}