Complete Hashcat rules implementation for GPU parallel processing. Production-ready OpenCL kernel used by Aether and Ranker.
The kernel is written in OpenCL C and compiles to any GPU supporting OpenCL 1.2+. Tested on NVIDIA, AMD, and Intel GPUs.
Production-ready kernel. Download from GitHub for the full implementation.
// ============================================================================
// hashcat_rules_kernel.cl - Complete Hashcat Rules Implementation for OpenCL
// ============================================================================
//
// DESCRIPTION:
// This kernel implements ALL Hashcat rule transformations ( single rules rules)
// including simple rules, substitution, insertion, deletion, case toggling,
// leetspeak, memory operations, and logical conditionals.
//
// Rules are categorized into groups as defined in Hashcat documentation:
// - Simple rules: l, u, c, C, t, r, k, :, d, f, pN, K, 'N, yN, YN, z, Z, q, E, eX,
// [, ], {, }
// - Position-based: Tn, Dn, Ln, Rn, inX, onX, 'n, xn m, etc.
// - Substitution: sXY, @X, pX, /X, !X
// - Case manipulation: TN, Tn m, LN, RN
// - String operations: ^X, $X
// - Memory operations: M, 4, 6, _ (partial - only placeholder)
// - Logical rules: ?nX, =nX, N, (N, )N, N, _N, !X, /X, (X, )X, %NX, Q (reject rules)
// - Special operations: q, z, Z, E, eX, 3nX, vnX, Kn m, *n m, yN, YN
//
// USAGE:
// 1. Prepare input buffers:
// - words[]: array of null-terminated strings
// - rules[]: array of rule strings (null-terminated)
// - rule_ids[]: corresponding rule IDs
//
// 2. Call kernel:
// apply_rule_kernel(words, rules, results, rule_ids, hits,
// num_words, num_rules, max_word_len, max_output_len);
//
// 3. Process results:
// - results[] contains transformed words
// - hits[] indicates successful transformations (1) or failures (0)
//
// COMPATIBILITY:
// - Supports all rules from Hashcat's rule engine (except memory‑dependent chain rules)
// - UTF-8 compatible (rules operate on byte level)
// - Thread-safe for parallel execution
//
// AUTHOR: Generated from comprehensive Hashcat rules specification
// VERSION: 2.0.4
// ============================================================================
#define MAX_WORD_LEN 256
#define MAX_RULE_LEN 255 // Increased to support longer rule strings
#define MAX_OUTPUT_LEN 512
// ============================================================================
// UTILITY FUNCTIONS
// ============================================================================
// Convert a digit or letter to its numeric value (0-9, A=10 ... Z=35)
int parse_position(unsigned char c) {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'A' && c <= 'Z') return c - 'A' + 10;
if (c >= 'a' && c <= 'z') return c - 'a' + 10; // also accept lowercase
return 0;
}
// Count occurrences of character X in a string
int count_char(const unsigned char* str, int len, unsigned char x) {
int cnt = 0;
for (int i = 0; i < len; i++) {
if (str[i] == x) cnt++;
}
return cnt;
}
// Check if character is lowercase
int is_lower(unsigned char c) {
return (c >= 'a' && c <= 'z');
}
// Check if character is uppercase
int is_upper(unsigned char c) {
return (c >= 'A' && c <= 'Z');
}
// Check if character is a digit
int is_digit(unsigned char c) {
return (c >= '0' && c <= '9');
}
// Check if character is alphanumeric
int is_alnum(unsigned char c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
}
// Toggle case of a single character
unsigned char toggle_case(unsigned char c) {
if (is_lower(c)) return c - 32;
if (is_upper(c)) return c + 32;
return c;
}
// Convert character to lowercase
unsigned char to_lower(unsigned char c) {
if (is_upper(c)) return c + 32;
return c;
}
// Convert character to uppercase
unsigned char to_upper(unsigned char c) {
if (is_lower(c)) return c - 32;
return c;
}
// ============================================================================
// MAIN KERNEL FUNCTION
// ============================================================================
__kernel void apply_rule_kernel(
__global const unsigne