diff --git a/OpenCL/inc_rp.cl b/OpenCL/inc_rp.cl index 174ac996e..f8a128216 100644 --- a/OpenCL/inc_rp.cl +++ b/OpenCL/inc_rp.cl @@ -249,7 +249,7 @@ DECLSPEC int mangle_lrest (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, P buf[idx] = t | generate_cmask (t); } - return (len); + return len; } DECLSPEC int mangle_lrest_ufirst (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) @@ -265,7 +265,7 @@ DECLSPEC int mangle_lrest_ufirst (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u buf[0] = t & ~(0x00000020 & generate_cmask (t)); - return (len); + return len; } DECLSPEC int mangle_urest (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) @@ -277,7 +277,7 @@ DECLSPEC int mangle_urest (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, P buf[idx] = t & ~(generate_cmask (t)); } - return (len); + return len; } DECLSPEC int mangle_urest_lfirst (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) @@ -293,7 +293,7 @@ DECLSPEC int mangle_urest_lfirst (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u buf[0] = t | (0x00000020 & generate_cmask (t)); - return (len); + return len; } DECLSPEC int mangle_trest (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) @@ -305,12 +305,12 @@ DECLSPEC int mangle_trest (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, P buf[idx] = t ^ generate_cmask (t); } - return (len); + return len; } DECLSPEC int mangle_toggle_at (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) { - if (p0 >= len) return (len); + if (p0 >= len) return len; const u8 p0d = p0 / 4; const u8 p0m = p0 & 3; @@ -321,12 +321,12 @@ DECLSPEC int mangle_toggle_at (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p buf[p0d] = t ^ (generate_cmask (t) & tmp); - return (len); + return len; } DECLSPEC int mangle_toggle_at_sep (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) { - if (len >= RP_PASSWORD_SIZE) return (len); + if (len >= RP_PASSWORD_SIZE) return len; u8 occurence = 0; @@ -350,7 +350,7 @@ DECLSPEC int mangle_toggle_at_sep (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const buf[idx] = t ^ (generate_cmask (t) & out); } - return (len); + return len; } DECLSPEC int mangle_reverse (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) @@ -362,25 +362,25 @@ DECLSPEC int mangle_reverse (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, exchange_byte (buf, l, r); } - return (len); + return len; } DECLSPEC int mangle_dupeword (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) { const int out_len = len * 2; - if (out_len >= RP_PASSWORD_SIZE) return (len); + if (out_len >= RP_PASSWORD_SIZE) return len; append_block (buf, 0, buf, len, len); - return (out_len); + return out_len; } DECLSPEC int mangle_dupeword_times (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { const int out_len = (len * p0) + len; - if (out_len >= RP_PASSWORD_SIZE) return (len); + if (out_len >= RP_PASSWORD_SIZE) return len; int out_pos = len; @@ -394,14 +394,14 @@ DECLSPEC int mangle_dupeword_times (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const } } - return (out_len); + return out_len; } DECLSPEC int mangle_reflect (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) { const int out_len = len * 2; - if (out_len >= RP_PASSWORD_SIZE) return (len); + if (out_len >= RP_PASSWORD_SIZE) return len; append_block (buf, 0, buf, len, len); @@ -419,18 +419,18 @@ DECLSPEC int mangle_append (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, { const int out_len = len + 1; - if (out_len >= RP_PASSWORD_SIZE) return (len); + if (out_len >= RP_PASSWORD_SIZE) return len; buf[len] = p0; - return (out_len); + return out_len; } DECLSPEC int mangle_prepend (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { const int out_len = len + 1; - if (out_len >= RP_PASSWORD_SIZE) return (len); + if (out_len >= RP_PASSWORD_SIZE) return len; for (int pos = len - 1; pos >= 0; pos--) { @@ -439,7 +439,7 @@ DECLSPEC int mangle_prepend (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, buf[0] = p0; - return (out_len); + return out_len; } DECLSPEC int mangle_rotate_left (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) @@ -449,7 +449,7 @@ DECLSPEC int mangle_rotate_left (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 exchange_byte (buf, l, r); } - return (len); + return len; } DECLSPEC int mangle_rotate_right (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) @@ -459,12 +459,12 @@ DECLSPEC int mangle_rotate_right (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u exchange_byte (buf, l, r); } - return (len); + return len; } DECLSPEC int mangle_delete_at (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 >= len) return (len); + if (p0 >= len) return len; for (int pos = p0; pos < len - 1; pos++) { @@ -490,9 +490,9 @@ DECLSPEC int mangle_delete_last (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 DECLSPEC int mangle_extract (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 >= len) return (len); + if (p0 >= len) return len; - if ((p0 + p1) > len) return (len); + if ((p0 + p1) > len) return len; for (int pos = 0; pos < p1; pos++) { @@ -504,14 +504,14 @@ DECLSPEC int mangle_extract (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, buf[pos] = 0; } - return (p1); + return p1; } DECLSPEC int mangle_omit (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 >= len) return (len); + if (p0 >= len) return len; - if ((p0 + p1) > len) return (len); + if ((p0 + p1) > len) return len; for (int pos = p0; pos < len - p1; pos++) { @@ -528,11 +528,11 @@ DECLSPEC int mangle_omit (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PR DECLSPEC int mangle_insert (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 >= len + 1) return (len); + if (p0 >= len + 1) return len; const int out_len = len + 1; - if (out_len >= RP_PASSWORD_SIZE) return (len); + if (out_len >= RP_PASSWORD_SIZE) return len; for (int pos = len - 1; pos > p0 - 1; pos--) { @@ -541,28 +541,28 @@ DECLSPEC int mangle_insert (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, buf[p0] = p1; - return (out_len); + return out_len; } DECLSPEC int mangle_overstrike (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 >= len) return (len); + if (p0 >= len) return len; buf[p0] = p1; - return (len); + return len; } DECLSPEC int mangle_truncate_at (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 >= len) return (len); + if (p0 >= len) return len; for (int pos = p0; pos < len; pos++) { buf[pos] = 0; } - return (p0); + return p0; } DECLSPEC int mangle_replace (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -574,7 +574,7 @@ DECLSPEC int mangle_replace (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, buf[pos] = p1; } - return (len); + return len; } DECLSPEC int mangle_replace_class_l (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -586,7 +586,7 @@ DECLSPEC int mangle_replace_class_l (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED cons buf[pos] = p1; } - return (len); + return len; } DECLSPEC int mangle_replace_class_u (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -598,7 +598,7 @@ DECLSPEC int mangle_replace_class_u (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED cons buf[pos] = p1; } - return (len); + return len; } DECLSPEC int mangle_replace_class_d (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -610,7 +610,7 @@ DECLSPEC int mangle_replace_class_d (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED cons buf[pos] = p1; } - return (len); + return len; } DECLSPEC int mangle_replace_class_lh (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -622,7 +622,7 @@ DECLSPEC int mangle_replace_class_lh (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED con buf[pos] = p1; } - return (len); + return len; } DECLSPEC int mangle_replace_class_uh (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -634,7 +634,7 @@ DECLSPEC int mangle_replace_class_uh (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED con buf[pos] = p1; } - return (len); + return len; } DECLSPEC int mangle_replace_class_s (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -646,7 +646,7 @@ DECLSPEC int mangle_replace_class_s (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED cons buf[pos] = p1; } - return (len); + return len; } DECLSPEC int mangle_replace_class (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -679,7 +679,7 @@ DECLSPEC int mangle_purgechar (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p buf[pos] = 0; } - return (out_len); + return out_len; } DECLSPEC int mangle_purgechar_class_l (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -700,7 +700,7 @@ DECLSPEC int mangle_purgechar_class_l (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED co buf[pos] = 0; } - return (out_len); + return out_len; } DECLSPEC int mangle_purgechar_class_u (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -721,7 +721,7 @@ DECLSPEC int mangle_purgechar_class_u (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED co buf[pos] = 0; } - return (out_len); + return out_len; } DECLSPEC int mangle_purgechar_class_d (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -742,7 +742,7 @@ DECLSPEC int mangle_purgechar_class_d (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED co buf[pos] = 0; } - return (out_len); + return out_len; } DECLSPEC int mangle_purgechar_class_lh (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -763,7 +763,7 @@ DECLSPEC int mangle_purgechar_class_lh (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED c buf[pos] = 0; } - return (out_len); + return out_len; } DECLSPEC int mangle_purgechar_class_uh (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -784,7 +784,7 @@ DECLSPEC int mangle_purgechar_class_uh (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED c buf[pos] = 0; } - return (out_len); + return out_len; } DECLSPEC int mangle_purgechar_class_s (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -805,7 +805,7 @@ DECLSPEC int mangle_purgechar_class_s (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED co buf[pos] = 0; } - return (out_len); + return out_len; } DECLSPEC int mangle_purgechar_class (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) @@ -824,8 +824,8 @@ DECLSPEC int mangle_dupechar_first (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const { const int out_len = len + p0; - if (len == 0) return (len); - if (out_len >= RP_PASSWORD_SIZE) return (len); + if (len == 0) return len; + if (out_len >= RP_PASSWORD_SIZE) return len; const u8 c = buf[0]; @@ -834,15 +834,15 @@ DECLSPEC int mangle_dupechar_first (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const mangle_prepend (c, 0, buf, len + i); } - return (out_len); + return out_len; } DECLSPEC int mangle_dupechar_last (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { const int out_len = len + p0; - if (len == 0) return (len); - if (out_len >= RP_PASSWORD_SIZE) return (len); + if (len == 0) return len; + if (out_len >= RP_PASSWORD_SIZE) return len; const u8 c = buf[len - 1]; @@ -851,14 +851,14 @@ DECLSPEC int mangle_dupechar_last (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const mangle_append (c, 0, buf, len + i); } - return (out_len); + return out_len; } DECLSPEC int mangle_dupechar_all (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { const int out_len = len + len; - if (out_len >= RP_PASSWORD_SIZE) return (len); + if (out_len >= RP_PASSWORD_SIZE) return len; for (int pos = len - 1; pos >= 0; pos--) { @@ -869,100 +869,100 @@ DECLSPEC int mangle_dupechar_all (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u buf[new_pos + 1] = buf[pos]; } - return (out_len); + return out_len; } DECLSPEC int mangle_switch_first (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) { - if (len < 2) return (len); + if (len < 2) return len; exchange_byte (buf, 0, 1); - return (len); + return len; } DECLSPEC int mangle_switch_last (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) { - if (len < 2) return (len); + if (len < 2) return len; exchange_byte (buf, len - 2, len - 1); - return (len); + return len; } DECLSPEC int mangle_switch_at (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) { - if (p0 >= len) return (len); - if (p1 >= len) return (len); + if (p0 >= len) return len; + if (p1 >= len) return len; exchange_byte (buf, p0, p1); - return (len); + return len; } DECLSPEC int mangle_chr_shiftl (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 >= len) return (len); + if (p0 >= len) return len; buf[p0] <<= 1; - return (len); + return len; } DECLSPEC int mangle_chr_shiftr (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 >= len) return (len); + if (p0 >= len) return len; buf[p0] >>= 1; - return (len); + return len; } DECLSPEC int mangle_chr_incr (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 >= len) return (len); + if (p0 >= len) return len; buf[p0]++; - return (len); + return len; } DECLSPEC int mangle_chr_decr (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 >= len) return (len); + if (p0 >= len) return len; buf[p0]--; - return (len); + return len; } DECLSPEC int mangle_replace_np1 (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if ((p0 + 1) >= len) return (len); + if ((p0 + 1) >= len) return len; buf[p0] = buf[p0 + 1]; - return (len); + return len; } DECLSPEC int mangle_replace_nm1 (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 == 0) return (len); + if (p0 == 0) return len; - if (p0 >= len) return (len); + if (p0 >= len) return len; buf[p0] = buf[p0 - 1]; - return (len); + return len; } DECLSPEC int mangle_dupeblock_first (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 > len) return (len); + if (p0 > len) return len; const int out_len = len + p0; - if (out_len >= RP_PASSWORD_SIZE) return (len); + if (out_len >= RP_PASSWORD_SIZE) return len; for (int i = 0; i < p0; i++) { @@ -971,16 +971,16 @@ DECLSPEC int mangle_dupeblock_first (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED cons mangle_insert (i, c, buf, len + i); } - return (out_len); + return out_len; } DECLSPEC int mangle_dupeblock_last (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { - if (p0 > len) return (len); + if (p0 > len) return len; const int out_len = len + p0; - if (out_len >= RP_PASSWORD_SIZE) return (len); + if (out_len >= RP_PASSWORD_SIZE) return len; for (int i = 0; i < p0; i++) { @@ -989,12 +989,12 @@ DECLSPEC int mangle_dupeblock_last (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const mangle_append (c, 0, buf, len + i); } - return (out_len); + return out_len; } DECLSPEC int mangle_title_sep (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) { - if (len >= RP_PASSWORD_SIZE) return (len); + if (len >= RP_PASSWORD_SIZE) return len; u32 rem = 0xff; @@ -1016,7 +1016,181 @@ DECLSPEC int mangle_title_sep (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p buf[idx] &= ~(generate_cmask (buf[idx]) & out); } - return (len); + return len; +} + +DECLSPEC int mangle_title_sep_class_l (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) +{ + if (len >= RP_PASSWORD_SIZE) return len; + + u32 rem = 0xff; + + for (int i = 0, idx = 0; i < len; i += 4, idx += 1) + { + const u32 t = buf[idx]; + + buf[idx] = t | generate_cmask (t); + + u32 out = rem; + + rem = 0; + + if (is_l ((t >> 0) & 0xff)) out |= 0x0000ff00; + if (is_l ((t >> 8) & 0xff)) out |= 0x00ff0000; + if (is_l ((t >> 16) & 0xff)) out |= 0xff000000; + if (is_l ((t >> 24) & 0xff)) rem |= 0x000000ff; + + buf[idx] &= ~(generate_cmask (buf[idx]) & out); + } + + return len; +} + +DECLSPEC int mangle_title_sep_class_u (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) +{ + if (len >= RP_PASSWORD_SIZE) return len; + + u32 rem = 0xff; + + for (int i = 0, idx = 0; i < len; i += 4, idx += 1) + { + const u32 t = buf[idx]; + + buf[idx] = t | generate_cmask (t); + + u32 out = rem; + + rem = 0; + + if (is_u ((t >> 0) & 0xff)) out |= 0x0000ff00; + if (is_u ((t >> 8) & 0xff)) out |= 0x00ff0000; + if (is_u ((t >> 16) & 0xff)) out |= 0xff000000; + if (is_u ((t >> 24) & 0xff)) rem |= 0x000000ff; + + buf[idx] &= ~(generate_cmask (buf[idx]) & out); + } + + return len; +} + +DECLSPEC int mangle_title_sep_class_d (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) +{ + if (len >= RP_PASSWORD_SIZE) return len; + + u32 rem = 0xff; + + for (int i = 0, idx = 0; i < len; i += 4, idx += 1) + { + const u32 t = buf[idx]; + + buf[idx] = t | generate_cmask (t); + + u32 out = rem; + + rem = 0; + + if (is_d ((t >> 0) & 0xff)) out |= 0x0000ff00; + if (is_d ((t >> 8) & 0xff)) out |= 0x00ff0000; + if (is_d ((t >> 16) & 0xff)) out |= 0xff000000; + if (is_d ((t >> 24) & 0xff)) rem |= 0x000000ff; + + buf[idx] &= ~(generate_cmask (buf[idx]) & out); + } + + return len; +} + +DECLSPEC int mangle_title_sep_class_lh (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) +{ + if (len >= RP_PASSWORD_SIZE) return len; + + u32 rem = 0xff; + + for (int i = 0, idx = 0; i < len; i += 4, idx += 1) + { + const u32 t = buf[idx]; + + buf[idx] = t | generate_cmask (t); + + u32 out = rem; + + rem = 0; + + if (is_lh ((t >> 0) & 0xff)) out |= 0x0000ff00; + if (is_lh ((t >> 8) & 0xff)) out |= 0x00ff0000; + if (is_lh ((t >> 16) & 0xff)) out |= 0xff000000; + if (is_lh ((t >> 24) & 0xff)) rem |= 0x000000ff; + + buf[idx] &= ~(generate_cmask (buf[idx]) & out); + } + + return len; +} + +DECLSPEC int mangle_title_sep_class_uh (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) +{ + if (len >= RP_PASSWORD_SIZE) return len; + + u32 rem = 0xff; + + for (int i = 0, idx = 0; i < len; i += 4, idx += 1) + { + const u32 t = buf[idx]; + + buf[idx] = t | generate_cmask (t); + + u32 out = rem; + + rem = 0; + + if (is_uh ((t >> 0) & 0xff)) out |= 0x0000ff00; + if (is_uh ((t >> 8) & 0xff)) out |= 0x00ff0000; + if (is_uh ((t >> 16) & 0xff)) out |= 0xff000000; + if (is_uh ((t >> 24) & 0xff)) rem |= 0x000000ff; + + buf[idx] &= ~(generate_cmask (buf[idx]) & out); + } + + return len; +} + +DECLSPEC int mangle_title_sep_class_s (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) +{ + if (len >= RP_PASSWORD_SIZE) return len; + + u32 rem = 0xff; + + for (int i = 0, idx = 0; i < len; i += 4, idx += 1) + { + const u32 t = buf[idx]; + + buf[idx] = t | generate_cmask (t); + + u32 out = rem; + + rem = 0; + + if (is_s ((t >> 0) & 0xff)) out |= 0x0000ff00; + if (is_s ((t >> 8) & 0xff)) out |= 0x00ff0000; + if (is_s ((t >> 16) & 0xff)) out |= 0xff000000; + if (is_s ((t >> 24) & 0xff)) rem |= 0x000000ff; + + buf[idx] &= ~(generate_cmask (buf[idx]) & out); + } + + return len; +} + +DECLSPEC int mangle_title_sep_class (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len) +{ + if (p0 == 'l') return mangle_title_sep_class_l (p0, p1, buf, len); + else if (p0 == 'u') return mangle_title_sep_class_u (p0, p1, buf, len); + else if (p0 == 'd') return mangle_title_sep_class_d (p0, p1, buf, len); + else if (p0 == 'h') return mangle_title_sep_class_lh (p0, p1, buf, len); + else if (p0 == 'H') return mangle_title_sep_class_uh (p0, p1, buf, len); + else if (p0 == 's') return mangle_title_sep_class_s (p0, p1, buf, len); + + return len; } DECLSPEC int apply_rule (const u32 name, MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int in_len) @@ -1067,6 +1241,7 @@ DECLSPEC int apply_rule (const u32 name, MAYBE_UNUSED const u8 p0, MAYBE_UNUSED case RULE_OP_MANGLE_DUPEBLOCK_FIRST: out_len = mangle_dupeblock_first (p0, p1, (PRIVATE_AS u8 *) buf, out_len); break; case RULE_OP_MANGLE_DUPEBLOCK_LAST: out_len = mangle_dupeblock_last (p0, p1, (PRIVATE_AS u8 *) buf, out_len); break; case RULE_OP_MANGLE_TITLE_SEP: out_len = mangle_title_sep (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_TITLE_SEP_CLASS: out_len = mangle_title_sep_class (p0, p1, buf, out_len); break; case RULE_OP_MANGLE_TITLE: out_len = mangle_title_sep (' ', p1, buf, out_len); break; } diff --git a/OpenCL/inc_rp.h b/OpenCL/inc_rp.h index 60759966c..e40ef3ba7 100644 --- a/OpenCL/inc_rp.h +++ b/OpenCL/inc_rp.h @@ -72,12 +72,13 @@ /* using character classes */ #define RULE_OP_MANGLE_REPLACE_CLASS 0x01 #define RULE_OP_MANGLE_PURGECHAR_CLASS 0x02 -#define RULE_OP_REJECT_CONTAIN_CLASS 0x03 -#define RULE_OP_REJECT_NOT_CONTAIN_CLASS 0x04 -#define RULE_OP_REJECT_EQUAL_FIRST_CLASS 0x05 -#define RULE_OP_REJECT_EQUAL_LAST_CLASS 0x06 -#define RULE_OP_REJECT_EQUAL_AT_CLASS 0x07 -#define RULE_OP_REJECT_CONTAINS_CLASS 0x08 +#define RULE_OP_MANGLE_TITLE_SEP_CLASS 0x03 +#define RULE_OP_REJECT_CONTAIN_CLASS 0x04 +#define RULE_OP_REJECT_NOT_CONTAIN_CLASS 0x05 +#define RULE_OP_REJECT_EQUAL_FIRST_CLASS 0x06 +#define RULE_OP_REJECT_EQUAL_LAST_CLASS 0x07 +#define RULE_OP_REJECT_EQUAL_AT_CLASS 0x08 +#define RULE_OP_REJECT_CONTAINS_CLASS 0x09 #define RP_PASSWORD_SIZE 256 @@ -131,6 +132,7 @@ DECLSPEC int mangle_replace_nm1 (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 DECLSPEC int mangle_dupeblock_first (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len); DECLSPEC int mangle_dupeblock_last (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len); DECLSPEC int mangle_title_sep (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len); +DECLSPEC int mangle_title_sep_class (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int len); DECLSPEC int apply_rule (const u32 name, MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u32 *buf, const int in_len); DECLSPEC int apply_rules (CONSTANT_AS const u32 *cmds, PRIVATE_AS u32 *buf, const int in_len); diff --git a/OpenCL/inc_rp_optimized.cl b/OpenCL/inc_rp_optimized.cl index fa7f2b0a2..51d00ec72 100644 --- a/OpenCL/inc_rp_optimized.cl +++ b/OpenCL/inc_rp_optimized.cl @@ -1215,7 +1215,7 @@ DECLSPEC HC_INLINE_RP u32 rule_op_mangle_toggle_at (MAYBE_UNUSED const u32 p0, M buf1[2] = t[6]; buf1[3] = t[7]; - return (in_len); + return in_len; } DECLSPEC HC_INLINE_RP u32 rule_op_mangle_toggle_at_sep (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) @@ -2914,6 +2914,324 @@ DECLSPEC HC_INLINE_RP u32 rule_op_mangle_title_sep (MAYBE_UNUSED const u32 p0, M return in_len; } +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_title_sep_class_l (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + if (in_len == 0) return in_len; + + u32 buf_in[8]; + + buf_in[0] = buf0[0]; + buf_in[1] = buf0[1]; + buf_in[2] = buf0[2]; + buf_in[3] = buf0[3]; + buf_in[4] = buf1[0]; + buf_in[5] = buf1[1]; + buf_in[6] = buf1[2]; + buf_in[7] = buf1[3]; + + u32 rem = 0xff; + + u32 rn = 0; + + for (u32 i = 0, idx = 0; i < in_len; i += 4, idx += 1) + { + const u32 t = buf_in[idx]; + + buf_in[idx] = t | generate_cmask_optimized (t); + + u32 out = rem; + + rem = 0; + + if (is_l ((t >> 0) & 0xff)) { rn++; out |= 0x0000ff00; } + if (is_l ((t >> 8) & 0xff)) { rn++; out |= 0x00ff0000; } + if (is_l ((t >> 16) & 0xff)) { rn++; out |= 0xff000000; } + if (is_l ((t >> 24) & 0xff)) { rn++; rem |= 0x000000ff; } + + buf_in[idx] &= ~(generate_cmask_optimized (buf_in[idx]) & out); + } + + if (rn == 0) return in_len; + + buf0[0] = buf_in[0]; + buf0[1] = buf_in[1]; + buf0[2] = buf_in[2]; + buf0[3] = buf_in[3]; + buf1[0] = buf_in[4]; + buf1[1] = buf_in[5]; + buf1[2] = buf_in[6]; + buf1[3] = buf_in[7]; + + return in_len; +} + +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_title_sep_class_u (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + if (in_len == 0) return in_len; + + u32 buf_in[8]; + + buf_in[0] = buf0[0]; + buf_in[1] = buf0[1]; + buf_in[2] = buf0[2]; + buf_in[3] = buf0[3]; + buf_in[4] = buf1[0]; + buf_in[5] = buf1[1]; + buf_in[6] = buf1[2]; + buf_in[7] = buf1[3]; + + u32 rem = 0xff; + + u32 rn = 0; + + for (u32 i = 0, idx = 0; i < in_len; i += 4, idx += 1) + { + const u32 t = buf_in[idx]; + + buf_in[idx] = t | generate_cmask_optimized (t); + + u32 out = rem; + + rem = 0; + + if (is_u ((t >> 0) & 0xff)) { rn++; out |= 0x0000ff00; } + if (is_u ((t >> 8) & 0xff)) { rn++; out |= 0x00ff0000; } + if (is_u ((t >> 16) & 0xff)) { rn++; out |= 0xff000000; } + if (is_u ((t >> 24) & 0xff)) { rn++; rem |= 0x000000ff; } + + buf_in[idx] &= ~(generate_cmask_optimized (buf_in[idx]) & out); + } + + if (rn == 0) return in_len; + + buf0[0] = buf_in[0]; + buf0[1] = buf_in[1]; + buf0[2] = buf_in[2]; + buf0[3] = buf_in[3]; + buf1[0] = buf_in[4]; + buf1[1] = buf_in[5]; + buf1[2] = buf_in[6]; + buf1[3] = buf_in[7]; + + return in_len; +} + +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_title_sep_class_d (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + if (in_len == 0) return in_len; + + u32 buf_in[8]; + + buf_in[0] = buf0[0]; + buf_in[1] = buf0[1]; + buf_in[2] = buf0[2]; + buf_in[3] = buf0[3]; + buf_in[4] = buf1[0]; + buf_in[5] = buf1[1]; + buf_in[6] = buf1[2]; + buf_in[7] = buf1[3]; + + u32 rem = 0xff; + + u32 rn = 0; + + for (u32 i = 0, idx = 0; i < in_len; i += 4, idx += 1) + { + const u32 t = buf_in[idx]; + + buf_in[idx] = t | generate_cmask_optimized (t); + + u32 out = rem; + + rem = 0; + + if (is_d ((t >> 0) & 0xff)) { rn++; out |= 0x0000ff00; } + if (is_d ((t >> 8) & 0xff)) { rn++; out |= 0x00ff0000; } + if (is_d ((t >> 16) & 0xff)) { rn++; out |= 0xff000000; } + if (is_d ((t >> 24) & 0xff)) { rn++; rem |= 0x000000ff; } + + buf_in[idx] &= ~(generate_cmask_optimized (buf_in[idx]) & out); + } + + if (rn == 0) return in_len; + + buf0[0] = buf_in[0]; + buf0[1] = buf_in[1]; + buf0[2] = buf_in[2]; + buf0[3] = buf_in[3]; + buf1[0] = buf_in[4]; + buf1[1] = buf_in[5]; + buf1[2] = buf_in[6]; + buf1[3] = buf_in[7]; + + return in_len; +} + +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_title_sep_class_lh (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + if (in_len == 0) return in_len; + + u32 buf_in[8]; + + buf_in[0] = buf0[0]; + buf_in[1] = buf0[1]; + buf_in[2] = buf0[2]; + buf_in[3] = buf0[3]; + buf_in[4] = buf1[0]; + buf_in[5] = buf1[1]; + buf_in[6] = buf1[2]; + buf_in[7] = buf1[3]; + + u32 rem = 0xff; + + u32 rn = 0; + + for (u32 i = 0, idx = 0; i < in_len; i += 4, idx += 1) + { + const u32 t = buf_in[idx]; + + buf_in[idx] = t | generate_cmask_optimized (t); + + u32 out = rem; + + rem = 0; + + if (is_lh ((t >> 0) & 0xff)) { rn++; out |= 0x0000ff00; } + if (is_lh ((t >> 8) & 0xff)) { rn++; out |= 0x00ff0000; } + if (is_lh ((t >> 16) & 0xff)) { rn++; out |= 0xff000000; } + if (is_lh ((t >> 24) & 0xff)) { rn++; rem |= 0x000000ff; } + + buf_in[idx] &= ~(generate_cmask_optimized (buf_in[idx]) & out); + } + + if (rn == 0) return in_len; + + buf0[0] = buf_in[0]; + buf0[1] = buf_in[1]; + buf0[2] = buf_in[2]; + buf0[3] = buf_in[3]; + buf1[0] = buf_in[4]; + buf1[1] = buf_in[5]; + buf1[2] = buf_in[6]; + buf1[3] = buf_in[7]; + + return in_len; +} + +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_title_sep_class_uh (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + if (in_len == 0) return in_len; + + u32 buf_in[8]; + + buf_in[0] = buf0[0]; + buf_in[1] = buf0[1]; + buf_in[2] = buf0[2]; + buf_in[3] = buf0[3]; + buf_in[4] = buf1[0]; + buf_in[5] = buf1[1]; + buf_in[6] = buf1[2]; + buf_in[7] = buf1[3]; + + u32 rem = 0xff; + + u32 rn = 0; + + for (u32 i = 0, idx = 0; i < in_len; i += 4, idx += 1) + { + const u32 t = buf_in[idx]; + + buf_in[idx] = t | generate_cmask_optimized (t); + + u32 out = rem; + + rem = 0; + + if (is_uh ((t >> 0) & 0xff)) { rn++; out |= 0x0000ff00; } + if (is_uh ((t >> 8) & 0xff)) { rn++; out |= 0x00ff0000; } + if (is_uh ((t >> 16) & 0xff)) { rn++; out |= 0xff000000; } + if (is_uh ((t >> 24) & 0xff)) { rn++; rem |= 0x000000ff; } + + buf_in[idx] &= ~(generate_cmask_optimized (buf_in[idx]) & out); + } + + if (rn == 0) return in_len; + + buf0[0] = buf_in[0]; + buf0[1] = buf_in[1]; + buf0[2] = buf_in[2]; + buf0[3] = buf_in[3]; + buf1[0] = buf_in[4]; + buf1[1] = buf_in[5]; + buf1[2] = buf_in[6]; + buf1[3] = buf_in[7]; + + return in_len; +} + +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_title_sep_class_s (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + if (in_len == 0) return in_len; + + u32 buf_in[8]; + + buf_in[0] = buf0[0]; + buf_in[1] = buf0[1]; + buf_in[2] = buf0[2]; + buf_in[3] = buf0[3]; + buf_in[4] = buf1[0]; + buf_in[5] = buf1[1]; + buf_in[6] = buf1[2]; + buf_in[7] = buf1[3]; + + u32 rem = 0xff; + + u32 rn = 0; + + for (u32 i = 0, idx = 0; i < in_len; i += 4, idx += 1) + { + const u32 t = buf_in[idx]; + + buf_in[idx] = t | generate_cmask_optimized (t); + + u32 out = rem; + + rem = 0; + + if (is_s ((t >> 0) & 0xff)) { rn++; out |= 0x0000ff00; } + if (is_s ((t >> 8) & 0xff)) { rn++; out |= 0x00ff0000; } + if (is_s ((t >> 16) & 0xff)) { rn++; out |= 0xff000000; } + if (is_s ((t >> 24) & 0xff)) { rn++; rem |= 0x000000ff; } + + buf_in[idx] &= ~(generate_cmask_optimized (buf_in[idx]) & out); + } + + if (rn == 0) return in_len; + + buf0[0] = buf_in[0]; + buf0[1] = buf_in[1]; + buf0[2] = buf_in[2]; + buf0[3] = buf_in[3]; + buf1[0] = buf_in[4]; + buf1[1] = buf_in[5]; + buf1[2] = buf_in[6]; + buf1[3] = buf_in[7]; + + return in_len; +} + +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_title_sep_class (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + if ((u8)p0 == 'l') return rule_op_mangle_title_sep_class_l (p0, p1, buf0, buf1, in_len); + else if ((u8)p0 == 'u') return rule_op_mangle_title_sep_class_u (p0, p1, buf0, buf1, in_len); + else if ((u8)p0 == 'd') return rule_op_mangle_title_sep_class_d (p0, p1, buf0, buf1, in_len); + else if ((u8)p0 == 'h') return rule_op_mangle_title_sep_class_lh (p0, p1, buf0, buf1, in_len); + else if ((u8)p0 == 'H') return rule_op_mangle_title_sep_class_uh (p0, p1, buf0, buf1, in_len); + else if ((u8)p0 == 's') return rule_op_mangle_title_sep_class_s (p0, p1, buf0, buf1, in_len); + + return in_len; +} + DECLSPEC u32 apply_rule_optimized (const u32 name, const u32 p0, const u32 p1, PRIVATE_AS u32 *buf0, PRIVATE_AS u32 *buf1, const u32 in_len) { u32 out_len = in_len; @@ -2963,6 +3281,7 @@ DECLSPEC u32 apply_rule_optimized (const u32 name, const u32 p0, const u32 p1, P case RULE_OP_MANGLE_DUPEBLOCK_FIRST: out_len = rule_op_mangle_dupeblock_first (p0, p1, buf0, buf1, out_len); break; case RULE_OP_MANGLE_DUPEBLOCK_LAST: out_len = rule_op_mangle_dupeblock_last (p0, p1, buf0, buf1, out_len); break; case RULE_OP_MANGLE_TITLE_SEP: out_len = rule_op_mangle_title_sep (p0, p1, buf0, buf1, out_len); break; + case RULE_OP_MANGLE_TITLE_SEP_CLASS: out_len = rule_op_mangle_title_sep_class (p0, p1, buf0, buf1, out_len); break; case RULE_OP_MANGLE_TITLE: out_len = rule_op_mangle_title_sep (' ', p1, buf0, buf1, out_len); break; } diff --git a/OpenCL/inc_rp_optimized.h b/OpenCL/inc_rp_optimized.h index 6aa60162b..a4a4c2656 100644 --- a/OpenCL/inc_rp_optimized.h +++ b/OpenCL/inc_rp_optimized.h @@ -78,12 +78,13 @@ /* using character classes */ #define RULE_OP_MANGLE_REPLACE_CLASS 0x01 #define RULE_OP_MANGLE_PURGECHAR_CLASS 0x02 -#define RULE_OP_REJECT_CONTAIN_CLASS 0x03 -#define RULE_OP_REJECT_NOT_CONTAIN_CLASS 0x04 -#define RULE_OP_REJECT_EQUAL_FIRST_CLASS 0x05 -#define RULE_OP_REJECT_EQUAL_LAST_CLASS 0x06 -#define RULE_OP_REJECT_EQUAL_AT_CLASS 0x07 -#define RULE_OP_REJECT_CONTAINS_CLASS 0x08 +#define RULE_OP_MANGLE_TITLE_SEP_CLASS 0x03 +#define RULE_OP_REJECT_CONTAIN_CLASS 0x04 +#define RULE_OP_REJECT_NOT_CONTAIN_CLASS 0x05 +#define RULE_OP_REJECT_EQUAL_FIRST_CLASS 0x06 +#define RULE_OP_REJECT_EQUAL_LAST_CLASS 0x07 +#define RULE_OP_REJECT_EQUAL_AT_CLASS 0x08 +#define RULE_OP_REJECT_CONTAINS_CLASS 0x09 DECLSPEC u32 generate_cmask_optimized (const u32 value); DECLSPEC void truncate_right_optimized (PRIVATE_AS u32 *buf0, PRIVATE_AS u32 *buf1, const u32 offset); @@ -141,6 +142,7 @@ DECLSPEC HC_INLINE_RP u32 rule_op_mangle_dupeblock_first (MAYBE_UNUSED const u32 DECLSPEC HC_INLINE_RP u32 rule_op_mangle_dupeblock_last (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len); DECLSPEC u32 toggle_on_register (const u32 in, const u32 r); DECLSPEC HC_INLINE_RP u32 rule_op_mangle_title_sep (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len); +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_title_sep_class (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len); DECLSPEC u32 apply_rule_optimized (const u32 name, const u32 p0, const u32 p1, PRIVATE_AS u32 *buf0, PRIVATE_AS u32 *buf1, const u32 in_len); DECLSPEC u32 apply_rules_optimized (CONSTANT_AS const u32 *cmds, PRIVATE_AS u32 *buf0, PRIVATE_AS u32 *buf1, const u32 len); DECLSPEC u32x apply_rules_vect_optimized (PRIVATE_AS const u32 *pw_buf0, PRIVATE_AS const u32 *pw_buf1, const u32 pw_len, CONSTANT_AS const kernel_rule_t *kernel_rules, const u32 il_pos, PRIVATE_AS u32x *buf0, PRIVATE_AS u32x *buf1); diff --git a/docs/rules.txt b/docs/rules.txt index e894acf7f..689f66bdf 100644 --- a/docs/rules.txt +++ b/docs/rules.txt @@ -65,12 +65,13 @@ #define RULE_OP_CLASS_BASED '~' #define RULE_OP_MANGLE_REPLACE_CLASS 0x01 // replace all instances of chars in class C with char Y, ~s?CY #define RULE_OP_MANGLE_PURGECHAR_CLASS 0x02 // purge all instances of chars in class C, ~@?C +#define RULE_OP_MANGLE_TITLE_SEP_CLASS 0x03 // lowercase everything then upper case the first letter and every letter after chars in class C, ~e?C /* using character classes, with -j or -k only */ -#define RULE_OP_REJECT_CONTAIN_CLASS 0x03 // reject plains that contain chars in class C, ~!?C -#define RULE_OP_REJECT_NOT_CONTAIN_CLASS 0x04 // reject plains that do not contain chars in class C, ~/?C -#define RULE_OP_REJECT_EQUAL_FIRST_CLASS 0x05 // reject plains that do not contain char in class C at first pos, ~(?C -#define RULE_OP_REJECT_EQUAL_LAST_CLASS 0x06 // reject plains that do not contain char in class C at last pos, ~)?C -#define RULE_OP_REJECT_EQUAL_AT_CLASS 0x07 // reject plains that do not contain char in class C at pos N, ~=N?C -#define RULE_OP_REJECT_CONTAINS_CLASS 0x08 // reject plains that contain char in class C less than N times, ~%N?C +#define RULE_OP_REJECT_CONTAIN_CLASS 0x04 // reject plains that contain chars in class C, ~!?C +#define RULE_OP_REJECT_NOT_CONTAIN_CLASS 0x05 // reject plains that do not contain chars in class C, ~/?C +#define RULE_OP_REJECT_EQUAL_FIRST_CLASS 0x06 // reject plains that do not contain chars in class C at first pos, ~(?C +#define RULE_OP_REJECT_EQUAL_LAST_CLASS 0x07 // reject plains that do not contain chars in class C at last pos, ~)?C +#define RULE_OP_REJECT_EQUAL_AT_CLASS 0x08 // reject plains that do not contain chars in class C at pos N, ~=N?C +#define RULE_OP_REJECT_CONTAINS_CLASS 0x09 // reject plains that contain chars in class C less than N times, ~%N?C diff --git a/include/types.h b/include/types.h index e68e90160..085d4316f 100644 --- a/include/types.h +++ b/include/types.h @@ -371,12 +371,13 @@ typedef enum rule_functions RULE_OP_CLASS_BASED = '~', RULE_OP_MANGLE_REPLACE_CLASS = 0x01, RULE_OP_MANGLE_PURGECHAR_CLASS = 0x02, - RULE_OP_REJECT_CONTAIN_CLASS = 0x03, - RULE_OP_REJECT_NOT_CONTAIN_CLASS = 0x04, - RULE_OP_REJECT_EQUAL_FIRST_CLASS = 0x05, - RULE_OP_REJECT_EQUAL_LAST_CLASS = 0x06, - RULE_OP_REJECT_EQUAL_AT_CLASS = 0x07, - RULE_OP_REJECT_CONTAINS_CLASS = 0x08, + RULE_OP_MANGLE_TITLE_SEP_CLASS = 0x03, + RULE_OP_REJECT_CONTAIN_CLASS = 0x04, + RULE_OP_REJECT_NOT_CONTAIN_CLASS = 0x05, + RULE_OP_REJECT_EQUAL_FIRST_CLASS = 0x06, + RULE_OP_REJECT_EQUAL_LAST_CLASS = 0x07, + RULE_OP_REJECT_EQUAL_AT_CLASS = 0x08, + RULE_OP_REJECT_CONTAINS_CLASS = 0x09, } rule_functions_t; diff --git a/src/rp.c b/src/rp.c index ea987bdc6..022a2876c 100644 --- a/src/rp.c +++ b/src/rp.c @@ -232,7 +232,7 @@ int generate_random_rule (char rule_buf[RP_RULE_SIZE], const u32 rp_gen_func_min } } - return (rule_pos); + return rule_pos; } #define INCR_POS if (++rule_pos == rule_len) return (-1) @@ -488,12 +488,21 @@ int cpu_rule_to_kernel_rule (char *rule_buf, u32 rule_len, kernel_rule_t *rule) SET_P0 (rule, rule_buf[rule_pos]); SET_P1 (rule, rule_buf[rule_pos]); break; + case RULE_OP_MANGLE_PURGECHAR: // ~@?C SET_NAME (rule, RULE_OP_MANGLE_PURGECHAR_CLASS); INCR_POS; INCR_POS; SET_P0 (rule, rule_buf[rule_pos]); break; + + case RULE_OP_MANGLE_TITLE_SEP: // ~e?C + SET_NAME (rule, RULE_OP_MANGLE_TITLE_SEP_CLASS); + INCR_POS; + INCR_POS; + SET_P0 (rule, rule_buf[rule_pos]); + break; + /* case '!': // ~!?C SET_NAME (rule, RULE_OP_REJECT_CONTAIN_CLASS); @@ -784,6 +793,13 @@ int kernel_rule_to_cpu_rule (char *rule_buf, kernel_rule_t *rule) GET_P0 (rule); break; + case RULE_OP_MANGLE_TITLE_SEP_CLASS: + rule_buf[rule_pos++] = RULE_OP_CLASS_BASED; + rule_buf[rule_pos++] = RULE_OP_MANGLE_TITLE_SEP; + rule_buf[rule_pos] = '?'; + GET_P0 (rule); + break; + case 0: if (rule_pos == 0) return -1; return rule_pos - 1; diff --git a/src/rp_cpu.c b/src/rp_cpu.c index f11858e13..7ea9c4b4a 100644 --- a/src/rp_cpu.c +++ b/src/rp_cpu.c @@ -48,12 +48,9 @@ static void MANGLE_SWITCH (char *arr, const int l, const int r) static int mangle_toggle_at_sep (char arr[RP_PASSWORD_SIZE], int arr_len, char c, int upos) { int toggle_next = 0; + int occurrence = 0; - int occurrence = 0; - - int pos; - - for (pos = 0; pos < arr_len; pos++) + for (int pos = 0; pos < arr_len; pos++) { if (arr[pos] == c) { @@ -77,41 +74,33 @@ static int mangle_toggle_at_sep (char arr[RP_PASSWORD_SIZE], int arr_len, char c } } - return (arr_len); + return arr_len; } static int mangle_lrest (char arr[RP_PASSWORD_SIZE], int arr_len) { - int pos; + for (int pos = 0; pos < arr_len; pos++) MANGLE_LOWER_AT (arr, pos); - for (pos = 0; pos < arr_len; pos++) MANGLE_LOWER_AT (arr, pos); - - return (arr_len); + return arr_len; } static int mangle_urest (char arr[RP_PASSWORD_SIZE], int arr_len) { - int pos; + for (int pos = 0; pos < arr_len; pos++) MANGLE_UPPER_AT (arr, pos); - for (pos = 0; pos < arr_len; pos++) MANGLE_UPPER_AT (arr, pos); - - return (arr_len); + return arr_len; } static int mangle_trest (char arr[RP_PASSWORD_SIZE], int arr_len) { - int pos; + for (int pos = 0; pos < arr_len; pos++) MANGLE_TOGGLE_AT (arr, pos); - for (pos = 0; pos < arr_len; pos++) MANGLE_TOGGLE_AT (arr, pos); - - return (arr_len); + return arr_len; } static int mangle_reverse (char arr[RP_PASSWORD_SIZE], int arr_len) { - int l; - - for (l = 0; l < arr_len; l++) + for (int l = 0; l < arr_len; l++) { int r = arr_len - 1 - l; @@ -120,12 +109,12 @@ static int mangle_reverse (char arr[RP_PASSWORD_SIZE], int arr_len) MANGLE_SWITCH (arr, l, r); } - return (arr_len); + return arr_len; } static int mangle_double (char arr[RP_PASSWORD_SIZE], int arr_len) { - if ((arr_len * 2) >= RP_PASSWORD_SIZE) return (arr_len); + if ((arr_len * 2) >= RP_PASSWORD_SIZE) return arr_len; memcpy (&arr[arr_len], arr, (size_t) arr_len); @@ -134,25 +123,23 @@ static int mangle_double (char arr[RP_PASSWORD_SIZE], int arr_len) static int mangle_double_times (char arr[RP_PASSWORD_SIZE], int arr_len, int times) { - if (((arr_len * times) + arr_len) >= RP_PASSWORD_SIZE) return (arr_len); + if (((arr_len * times) + arr_len) >= RP_PASSWORD_SIZE) return arr_len; int orig_len = arr_len; - int i; - - for (i = 0; i < times; i++) + for (int i = 0; i < times; i++) { memcpy (&arr[arr_len], arr, orig_len); arr_len += orig_len; } - return (arr_len); + return arr_len; } static int mangle_reflect (char arr[RP_PASSWORD_SIZE], int arr_len) { - if ((arr_len * 2) >= RP_PASSWORD_SIZE) return (arr_len); + if ((arr_len * 2) >= RP_PASSWORD_SIZE) return arr_len; mangle_double (arr, arr_len); @@ -163,33 +150,27 @@ static int mangle_reflect (char arr[RP_PASSWORD_SIZE], int arr_len) static int mangle_rotate_left (char arr[RP_PASSWORD_SIZE], int arr_len) { - int l; - int r; - - for (l = 0, r = arr_len - 1; r > 0; r--) + for (int l = 0, r = arr_len - 1; r > 0; r--) { MANGLE_SWITCH (arr, l, r); } - return (arr_len); + return arr_len; } static int mangle_rotate_right (char arr[RP_PASSWORD_SIZE], int arr_len) { - int l; - int r; - - for (l = 0, r = arr_len - 1; l < r; l++) + for (int l = 0, r = arr_len - 1; l < r; l++) { MANGLE_SWITCH (arr, l, r); } - return (arr_len); + return arr_len; } static int mangle_append (char arr[RP_PASSWORD_SIZE], int arr_len, char c) { - if ((arr_len + 1) >= RP_PASSWORD_SIZE) return (arr_len); + if ((arr_len + 1) >= RP_PASSWORD_SIZE) return arr_len; arr[arr_len] = c; @@ -198,11 +179,9 @@ static int mangle_append (char arr[RP_PASSWORD_SIZE], int arr_len, char c) static int mangle_prepend (char arr[RP_PASSWORD_SIZE], int arr_len, char c) { - if ((arr_len + 1) >= RP_PASSWORD_SIZE) return (arr_len); + if ((arr_len + 1) >= RP_PASSWORD_SIZE) return arr_len; - int arr_pos; - - for (arr_pos = arr_len - 1; arr_pos > -1; arr_pos--) + for (int arr_pos = arr_len - 1; arr_pos > -1; arr_pos--) { arr[arr_pos + 1] = arr[arr_pos]; } @@ -214,11 +193,9 @@ static int mangle_prepend (char arr[RP_PASSWORD_SIZE], int arr_len, char c) static int mangle_delete_at (char arr[RP_PASSWORD_SIZE], int arr_len, int upos) { - if (upos >= arr_len) return (arr_len); + if (upos >= arr_len) return arr_len; - int arr_pos; - - for (arr_pos = upos; arr_pos < arr_len - 1; arr_pos++) + for (int arr_pos = upos; arr_pos < arr_len - 1; arr_pos++) { arr[arr_pos] = arr[arr_pos + 1]; } @@ -228,29 +205,25 @@ static int mangle_delete_at (char arr[RP_PASSWORD_SIZE], int arr_len, int upos) static int mangle_extract (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, int ulen) { - if (upos >= arr_len) return (arr_len); + if (upos >= arr_len) return arr_len; - if ((upos + ulen) > arr_len) return (arr_len); + if ((upos + ulen) > arr_len) return arr_len; - int arr_pos; - - for (arr_pos = 0; arr_pos < ulen; arr_pos++) + for (int arr_pos = 0; arr_pos < ulen; arr_pos++) { arr[arr_pos] = arr[upos + arr_pos]; } - return (ulen); + return ulen; } static int mangle_omit (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, int ulen) { - if (upos >= arr_len) return (arr_len); + if (upos >= arr_len) return arr_len; - if ((upos + ulen) > arr_len) return (arr_len); + if ((upos + ulen) > arr_len) return arr_len; - int arr_pos; - - for (arr_pos = upos; arr_pos < arr_len - ulen; arr_pos++) + for (int arr_pos = upos; arr_pos < arr_len - ulen; arr_pos++) { arr[arr_pos] = arr[arr_pos + ulen]; } @@ -260,13 +233,11 @@ static int mangle_omit (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, int u static int mangle_insert (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, char c) { - if (upos > arr_len) return (arr_len); + if (upos > arr_len) return arr_len; - if ((arr_len + 1) >= RP_PASSWORD_SIZE) return (arr_len); + if ((arr_len + 1) >= RP_PASSWORD_SIZE) return arr_len; - int arr_pos; - - for (arr_pos = arr_len - 1; arr_pos > upos - 1; arr_pos--) + for (int arr_pos = arr_len - 1; arr_pos > upos - 1; arr_pos--) { arr[arr_pos + 1] = arr[arr_pos]; } @@ -299,118 +270,104 @@ static int mangle_insert_multi (char arr[RP_PASSWORD_SIZE], int arr_len, int arr static int mangle_overstrike (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, char c) { - if (upos >= arr_len) return (arr_len); + if (upos >= arr_len) return arr_len; arr[upos] = c; - return (arr_len); + return arr_len; } static int mangle_truncate_at (char arr[RP_PASSWORD_SIZE], int arr_len, int upos) { - if (upos >= arr_len) return (arr_len); + if (upos >= arr_len) return arr_len; memset (arr + upos, 0, arr_len - upos); - return (upos); + return upos; } static int mangle_replace (char arr[RP_PASSWORD_SIZE], int arr_len, char oldc, char newc) { - int arr_pos; - - for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (arr[arr_pos] != oldc) continue; arr[arr_pos] = newc; } - return (arr_len); + return arr_len; } static int mangle_replace_class_l (char arr[RP_PASSWORD_SIZE], int arr_len, char newc) { - int arr_pos; - - for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (!class_lower (arr[arr_pos])) continue; arr[arr_pos] = newc; } - return (arr_len); + return arr_len; } static int mangle_replace_class_u (char arr[RP_PASSWORD_SIZE], int arr_len, char newc) { - int arr_pos; - - for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (!class_upper (arr[arr_pos])) continue; arr[arr_pos] = newc; } - return (arr_len); + return arr_len; } static int mangle_replace_class_d (char arr[RP_PASSWORD_SIZE], int arr_len, char newc) { - int arr_pos; - - for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (!class_num (arr[arr_pos])) continue; arr[arr_pos] = newc; } - return (arr_len); + return arr_len; } static int mangle_replace_class_lh (char arr[RP_PASSWORD_SIZE], int arr_len, char newc) { - int arr_pos; - - for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (!class_lower_hex (arr[arr_pos])) continue; arr[arr_pos] = newc; } - return (arr_len); + return arr_len; } static int mangle_replace_class_uh (char arr[RP_PASSWORD_SIZE], int arr_len, char newc) { - int arr_pos; - - for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (!class_upper_hex (arr[arr_pos])) continue; arr[arr_pos] = newc; } - return (arr_len); + return arr_len; } static int mangle_replace_class_s (char arr[RP_PASSWORD_SIZE], int arr_len, char newc) { - int arr_pos; - - for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (!class_sym (arr[arr_pos])) continue; arr[arr_pos] = newc; } - return (arr_len); + return arr_len; } static int mangle_replace_class (char arr[RP_PASSWORD_SIZE], int arr_len, char oldc, char newc) @@ -422,16 +379,14 @@ static int mangle_replace_class (char arr[RP_PASSWORD_SIZE], int arr_len, char o else if (oldc == 'H') return mangle_replace_class_uh (arr, arr_len, newc); else if (oldc == 's') return mangle_replace_class_s (arr, arr_len, newc); - return (arr_len); + return arr_len; } static int mangle_purgechar (char arr[RP_PASSWORD_SIZE], int arr_len, char c) { - int arr_pos; + int ret_len = 0; - int ret_len; - - for (ret_len = 0, arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (arr[arr_pos] == c) continue; @@ -440,16 +395,14 @@ static int mangle_purgechar (char arr[RP_PASSWORD_SIZE], int arr_len, char c) ret_len++; } - return (ret_len); + return ret_len; } static int mangle_purgechar_class_l (char arr[RP_PASSWORD_SIZE], int arr_len) { - int arr_pos; + int ret_len = 0; - int ret_len; - - for (ret_len = 0, arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (class_lower (arr[arr_pos])) continue; @@ -458,16 +411,14 @@ static int mangle_purgechar_class_l (char arr[RP_PASSWORD_SIZE], int arr_len) ret_len++; } - return (ret_len); + return ret_len; } static int mangle_purgechar_class_u (char arr[RP_PASSWORD_SIZE], int arr_len) { - int arr_pos; + int ret_len = 0; - int ret_len; - - for (ret_len = 0, arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (class_upper (arr[arr_pos])) continue; @@ -476,16 +427,14 @@ static int mangle_purgechar_class_u (char arr[RP_PASSWORD_SIZE], int arr_len) ret_len++; } - return (ret_len); + return ret_len; } static int mangle_purgechar_class_d (char arr[RP_PASSWORD_SIZE], int arr_len) { - int arr_pos; + int ret_len = 0; - int ret_len; - - for (ret_len = 0, arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (class_num (arr[arr_pos])) continue; @@ -494,16 +443,14 @@ static int mangle_purgechar_class_d (char arr[RP_PASSWORD_SIZE], int arr_len) ret_len++; } - return (ret_len); + return ret_len; } static int mangle_purgechar_class_lh (char arr[RP_PASSWORD_SIZE], int arr_len) { - int arr_pos; + int ret_len = 0; - int ret_len; - - for (ret_len = 0, arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (class_lower_hex (arr[arr_pos])) continue; @@ -512,16 +459,14 @@ static int mangle_purgechar_class_lh (char arr[RP_PASSWORD_SIZE], int arr_len) ret_len++; } - return (ret_len); + return ret_len; } static int mangle_purgechar_class_uh (char arr[RP_PASSWORD_SIZE], int arr_len) { - int arr_pos; + int ret_len = 0; - int ret_len; - - for (ret_len = 0, arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (class_upper_hex (arr[arr_pos])) continue; @@ -530,16 +475,14 @@ static int mangle_purgechar_class_uh (char arr[RP_PASSWORD_SIZE], int arr_len) ret_len++; } - return (ret_len); + return ret_len; } static int mangle_purgechar_class_s (char arr[RP_PASSWORD_SIZE], int arr_len) { - int arr_pos; + int ret_len = 0; - int ret_len; - - for (ret_len = 0, arr_pos = 0; arr_pos < arr_len; arr_pos++) + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) { if (class_sym (arr[arr_pos])) continue; @@ -548,7 +491,7 @@ static int mangle_purgechar_class_s (char arr[RP_PASSWORD_SIZE], int arr_len) ret_len++; } - return (ret_len); + return ret_len; } static int mangle_purgechar_class (char arr[RP_PASSWORD_SIZE], int arr_len, char c) @@ -560,76 +503,67 @@ static int mangle_purgechar_class (char arr[RP_PASSWORD_SIZE], int arr_len, char else if (c == 'H') return mangle_purgechar_class_uh (arr, arr_len); else if (c == 's') return mangle_purgechar_class_s (arr, arr_len); - return (arr_len); + return arr_len; } static int mangle_dupeblock_prepend (char arr[RP_PASSWORD_SIZE], int arr_len, int ulen) { - if (ulen > arr_len) return (arr_len); + if (ulen > arr_len) return arr_len; - if ((arr_len + ulen) >= RP_PASSWORD_SIZE) return (arr_len); + if ((arr_len + ulen) >= RP_PASSWORD_SIZE) return arr_len; - char cs[100] = { 0 }; + char cs[100]; + memset (cs, 0, sizeof (cs)); memcpy (cs, arr, ulen); - int i; - - for (i = 0; i < ulen; i++) + for (int i = 0; i < ulen; i++) { - char c = cs[i]; - - arr_len = mangle_insert (arr, arr_len, i, c); + arr_len = mangle_insert (arr, arr_len, i, cs[i]); } - return (arr_len); + return arr_len; } static int mangle_dupeblock_append (char arr[RP_PASSWORD_SIZE], int arr_len, int ulen) { - if (ulen > arr_len) return (arr_len); + if (ulen > arr_len) return arr_len; - if ((arr_len + ulen) >= RP_PASSWORD_SIZE) return (arr_len); + if ((arr_len + ulen) >= RP_PASSWORD_SIZE) return arr_len; int upos = arr_len - ulen; - int i; - - for (i = 0; i < ulen; i++) + for (int i = 0; i < ulen; i++) { char c = arr[upos + i]; arr_len = mangle_append (arr, arr_len, c); } - return (arr_len); + return arr_len; } static int mangle_dupechar_at (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, int ulen) { - if ( arr_len == 0) return (arr_len); - if ((arr_len + ulen) >= RP_PASSWORD_SIZE) return (arr_len); + if ( arr_len == 0) return arr_len; + if ((arr_len + ulen) >= RP_PASSWORD_SIZE) return arr_len; char c = arr[upos]; - int i; - - for (i = 0; i < ulen; i++) + for (int i = 0; i < ulen; i++) { arr_len = mangle_insert (arr, arr_len, upos, c); } - return (arr_len); + return arr_len; } static int mangle_dupechar (char arr[RP_PASSWORD_SIZE], int arr_len) { - if ( arr_len == 0) return (arr_len); - if ((arr_len + arr_len) >= RP_PASSWORD_SIZE) return (arr_len); + if ( arr_len == 0) return arr_len; + if ((arr_len + arr_len) >= RP_PASSWORD_SIZE) return arr_len; - int arr_pos; - - for (arr_pos = arr_len - 1; arr_pos > -1; arr_pos--) + for (int arr_pos = arr_len - 1; arr_pos > -1; arr_pos--) { int new_pos = arr_pos * 2; @@ -643,64 +577,62 @@ static int mangle_dupechar (char arr[RP_PASSWORD_SIZE], int arr_len) static int mangle_switch_at_check (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, int upos2) { - if (upos >= arr_len) return (arr_len); - if (upos2 >= arr_len) return (arr_len); + if (upos >= arr_len) return arr_len; + if (upos2 >= arr_len) return arr_len; MANGLE_SWITCH (arr, upos, upos2); - return (arr_len); + return arr_len; } static int mangle_switch_at (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, int upos2) { MANGLE_SWITCH (arr, upos, upos2); - return (arr_len); + return arr_len; } static int mangle_chr_shiftl (char arr[RP_PASSWORD_SIZE], int arr_len, int upos) { - if (upos >= arr_len) return (arr_len); + if (upos >= arr_len) return arr_len; arr[upos] <<= 1; - return (arr_len); + return arr_len; } static int mangle_chr_shiftr (char arr[RP_PASSWORD_SIZE], int arr_len, int upos) { - if (upos >= arr_len) return (arr_len); + if (upos >= arr_len) return arr_len; arr[upos] >>= 1; - return (arr_len); + return arr_len; } static int mangle_chr_incr (char arr[RP_PASSWORD_SIZE], int arr_len, int upos) { - if (upos >= arr_len) return (arr_len); + if (upos >= arr_len) return arr_len; arr[upos] += 1; - return (arr_len); + return arr_len; } static int mangle_chr_decr (char arr[RP_PASSWORD_SIZE], int arr_len, int upos) { - if (upos >= arr_len) return (arr_len); + if (upos >= arr_len) return arr_len; arr[upos] -= 1; - return (arr_len); + return arr_len; } static int mangle_title_sep (char arr[RP_PASSWORD_SIZE], int arr_len, char c) { int upper_next = 1; - int pos; - - for (pos = 0; pos < arr_len; pos++) + for (int pos = 0; pos < arr_len; pos++) { if (arr[pos] == c) { @@ -723,7 +655,199 @@ static int mangle_title_sep (char arr[RP_PASSWORD_SIZE], int arr_len, char c) MANGLE_UPPER_AT (arr, 0); - return (arr_len); + return arr_len; +} + +static int mangle_title_sep_class_l (char arr[RP_PASSWORD_SIZE], int arr_len) +{ + int upper_next = 1; + + for (int pos = 0; pos < arr_len; pos++) + { + if (class_lower (arr[pos])) + { + upper_next = 1; + + continue; + } + + if (upper_next) + { + upper_next = 0; + + MANGLE_UPPER_AT (arr, pos); + } + else + { + MANGLE_LOWER_AT (arr, pos); + } + } + + MANGLE_UPPER_AT (arr, 0); + + return arr_len; +} + +static int mangle_title_sep_class_u (char arr[RP_PASSWORD_SIZE], int arr_len) +{ + int upper_next = 1; + + for (int pos = 0; pos < arr_len; pos++) + { + if (class_upper (arr[pos])) + { + upper_next = 1; + + continue; + } + + if (upper_next) + { + upper_next = 0; + + MANGLE_UPPER_AT (arr, pos); + } + else + { + MANGLE_LOWER_AT (arr, pos); + } + } + + MANGLE_UPPER_AT (arr, 0); + + return arr_len; +} + +static int mangle_title_sep_class_d (char arr[RP_PASSWORD_SIZE], int arr_len) +{ + int upper_next = 1; + + for (int pos = 0; pos < arr_len; pos++) + { + if (class_num (arr[pos])) + { + upper_next = 1; + + continue; + } + + if (upper_next) + { + upper_next = 0; + + MANGLE_UPPER_AT (arr, pos); + } + else + { + MANGLE_LOWER_AT (arr, pos); + } + } + + MANGLE_UPPER_AT (arr, 0); + + return arr_len; +} + +static int mangle_title_sep_class_lh (char arr[RP_PASSWORD_SIZE], int arr_len) +{ + int upper_next = 1; + + for (int pos = 0; pos < arr_len; pos++) + { + if (class_lower_hex (arr[pos])) + { + upper_next = 1; + + continue; + } + + if (upper_next) + { + upper_next = 0; + + MANGLE_UPPER_AT (arr, pos); + } + else + { + MANGLE_LOWER_AT (arr, pos); + } + } + + MANGLE_UPPER_AT (arr, 0); + + return arr_len; +} + +static int mangle_title_sep_class_uh (char arr[RP_PASSWORD_SIZE], int arr_len) +{ + int upper_next = 1; + + for (int pos = 0; pos < arr_len; pos++) + { + if (class_upper_hex (arr[pos])) + { + upper_next = 1; + + continue; + } + + if (upper_next) + { + upper_next = 0; + + MANGLE_UPPER_AT (arr, pos); + } + else + { + MANGLE_LOWER_AT (arr, pos); + } + } + + MANGLE_UPPER_AT (arr, 0); + + return arr_len; +} + +static int mangle_title_sep_class_s (char arr[RP_PASSWORD_SIZE], int arr_len) +{ + int upper_next = 1; + + for (int pos = 0; pos < arr_len; pos++) + { + if (class_sym (arr[pos])) + { + upper_next = 1; + + continue; + } + + if (upper_next) + { + upper_next = 0; + + MANGLE_UPPER_AT (arr, pos); + } + else + { + MANGLE_LOWER_AT (arr, pos); + } + } + + MANGLE_UPPER_AT (arr, 0); + + return arr_len; +} + +static int mangle_title_sep_class (char arr[RP_PASSWORD_SIZE], int arr_len, char c) +{ + if (c == 'l') return mangle_title_sep_class_l (arr, arr_len); + else if (c == 'u') return mangle_title_sep_class_u (arr, arr_len); + else if (c == 'd') return mangle_title_sep_class_d (arr, arr_len); + else if (c == 'h') return mangle_title_sep_class_lh (arr, arr_len); + else if (c == 'H') return mangle_title_sep_class_uh (arr, arr_len); + else if (c == 's') return mangle_title_sep_class_s (arr, arr_len); + + return arr_len; } static bool reject_contain_class_l (char arr[RP_PASSWORD_SIZE], int arr_len, int *pos_mem) @@ -958,7 +1082,7 @@ static bool reject_contains (const char arr[RP_PASSWORD_SIZE], int arr_len, char int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], int in_len, char out[RP_PASSWORD_SIZE]) { - char mem[RP_PASSWORD_SIZE] = { 0 }; + char mem[RP_PASSWORD_SIZE]; int pos_mem = -1; @@ -973,6 +1097,8 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], int out_len = in_len; int mem_len = in_len; + memset (mem, 0, sizeof (mem)); + memcpy (out, in, out_len); char *rule_new = (char *) hcmalloc (rule_len); @@ -1345,6 +1471,7 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], NEXT_RULEPOS (rule_pos); out_len = mangle_replace (out, out_len, rule_new[rule_pos - 1], rule_new[rule_pos]); break; + case 'l': case 'u': case 'd': @@ -1354,11 +1481,13 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], NEXT_RULEPOS (rule_pos); out_len = mangle_replace_class (out, out_len, rule_new[rule_pos - 1], rule_new[rule_pos]); break; + default : HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); } break; + case RULE_OP_MANGLE_PURGECHAR: // ~@?C NEXT_RULEPOS (rule_pos); if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); @@ -1369,6 +1498,7 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case '?': out_len = mangle_purgechar (out, out_len, rule_new[rule_pos]); break; + case 'l': case 'u': case 'd': @@ -1377,11 +1507,39 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case 's': out_len = mangle_purgechar_class (out, out_len, rule_new[rule_pos]); break; + default : HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); } break; + + case RULE_OP_MANGLE_TITLE_SEP: // ~e?C + NEXT_RULEPOS (rule_pos); + if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + + NEXT_RULEPOS (rule_pos); + switch (rule_new[rule_pos]) + { + case '?': + out_len = mangle_title_sep (out, out_len, rule_new[rule_pos]); + break; + + case 'l': + case 'u': + case 'd': + case 'h': + case 'H': + case 's': + out_len = mangle_title_sep_class (out, out_len, rule_new[rule_pos]); + break; + + default : + HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + } + + break; + case RULE_OP_REJECT_CONTAIN: // ~!?C NEXT_RULEPOS (rule_pos); if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); @@ -1392,6 +1550,7 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case '?': if (reject_contain (out, rule_new[rule_pos], &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'l': case 'u': case 'd': @@ -1400,11 +1559,13 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case 's': if (reject_contain_class (out, out_len, rule_new[rule_pos], &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + default : HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); } break; + case RULE_OP_REJECT_NOT_CONTAIN: // ~/?C NEXT_RULEPOS (rule_pos); if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); @@ -1415,6 +1576,7 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case '?': if (!reject_contain (out, rule_new[rule_pos], &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'l': case 'u': case 'd': @@ -1423,11 +1585,13 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case 's': if (!reject_contain_class (out, out_len, rule_new[rule_pos], &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + default : HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); } break; + case RULE_OP_REJECT_EQUAL_FIRST: // ~(?C NEXT_RULEPOS (rule_pos); if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); @@ -1438,24 +1602,31 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case '?': if (out[0] != rule_new[rule_pos]) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'l': if (!class_lower (out[0])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'u': if (!class_upper (out[0])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'd': if (!class_num (out[0])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'h': if (!class_lower_hex (out[0])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'H': if (!class_upper_hex (out[0])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 's': if (!class_sym (out[0])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + default : HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); } @@ -1471,29 +1642,37 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case '?': if (out[out_len - 1] != rule_new[rule_pos]) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'l': if (!class_lower (out[out_len - 1])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'u': if (!class_upper (out[out_len - 1])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'd': if (!class_num (out[out_len - 1])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'h': if (!class_lower_hex (out[out_len - 1])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'H': if (!class_upper_hex (out[out_len - 1])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 's': if (!class_sym (out[out_len - 1])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + default : HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); } break; + case RULE_OP_REJECT_EQUAL_AT: // ~=N?C NEXT_RULEPOS (rule_pos); NEXT_RPTOI (rule_new, rule_pos, upos); @@ -1508,24 +1687,31 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case '?': if (out[upos] != rule_new[rule_pos]) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'l': if (!class_lower (out[upos])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'u': if (!class_upper (out[upos])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'd': if (!class_num (out[upos])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'h': if (!class_lower_hex (out[upos])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'H': if (!class_upper_hex (out[upos])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 's': if (!class_sym (out[upos])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + default : HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); } @@ -1545,6 +1731,7 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case '?': if (reject_contains (out, out_len, rule_new[rule_pos], upos, &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case 'l': case 'u': case 'd': @@ -1553,6 +1740,7 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case 's': if (reject_contains_class (out, out_len, rule_new[rule_pos], upos, &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + default : HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); }