Optimize and clean up -m 25200 code.
Speed on CPU: 1521 -> 2066 (35% faster) Speed on GPU: 16610 -> 157754 (9.4 times faster) Works for all password lengths
This commit is contained in:
+57
-36
@@ -44,27 +44,35 @@ const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig,
|
||||
|
||||
static const char *SIGNATURE_SNMPV3 = "$SNMPv3$2$";
|
||||
|
||||
#define SNMPV3_SALT_MAX 1500
|
||||
#define SNMPV3_SALT_MAX_BIN 752
|
||||
#define SNMPV3_ENGINEID_MAX 32
|
||||
#define SNMPV3_MSG_AUTH_PARAMS_MAX 12
|
||||
#define SNMPV3_SALT_MAX 1500
|
||||
#define SNMPV3_ENGINEID_MAX 32
|
||||
#define SNMPV3_MSG_AUTH_PARAMS_MAX 12
|
||||
#define SNMPV3_ROUNDS 1048576
|
||||
#define SNMPV3_MAX_PW_LENGTH 64
|
||||
|
||||
#define SNMPV3_TMP_ELEMS 4096 // 4096 = (256 (max pw length) * 64) / sizeof (u32)
|
||||
#define SNMPV3_HASH_ELEMS 8 // 8 = aligned 5
|
||||
|
||||
typedef struct hmac_sha1_tmp
|
||||
{
|
||||
u32 idx;
|
||||
sha1_ctx_t ctx;
|
||||
u32 tmp[SNMPV3_TMP_ELEMS];
|
||||
u32 h[SNMPV3_HASH_ELEMS];
|
||||
|
||||
} hmac_sha1_tmp_t;
|
||||
|
||||
#define SNMPV3_MAX_SALT_ELEMS 512 // 512 * 4 = 2048 > 1500, also has to be multiple of 64
|
||||
#define SNMPV3_MAX_ENGINE_ELEMS 16 // 16 * 4 = 64 > 32, also has to be multiple of 64
|
||||
#define SNMPV3_MAX_PNUM_ELEMS 4 // 4 * 4 = 16 > 9
|
||||
|
||||
typedef struct snmpv3
|
||||
{
|
||||
u32 salt_buf[SNMPV3_SALT_MAX_BIN];
|
||||
u32 salt_buf[SNMPV3_MAX_SALT_ELEMS];
|
||||
u32 salt_len;
|
||||
|
||||
u8 engineID_buf[SNMPV3_ENGINEID_MAX];
|
||||
u32 engineID_buf[SNMPV3_MAX_ENGINE_ELEMS];
|
||||
u32 engineID_len;
|
||||
|
||||
u8 packet_number[8+1];
|
||||
u32 packet_number[SNMPV3_MAX_PNUM_ELEMS];
|
||||
|
||||
} snmpv3_t;
|
||||
|
||||
@@ -82,6 +90,23 @@ u64 module_tmp_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED c
|
||||
return tmp_size;
|
||||
}
|
||||
|
||||
u32 module_kernel_loops_min (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra)
|
||||
{
|
||||
// we need to fix iteration count to guarantee the loop count is a multiple of 64
|
||||
// 2k calls to sha1_transform typically is enough to overtime pcie bottleneck
|
||||
|
||||
const u32 kernel_loops_min = 2048 * 64;
|
||||
|
||||
return kernel_loops_min;
|
||||
}
|
||||
|
||||
u32 module_kernel_loops_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 kernel_loops_max = 2048 * 64;
|
||||
|
||||
return kernel_loops_max;
|
||||
}
|
||||
|
||||
int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED 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)
|
||||
{
|
||||
u32 *digest = (u32 *) digest_buf;
|
||||
@@ -146,12 +171,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
|
||||
|
||||
snmpv3->salt_len = hex_decode (salt_pos, salt_len, salt_ptr);
|
||||
|
||||
for (uint i = 0; i < snmpv3->salt_len / 2; i++)
|
||||
{
|
||||
snmpv3->salt_buf[i] = byte_swap_32 (snmpv3->salt_buf[i]);
|
||||
}
|
||||
|
||||
salt->salt_iter = 16384 - 1;
|
||||
salt->salt_iter = SNMPV3_ROUNDS;
|
||||
|
||||
// handle unique salts detection
|
||||
|
||||
@@ -163,9 +183,9 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
|
||||
|
||||
// store sha1(snmpv3->salt_buf) in salt_buf
|
||||
|
||||
salt->salt_len = 20;
|
||||
memcpy (salt->salt_buf, sha1_ctx.h, 20);
|
||||
|
||||
memcpy (salt->salt_buf, sha1_ctx.h, salt->salt_len);
|
||||
salt->salt_len = 20;
|
||||
|
||||
// engineid
|
||||
|
||||
@@ -183,13 +203,12 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
|
||||
digest[0] = hex_to_u32 (hash_pos + 0);
|
||||
digest[1] = hex_to_u32 (hash_pos + 8);
|
||||
digest[2] = hex_to_u32 (hash_pos + 16);
|
||||
digest[3] = 0;
|
||||
|
||||
digest[0] = byte_swap_32 (digest[0]);
|
||||
digest[1] = byte_swap_32 (digest[1]);
|
||||
digest[2] = byte_swap_32 (digest[2]);
|
||||
|
||||
digest[3] = 0;
|
||||
|
||||
return (PARSER_OK);
|
||||
}
|
||||
|
||||
@@ -199,33 +218,35 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
|
||||
|
||||
snmpv3_t *snmpv3 = (snmpv3_t *) esalt_buf;
|
||||
|
||||
int line_len = snprintf (line_buf, 10 + strlen ((char *) snmpv3->packet_number) + 1 + 1, "%s%s$", SIGNATURE_SNMPV3, snmpv3->packet_number);
|
||||
u8 *out_buf = (u8 *) line_buf;
|
||||
|
||||
uint i;
|
||||
int out_len = snprintf (line_buf, line_size, "%s%s$", SIGNATURE_SNMPV3, (char *) snmpv3->packet_number);
|
||||
|
||||
u32 salt_buf_32[SNMPV3_SALT_MAX_BIN] = { 0 };
|
||||
out_len += hex_encode ((u8 *) snmpv3->salt_buf, snmpv3->salt_len, out_buf + out_len);
|
||||
|
||||
for (i = 0; i < SNMPV3_SALT_MAX_BIN; i++) salt_buf_32[i] = byte_swap_32 (snmpv3->salt_buf[i]);
|
||||
out_buf[out_len] = '$';
|
||||
|
||||
const u8 *salt_buf_ptr = (u8 *) salt_buf_32;
|
||||
out_len++;
|
||||
|
||||
line_len += hex_encode (salt_buf_ptr, snmpv3->salt_len, (u8 *) line_buf+line_len);
|
||||
out_len += hex_encode ((u8 *) snmpv3->engineID_buf, snmpv3->engineID_len, out_buf + out_len);
|
||||
|
||||
line_buf[line_len] = '$';
|
||||
out_buf[out_len] = '$';
|
||||
|
||||
line_len++;
|
||||
out_len++;
|
||||
|
||||
line_len += hex_encode (snmpv3->engineID_buf, snmpv3->engineID_len, (u8 *) line_buf+line_len);
|
||||
u32 digest_tmp[3];
|
||||
|
||||
line_buf[line_len] = '$';
|
||||
digest_tmp[0] = byte_swap_32 (digest[0]);
|
||||
digest_tmp[1] = byte_swap_32 (digest[1]);
|
||||
digest_tmp[2] = byte_swap_32 (digest[2]);
|
||||
|
||||
line_len++;
|
||||
u32_to_hex (digest_tmp[0], out_buf + out_len); out_len += 8;
|
||||
u32_to_hex (digest_tmp[1], out_buf + out_len); out_len += 8;
|
||||
u32_to_hex (digest_tmp[2], out_buf + out_len); out_len += 8;
|
||||
|
||||
u32_to_hex (byte_swap_32 (digest[0]), (u8 *) line_buf+line_len); line_len += 8;
|
||||
u32_to_hex (byte_swap_32 (digest[1]), (u8 *) line_buf+line_len); line_len += 8;
|
||||
u32_to_hex (byte_swap_32 (digest[2]), (u8 *) line_buf+line_len); line_len += 8;
|
||||
out_buf[out_len] = 0;
|
||||
|
||||
return line_len;
|
||||
return out_len;
|
||||
}
|
||||
|
||||
void module_init (module_ctx_t *module_ctx)
|
||||
@@ -277,8 +298,8 @@ void module_init (module_ctx_t *module_ctx)
|
||||
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_loops_max = module_kernel_loops_max;
|
||||
module_ctx->module_kernel_loops_min = module_kernel_loops_min;
|
||||
module_ctx->module_kernel_threads_max = MODULE_DEFAULT;
|
||||
module_ctx->module_kernel_threads_min = MODULE_DEFAULT;
|
||||
module_ctx->module_kern_type = module_kern_type;
|
||||
|
||||
Reference in New Issue
Block a user