From c39e3dfceaade5d01aa0ce074b2df54757a734a7 Mon Sep 17 00:00:00 2001 From: Matt Palmer Date: Thu, 23 Apr 2020 12:36:15 +1000 Subject: [PATCH 1/5] Add some more generic error messages These are almost all taken from error messages that are specific to one particular module, and turned into generic errors that can be used for any module. It seemed like a better idea to provide generic messages than to encourage infinite proliferation of error codes (which would probably end up blowing the 255 value threshold sooner or later). It doesn't seem necessary to provide module-specific error messages for things like "Invalid filesize", since users should already know what sort of file they're asking to be parsed. --- include/types.h | 4 ++++ src/shared.c | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/include/types.h b/include/types.h index fdc1285e5..b610b46fa 100644 --- a/include/types.h +++ b/include/types.h @@ -535,6 +535,10 @@ typedef enum parser_rc PARSER_TOKEN_LENGTH = -35, PARSER_INSUFFICIENT_ENTROPY = -36, PARSER_PKZIP_CT_UNMATCHED = -37, + PARSER_KEY_SIZE = -38, + PARSER_BLOCK_SIZE = -39, + PARSER_CIPHER = -40, + PARSER_FILE_SIZE = -41, PARSER_UNKNOWN_ERROR = -255 } parser_rc_t; diff --git a/src/shared.c b/src/shared.c index 8b59d600f..11fde9771 100644 --- a/src/shared.c +++ b/src/shared.c @@ -53,6 +53,10 @@ static const char *PA_034 = "Token encoding exception"; static const char *PA_035 = "Token length exception"; static const char *PA_036 = "Insufficient entropy exception"; static const char *PA_037 = "Hash contains unsupported compression type for current mode"; +static const char *PA_038 = "Invalid key size"; +static const char *PA_039 = "Invalid block size"; +static const char *PA_040 = "Invalid or unsupported cipher"; +static const char *PA_041 = "Invalid filesize"; static const char *PA_255 = "Unknown error"; static const char *OPTI_STR_OPTIMIZED_KERNEL = "Optimized-Kernel"; @@ -1022,6 +1026,10 @@ const char *strparser (const u32 parser_status) case PARSER_TOKEN_LENGTH: return PA_035; case PARSER_INSUFFICIENT_ENTROPY: return PA_036; case PARSER_PKZIP_CT_UNMATCHED: return PA_037; + case PARSER_KEY_SIZE: return PA_038; + case PARSER_BLOCK_SIZE: return PA_039; + case PARSER_CIPHER: return PA_040; + case PARSER_FILE_SIZE: return PA_041; } return PA_255; From f2c69ecfe515cad5ac660f0f37dc96b7527d31be Mon Sep 17 00:00:00 2001 From: Matt Palmer Date: Sat, 25 Apr 2020 16:04:20 +1000 Subject: [PATCH 2/5] Add md5_update_vector_from_scalar This is similar in concept to *_init_v_f_s, except that all contexts in the vector are updated from the same scalar array of data. --- OpenCL/inc_hash_md5.cl | 52 ++++++++++++++++++++++++++++++++++++++++++ OpenCL/inc_hash_md5.h | 1 + 2 files changed, 53 insertions(+) diff --git a/OpenCL/inc_hash_md5.cl b/OpenCL/inc_hash_md5.cl index 3c52c1f40..7e18a735f 100644 --- a/OpenCL/inc_hash_md5.cl +++ b/OpenCL/inc_hash_md5.cl @@ -1486,6 +1486,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]; diff --git a/OpenCL/inc_hash_md5.h b/OpenCL/inc_hash_md5.h index 1e6eaaf93..8b37d6969 100644 --- a/OpenCL/inc_hash_md5.h +++ b/OpenCL/inc_hash_md5.h @@ -121,6 +121,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); From 2d83149a54c5b84f3c29c430450b0266c5387cbf Mon Sep 17 00:00:00 2001 From: Matt Palmer Date: Tue, 19 May 2020 23:58:09 +1000 Subject: [PATCH 3/5] Module to decrypt PEM-encoded encrypted private keys (#74) Supports a variety of common PKCS#1 ciphers, with fast kernels in all available colours, shapes, and sizes. --- OpenCL/inc_hash_md5.cl | 256 +++++++++++++++++++ OpenCL/inc_hash_md5.h | 4 + OpenCL/inc_pkcs1_common.cl | 190 ++++++++++++++ OpenCL/inc_pkcs1_common.h | 35 +++ OpenCL/m24111_a0-pure.cl | 238 +++++++++++++++++ OpenCL/m24111_a1-pure.cl | 261 +++++++++++++++++++ OpenCL/m24111_a3-pure.cl | 253 ++++++++++++++++++ OpenCL/m24121_a0-pure.cl | 229 +++++++++++++++++ OpenCL/m24121_a1-pure.cl | 252 ++++++++++++++++++ OpenCL/m24121_a3-pure.cl | 244 ++++++++++++++++++ OpenCL/m24131_a0-pure.cl | 241 +++++++++++++++++ OpenCL/m24131_a1-pure.cl | 264 +++++++++++++++++++ OpenCL/m24131_a3-pure.cl | 265 +++++++++++++++++++ OpenCL/m24151_a0-pure.cl | 241 +++++++++++++++++ OpenCL/m24151_a1-pure.cl | 264 +++++++++++++++++++ OpenCL/m24151_a3-pure.cl | 262 +++++++++++++++++++ docs/changes.txt | 1 + docs/readme.txt | 1 + src/modules/module_24100.c | 512 +++++++++++++++++++++++++++++++++++++ 19 files changed, 4013 insertions(+) create mode 100644 OpenCL/inc_pkcs1_common.cl create mode 100644 OpenCL/inc_pkcs1_common.h create mode 100644 OpenCL/m24111_a0-pure.cl create mode 100644 OpenCL/m24111_a1-pure.cl create mode 100644 OpenCL/m24111_a3-pure.cl create mode 100644 OpenCL/m24121_a0-pure.cl create mode 100644 OpenCL/m24121_a1-pure.cl create mode 100644 OpenCL/m24121_a3-pure.cl create mode 100644 OpenCL/m24131_a0-pure.cl create mode 100644 OpenCL/m24131_a1-pure.cl create mode 100644 OpenCL/m24131_a3-pure.cl create mode 100644 OpenCL/m24151_a0-pure.cl create mode 100644 OpenCL/m24151_a1-pure.cl create mode 100644 OpenCL/m24151_a3-pure.cl create mode 100644 src/modules/module_24100.c diff --git a/OpenCL/inc_hash_md5.cl b/OpenCL/inc_hash_md5.cl index 7e18a735f..fe31dc099 100644 --- a/OpenCL/inc_hash_md5.cl +++ b/OpenCL/inc_hash_md5.cl @@ -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; diff --git a/OpenCL/inc_hash_md5.h b/OpenCL/inc_hash_md5.h index 8b37d6969..e16dda780 100644 --- a/OpenCL/inc_hash_md5.h +++ b/OpenCL/inc_hash_md5.h @@ -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); diff --git a/OpenCL/inc_pkcs1_common.cl b/OpenCL/inc_pkcs1_common.cl new file mode 100644 index 000000000..bd7a30a03 --- /dev/null +++ b/OpenCL/inc_pkcs1_common.cl @@ -0,0 +1,190 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#include "inc_types.h" +#include "inc_vendor.h" +#include "inc_pkcs1_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_PKCS1_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_PKCS1_MD_LENGTH / 4; i++) + { + md_buf[i] = md_ctx.h[i]; + } + + md5_init (&md_ctx); + md5_update (&md_ctx, md_buf, HC_PKCS1_MD_LENGTH); + md5_update (&md_ctx, pw, pw_len); + md5_update (&md_ctx, salt_buf, HC_PKCS1_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_PKCS1_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_PKCS1_MD_LENGTH / 4; i++) + { + md_buf[i] = md_ctx.h[i]; + } + + md5_init_vector (&md_ctx); + md5_update_vector (&md_ctx, md_buf, HC_PKCS1_MD_LENGTH); + md5_update_vector (&md_ctx, pw, pw_len); + md5_update_vector_from_scalar (&md_ctx, salt_buf, HC_PKCS1_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 pkcs1_t *esalt) +{ + #ifdef _unroll + #pragma unroll + #endif + for (u32 i = 0; i < HC_PKCS1_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]; + } +} diff --git a/OpenCL/inc_pkcs1_common.h b/OpenCL/inc_pkcs1_common.h new file mode 100644 index 000000000..aaae48fa0 --- /dev/null +++ b/OpenCL/inc_pkcs1_common.h @@ -0,0 +1,35 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#ifndef _INC_PKCS1_COMMON_H +#define _INC_PKCS1_COMMON_H + +#define HC_PKCS1_SALT_LENGTH 8 +#define HC_PKCS1_MD_LENGTH 16 + +#define HC_PKCS1_MAX_BLOCK_SIZE 16 +#define HC_PKCS1_MAX_KEY_LENGTH 32 +#define HC_PKCS1_MAX_DATA_LENGTH 12288 + +typedef struct pkcs1 +{ + void *chosen_cipher; + u32 salt_iv[HC_PKCS1_MAX_BLOCK_SIZE / 4]; + + u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + size_t data_len; +} pkcs1_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 pkcs1_t *esalt); + +#endif // _INC_PKCS1_COMMON_H diff --git a/OpenCL/m24111_a0-pure.cl b/OpenCL/m24111_a0-pure.cl new file mode 100644 index 000000000..c37e2c70f --- /dev/null +++ b/OpenCL/m24111_a0-pure.cl @@ -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_pkcs1_common.cl" +#endif // KERNEL_STATIC + +KERNEL_FQ void m24111_sxx (KERN_ATTR_RULES_ESALT (pkcs1_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_PKCS1_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_PKCS1_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_PKCS1_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); + } + } + } +} diff --git a/OpenCL/m24111_a1-pure.cl b/OpenCL/m24111_a1-pure.cl new file mode 100644 index 000000000..213ad1f38 --- /dev/null +++ b/OpenCL/m24111_a1-pure.cl @@ -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_pkcs1_common.cl" +#endif // KERNEL_STATIC + +KERNEL_FQ void m24111_sxx (KERN_ATTR_ESALT (pkcs1_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_PKCS1_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_PKCS1_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_PKCS1_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); + } + } + } +} diff --git a/OpenCL/m24111_a3-pure.cl b/OpenCL/m24111_a3-pure.cl new file mode 100644 index 000000000..009408c72 --- /dev/null +++ b/OpenCL/m24111_a3-pure.cl @@ -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_pkcs1_common.cl" +#endif // KERNEL_STATIC + +KERNEL_FQ void m24111_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_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_PKCS1_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_PKCS1_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_PKCS1_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); + } + } + } + } +} diff --git a/OpenCL/m24121_a0-pure.cl b/OpenCL/m24121_a0-pure.cl new file mode 100644 index 000000000..f066f3fcf --- /dev/null +++ b/OpenCL/m24121_a0-pure.cl @@ -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_pkcs1_common.cl" +#endif // KERNEL_STATIC + +KERNEL_FQ void m24121_sxx (KERN_ATTR_RULES_ESALT (pkcs1_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_PKCS1_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_PKCS1_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_PKCS1_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); + } + } + } +} diff --git a/OpenCL/m24121_a1-pure.cl b/OpenCL/m24121_a1-pure.cl new file mode 100644 index 000000000..7425468d0 --- /dev/null +++ b/OpenCL/m24121_a1-pure.cl @@ -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_pkcs1_common.cl" +#endif // KERNEL_STATIC + +KERNEL_FQ void m24121_sxx (KERN_ATTR_ESALT (pkcs1_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_PKCS1_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_PKCS1_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_PKCS1_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); + } + } + } +} diff --git a/OpenCL/m24121_a3-pure.cl b/OpenCL/m24121_a3-pure.cl new file mode 100644 index 000000000..096d62584 --- /dev/null +++ b/OpenCL/m24121_a3-pure.cl @@ -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_pkcs1_common.cl" +#endif // KERNEL_STATIC + +KERNEL_FQ void m24121_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_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_PKCS1_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_PKCS1_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_PKCS1_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); + } + } + } + } +} diff --git a/OpenCL/m24131_a0-pure.cl b/OpenCL/m24131_a0-pure.cl new file mode 100644 index 000000000..faecb7269 --- /dev/null +++ b/OpenCL/m24131_a0-pure.cl @@ -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_pkcs1_common.cl" +#endif // KERNEL_STATIC + +KERNEL_FQ void m24131_sxx (KERN_ATTR_RULES_ESALT (pkcs1_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_PKCS1_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_PKCS1_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_PKCS1_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); + } + } + } +} diff --git a/OpenCL/m24131_a1-pure.cl b/OpenCL/m24131_a1-pure.cl new file mode 100644 index 000000000..a535870c3 --- /dev/null +++ b/OpenCL/m24131_a1-pure.cl @@ -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_pkcs1_common.cl" +#endif // KERNEL_STATIC + +KERNEL_FQ void m24131_sxx (KERN_ATTR_ESALT (pkcs1_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_PKCS1_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_PKCS1_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_PKCS1_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); + } + } + } +} diff --git a/OpenCL/m24131_a3-pure.cl b/OpenCL/m24131_a3-pure.cl new file mode 100644 index 000000000..02a535a54 --- /dev/null +++ b/OpenCL/m24131_a3-pure.cl @@ -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_pkcs1_common.cl" +#endif // KERNEL_STATIC + +KERNEL_FQ void m24131_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_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_PKCS1_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_PKCS1_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); + } + } + } + } +} diff --git a/OpenCL/m24151_a0-pure.cl b/OpenCL/m24151_a0-pure.cl new file mode 100644 index 000000000..ef455a956 --- /dev/null +++ b/OpenCL/m24151_a0-pure.cl @@ -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_pkcs1_common.cl" +#endif // KERNEL_STATIC + +KERNEL_FQ void m24151_sxx (KERN_ATTR_RULES_ESALT (pkcs1_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_PKCS1_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_PKCS1_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_PKCS1_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); + } + } + } +} diff --git a/OpenCL/m24151_a1-pure.cl b/OpenCL/m24151_a1-pure.cl new file mode 100644 index 000000000..712536350 --- /dev/null +++ b/OpenCL/m24151_a1-pure.cl @@ -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_pkcs1_common.cl" +#endif // KERNEL_STATIC + +KERNEL_FQ void m24151_sxx (KERN_ATTR_ESALT (pkcs1_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_PKCS1_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_PKCS1_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_PKCS1_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); + } + } + } +} diff --git a/OpenCL/m24151_a3-pure.cl b/OpenCL/m24151_a3-pure.cl new file mode 100644 index 000000000..791ec86d5 --- /dev/null +++ b/OpenCL/m24151_a3-pure.cl @@ -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_pkcs1_common.cl" +#endif // KERNEL_STATIC + +KERNEL_FQ void m24151_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_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_PKCS1_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_PKCS1_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_PKCS1_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); + } + } + } + } +} diff --git a/docs/changes.txt b/docs/changes.txt index c4e7c8c4a..cb0de7412 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -70,6 +70,7 @@ - Added hash-mode: Web2py pbkdf2-sha512 - Added hash-mode: WPA-PBKDF2-PMKID+EAPOL - Added hash-mode: WPA-PMK-PMKID+EAPOL +- Added hash-mode: PKCS#1 key ## ## Bugs diff --git a/docs/readme.txt b/docs/readme.txt index 9f545eb3a..8c8febbd7 100644 --- a/docs/readme.txt +++ b/docs/readme.txt @@ -322,6 +322,7 @@ 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 diff --git a/src/modules/module_24100.c b/src/modules/module_24100.c new file mode 100644 index 000000000..db478998c --- /dev/null +++ b/src/modules/module_24100.c @@ -0,0 +1,512 @@ +/** + * 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_PKCS1_SALT_LENGTH 8 +#define HC_PKCS1_MAX_BLOCK_SIZE 16 +#define HC_PKCS1_MAX_KEY_LENGTH 32 +#define HC_PKCS1_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_PKCS1_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 = "PKCS#1 key"; +static const u64 KERN_TYPE = 24100; // this gets overwritten later instead of in benchmark +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; // ST_HASH_24100 multi-hash-mode algorithm, unlikely to match self-test hash settings + +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 kern_type_pkcs1 +{ + KERN_TYPE_PKCS1_3DES_CBC = 24111, + KERN_TYPE_PKCS1_DES_CBC = 24121, + KERN_TYPE_PKCS1_AES128_CBC = 24131, + KERN_TYPE_PKCS1_AES192_CBC = 24141, + KERN_TYPE_PKCS1_AES256_CBC = 24151, +} kern_type_pkcs1_t; + +typedef enum hc_pkcs1_cipher_type +{ + HC_PKCS1_CIPHER_TYPE_3DES = 1, + HC_PKCS1_CIPHER_TYPE_DES = 2, + HC_PKCS1_CIPHER_TYPE_AES128 = 3, + HC_PKCS1_CIPHER_TYPE_AES192 = 4, + HC_PKCS1_CIPHER_TYPE_AES256 = 5, +} hc_pkcs1_cipher_type_t; + +typedef enum hc_pkcs1_cipher_mode +{ + HC_PKCS1_CIPHER_MODE_CBC = 1, +} hc_pkcs1_cipher_mode_t; + +typedef struct pkcs1_cipher +{ + char *name; + + u32 block_size; + u32 key_length; + u32 cipher_type; + u32 cipher_mode; +} hc_pkcs1_cipher_t; + +static hc_pkcs1_cipher_t pkcs1_ciphers[] = { + {"des-ede3-cbc", 8, 24, HC_PKCS1_CIPHER_TYPE_3DES, HC_PKCS1_CIPHER_MODE_CBC}, + {"des-cbc", 8, 8, HC_PKCS1_CIPHER_TYPE_DES, HC_PKCS1_CIPHER_MODE_CBC}, + {"aes-128-cbc", 16, 16, HC_PKCS1_CIPHER_TYPE_AES128, HC_PKCS1_CIPHER_MODE_CBC}, + {"aes-192-cbc", 16, 24, HC_PKCS1_CIPHER_TYPE_AES192, HC_PKCS1_CIPHER_MODE_CBC}, + {"aes-256-cbc", 16, 32, HC_PKCS1_CIPHER_TYPE_AES256, HC_PKCS1_CIPHER_MODE_CBC}, + {NULL, 0, 0, 0, 0} +}; + +typedef struct pkcs1 +{ + hc_pkcs1_cipher_t *chosen_cipher; + + u32 salt_iv[HC_PKCS1_MAX_BLOCK_SIZE / 4]; + + u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + size_t data_len; +} pkcs1_t; + +typedef struct pkcs1_tmp +{ + u32 key[HC_PKCS1_MAX_KEY_LENGTH / 4]; +} pkcs1_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 (pkcs1_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_PKCS1_MAX_BLOCK_SIZE) + { + return PARSER_SALT_LENGTH; + } + } + else if (line[1] == '\0') + { + if (salty < HC_PKCS1_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_PKCS1_MAX_CIPHER_NAME_LENGTH) + { + return PARSER_CIPHER; + } + } + } + + return PARSER_SALT_VALUE; +} + +static int parse_pkcs1_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_PKCS1_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) +{ + pkcs1_t *pkcs1 = (pkcs1_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_PKCS1_MAX_CIPHER_NAME_LENGTH] = { 0 }; + u8 saltbytes[MAX(HC_PKCS1_SALT_LENGTH, HC_PKCS1_MAX_BLOCK_SIZE)]; + int err; + + if ((err = parse_pkcs1_key_data ((char *) filebuf, cipher_name, saltbytes, (u8 *) pkcs1->data, &pkcs1->data_len)) < 0) + { + hcfree (filebuf); + + return err; + } + + u32 *saltwords = (u32 *) saltbytes; + + for (u32 i = 0; i < HC_PKCS1_SALT_LENGTH / 4; i++) + { + pkcs1->salt_iv[i] = saltwords[i]; + } + + hc_pkcs1_cipher_t *candidate_cipher = pkcs1_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_PKCS1_MAX_BLOCK_SIZE) + { + hcfree (filebuf); + + return PARSER_BLOCK_SIZE; + } + + if (pkcs1->data_len % chosen_cipher->block_size) + { + hcfree (filebuf); + + return PARSER_HASH_LENGTH; + } + + if (chosen_cipher->key_length > HC_PKCS1_MAX_KEY_LENGTH) + { + // Nope nope nopety nope + return PARSER_KEY_SIZE; + } + + pkcs1->chosen_cipher = chosen_cipher; + + memcpy (salt->salt_buf, pkcs1->salt_iv, MIN (HC_PKCS1_SALT_LENGTH, 64 * 4)); + salt->salt_iter = 1; + + return 1; +} + +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 pkcs1_t *pkcs1 = (const pkcs1_t *) esalt_buf; + + u64 kern_type = 24100; + + kern_type += pkcs1->chosen_cipher->cipher_type * 10; + kern_type += pkcs1->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 (pkcs1_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_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_salt = MODULE_DEFAULT; + 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; +} From cff3fbda9bed1494eef338308ef8cb86dc2ebd26 Mon Sep 17 00:00:00 2001 From: Matt Palmer Date: Wed, 27 May 2020 20:30:00 +1000 Subject: [PATCH 4/5] Provide benchmark esalt structure --- src/modules/module_24100.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/modules/module_24100.c b/src/modules/module_24100.c index db478998c..4c222b528 100644 --- a/src/modules/module_24100.c +++ b/src/modules/module_24100.c @@ -27,14 +27,14 @@ 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 = "PKCS#1 key"; -static const u64 KERN_TYPE = 24100; // this gets overwritten later instead of in benchmark +static const char *HASH_NAME = "PEM encrypted private key"; +static const u64 KERN_TYPE = 24111; // 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; // ST_HASH_24100 multi-hash-mode algorithm, unlikely to match self-test hash settings +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; } @@ -410,6 +410,27 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYBE_UNUS 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) +{ + pkcs1_t *pkcs1 = (pkcs1_t *) hcmalloc (sizeof (pkcs1_t)); + + pkcs1->chosen_cipher = &pkcs1_ciphers[0]; + hex_decode ((u8 *) "7CC48DB27D461D30", 16, (u8 *) pkcs1->salt_iv); + pkcs1->data_len = base64_decode (base64_to_int, (u8 *) "ysVmp6tkcZXRqHyy3YMk5zd4bsT9D97kFcDIKkD2g5o/OBgc0pGQ/iSwJm/V+A2IkwgQlwvLW1OfKkAWdjcSFNKhmiWApVQB", 96, (u8 *) pkcs1->data); + + return pkcs1; +} + +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 pkcs1_t *pkcs1 = (const pkcs1_t *) esalt_buf; @@ -444,10 +465,10 @@ void module_init (module_ctx_t * module_ctx) module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; module_ctx->module_attack_exec = module_attack_exec; - module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + 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_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; From 70441138ed00579e1780e1bdc8f530fe68d9432b Mon Sep 17 00:00:00 2001 From: Matt Palmer Date: Mon, 8 Jun 2020 13:35:56 +1000 Subject: [PATCH 5/5] Renumber PEM module to 22900 Also took the liberty of removing old PKCS1 naming everywhere, so as to prevent future confusion. --- ...{inc_pkcs1_common.cl => inc_pem_common.cl} | 22 +-- OpenCL/inc_pem_common.h | 35 +++++ OpenCL/inc_pkcs1_common.h | 35 ----- .../{m24111_a0-pure.cl => m22911_a0-pure.cl} | 10 +- .../{m24111_a1-pure.cl => m22911_a1-pure.cl} | 10 +- .../{m24111_a3-pure.cl => m22911_a3-pure.cl} | 10 +- .../{m24121_a0-pure.cl => m22921_a0-pure.cl} | 10 +- .../{m24121_a1-pure.cl => m22921_a1-pure.cl} | 10 +- .../{m24121_a3-pure.cl => m22921_a3-pure.cl} | 10 +- .../{m24131_a0-pure.cl => m22931_a0-pure.cl} | 10 +- .../{m24131_a1-pure.cl => m22931_a1-pure.cl} | 10 +- .../{m24131_a3-pure.cl => m22931_a3-pure.cl} | 8 +- .../{m24151_a0-pure.cl => m22951_a0-pure.cl} | 10 +- .../{m24151_a1-pure.cl => m22951_a1-pure.cl} | 10 +- .../{m24151_a3-pure.cl => m22951_a3-pure.cl} | 10 +- .../{module_24100.c => module_22900.c} | 129 ++++++++---------- 16 files changed, 165 insertions(+), 174 deletions(-) rename OpenCL/{inc_pkcs1_common.cl => inc_pem_common.cl} (84%) create mode 100644 OpenCL/inc_pem_common.h delete mode 100644 OpenCL/inc_pkcs1_common.h rename OpenCL/{m24111_a0-pure.cl => m22911_a0-pure.cl} (96%) rename OpenCL/{m24111_a1-pure.cl => m22911_a1-pure.cl} (96%) rename OpenCL/{m24111_a3-pure.cl => m22911_a3-pure.cl} (96%) rename OpenCL/{m24121_a0-pure.cl => m22921_a0-pure.cl} (95%) rename OpenCL/{m24121_a1-pure.cl => m22921_a1-pure.cl} (96%) rename OpenCL/{m24121_a3-pure.cl => m22921_a3-pure.cl} (96%) rename OpenCL/{m24131_a0-pure.cl => m22931_a0-pure.cl} (96%) rename OpenCL/{m24131_a1-pure.cl => m22931_a1-pure.cl} (96%) rename OpenCL/{m24131_a3-pure.cl => m22931_a3-pure.cl} (97%) rename OpenCL/{m24151_a0-pure.cl => m22951_a0-pure.cl} (96%) rename OpenCL/{m24151_a1-pure.cl => m22951_a1-pure.cl} (96%) rename OpenCL/{m24151_a3-pure.cl => m22951_a3-pure.cl} (96%) rename src/modules/{module_24100.c => module_22900.c} (82%) diff --git a/OpenCL/inc_pkcs1_common.cl b/OpenCL/inc_pem_common.cl similarity index 84% rename from OpenCL/inc_pkcs1_common.cl rename to OpenCL/inc_pem_common.cl index bd7a30a03..9266b62cf 100644 --- a/OpenCL/inc_pkcs1_common.cl +++ b/OpenCL/inc_pem_common.cl @@ -5,7 +5,7 @@ #include "inc_types.h" #include "inc_vendor.h" -#include "inc_pkcs1_common.h" +#include "inc_pem_common.h" #ifdef KERNEL_STATIC #include "inc_hash_md5.cl" @@ -28,7 +28,7 @@ DECLSPEC void generate_key (u32 *salt_buf, u32 *pw, size_t pw_len, u32 *key) md5_init (&md_ctx); md5_update (&md_ctx, pw, pw_len); - md5_update (&md_ctx, salt_buf, HC_PKCS1_SALT_LENGTH); + md5_update (&md_ctx, salt_buf, HC_PEM_SALT_LENGTH); md5_final (&md_ctx); key[0] = md_ctx.h[0]; @@ -50,15 +50,15 @@ DECLSPEC void generate_key (u32 *salt_buf, u32 *pw, size_t pw_len, u32 *key) #ifdef _unroll #pragma unroll #endif - for (u32 i = 0; i < HC_PKCS1_MD_LENGTH / 4; i++) + 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_PKCS1_MD_LENGTH); + md5_update (&md_ctx, md_buf, HC_PEM_MD_LENGTH); md5_update (&md_ctx, pw, pw_len); - md5_update (&md_ctx, salt_buf, HC_PKCS1_SALT_LENGTH); + md5_update (&md_ctx, salt_buf, HC_PEM_SALT_LENGTH); md5_final (&md_ctx); key[4] = md_ctx.h[0]; @@ -107,7 +107,7 @@ DECLSPEC void generate_key_vector (u32 *salt_buf, u32x *pw, size_t pw_len, u32x md5_init_vector (&md_ctx); md5_update_vector (&md_ctx, pw, pw_len); - md5_update_vector_from_scalar (&md_ctx, salt_buf, HC_PKCS1_SALT_LENGTH); + md5_update_vector_from_scalar (&md_ctx, salt_buf, HC_PEM_SALT_LENGTH); md5_final_vector (&md_ctx); key[0] = md_ctx.h[0]; @@ -129,15 +129,15 @@ DECLSPEC void generate_key_vector (u32 *salt_buf, u32x *pw, size_t pw_len, u32x #ifdef _unroll #pragma unroll #endif - for (u32 i = 0; i < HC_PKCS1_MD_LENGTH / 4; i++) + 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_PKCS1_MD_LENGTH); + 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_PKCS1_SALT_LENGTH); + md5_update_vector_from_scalar (&md_ctx, salt_buf, HC_PEM_SALT_LENGTH); md5_final_vector (&md_ctx); key[4] = md_ctx.h[0]; @@ -169,12 +169,12 @@ DECLSPEC void generate_key_vector (u32 *salt_buf, u32x *pw, size_t pw_len, u32x #endif // DEBUG } -DECLSPEC void prep_buffers(u32 *salt_buf, u32 *salt_iv, u32 *first_block, PSEUDO_SHM_TYPE u32 *data, GLOBAL_AS const pkcs1_t *esalt) +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_PKCS1_SALT_LENGTH / 4; i++) + for (u32 i = 0; i < HC_PEM_SALT_LENGTH / 4; i++) { salt_buf[i] = esalt->salt_iv[i]; } diff --git a/OpenCL/inc_pem_common.h b/OpenCL/inc_pem_common.h new file mode 100644 index 000000000..ddd189412 --- /dev/null +++ b/OpenCL/inc_pem_common.h @@ -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 diff --git a/OpenCL/inc_pkcs1_common.h b/OpenCL/inc_pkcs1_common.h deleted file mode 100644 index aaae48fa0..000000000 --- a/OpenCL/inc_pkcs1_common.h +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Author......: See docs/credits.txt - * License.....: MIT - */ - -#ifndef _INC_PKCS1_COMMON_H -#define _INC_PKCS1_COMMON_H - -#define HC_PKCS1_SALT_LENGTH 8 -#define HC_PKCS1_MD_LENGTH 16 - -#define HC_PKCS1_MAX_BLOCK_SIZE 16 -#define HC_PKCS1_MAX_KEY_LENGTH 32 -#define HC_PKCS1_MAX_DATA_LENGTH 12288 - -typedef struct pkcs1 -{ - void *chosen_cipher; - u32 salt_iv[HC_PKCS1_MAX_BLOCK_SIZE / 4]; - - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; - size_t data_len; -} pkcs1_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 pkcs1_t *esalt); - -#endif // _INC_PKCS1_COMMON_H diff --git a/OpenCL/m24111_a0-pure.cl b/OpenCL/m22911_a0-pure.cl similarity index 96% rename from OpenCL/m24111_a0-pure.cl rename to OpenCL/m22911_a0-pure.cl index c37e2c70f..d084296e4 100644 --- a/OpenCL/m24111_a0-pure.cl +++ b/OpenCL/m22911_a0-pure.cl @@ -13,10 +13,10 @@ #include "inc_common.cl" #include "inc_rp.cl" #include "inc_cipher_des.cl" -#include "inc_pkcs1_common.cl" +#include "inc_pem_common.cl" #endif // KERNEL_STATIC -KERNEL_FQ void m24111_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) +KERNEL_FQ void m22911_sxx (KERN_ATTR_RULES_ESALT (pem_t)) { /** * base @@ -33,7 +33,7 @@ KERNEL_FQ void m24111_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) LOCAL_VK u32 data_len; data_len = esalt_bufs[digests_offset].data_len; - LOCAL_VK u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; for (u32 i = lid; i <= data_len / 4; i += lsz) { @@ -69,7 +69,7 @@ KERNEL_FQ void m24111_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) #else const size_t data_len = esalt_bufs[digests_offset].data_len; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; #ifdef _unroll #pragma unroll @@ -97,7 +97,7 @@ KERNEL_FQ void m24111_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - u32 key[HC_PKCS1_MAX_KEY_LENGTH / 4]; + u32 key[HC_PEM_MAX_KEY_LENGTH / 4]; pw_t tmp = PASTE_PW; diff --git a/OpenCL/m24111_a1-pure.cl b/OpenCL/m22911_a1-pure.cl similarity index 96% rename from OpenCL/m24111_a1-pure.cl rename to OpenCL/m22911_a1-pure.cl index 213ad1f38..e611b1ebc 100644 --- a/OpenCL/m24111_a1-pure.cl +++ b/OpenCL/m22911_a1-pure.cl @@ -12,10 +12,10 @@ #include "inc_platform.cl" #include "inc_common.cl" #include "inc_cipher_des.cl" -#include "inc_pkcs1_common.cl" +#include "inc_pem_common.cl" #endif // KERNEL_STATIC -KERNEL_FQ void m24111_sxx (KERN_ATTR_ESALT (pkcs1_t)) +KERNEL_FQ void m22911_sxx (KERN_ATTR_ESALT (pem_t)) { /** * base @@ -32,7 +32,7 @@ KERNEL_FQ void m24111_sxx (KERN_ATTR_ESALT (pkcs1_t)) LOCAL_VK u32 data_len; data_len = esalt_bufs[digests_offset].data_len; - LOCAL_VK u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; for (u32 i = lid; i <= data_len / 4; i += lsz) { @@ -68,7 +68,7 @@ KERNEL_FQ void m24111_sxx (KERN_ATTR_ESALT (pkcs1_t)) #else const size_t data_len = esalt_bufs[digests_offset].data_len; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; #ifdef _unroll #pragma unroll @@ -124,7 +124,7 @@ KERNEL_FQ void m24111_sxx (KERN_ATTR_ESALT (pkcs1_t)) c[i] |= w[i]; } - u32 key[HC_PKCS1_MAX_KEY_LENGTH / 4]; + u32 key[HC_PEM_MAX_KEY_LENGTH / 4]; generate_key (salt_buf, c, pw_len + comb_len, key); diff --git a/OpenCL/m24111_a3-pure.cl b/OpenCL/m22911_a3-pure.cl similarity index 96% rename from OpenCL/m24111_a3-pure.cl rename to OpenCL/m22911_a3-pure.cl index 009408c72..585c96b15 100644 --- a/OpenCL/m24111_a3-pure.cl +++ b/OpenCL/m22911_a3-pure.cl @@ -15,10 +15,10 @@ #include "inc_common.cl" #include "inc_simd.cl" #include "inc_cipher_des.cl" -#include "inc_pkcs1_common.cl" +#include "inc_pem_common.cl" #endif // KERNEL_STATIC -KERNEL_FQ void m24111_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) +KERNEL_FQ void m22911_sxx (KERN_ATTR_VECTOR_ESALT (pem_t)) { /** * base @@ -35,7 +35,7 @@ KERNEL_FQ void m24111_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) LOCAL_VK u32 data_len; data_len = esalt_bufs[digests_offset].data_len; - LOCAL_VK u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; for (u32 i = lid; i <= data_len / 4; i += lsz) { @@ -71,7 +71,7 @@ KERNEL_FQ void m24111_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) #else const size_t data_len = esalt_bufs[digests_offset].data_len; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; #ifdef _unroll #pragma unroll @@ -113,7 +113,7 @@ KERNEL_FQ void m24111_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) w[0] = w0; - u32x key[HC_PKCS1_MAX_KEY_LENGTH / 4]; + u32x key[HC_PEM_MAX_KEY_LENGTH / 4]; generate_key_vector (salt_buf, w, pw_len, key); diff --git a/OpenCL/m24121_a0-pure.cl b/OpenCL/m22921_a0-pure.cl similarity index 95% rename from OpenCL/m24121_a0-pure.cl rename to OpenCL/m22921_a0-pure.cl index f066f3fcf..3ded312d8 100644 --- a/OpenCL/m24121_a0-pure.cl +++ b/OpenCL/m22921_a0-pure.cl @@ -13,10 +13,10 @@ #include "inc_common.cl" #include "inc_rp.cl" #include "inc_cipher_des.cl" -#include "inc_pkcs1_common.cl" +#include "inc_pem_common.cl" #endif // KERNEL_STATIC -KERNEL_FQ void m24121_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) +KERNEL_FQ void m22921_sxx (KERN_ATTR_RULES_ESALT (pem_t)) { /** * base @@ -33,7 +33,7 @@ KERNEL_FQ void m24121_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) LOCAL_VK u32 data_len; data_len = esalt_bufs[digests_offset].data_len; - LOCAL_VK u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; for (u32 i = lid; i <= data_len / 4; i += lsz) { @@ -69,7 +69,7 @@ KERNEL_FQ void m24121_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) #else const size_t data_len = esalt_bufs[digests_offset].data_len; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; #ifdef _unroll #pragma unroll @@ -97,7 +97,7 @@ KERNEL_FQ void m24121_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - u32 key[HC_PKCS1_MAX_KEY_LENGTH / 4]; + u32 key[HC_PEM_MAX_KEY_LENGTH / 4]; pw_t tmp = PASTE_PW; diff --git a/OpenCL/m24121_a1-pure.cl b/OpenCL/m22921_a1-pure.cl similarity index 96% rename from OpenCL/m24121_a1-pure.cl rename to OpenCL/m22921_a1-pure.cl index 7425468d0..ca5358595 100644 --- a/OpenCL/m24121_a1-pure.cl +++ b/OpenCL/m22921_a1-pure.cl @@ -12,10 +12,10 @@ #include "inc_platform.cl" #include "inc_common.cl" #include "inc_cipher_des.cl" -#include "inc_pkcs1_common.cl" +#include "inc_pem_common.cl" #endif // KERNEL_STATIC -KERNEL_FQ void m24121_sxx (KERN_ATTR_ESALT (pkcs1_t)) +KERNEL_FQ void m22921_sxx (KERN_ATTR_ESALT (pem_t)) { /** * base @@ -32,7 +32,7 @@ KERNEL_FQ void m24121_sxx (KERN_ATTR_ESALT (pkcs1_t)) LOCAL_VK u32 data_len; data_len = esalt_bufs[digests_offset].data_len; - LOCAL_VK u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; for (u32 i = lid; i <= data_len / 4; i += lsz) { @@ -68,7 +68,7 @@ KERNEL_FQ void m24121_sxx (KERN_ATTR_ESALT (pkcs1_t)) #else const size_t data_len = esalt_bufs[digests_offset].data_len; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; #ifdef _unroll #pragma unroll @@ -124,7 +124,7 @@ KERNEL_FQ void m24121_sxx (KERN_ATTR_ESALT (pkcs1_t)) c[i] |= w[i]; } - u32 key[HC_PKCS1_MAX_KEY_LENGTH / 4]; + u32 key[HC_PEM_MAX_KEY_LENGTH / 4]; generate_key (salt_buf, c, pw_len + comb_len, key); diff --git a/OpenCL/m24121_a3-pure.cl b/OpenCL/m22921_a3-pure.cl similarity index 96% rename from OpenCL/m24121_a3-pure.cl rename to OpenCL/m22921_a3-pure.cl index 096d62584..85b81d7e9 100644 --- a/OpenCL/m24121_a3-pure.cl +++ b/OpenCL/m22921_a3-pure.cl @@ -15,10 +15,10 @@ #include "inc_common.cl" #include "inc_simd.cl" #include "inc_cipher_des.cl" -#include "inc_pkcs1_common.cl" +#include "inc_pem_common.cl" #endif // KERNEL_STATIC -KERNEL_FQ void m24121_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) +KERNEL_FQ void m22921_sxx (KERN_ATTR_VECTOR_ESALT (pem_t)) { /** * base @@ -35,7 +35,7 @@ KERNEL_FQ void m24121_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) LOCAL_VK u32 data_len; data_len = esalt_bufs[digests_offset].data_len; - LOCAL_VK u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; for (u32 i = lid; i <= data_len / 4; i += lsz) { @@ -71,7 +71,7 @@ KERNEL_FQ void m24121_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) #else const size_t data_len = esalt_bufs[digests_offset].data_len; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; #ifdef _unroll #pragma unroll @@ -113,7 +113,7 @@ KERNEL_FQ void m24121_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) w[0] = w0; - u32x key[HC_PKCS1_MAX_KEY_LENGTH / 4]; + u32x key[HC_PEM_MAX_KEY_LENGTH / 4]; generate_key_vector (salt_buf, w, pw_len, key); diff --git a/OpenCL/m24131_a0-pure.cl b/OpenCL/m22931_a0-pure.cl similarity index 96% rename from OpenCL/m24131_a0-pure.cl rename to OpenCL/m22931_a0-pure.cl index faecb7269..816e82d67 100644 --- a/OpenCL/m24131_a0-pure.cl +++ b/OpenCL/m22931_a0-pure.cl @@ -13,10 +13,10 @@ #include "inc_common.cl" #include "inc_rp.cl" #include "inc_cipher_aes.cl" -#include "inc_pkcs1_common.cl" +#include "inc_pem_common.cl" #endif // KERNEL_STATIC -KERNEL_FQ void m24131_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) +KERNEL_FQ void m22931_sxx (KERN_ATTR_RULES_ESALT (pem_t)) { /** * base @@ -33,7 +33,7 @@ KERNEL_FQ void m24131_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) LOCAL_VK u32 data_len; data_len = esalt_bufs[digests_offset].data_len; - LOCAL_VK u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; for (u32 i = lid; i <= data_len / 4; i += lsz) { @@ -72,7 +72,7 @@ KERNEL_FQ void m24131_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) #else const size_t data_len = esalt_bufs[digests_offset].data_len; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; #ifdef _unroll #pragma unroll @@ -109,7 +109,7 @@ KERNEL_FQ void m24131_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - u32 key[HC_PKCS1_MAX_KEY_LENGTH / 4]; + u32 key[HC_PEM_MAX_KEY_LENGTH / 4]; pw_t tmp = PASTE_PW; diff --git a/OpenCL/m24131_a1-pure.cl b/OpenCL/m22931_a1-pure.cl similarity index 96% rename from OpenCL/m24131_a1-pure.cl rename to OpenCL/m22931_a1-pure.cl index a535870c3..9d0072da3 100644 --- a/OpenCL/m24131_a1-pure.cl +++ b/OpenCL/m22931_a1-pure.cl @@ -12,10 +12,10 @@ #include "inc_platform.cl" #include "inc_common.cl" #include "inc_cipher_aes.cl" -#include "inc_pkcs1_common.cl" +#include "inc_pem_common.cl" #endif // KERNEL_STATIC -KERNEL_FQ void m24131_sxx (KERN_ATTR_ESALT (pkcs1_t)) +KERNEL_FQ void m22931_sxx (KERN_ATTR_ESALT (pem_t)) { /** * base @@ -32,7 +32,7 @@ KERNEL_FQ void m24131_sxx (KERN_ATTR_ESALT (pkcs1_t)) LOCAL_VK u32 data_len; data_len = esalt_bufs[digests_offset].data_len; - LOCAL_VK u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; for (u32 i = lid; i <= data_len / 4; i += lsz) { @@ -71,7 +71,7 @@ KERNEL_FQ void m24131_sxx (KERN_ATTR_ESALT (pkcs1_t)) #else const size_t data_len = esalt_bufs[digests_offset].data_len; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; #ifdef _unroll #pragma unroll @@ -136,7 +136,7 @@ KERNEL_FQ void m24131_sxx (KERN_ATTR_ESALT (pkcs1_t)) c[i] |= w[i]; } - u32 key[HC_PKCS1_MAX_KEY_LENGTH / 4]; + u32 key[HC_PEM_MAX_KEY_LENGTH / 4]; generate_key (salt_buf, c, pw_len + comb_len, key); diff --git a/OpenCL/m24131_a3-pure.cl b/OpenCL/m22931_a3-pure.cl similarity index 97% rename from OpenCL/m24131_a3-pure.cl rename to OpenCL/m22931_a3-pure.cl index 02a535a54..fd9e4c438 100644 --- a/OpenCL/m24131_a3-pure.cl +++ b/OpenCL/m22931_a3-pure.cl @@ -15,10 +15,10 @@ #include "inc_common.cl" #include "inc_simd.cl" #include "inc_cipher_aes.cl" -#include "inc_pkcs1_common.cl" +#include "inc_pem_common.cl" #endif // KERNEL_STATIC -KERNEL_FQ void m24131_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) +KERNEL_FQ void m22931_sxx (KERN_ATTR_VECTOR_ESALT (pem_t)) { /** * base @@ -35,7 +35,7 @@ KERNEL_FQ void m24131_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) LOCAL_VK u32 data_len; data_len = esalt_bufs[digests_offset].data_len; - LOCAL_VK u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; for (u32 i = lid; i <= data_len / 4; i += lsz) { @@ -74,7 +74,7 @@ KERNEL_FQ void m24131_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) #else const size_t data_len = esalt_bufs[digests_offset].data_len; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; #ifdef _unroll #pragma unroll diff --git a/OpenCL/m24151_a0-pure.cl b/OpenCL/m22951_a0-pure.cl similarity index 96% rename from OpenCL/m24151_a0-pure.cl rename to OpenCL/m22951_a0-pure.cl index ef455a956..3f53e4edb 100644 --- a/OpenCL/m24151_a0-pure.cl +++ b/OpenCL/m22951_a0-pure.cl @@ -13,10 +13,10 @@ #include "inc_common.cl" #include "inc_rp.cl" #include "inc_cipher_aes.cl" -#include "inc_pkcs1_common.cl" +#include "inc_pem_common.cl" #endif // KERNEL_STATIC -KERNEL_FQ void m24151_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) +KERNEL_FQ void m22951_sxx (KERN_ATTR_RULES_ESALT (pem_t)) { /** * base @@ -33,7 +33,7 @@ KERNEL_FQ void m24151_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) LOCAL_VK u32 data_len; data_len = esalt_bufs[digests_offset].data_len; - LOCAL_VK u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; for (u32 i = lid; i <= data_len / 4; i += lsz) { @@ -72,7 +72,7 @@ KERNEL_FQ void m24151_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) #else const size_t data_len = esalt_bufs[digests_offset].data_len; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; #ifdef _unroll #pragma unroll @@ -109,7 +109,7 @@ KERNEL_FQ void m24151_sxx (KERN_ATTR_RULES_ESALT (pkcs1_t)) for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - u32 key[HC_PKCS1_MAX_KEY_LENGTH / 4]; + u32 key[HC_PEM_MAX_KEY_LENGTH / 4]; pw_t tmp = PASTE_PW; diff --git a/OpenCL/m24151_a1-pure.cl b/OpenCL/m22951_a1-pure.cl similarity index 96% rename from OpenCL/m24151_a1-pure.cl rename to OpenCL/m22951_a1-pure.cl index 712536350..b3ded8b40 100644 --- a/OpenCL/m24151_a1-pure.cl +++ b/OpenCL/m22951_a1-pure.cl @@ -12,10 +12,10 @@ #include "inc_platform.cl" #include "inc_common.cl" #include "inc_cipher_aes.cl" -#include "inc_pkcs1_common.cl" +#include "inc_pem_common.cl" #endif // KERNEL_STATIC -KERNEL_FQ void m24151_sxx (KERN_ATTR_ESALT (pkcs1_t)) +KERNEL_FQ void m22951_sxx (KERN_ATTR_ESALT (pem_t)) { /** * base @@ -32,7 +32,7 @@ KERNEL_FQ void m24151_sxx (KERN_ATTR_ESALT (pkcs1_t)) LOCAL_VK u32 data_len; data_len = esalt_bufs[digests_offset].data_len; - LOCAL_VK u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; for (u32 i = lid; i <= data_len / 4; i += lsz) { @@ -71,7 +71,7 @@ KERNEL_FQ void m24151_sxx (KERN_ATTR_ESALT (pkcs1_t)) #else const size_t data_len = esalt_bufs[digests_offset].data_len; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; #ifdef _unroll #pragma unroll @@ -136,7 +136,7 @@ KERNEL_FQ void m24151_sxx (KERN_ATTR_ESALT (pkcs1_t)) c[i] |= w[i]; } - u32 key[HC_PKCS1_MAX_KEY_LENGTH / 4]; + u32 key[HC_PEM_MAX_KEY_LENGTH / 4]; generate_key (salt_buf, c, pw_len + comb_len, key); diff --git a/OpenCL/m24151_a3-pure.cl b/OpenCL/m22951_a3-pure.cl similarity index 96% rename from OpenCL/m24151_a3-pure.cl rename to OpenCL/m22951_a3-pure.cl index 791ec86d5..875f20333 100644 --- a/OpenCL/m24151_a3-pure.cl +++ b/OpenCL/m22951_a3-pure.cl @@ -15,10 +15,10 @@ #include "inc_common.cl" #include "inc_simd.cl" #include "inc_cipher_aes.cl" -#include "inc_pkcs1_common.cl" +#include "inc_pem_common.cl" #endif // KERNEL_STATIC -KERNEL_FQ void m24151_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) +KERNEL_FQ void m22951_sxx (KERN_ATTR_VECTOR_ESALT (pem_t)) { /** * base @@ -35,7 +35,7 @@ KERNEL_FQ void m24151_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) LOCAL_VK u32 data_len; data_len = esalt_bufs[digests_offset].data_len; - LOCAL_VK u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + LOCAL_VK u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; for (u32 i = lid; i <= data_len / 4; i += lsz) { @@ -74,7 +74,7 @@ KERNEL_FQ void m24151_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) #else const size_t data_len = esalt_bufs[digests_offset].data_len; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; #ifdef _unroll #pragma unroll @@ -125,7 +125,7 @@ KERNEL_FQ void m24151_sxx (KERN_ATTR_VECTOR_ESALT (pkcs1_t)) w[0] = w0; - u32x keys[HC_PKCS1_MAX_KEY_LENGTH / 4]; + u32x keys[HC_PEM_MAX_KEY_LENGTH / 4]; generate_key_vector (salt_buf, w, pw_len, keys); diff --git a/src/modules/module_24100.c b/src/modules/module_22900.c similarity index 82% rename from src/modules/module_24100.c rename to src/modules/module_22900.c index 4c222b528..349e8d582 100644 --- a/src/modules/module_24100.c +++ b/src/modules/module_22900.c @@ -11,14 +11,14 @@ #include "shared.h" #include "memory.h" -#define HC_PKCS1_SALT_LENGTH 8 -#define HC_PKCS1_MAX_BLOCK_SIZE 16 -#define HC_PKCS1_MAX_KEY_LENGTH 32 -#define HC_PKCS1_MAX_DATA_LENGTH 12288 +#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_PKCS1_MAX_CIPHER_NAME_LENGTH 32 +#define HC_PEM_MAX_CIPHER_NAME_LENGTH 32 static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; static const u32 DGST_POS0 = 0; @@ -28,7 +28,7 @@ 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 = 24111; // Kernel used for the benchmark esalt; will likely be overridden in production +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; @@ -51,30 +51,21 @@ u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, 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 kern_type_pkcs1 +typedef enum hc_pem_cipher_type { - KERN_TYPE_PKCS1_3DES_CBC = 24111, - KERN_TYPE_PKCS1_DES_CBC = 24121, - KERN_TYPE_PKCS1_AES128_CBC = 24131, - KERN_TYPE_PKCS1_AES192_CBC = 24141, - KERN_TYPE_PKCS1_AES256_CBC = 24151, -} kern_type_pkcs1_t; + 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_pkcs1_cipher_type +typedef enum hc_pem_cipher_mode { - HC_PKCS1_CIPHER_TYPE_3DES = 1, - HC_PKCS1_CIPHER_TYPE_DES = 2, - HC_PKCS1_CIPHER_TYPE_AES128 = 3, - HC_PKCS1_CIPHER_TYPE_AES192 = 4, - HC_PKCS1_CIPHER_TYPE_AES256 = 5, -} hc_pkcs1_cipher_type_t; + HC_PEM_CIPHER_MODE_CBC = 1, +} hc_pem_cipher_mode_t; -typedef enum hc_pkcs1_cipher_mode -{ - HC_PKCS1_CIPHER_MODE_CBC = 1, -} hc_pkcs1_cipher_mode_t; - -typedef struct pkcs1_cipher +typedef struct pem_cipher { char *name; @@ -82,31 +73,31 @@ typedef struct pkcs1_cipher u32 key_length; u32 cipher_type; u32 cipher_mode; -} hc_pkcs1_cipher_t; +} hc_pem_cipher_t; -static hc_pkcs1_cipher_t pkcs1_ciphers[] = { - {"des-ede3-cbc", 8, 24, HC_PKCS1_CIPHER_TYPE_3DES, HC_PKCS1_CIPHER_MODE_CBC}, - {"des-cbc", 8, 8, HC_PKCS1_CIPHER_TYPE_DES, HC_PKCS1_CIPHER_MODE_CBC}, - {"aes-128-cbc", 16, 16, HC_PKCS1_CIPHER_TYPE_AES128, HC_PKCS1_CIPHER_MODE_CBC}, - {"aes-192-cbc", 16, 24, HC_PKCS1_CIPHER_TYPE_AES192, HC_PKCS1_CIPHER_MODE_CBC}, - {"aes-256-cbc", 16, 32, HC_PKCS1_CIPHER_TYPE_AES256, HC_PKCS1_CIPHER_MODE_CBC}, +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 pkcs1 +typedef struct pem { - hc_pkcs1_cipher_t *chosen_cipher; + hc_pem_cipher_t *chosen_cipher; - u32 salt_iv[HC_PKCS1_MAX_BLOCK_SIZE / 4]; + u32 salt_iv[HC_PEM_MAX_BLOCK_SIZE / 4]; - u32 data[HC_PKCS1_MAX_DATA_LENGTH / 4]; + u32 data[HC_PEM_MAX_DATA_LENGTH / 4]; size_t data_len; -} pkcs1_t; +} pem_t; -typedef struct pkcs1_tmp +typedef struct pem_tmp { - u32 key[HC_PKCS1_MAX_KEY_LENGTH / 4]; -} pkcs1_tmp_t; + 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) @@ -134,7 +125,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYB hash_t *hash = &hashes_buf[0]; memset (hash->salt, 0, sizeof (salt_t)); - memset (hash->esalt, 0, sizeof (pkcs1_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)); } @@ -203,14 +194,14 @@ static int parse_dek_info (char *line, char *cipher_name, u8 * salt) salt[salty++] = hex_to_u8 ((u8 *) line); - if (salty > HC_PKCS1_MAX_BLOCK_SIZE) + if (salty > HC_PEM_MAX_BLOCK_SIZE) { return PARSER_SALT_LENGTH; } } else if (line[1] == '\0') { - if (salty < HC_PKCS1_SALT_LENGTH) + if (salty < HC_PEM_SALT_LENGTH) { // Malformed salt, not long enough for PKCS5's liking return PARSER_SALT_LENGTH; @@ -230,7 +221,7 @@ static int parse_dek_info (char *line, char *cipher_name, u8 * salt) else { cipher_name[i++] = *line; - if (i >= HC_PKCS1_MAX_CIPHER_NAME_LENGTH) + if (i >= HC_PEM_MAX_CIPHER_NAME_LENGTH) { return PARSER_CIPHER; } @@ -240,7 +231,7 @@ static int parse_dek_info (char *line, char *cipher_name, u8 * salt) return PARSER_SALT_VALUE; } -static int parse_pkcs1_key_data (char *buf, char *cipher_name, u8 * salt, u8 * data, size_t * data_len) +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; @@ -304,7 +295,7 @@ static int parse_pkcs1_key_data (char *buf, char *cipher_name, u8 * salt, u8 * d } } - if (b64_idx * 6 / 8 > HC_PKCS1_MAX_DATA_LENGTH) + if (b64_idx * 6 / 8 > HC_PEM_MAX_DATA_LENGTH) { return PARSER_TOKEN_LENGTH; } @@ -316,7 +307,7 @@ static int parse_pkcs1_key_data (char *buf, char *cipher_name, u8 * salt, u8 * d 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) { - pkcs1_t *pkcs1 = (pkcs1_t *) esalt_buf; + pem_t *pem = (pem_t *) esalt_buf; HCFILE fp; struct stat fileinfo; @@ -342,11 +333,11 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYBE_UNUS filebuf[fileinfo.st_size] = '\0'; - char cipher_name[HC_PKCS1_MAX_CIPHER_NAME_LENGTH] = { 0 }; - u8 saltbytes[MAX(HC_PKCS1_SALT_LENGTH, HC_PKCS1_MAX_BLOCK_SIZE)]; + 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_pkcs1_key_data ((char *) filebuf, cipher_name, saltbytes, (u8 *) pkcs1->data, &pkcs1->data_len)) < 0) + if ((err = parse_pem_key_data ((char *) filebuf, cipher_name, saltbytes, (u8 *) pem->data, &pem->data_len)) < 0) { hcfree (filebuf); @@ -355,12 +346,12 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYBE_UNUS u32 *saltwords = (u32 *) saltbytes; - for (u32 i = 0; i < HC_PKCS1_SALT_LENGTH / 4; i++) + for (u32 i = 0; i < HC_PEM_SALT_LENGTH / 4; i++) { - pkcs1->salt_iv[i] = saltwords[i]; + pem->salt_iv[i] = saltwords[i]; } - hc_pkcs1_cipher_t *candidate_cipher = pkcs1_ciphers, *chosen_cipher = NULL; + hc_pem_cipher_t *candidate_cipher = pem_ciphers, *chosen_cipher = NULL; while (candidate_cipher->name) { @@ -382,29 +373,29 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYBE_UNUS return PARSER_CIPHER; } - if (chosen_cipher->block_size > HC_PKCS1_MAX_BLOCK_SIZE) + if (chosen_cipher->block_size > HC_PEM_MAX_BLOCK_SIZE) { hcfree (filebuf); return PARSER_BLOCK_SIZE; } - if (pkcs1->data_len % chosen_cipher->block_size) + if (pem->data_len % chosen_cipher->block_size) { hcfree (filebuf); return PARSER_HASH_LENGTH; } - if (chosen_cipher->key_length > HC_PKCS1_MAX_KEY_LENGTH) + if (chosen_cipher->key_length > HC_PEM_MAX_KEY_LENGTH) { // Nope nope nopety nope return PARSER_KEY_SIZE; } - pkcs1->chosen_cipher = chosen_cipher; + pem->chosen_cipher = chosen_cipher; - memcpy (salt->salt_buf, pkcs1->salt_iv, MIN (HC_PKCS1_SALT_LENGTH, 64 * 4)); + memcpy (salt->salt_buf, pem->salt_iv, MIN (HC_PEM_SALT_LENGTH, 64 * 4)); salt->salt_iter = 1; return 1; @@ -412,13 +403,13 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t * hashconfig, MAYBE_UNUS 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) { - pkcs1_t *pkcs1 = (pkcs1_t *) hcmalloc (sizeof (pkcs1_t)); + pem_t *pem = (pem_t *) hcmalloc (sizeof (pem_t)); - pkcs1->chosen_cipher = &pkcs1_ciphers[0]; - hex_decode ((u8 *) "7CC48DB27D461D30", 16, (u8 *) pkcs1->salt_iv); - pkcs1->data_len = base64_decode (base64_to_int, (u8 *) "ysVmp6tkcZXRqHyy3YMk5zd4bsT9D97kFcDIKkD2g5o/OBgc0pGQ/iSwJm/V+A2IkwgQlwvLW1OfKkAWdjcSFNKhmiWApVQB", 96, (u8 *) pkcs1->data); + 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 pkcs1; + 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) @@ -433,19 +424,19 @@ salt_t *module_benchmark_salt (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYB 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 pkcs1_t *pkcs1 = (const pkcs1_t *) esalt_buf; + const pem_t *pem = (const pem_t *) esalt_buf; - u64 kern_type = 24100; + u64 kern_type = 22900; - kern_type += pkcs1->chosen_cipher->cipher_type * 10; - kern_type += pkcs1->chosen_cipher->cipher_mode; + 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 (pkcs1_t); + const u64 esalt_size = (const u64) sizeof (pem_t); return esalt_size; }