1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-21 15:48:08 +00:00

Add new function count_bits_32() in inc_common.cl

This commit is contained in:
jsteube 2023-11-22 03:36:28 +00:00
parent 13559cf902
commit f8bd133373
2 changed files with 20 additions and 0 deletions

View File

@ -2992,6 +2992,24 @@ DECLSPEC int hc_execute_keyboard_layout_mapping (PRIVATE_AS u32 *w, const int pw
return out_len;
}
DECLSPEC int count_bits_32 (const u32 v0, const u32 v1)
{
u32 r = v0 ^ v1;
if (r == 0) return 0;
// from https://stackoverflow.com/questions/109023/count-the-number-of-set-bits-in-a-32-bit-integer
r = r - ((r >> 1) & 0x55555555); // add pairs of bits
r = (r & 0x33333333) + ((r >> 2) & 0x33333333); // quads
r = (r + (r >> 4)) & 0x0F0F0F0F; // groups of 8
r *= 0x01010101; // horizontal sum of bytes
// return just that top byte (after truncating to 32-bit even when int is wider than uint32_t)
return r >> 24;
}
/**
* vector functions
*/

View File

@ -315,6 +315,8 @@ DECLSPEC int is_valid_printable_8 (const u8 v);
DECLSPEC int is_valid_printable_32 (const u32 v);
DECLSPEC int hc_find_keyboard_layout_map (const u32 search, const int search_len, LOCAL_AS keyboard_layout_mapping_t *s_keyboard_layout_mapping_buf, const int keyboard_layout_mapping_cnt);
DECLSPEC int hc_execute_keyboard_layout_mapping (PRIVATE_AS u32 *w, const int pw_len, LOCAL_AS keyboard_layout_mapping_t *s_keyboard_layout_mapping_buf, const int keyboard_layout_mapping_cnt);
DECLSPEC int count_bits_32 (const u32 v0, const u32 v1);
DECLSPEC void make_utf16be (PRIVATE_AS const u32x *in, PRIVATE_AS u32x *out1, PRIVATE_AS u32x *out2);
DECLSPEC void make_utf16beN (PRIVATE_AS const u32x *in, PRIVATE_AS u32x *out1, PRIVATE_AS u32x *out2);
DECLSPEC void make_utf16beN_S (PRIVATE_AS const u32 *in, PRIVATE_AS u32 *out1, PRIVATE_AS u32 *out2);