void status_init(int (*get_progress)(int *), int start) { char *cfg_threshold; if (start) { if (!status_restored_time) memset(&status, 0, sizeof(status)); status.start_time = get_time(); } status_get_progress = get_progress; if (!(timeformat = cfg_get_param(SECTION_OPTIONS, NULL, "TimeFormat"))) timeformat = "%c"; if ((cfg_threshold = cfg_get_param(SECTION_OPTIONS, NULL, "ETAthreshold"))) if ((ETAthreshold = atof(cfg_threshold)) < 0.01) ETAthreshold = 0.01; showcand = cfg_get_bool(SECTION_OPTIONS, NULL, "StatusShowCandidates", 0); clk_tck_init(); /* This makes --max-run-time disregard loading time */ timer_abort = options.max_run_time; }
void status_init(int (*get_progress)(int *), int start) { char *cfg_threshold; if (start) { if (!status_restored_time) memset(&status, 0, sizeof(status)); status.start_time = get_time(); } status_get_progress = get_progress; if (!(timeFmt = cfg_get_param(SECTION_OPTIONS, NULL, "TimeFormat"))) timeFmt = "%Y-%m-%d %H:%M"; if (!(timeFmt24 = cfg_get_param(SECTION_OPTIONS, NULL, "TimeFormat24"))) timeFmt24 = "%H:%M:%S"; if ((cfg_threshold = cfg_get_param(SECTION_OPTIONS, NULL, "ETAthreshold"))) if ((ETAthreshold = atof(cfg_threshold)) < 0.01) ETAthreshold = 0.01; showcand = cfg_get_bool(SECTION_OPTIONS, NULL, "StatusShowCandidates", 0); clk_tck_init(); }
static void do_wordlist_pass(struct db_main *db) { char *name; if (!(name = cfg_get_param(SECTION_OPTIONS, NULL, "Wordlist"))) if (!(name = cfg_get_param(SECTION_OPTIONS, NULL, "Wordfile"))) name = WORDLIST_NAME; do_wordlist_crack(db, name, 1); }
static void fmt_ssha_init(struct fmt_main *self) { char *temp; cl_ulong maxsize; global_work_size = 0; opencl_init("$JOHN/ssha_kernel.cl", ocl_gpu_id, platform_id); // create kernel to execute crypt_kernel = clCreateKernel(program[ocl_gpu_id], "sha1_crypt_kernel", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?"); HANDLE_CLERROR(clGetKernelWorkGroupInfo(crypt_kernel, devices[ocl_gpu_id], CL_KERNEL_WORK_GROUP_SIZE, sizeof(maxsize), &maxsize, NULL), "Query max work group size"); if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, LWS_CONFIG))) local_work_size = atoi(temp); if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, GWS_CONFIG))) global_work_size = atoi(temp); if ((temp = getenv("LWS"))) local_work_size = atoi(temp); if ((temp = getenv("GWS"))) global_work_size = atoi(temp); if (!local_work_size) { int temp = global_work_size; local_work_size = maxsize; global_work_size = global_work_size ? global_work_size : 4 * maxsize; create_clobj(global_work_size, self); opencl_find_best_workgroup_limit(self, maxsize); release_clobj(); global_work_size = temp; } if (local_work_size > maxsize) { fprintf(stderr, "LWS %d is too large for this GPU. Max allowed is %d, using that.\n", (int)local_work_size, (int)maxsize); local_work_size = maxsize; } if (!global_work_size) find_best_gws(getenv("GWS") == NULL ? 0 : 1, self); if (global_work_size < local_work_size) global_work_size = local_work_size; fprintf(stderr, "Local worksize (LWS) %d, Global worksize (GWS) %d\n", (int)local_work_size, (int)global_work_size); create_clobj(global_work_size, self); atexit(release_clobj); }
void sig_init(void) { clk_tck_init(); timer_save_interval = cfg_get_int(SECTION_OPTIONS, NULL, "Save"); if (timer_save_interval < 0) timer_save_interval = TIMER_SAVE_DELAY; else if ((timer_save_interval /= TIMER_INTERVAL) <= 0) timer_save_interval = 1; if (cfg_get_param(SECTION_OPTIONS, NULL, "AbortGraceTime")) { abort_grace_time = cfg_get_int(SECTION_OPTIONS, NULL, "AbortGraceTime"); } #if OS_TIMER timer_save_value = timer_save_interval; #elif !defined(BENCH_BUILD) timer_save_value = status_get_time() + timer_save_interval; #endif timer_ticksafety_interval = (clock_t)1 << (sizeof(clock_t) * 8 - 4); timer_ticksafety_interval /= clk_tck; if ((timer_ticksafety_interval /= TIMER_INTERVAL) <= 0) timer_ticksafety_interval = 1; timer_ticksafety_value = timer_ticksafety_interval; atexit(sig_done); sig_install(sig_handle_update, SIGHUP); sig_install_abort(); sig_install_timer(); }
static void fmt_ssha_init(struct fmt_main *pFmt) { char *temp; opencl_init("$JOHN/ssha_kernel.cl", gpu_id, platform_id); // create kernel to execute crypt_kernel = clCreateKernel(program[gpu_id], "sha1_crypt_kernel", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?"); if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, LWS_CONFIG))) local_work_size = atoi(temp); if ((temp = getenv("LWS"))) local_work_size = atoi(temp); if (!local_work_size) { create_clobj(SSHA_NUM_KEYS); find_best_workgroup(); release_clobj(); } if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, KPC_CONFIG))) max_keys_per_crypt = atoi(temp); else max_keys_per_crypt = SSHA_NUM_KEYS; if ((temp = getenv("KPC"))) max_keys_per_crypt = atoi(temp); if (max_keys_per_crypt) { create_clobj(max_keys_per_crypt); } else { //user chose to die of boredom max_keys_per_crypt = SSHA_NUM_KEYS; create_clobj(SSHA_NUM_KEYS); find_best_kpc(); } printf("Local work size (LWS) %d, Keys per crypt (KPC) %d\n",(int)local_work_size,max_keys_per_crypt); pFmt->params.max_keys_per_crypt = max_keys_per_crypt; }
static void john_register_all(void) { int i, cnt; struct fmt_main *selfs; if (options.format) strlwr(options.format); // NOTE, this MUST happen, before ANY format that links a 'thin' format // to dynamic. // Since gen(27) and gen(28) are MD5 and MD5a formats, we build the // generic format first cnt = dynamic_Register_formats(&selfs); john_register_one(&fmt_DES); john_register_one(&fmt_BSDI); john_register_one(&fmt_MD5); john_register_one(&fmt_BF); john_register_one(&fmt_scrypt); john_register_one(&fmt_LM); john_register_one(&fmt_AFS); john_register_one(&fmt_trip); john_register_one(&fmt_dummy); for (i = 0; i < cnt; ++i) john_register_one(&(selfs[i])); #include "fmt_registers.h" #if HAVE_CUDA john_register_one(&fmt_cuda_rawsha224); john_register_one(&fmt_cuda_rawsha256); #endif #if HAVE_CRYPT john_register_one(&fmt_crypt); #endif #if HAVE_LIBDL if (options.fmt_dlls) register_dlls ( options.fmt_dlls, cfg_get_param(SECTION_OPTIONS, NULL, "plugin"), john_register_one ); #endif if (!fmt_list) { if (john_main_process) fprintf(stderr, "Unknown ciphertext format name requested\n"); error(); } }
int cfg_get_int(char *section, char *subsection, char *param) { char *s_value, *error; long l_value; if ((s_value = cfg_get_param(section, subsection, param))) { l_value = strtol(s_value, &error, 10); if (!*s_value || *error || (l_value & ~0x3FFFFFFFL)) return -1; return (int)l_value; } return -1; }
int cfg_get_bool(char *section, char *subsection, char *param, int def) { char *value; if (!(value = cfg_get_param(section, subsection, param))) return def; switch (*value) { case 'y': case 'Y': case 't': case 'T': case '1': return 1; } return 0; }
int cfg_print_section_params(char *section, char *subsection) { struct cfg_section *current; struct cfg_param *param; char *value; int param_count = 0; if ((current = cfg_get_section(section, subsection))) { if((param = current->params)) do { value = cfg_get_param(section, subsection, param->name); if(!strcmp(param->value, value)) { printf("%s = %s\n", param->name, param->value); param_count++; } } while ((param = param-> next)); return param_count; } else return -1; }
static void john_register_all(void) { int i, cnt; struct fmt_main *pFmts; if (options.format) strlwr(options.format); // NOTE, this MUST happen, before ANY format that links a 'thin' format to dynamic. // Since gen(27) and gen(28) are MD5 and MD5a formats, we build the // generic format first cnt = dynamic_Register_formats(&pFmts); john_register_one(&fmt_DES); john_register_one(&fmt_BSDI); john_register_one(&fmt_MD5); john_register_one(&fmt_BF); john_register_one(&fmt_AFS); john_register_one(&fmt_LM); for (i = 0; i < cnt; ++i) john_register_one(&(pFmts[i])); #include "fmt_registers.h" john_register_one(&fmt_hmacMD5); john_register_one(&fmt_hmacSHA1); #if OPENSSL_VERSION_NUMBER >= 0x00908000 john_register_one(&fmt_rawSHA224); john_register_one(&fmt_rawSHA256); john_register_one(&fmt_rawSHA384); john_register_one(&fmt_rawSHA512); john_register_one(&fmt_hmacSHA224); john_register_one(&fmt_hmacSHA256); john_register_one(&fmt_hmacSHA384); john_register_one(&fmt_hmacSHA512); john_register_one(&fmt_XSHA512); john_register_one(&fmt_hmailserver); john_register_one(&fmt_SybaseASE); john_register_one(&fmt_dragonfly3_64); john_register_one(&fmt_dragonfly4_64); john_register_one(&fmt_dragonfly3_32); john_register_one(&fmt_dragonfly4_32); john_register_one(&fmt_drupal7); john_register_one(&fmt_cryptsha256); john_register_one(&fmt_cryptsha512); #endif #ifdef HAVE_NSS john_register_one(&mozilla_fmt); #endif #ifdef HAVE_CRYPT john_register_one(&fmt_crypt); #endif john_register_one(&fmt_trip); #ifdef HAVE_SKEY john_register_one(&fmt_SKEY); #endif john_register_one(&fmt_ssh); john_register_one(&fmt_pdf); #ifndef _MSC_VER john_register_one(&rar_fmt); #endif john_register_one(&zip_fmt); john_register_one(&fmt_dummy); #ifdef CL_VERSION_1_0 john_register_one(&fmt_opencl_NSLDAPS); john_register_one(&fmt_opencl_rawMD5); john_register_one(&fmt_opencl_NT); john_register_one(&fmt_opencl_rawSHA1); john_register_one(&fmt_opencl_cryptMD5); john_register_one(&fmt_opencl_phpass); john_register_one(&fmt_opencl_mysqlsha1); john_register_one(&fmt_opencl_cryptsha512); john_register_one(&fmt_opencl_mscash2); john_register_one(&fmt_opencl_wpapsk); john_register_one(&fmt_opencl_xsha512); john_register_one(&fmt_opencl_rawsha512); john_register_one(&fmt_opencl_bf); #endif #ifdef HAVE_CUDA john_register_one(&fmt_cuda_cryptmd5); john_register_one(&fmt_cuda_phpass); john_register_one(&fmt_cuda_cryptsha256); john_register_one(&fmt_cuda_cryptsha512); john_register_one(&fmt_cuda_mscash); john_register_one(&fmt_cuda_mscash2); john_register_one(&fmt_cuda_rawsha256); john_register_one(&fmt_cuda_rawsha224); john_register_one(&fmt_cuda_xsha512); john_register_one(&fmt_cuda_wpapsk); john_register_one(&fmt_cuda_rawsha512); #endif #ifdef HAVE_DL if (options.fmt_dlls) register_dlls ( options.fmt_dlls, cfg_get_param(SECTION_OPTIONS, NULL, "plugin"), john_register_one ); #endif if (!fmt_list) { #ifdef HAVE_MPI if (mpi_id == 0) #endif fprintf(stderr, "Unknown ciphertext format name requested\n"); error(); } }
static void john_init(char *name, int argc, char **argv) { int show_usage = 0; int make_check = (argc == 2 && !strcmp(argv[1], "--make_check")); if (make_check) argv[1] = "--test=0"; CPU_detect_or_fallback(argv, make_check); status_init(NULL, 1); if (argc < 2 || (argc == 2 && (!strcasecmp(argv[1], "--help") || !strcasecmp(argv[1], "-h") || !strcasecmp(argv[1], "-help")))) { john_register_all(); /* for printing by opt_init() */ show_usage = 1; } opt_init(name, argc, argv, show_usage); /* * --list=? needs to be supported, because it has been supported in the released * john-1.7.9-jumbo-6 version, and it is used by the bash completion script. * --list=? is, however, not longer mentioned in doc/OPTIONS and in the usage * output. Instead, --list=help is. */ if (options.listconf && (!strcasecmp(options.listconf, "help") || !strcmp(options.listconf, "?"))) { john_list_options(); exit(0); } if (options.listconf && (!strcasecmp(options.listconf, "help:help") || !strcasecmp(options.listconf, "help:"))) { john_list_help_options(); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "help:format-methods")) { john_list_method_names(); exit(0); } if (options.listconf && !strncasecmp(options.listconf, "help:", 5)) { if (strcasecmp(options.listconf, "help:parameters") && strcasecmp(options.listconf, "help:list-data")) { fprintf(stderr, "%s is not a --list option that supports additional values.\nSupported options:\n", options.listconf+5); john_list_help_options(); exit(1); } } if (options.listconf && !strcasecmp(options.listconf, "hidden-options")) { puts("--help print usage summary, just like running the command"); puts(" without any parameters"); puts("--subformat=FORMAT pick a benchmark format for --format=crypt"); puts("--mkpc=N force a lower max. keys per crypt"); puts("--length=N force a lower max. length"); puts("--field-separator-char=C use 'C' instead of the ':' in input and pot files"); puts("--fix-state-delay=N performance tweak, see documentation"); puts("--log-stderr log to screen instead of file\n"); exit(0); } if (!make_check) { #if defined(_OPENMP) && OMP_FALLBACK #if defined(__DJGPP__) || defined(__CYGWIN32__) #error OMP_FALLBACK is incompatible with the current DOS and Win32 code #endif if (!getenv("JOHN_NO_OMP_FALLBACK") && omp_get_max_threads() <= 1) { #define OMP_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" OMP_FALLBACK_BINARY execv(OMP_FALLBACK_PATHNAME, argv); perror("execv: " OMP_FALLBACK_PATHNAME); } #endif path_init(argv); if (options.listconf && !strcasecmp(options.listconf, "build-info")) { puts("Version: " JOHN_VERSION); puts("Build: " JOHN_BLD _MP_VERSION); printf("Arch: %d-bit %s\n", ARCH_BITS, ARCH_LITTLE_ENDIAN ? "LE" : "BE"); #if JOHN_SYSTEMWIDE puts("System-wide exec: " JOHN_SYSTEMWIDE_EXEC); puts("System-wide home: " JOHN_SYSTEMWIDE_HOME); puts("Private home: " JOHN_PRIVATE_HOME); #endif printf("$JOHN is %s\n", path_expand("$JOHN/")); printf("Format interface version: %d\n", FMT_MAIN_VERSION); puts("Rec file version: " RECOVERY_V); puts("Charset file version: " CHARSET_V); printf("CHARSET_MIN: %d (0x%02x)\n", CHARSET_MIN, CHARSET_MIN); printf("CHARSET_MAX: %d (0x%02x)\n", CHARSET_MAX, CHARSET_MAX); printf("CHARSET_LENGTH: %d\n", CHARSET_LENGTH); printf("Max. Markov mode level: %d\n", MAX_MKV_LVL); printf("Max. Markov mode password length: %d\n", MAX_MKV_LEN); #ifdef __VERSION__ printf("Compiler version: %s\n", __VERSION__); #endif #ifdef __GNUC__ printf("gcc version: %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); #endif #ifdef __ICC printf("icc version: %d\n", __ICC); #endif #ifdef __clang_version__ printf("clang version: %s\n", __clang_version__); #endif #ifdef OPENSSL_VERSION_NUMBER // The man page suggests the type of OPENSSL_VERSION_NUMBER is long, // gcc insists it is int. printf("OpenSSL library version: %lx", (unsigned long)OPENSSL_VERSION_NUMBER); // FIXME: How do I detect a missing library? // Even if if is extremely unlikely that openssl is missing, // at least flush all output buffers... fflush(NULL); if ((unsigned long)OPENSSL_VERSION_NUMBER != (unsigned long)SSLeay()) printf("\t(loaded: %lx)", (unsigned long)SSLeay()); printf("\n"); #endif exit(0); } } if (options.listconf && !strcasecmp(options.listconf, "encodings")) { listEncodings(); exit(0); } #ifdef CL_VERSION_1_0 if (options.listconf && !strcasecmp(options.listconf, "opencl-devices")) { listOpenCLdevices(); exit(0); } #endif #ifdef HAVE_CUDA if (options.listconf && !strcasecmp(options.listconf, "cuda-devices")) { cuda_device_list(); exit(0); } #endif if (!make_check) { if (options.config) { path_init_ex(options.config); cfg_init(options.config, 1); cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } else { #if JOHN_SYSTEMWIDE cfg_init(CFG_PRIVATE_FULL_NAME, 1); cfg_init(CFG_PRIVATE_ALT_NAME, 1); #endif cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } } /* This is --crack-status. We toggle here, so if it's enabled in john.conf, we can disable it using the command line option */ if (cfg_get_bool(SECTION_OPTIONS, NULL, "CrackStatus", 0)) options.flags ^= FLG_CRKSTAT; initUnicode(UNICODE_UNICODE); /* Init the unicode system */ john_register_all(); /* maybe restricted to one format by options */ if ((options.subformat && !strcasecmp(options.subformat, "list")) || (options.listconf && !strcasecmp(options.listconf, "subformats"))) { dynamic_DISPLAY_ALL_FORMATS(); /* NOTE if we have other 'generics', like sha1, sha2, rc4, ... * then EACH of them should have a DISPLAY_ALL_FORMATS() * function and we can call them here. */ exit(0); } if (options.listconf && !strcasecmp(options.listconf, "inc-modes")) { cfg_print_subsections("Incremental", NULL, NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "rules")) { cfg_print_subsections("List.Rules", NULL, NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "externals")) { cfg_print_subsections("List.External", NULL, NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "sections")) { cfg_print_section_names(0); exit(0); } if (options.listconf && !strncasecmp(options.listconf, "parameters", 10) && (options.listconf[10] == '=' || options.listconf[10] == ':') && options.listconf[11] != '\0') { cfg_print_section_params(&options.listconf[11], NULL); exit(0); } if (options.listconf && !strncasecmp(options.listconf, "list-data", 9) && (options.listconf[9] == '=' || options.listconf[9] == ':') && options.listconf[10] != '\0') { cfg_print_section_list_lines(&options.listconf[10], NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters")) { cfg_print_subsections("List.External", "filter", NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters-only")) { cfg_print_subsections("List.External", "filter", "generate", 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-modes")) { cfg_print_subsections("List.External", "generate", NULL, 0); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "formats")) { int column; struct fmt_main *format; int i, dynamics = 0; char **formats_list; i = 0; format = fmt_list; while ((format = format->next)) i++; formats_list = malloc(sizeof(char*) * i); i = 0; format = fmt_list; do { char *label = format->params.label; if (!strncmp(label, "dynamic", 7)) { if (dynamics++) continue; else label = "dynamic_n"; } formats_list[i++] = label; } while ((format = format->next)); formats_list[i] = NULL; column = 0; i = 0; do { int length; char *label = formats_list[i++]; length = strlen(label) + 2; column += length; if (column > 78) { printf("\n"); column = length; } printf("%s%s", label, formats_list[i] ? ", " : "\n"); } while (formats_list[i]); free(formats_list); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "format-details")) { struct fmt_main *format; format = fmt_list; do { int ntests = 0; if(format->params.tests) { while (format->params.tests[ntests++].ciphertext); ntests--; } printf("%s\t%d\t%d\t%d\t%08x\t%d\t%s\t%s\t%s\t%d\t%d\t%d\n", format->params.label, format->params.plaintext_length, format->params.min_keys_per_crypt, format->params.max_keys_per_crypt, format->params.flags, ntests, format->params.algorithm_name, format->params.format_name, format->params.benchmark_comment, format->params.benchmark_length, format->params.binary_size, ((format->params.flags & FMT_DYNAMIC) && format->params.salt_size) ? // salts are handled internally within the format. We want to know the 'real' salt size // dynamic will alway set params.salt_size to 0 or sizeof a pointer. dynamic_real_salt_length(format) : format->params.salt_size); } while ((format = format->next)); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "format-all-details")) { struct fmt_main *format; format = fmt_list; do { int ntests = 0; if(format->params.tests) { while (format->params.tests[ntests++].ciphertext); ntests--; } /* * attributes should be printed in the same sequence * as with format-details, but human-readable */ printf("Format label \t%s\n", format->params.label); printf("Max. password length in bytes \t%d\n", format->params.plaintext_length); printf("Min. keys per crypt \t%d\n", format->params.min_keys_per_crypt); printf("Max. keys per crypt \t%d\n", format->params.max_keys_per_crypt); printf("Flags\n"); printf(" Case sensitive \t%s\n", (format->params.flags & FMT_CASE) ? "yes" : "no"); printf(" Supports 8-bit characters \t%s\n", (format->params.flags & FMT_8_BIT) ? "yes" : "no"); printf(" Converts 8859-1 to UTF-16/UCS-2\t%s\n", (format->params.flags & FMT_UNICODE) ? "yes" : "no"); printf(" Honours --encoding=NAME \t%s\n", (format->params.flags & FMT_UTF8) ? "yes" : "no"); printf(" False positives possible \t%s\n", (format->params.flags & FMT_NOT_EXACT) ? "yes" : "no"); printf(" Uses a bitslice implementation \t%s\n", (format->params.flags & FMT_BS) ? "yes" : "no"); printf(" The split() method unifies case\t%s\n", (format->params.flags & FMT_SPLIT_UNIFIES_CASE) ? "yes" : "no"); printf(" A $dynamic$ format \t%s\n", (format->params.flags & FMT_DYNAMIC) ? "yes" : "no"); #ifdef _OPENMP printf(" Parallelized with OpenMP \t%s\n", (format->params.flags & FMT_OMP) ? "yes" : "no"); #endif printf("Number of test cases for --test \t%d\n", ntests); printf("Algorithm name \t%s\n", format->params.algorithm_name); printf("Format name \t%s\n", format->params.format_name); printf("Benchmark comment \t%s\n", format->params.benchmark_comment); printf("Benchmark length \t%d\n", format->params.benchmark_length); printf("Binary size \t%d\n", format->params.binary_size); printf("Salt size \t%d\n", ((format->params.flags & FMT_DYNAMIC) && format->params.salt_size) ? // salts are handled internally within the format. We want to know the 'real' salt size/ // dynamic will alway set params.salt_size to 0 or sizeof a pointer. dynamic_real_salt_length(format) : format->params.salt_size); printf("\n"); } while ((format = format->next)); exit(0); } if (options.listconf && !strncasecmp(options.listconf, "format-methods", 14)) { struct fmt_main *format; format = fmt_list; do { int ShowIt = 1, i; if (options.listconf[14] == '=' || options.listconf[14] == ':') { ShowIt = 0; if (!strcasecmp(&options.listconf[15], "set_key") || !strcasecmp(&options.listconf[15], "get_key") || !strcasecmp(&options.listconf[15], "crypt_all") || !strcasecmp(&options.listconf[15], "cmp_all") || !strcasecmp(&options.listconf[15], "cmp_one") || !strcasecmp(&options.listconf[15], "cmp_exact")) ShowIt = 1; else if (strcasecmp(&options.listconf[15], "init") && strcasecmp(&options.listconf[15], "prepare") && strcasecmp(&options.listconf[15], "valid") && strcasecmp(&options.listconf[15], "split") && strcasecmp(&options.listconf[15], "binary") && strcasecmp(&options.listconf[15], "clear_keys") && strcasecmp(&options.listconf[15], "salt") && strcasecmp(&options.listconf[15], "get_hash") && strcasecmp(&options.listconf[15], "get_hash[0]") && strcasecmp(&options.listconf[15], "get_hash[1]") && strcasecmp(&options.listconf[15], "get_hash[2]") && strcasecmp(&options.listconf[15], "get_hash[3]") && strcasecmp(&options.listconf[15], "get_hash[4]") && strcasecmp(&options.listconf[15], "get_hash[5]") && strcasecmp(&options.listconf[15], "set_salt") && strcasecmp(&options.listconf[15], "binary_hash") && strcasecmp(&options.listconf[15], "binary_hash[0]") && strcasecmp(&options.listconf[15], "binary_hash[1]") && strcasecmp(&options.listconf[15], "binary_hash[2]") && strcasecmp(&options.listconf[15], "binary_hash[3]") && strcasecmp(&options.listconf[15], "binary_hash[3]") && strcasecmp(&options.listconf[15], "binary_hash[5]") && strcasecmp(&options.listconf[15], "salt_hash")) { fprintf(stderr, "Error, invalid option (invalid method name) %s\n", options.listconf); fprintf(stderr, "Valid method names are:\n"); john_list_method_names(); exit(1); } if (format->methods.init != fmt_default_init && !strcasecmp(&options.listconf[15], "init")) ShowIt = 1; if (format->methods.prepare != fmt_default_prepare && !strcasecmp(&options.listconf[15], "prepare")) ShowIt = 1; if (format->methods.valid != fmt_default_valid && !strcasecmp(&options.listconf[15], "valid")) ShowIt = 1; if (format->methods.split != fmt_default_split && !strcasecmp(&options.listconf[15], "split")) ShowIt = 1; if (format->methods.binary != fmt_default_binary && !strcasecmp(&options.listconf[15], "binary")) ShowIt = 1; if (format->methods.salt != fmt_default_salt && !strcasecmp(&options.listconf[15], "salt")) ShowIt = 1; if (format->methods.clear_keys != fmt_default_clear_keys && !strcasecmp(&options.listconf[15], "clear_keys")) ShowIt = 1; for (i = 0; i < 6; ++i) { char Buf[20]; sprintf(Buf, "get_hash[%d]", i); if (format->methods.get_hash[i] && format->methods.get_hash[i] != fmt_default_get_hash && !strcasecmp(&options.listconf[15], Buf)) ShowIt = 1; } if (format->methods.get_hash[0] && format->methods.get_hash[0] != fmt_default_get_hash && !strcasecmp(&options.listconf[15], "get_hash")) ShowIt = 1; for (i = 0; i < 6; ++i) { char Buf[20]; sprintf(Buf, "binary_hash[%d]", i); if (format->methods.binary_hash[i] && format->methods.binary_hash[i] != fmt_default_binary_hash && !strcasecmp(&options.listconf[15], Buf)) ShowIt = 1; } if (format->methods.binary_hash[0] && format->methods.binary_hash[0] != fmt_default_binary_hash && !strcasecmp(&options.listconf[15], "binary_hash")) ShowIt = 1; if (format->methods.salt_hash != fmt_default_salt_hash && !strcasecmp(&options.listconf[15], "salt_hash")) ShowIt = 1; if (format->methods.set_salt != fmt_default_set_salt && !strcasecmp(&options.listconf[15], "set_salt")) ShowIt = 1; } if (ShowIt) { int i; printf("Methods overridden for: %s [%s] %s\n", format->params.label, format->params.algorithm_name, format->params.format_name); if (format->methods.init != fmt_default_init) printf("\tinit()\n"); if (format->methods.prepare != fmt_default_prepare) printf("\tprepare()\n"); if (format->methods.valid != fmt_default_valid) printf("\tvalid()\n"); if (format->methods.split != fmt_default_split) printf("\tsplit()\n"); if (format->methods.binary != fmt_default_binary) printf("\tbinary()\n"); if (format->methods.salt != fmt_default_salt) printf("\tsalt()\n"); for (i = 0; i < 6; ++i) if (format->methods.binary_hash[i] != fmt_default_binary_hash) { if (format->methods.binary_hash[i]) printf("\t\tbinary_hash[%d]()\n", i); else printf("\t\tbinary_hash[%d]() (NULL pointer)\n", i); } if (format->methods.salt_hash != fmt_default_salt_hash) printf("\tsalt_hash()\n"); if (format->methods.set_salt != fmt_default_set_salt) printf("\tset_salt()\n"); // there is no default for set_key() it must be defined. printf("\tset_key()\n"); // there is no default for get_key() it must be defined. printf("\tget_key()\n"); if (format->methods.clear_keys != fmt_default_clear_keys) printf("\tclear_keys()\n"); for (i = 0; i < 6; ++i) if (format->methods.get_hash[i] != fmt_default_get_hash) { if (format->methods.get_hash[i]) printf("\t\tget_hash[%d]()\n", i); else printf("\t\tget_hash[%d]() (NULL pointer)\n", i); } // there is no default for crypt_all() it must be defined. printf("\tcrypt_all()\n"); // there is no default for cmp_all() it must be defined. printf("\tcmp_all()\n"); // there is no default for cmp_one() it must be defined. printf("\tcmp_one()\n"); // there is no default for cmp_exact() it must be defined. printf("\tcmp_exact()\n"); printf("\n\n"); } } while ((format = format->next)); exit(0); } /* * Other --list=help:WHAT are processed earlier, but these require * a valid config: */ if (options.listconf && !strcasecmp(options.listconf, "help:parameters")) { cfg_print_section_names(1); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "help:list-data")) { cfg_print_section_names(2); exit(0); } /* --list last resort: list subsections of any john.conf section name */ if (options.listconf) { //printf("Subsections of [%s]:\n", options.listconf); if (cfg_print_subsections(options.listconf, NULL, NULL, 1)) exit(0); else { fprintf(stderr, "Section [%s] not found.\n", options.listconf); /* Just in case the user specified an invalid value * like help or list... * print the same list as with --list=?, but exit(1) */ john_list_options(); exit(1); } } #ifdef CL_VERSION_1_0 if (!options.ocl_platform) { if ((options.ocl_platform = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Platform"))) platform_id = atoi(options.ocl_platform); else platform_id = -1; } if (!options.gpu_device) { if ((options.gpu_device = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Device"))) ocl_gpu_id = atoi(options.gpu_device); else ocl_gpu_id = -1; } if (platform_id == -1 || ocl_gpu_id == -1) opencl_find_gpu(&ocl_gpu_id, &platform_id); #endif common_init(); sig_init(); john_load(); if (options.encodingStr && options.encodingStr[0]) log_event("- %s input encoding enabled", options.encodingStr); }
static void init(struct fmt_main *self) { char *temp; cl_ulong maxsize, maxsize2; char build_opts[64]; global_work_size = 0; snprintf(build_opts, sizeof(build_opts), "-DHASH_LOOPS=%u -DUNICODE_LENGTH=%u %s", HASH_LOOPS, UNICODE_LENGTH, (options.flags & FLG_VECTORIZE) ? "-DVECTORIZE" : (options.flags & FLG_SCALAR) ? "-DSCALAR" : ""); opencl_init_opt("$JOHN/office2007_kernel.cl", ocl_gpu_id, platform_id, build_opts); // create kernel to execute GenerateSHA1pwhash = clCreateKernel(program[ocl_gpu_id], "GenerateSHA1pwhash", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?"); crypt_kernel = clCreateKernel(program[ocl_gpu_id], "HashLoop", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?"); Generate2007key = clCreateKernel(program[ocl_gpu_id], "Generate2007key", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?"); if (options.flags & FLG_VECTORIZE) { /* Run vectorized code */ VF = 4; self->params.algorithm_name = "OpenCL 4x"; } if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, LWS_CONFIG))) local_work_size = atoi(temp); if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, GWS_CONFIG))) global_work_size = atoi(temp); if ((temp = getenv("LWS"))) local_work_size = atoi(temp); if ((temp = getenv("GWS"))) global_work_size = atoi(temp); /* Note: we ask for the kernels' max sizes, not the device's! */ HANDLE_CLERROR(clGetKernelWorkGroupInfo(GenerateSHA1pwhash, devices[ocl_gpu_id], CL_KERNEL_WORK_GROUP_SIZE, sizeof(maxsize), &maxsize, NULL), "Query max work group size"); HANDLE_CLERROR(clGetKernelWorkGroupInfo(crypt_kernel, devices[ocl_gpu_id], CL_KERNEL_WORK_GROUP_SIZE, sizeof(maxsize2), &maxsize2, NULL), "Query max work group size"); if (maxsize2 < maxsize) maxsize = maxsize2; HANDLE_CLERROR(clGetKernelWorkGroupInfo(Generate2007key, devices[ocl_gpu_id], CL_KERNEL_WORK_GROUP_SIZE, sizeof(maxsize2), &maxsize2, NULL), "Query max work group size"); if (maxsize2 < maxsize) maxsize = maxsize2; #if 0 /* Our use of local memory sets a limit for LWS */ maxsize2 = get_local_memory_size(ocl_gpu_id) / (24 * VF); while (maxsize > maxsize2) maxsize >>= 1; #endif /* maxsize is the lowest figure from the three different kernels */ if (!local_work_size) { if (getenv("LWS")) { /* LWS was explicitly set to 0 */ int temp = global_work_size; local_work_size = maxsize; global_work_size = global_work_size ? global_work_size : 4 * maxsize; create_clobj(global_work_size, self); opencl_find_best_workgroup_limit(self, maxsize); release_clobj(); global_work_size = temp; } else { if (cpu(device_info[ocl_gpu_id])) { if (get_platform_vendor_id(platform_id) == DEV_INTEL) local_work_size = MIN(maxsize, 8); else local_work_size = 1; } else local_work_size = MIN(maxsize, 64); } } if (local_work_size > maxsize) { fprintf(stderr, "LWS %d is too large for this GPU. Max allowed is %d, using that.\n", (int)local_work_size, (int)maxsize); local_work_size = maxsize; } if (!global_work_size) find_best_gws(getenv("GWS") == NULL ? 0 : 1, self); if (global_work_size < local_work_size) global_work_size = local_work_size; fprintf(stderr, "Local worksize (LWS) %d, Global worksize (GWS) %d\n", (int)local_work_size, (int)global_work_size); create_clobj(global_work_size, self); atexit(release_clobj); if (options.utf8) self->params.plaintext_length = MIN(125, 3 * PLAINTEXT_LENGTH); }
static void john_load_conf(void) { int internal, target; if (!(options.flags & FLG_VERBOSITY)) { options.verbosity = cfg_get_int(SECTION_OPTIONS, NULL, "Verbosity"); if (options.verbosity == -1) options.verbosity = 3; if (options.verbosity < 1 || options.verbosity > 5) { if (john_main_process) fprintf(stderr, "Invalid verbosity " "level in config file, use 1-5\n"); error(); } } if (pers_opts.activepot == NULL) { if (options.secure) pers_opts.activepot = str_alloc_copy(SEC_POT_NAME); else pers_opts.activepot = str_alloc_copy(POT_NAME); } if (pers_opts.activewordlistrules == NULL) if (!(pers_opts.activewordlistrules = cfg_get_param(SECTION_OPTIONS, NULL, "BatchModeWordlistRules"))) pers_opts.activewordlistrules = str_alloc_copy(SUBSECTION_WORDLIST); if (pers_opts.activesinglerules == NULL) if (!(pers_opts.activesinglerules = cfg_get_param(SECTION_OPTIONS, NULL, "SingleRules"))) pers_opts.activesinglerules = str_alloc_copy(SUBSECTION_SINGLE); if ((options.flags & FLG_LOOPBACK_CHK) && !(options.flags & FLG_RULES)) { if ((pers_opts.activewordlistrules = cfg_get_param(SECTION_OPTIONS, NULL, "LoopbackRules"))) options.flags |= FLG_RULES; } if ((options.flags & FLG_WORDLIST_CHK) && !(options.flags & FLG_RULES)) { if ((pers_opts.activewordlistrules = cfg_get_param(SECTION_OPTIONS, NULL, "WordlistRules"))) options.flags |= FLG_RULES; } options.secure = cfg_get_bool(SECTION_OPTIONS, NULL, "SecureMode", 0); options.reload_at_crack = cfg_get_bool(SECTION_OPTIONS, NULL, "ReloadAtCrack", 1); options.reload_at_save = cfg_get_bool(SECTION_OPTIONS, NULL, "ReloadAtSave", 1); options.abort_file = cfg_get_param(SECTION_OPTIONS, NULL, "AbortFile"); options.pause_file = cfg_get_param(SECTION_OPTIONS, NULL, "PauseFile"); /* This is --crack-status. We toggle here, so if it's enabled in john.conf, we can disable it using the command line option */ if (cfg_get_bool(SECTION_OPTIONS, NULL, "CrackStatus", 0)) options.flags ^= FLG_CRKSTAT; #if HAVE_OPENCL if (cfg_get_bool(SECTION_OPTIONS, SUBSECTION_OPENCL, "ForceScalar", 0)) options.flags |= FLG_SCALAR; #endif options.loader.log_passwords = options.secure || cfg_get_bool(SECTION_OPTIONS, NULL, "LogCrackedPasswords", 0); if (!pers_opts.input_enc && !(options.flags & FLG_TEST_CHK)) { if ((options.flags & FLG_LOOPBACK_CHK) && cfg_get_bool(SECTION_OPTIONS, NULL, "UnicodeStoreUTF8", 0)) pers_opts.input_enc = cp_name2id("UTF-8"); else { pers_opts.input_enc = cp_name2id(cfg_get_param(SECTION_OPTIONS, NULL, "DefaultEncoding")); } pers_opts.default_enc = pers_opts.input_enc; } /* Pre-init in case some format's prepare() needs it */ internal = pers_opts.internal_enc; target = pers_opts.target_enc; initUnicode(UNICODE_UNICODE); pers_opts.internal_enc = internal; pers_opts.target_enc = target; pers_opts.unicode_cp = CP_UNDEF; }
static void john_load_conf_db(void) { if (options.flags & FLG_STDOUT) { /* john.conf alternative for --internal-encoding */ if (!pers_opts.internal_enc && pers_opts.target_enc == UTF_8 && options.flags & (FLG_RULES | FLG_SINGLE_CHK | FLG_BATCH_CHK | FLG_MASK_CHK)) if (!(pers_opts.internal_enc = cp_name2id(cfg_get_param(SECTION_OPTIONS, NULL, "DefaultInternalEncoding")))) /* Deprecated alternative */ pers_opts.internal_enc = cp_name2id(cfg_get_param(SECTION_OPTIONS, NULL, "DefaultIntermediateEncoding")); } if (!pers_opts.unicode_cp) initUnicode(UNICODE_UNICODE); pers_opts.report_utf8 = cfg_get_bool(SECTION_OPTIONS, NULL, "AlwaysReportUTF8", 0); /* Unicode (UTF-16) formats may lack encoding support. We must stop the user from trying to use it because it will just result in false negatives. */ if (database.format && pers_opts.target_enc != ASCII && pers_opts.target_enc != ISO_8859_1 && database.format->params.flags & FMT_UNICODE && !(database.format->params.flags & FMT_UTF8)) { if (john_main_process) fprintf(stderr, "This format does not yet support" " other encodings than ISO-8859-1\n"); error(); } if (database.format && database.format->params.flags & FMT_UNICODE) pers_opts.store_utf8 = cfg_get_bool(SECTION_OPTIONS, NULL, "UnicodeStoreUTF8", 0); else pers_opts.store_utf8 = cfg_get_bool(SECTION_OPTIONS, NULL, "CPstoreUTF8", 0); if (!options.secure) { if (pers_opts.report_utf8 && options.loader.log_passwords) log_event("- Passwords in this logfile are " "UTF-8 encoded"); if (pers_opts.store_utf8) log_event("- Passwords will be stored UTF-8 " "encoded in .pot file"); } if (pers_opts.target_enc != pers_opts.input_enc && pers_opts.input_enc != UTF_8) { if (john_main_process) fprintf(stderr, "Target encoding can only be specified" " if input encoding is UTF-8\n"); exit(0); } if (!(options.flags & FLG_SHOW_CHK) && !options.loader.showuncracked) if (options.flags & (FLG_PASSWD | FLG_STDIN_CHK)) if (pers_opts.default_enc && john_main_process && pers_opts.input_enc != ASCII) fprintf(stderr, "Using default input encoding: %s\n", cp_id2name(pers_opts.input_enc)); if (!(options.flags & FLG_SHOW_CHK) && !options.loader.showuncracked) if (pers_opts.target_enc != pers_opts.input_enc && (!database.format || !(database.format->params.flags & FMT_UNICODE))) { log_event("- Target encoding: %s", cp_id2name(pers_opts.target_enc)); if (john_main_process) { if (pers_opts.default_target_enc) fprintf(stderr, "Using default target " "encoding: %s\n", cp_id2name(pers_opts.target_enc)); else fprintf(stderr, "Target encoding: %s\n", cp_id2name(pers_opts.target_enc)); } } if (!(options.flags & FLG_SHOW_CHK) && !options.loader.showuncracked) if (pers_opts.input_enc != pers_opts.internal_enc) { log_event("- Rules/masks using %s", cp_id2name(pers_opts.internal_enc)); if (john_main_process && (database.format->params.flags & FMT_UNICODE)) fprintf(stderr, "Rules/masks using %s\n", cp_id2name(pers_opts.internal_enc)); } }
static void find_best_gws(int do_benchmark) { int num; cl_ulong run_time, min_time = CL_ULONG_MAX; unsigned int SHAspeed, bestSHAspeed = 0; int optimal_gws = local_work_size; const int sha1perkey = (strlen(rar_fmt.params.tests[0].plaintext) * 2 + 8 + 3) * 0x40000 / 64 + 16; char *conf; unsigned long long int MaxRunTime = 5000000000ULL; if ((conf = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "rar_MaxDuration"))) MaxRunTime = atoi(conf) * 1000000000UL; #ifndef DEBUG if (do_benchmark) #endif { fprintf(stderr, "Calculating best keys per crypt (GWS) for LWS=%zd and max. %llu s duration.\n\n", local_work_size, MaxRunTime / 1000000000UL); fprintf(stderr, "Raw GPU speed figures including buffer transfers:\n"); } for (num = local_work_size; num; num *= 2) { if (!(run_time = gws_test(num))) break; SHAspeed = sha1perkey * (1000000000UL * num * VF / run_time); if (run_time < min_time) min_time = run_time; #ifndef DEBUG if (do_benchmark) #endif fprintf(stderr, "gws %6d\t%4llu c/s%14u sha1/s%8.3f sec per crypt_all()", num, (1000000000ULL * num * VF / run_time), SHAspeed, (float)run_time / 1000000000.); if (((float)run_time / (float)min_time) < ((float)SHAspeed / (float)bestSHAspeed)) { #ifndef DEBUG if (do_benchmark) #endif fprintf(stderr, "!\n"); bestSHAspeed = SHAspeed; optimal_gws = num; } else { if (run_time > MaxRunTime) { #ifndef DEBUG if (do_benchmark) #endif fprintf(stderr, "\n"); break; } if (SHAspeed > bestSHAspeed) { #ifndef DEBUG if (do_benchmark) #endif fprintf(stderr, "+"); bestSHAspeed = SHAspeed; optimal_gws = num; } #ifndef DEBUG if (do_benchmark) #endif fprintf(stderr, "\n"); } } if (get_device_type(ocl_gpu_id) != CL_DEVICE_TYPE_CPU) { fprintf(stderr, "Optimal keys per crypt %d\n",(int)optimal_gws); fprintf(stderr, "(to avoid this test on next run, put \"" GWS_CONFIG " = %d\" in john.conf, section [" SECTION_OPTIONS SUBSECTION_OPENCL "])\n", (int)optimal_gws); } *mkpc = VF * (global_work_size = optimal_gws); }
void do_incremental_crack(struct db_main *db, char *mode) { char *charset; int min_length, max_length, max_count; char *extra; FILE *file; struct charset_header *header; unsigned int check; char allchars[CHARSET_SIZE + 1]; char char1[CHARSET_SIZE + 1]; char2_table char2; chars_table chars[CHARSET_LENGTH - 2]; unsigned char *ptr; unsigned int length, fixed, count; unsigned int real_count; int last_length, last_count; int pos; if (!mode) { if (db->format == &fmt_LM) mode = "LanMan"; else if (db->format == &fmt_NETLM) mode = "LanMan"; else if (db->format == &fmt_NETHALFLM) mode = "LanMan"; else mode = "All"; } log_event("Proceeding with \"incremental\" mode: %.100s", mode); if (!(charset = cfg_get_param(SECTION_INC, mode, "File"))) { log_event("! No charset defined"); fprintf(stderr, "No charset defined for mode: %s\n", mode); error(); } extra = cfg_get_param(SECTION_INC, mode, "Extra"); if ((min_length = cfg_get_int(SECTION_INC, mode, "MinLen")) < 0) min_length = 0; if ((max_length = cfg_get_int(SECTION_INC, mode, "MaxLen")) < 0) max_length = CHARSET_LENGTH; max_count = cfg_get_int(SECTION_INC, mode, "CharCount"); if (min_length > max_length) { log_event("! MinLen = %d exceeds MaxLen = %d", min_length, max_length); fprintf(stderr, "MinLen = %d exceeds MaxLen = %d\n", min_length, max_length); error(); } if (min_length > db->format->params.plaintext_length) { log_event("! MinLen = %d is too large for this hash type", min_length); fprintf(stderr, "MinLen = %d exceeds the maximum possible " "length for the current hash type (%d)\n", min_length, db->format->params.plaintext_length); error(); } if (max_length > db->format->params.plaintext_length) { log_event("! MaxLen = %d is too large for this hash type", max_length); fprintf(stderr, "Warning: " "MaxLen = %d is too large for the current hash type, " "reduced to %d\n", max_length, db->format->params.plaintext_length); max_length = db->format->params.plaintext_length; } if (max_length > CHARSET_LENGTH) { log_event("! MaxLen = %d exceeds the compile-time limit of %d", max_length, CHARSET_LENGTH); fprintf(stderr, "\n" "MaxLen = %d exceeds the compile-time limit of %d\n\n" "There are several good reasons why you probably don't " "need to raise it:\n" "- many hash types don't support passwords " "(or password halves) longer than\n" "7 or 8 characters;\n" "- you probably don't have sufficient statistical " "information to generate a\n" "charset file for lengths beyond 8;\n" "- the limitation applies to incremental mode only.\n", max_length, CHARSET_LENGTH); error(); } if (!(file = fopen(path_expand(charset), "rb"))) pexit("fopen: %s", path_expand(charset)); header = (struct charset_header *)mem_alloc(sizeof(*header)); charset_read_header(file, header); if (ferror(file)) pexit("fread"); if (feof(file) || (memcmp(header->version, CHARSET_V1, sizeof(header->version)) && memcmp(header->version, CHARSET_V2, sizeof(header->version))) || !header->count) inc_format_error(charset); if (header->min != CHARSET_MIN || header->max != CHARSET_MAX || header->length != CHARSET_LENGTH) { log_event("! Incompatible charset file: %.100s", charset); fprintf(stderr, "Incompatible charset file: %s\n", charset); error(); } if (header->count > CHARSET_SIZE) inc_format_error(charset); check = (unsigned int)header->check[0] | ((unsigned int)header->check[1] << 8) | ((unsigned int)header->check[2] << 16) | ((unsigned int)header->check[3] << 24); if (!rec_restoring_now) rec_check = check; if (rec_check != check) { log_event("! Charset file has changed: %.100s", charset); fprintf(stderr, "Charset file has changed: %s\n", charset); error(); } fread(allchars, header->count, 1, file); if (ferror(file)) pexit("fread"); if (feof(file)) inc_format_error(charset); allchars[header->count] = 0; if (expand(allchars, extra ? extra : "", sizeof(allchars))) inc_format_error(charset); real_count = strlen(allchars); if (max_count < 0) max_count = CHARSET_SIZE; if (min_length != max_length) log_event("- Lengths %d to %d, up to %d different characters", min_length, max_length, max_count); else log_event("- Length %d, up to %d different characters", min_length, max_count); if ((unsigned int)max_count > real_count) { log_event("! Only %u characters available", real_count); fprintf(stderr, "Warning: only %u characters available\n", real_count); } if (!(db->format->params.flags & FMT_CASE)) switch (is_mixedcase(allchars)) { case -1: inc_format_error(charset); case 1: log_event("! Mixed-case charset, " "but the hash type is case-insensitive"); fprintf(stderr, "Warning: mixed-case charset, " "but the current hash type is case-insensitive;\n" "some candidate passwords may be unnecessarily " "tried more than once.\n"); } if (header->length >= 2) char2 = (char2_table)mem_alloc(sizeof(*char2)); else char2 = NULL; for (pos = 0; pos < (int)header->length - 2; pos++) chars[pos] = (chars_table)mem_alloc(sizeof(*chars[0])); rec_compat = 0; rec_entry = 0; memset(rec_numbers, 0, sizeof(rec_numbers)); status_init(NULL, 0); rec_restore_mode(restore_state); #ifdef WEBAPI if(packet_id) { int ret; // This is a new packet inc_rec_state.initialized = 0; inc_rec_state.words_requested = packet_rounds; inc_rec_state.words_generated = 0; inc_rec_state.cc_0 = -1; inc_rec_state.cc_1 = -1; inc_rec_state.cc_2 = -1; ret = sscanf(packet_state, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%127[^\n]", &rec_entry, &rec_numbers[0], &rec_numbers[1], &rec_numbers[2], &rec_numbers[3], &rec_numbers[4], &rec_numbers[5], &rec_numbers[6], &rec_numbers[7], &inc_rec_state.pos, &inc_rec_state.numbers_cache, &inc_rec_state.cc_0, &inc_rec_state.cc_1, &inc_rec_state.cc_2, inc_rec_state.key_i); if(ret < 14 || ret > 15) { log_event("Invalid packet state, found %d fields in %s", ret, packet_state); // XXX - Handle more gracefully.. error(); } status_init(webapi_inc_get_progress, 0); } #endif rec_init(db, save_state); ptr = header->order + (entry = rec_entry) * 3; memcpy(numbers, rec_numbers, sizeof(numbers)); crk_init(db, fix_state, NULL); last_count = last_length = -1; entry--; while (ptr < &header->order[sizeof(header->order) - 1]) { entry++; length = *ptr++; fixed = *ptr++; count = *ptr++; if (length >= CHARSET_LENGTH || fixed > length || count >= CHARSET_SIZE) inc_format_error(charset); if (entry != rec_entry) memset(numbers, 0, sizeof(numbers)); if (count >= real_count || (fixed && !count)) continue; if ((int)length + 1 < min_length || (int)length >= max_length || (int)count >= max_count) continue; if ((int)length != last_length) { inc_new_length(last_length = length, header, file, charset, char1, char2, chars); last_count = -1; } if ((int)count > last_count) inc_new_count(length, last_count = count, charset, allchars, char1, char2, chars); if (!length && !min_length) { min_length = 1; if (crk_process_key("")) break; } #if 0 log_event("- Trying length %d, fixed @%d, character count %d", length + 1, fixed + 1, count + 1); #endif if (inc_key_loop(length, fixed, count, char1, char2, chars)) break; } crk_done(); rec_done(event_abort); for (pos = 0; pos < (int)header->length - 2; pos++) MEM_FREE(chars[pos]); MEM_FREE(char2); MEM_FREE(header); fclose(file); }
/* ------- Initialization ------- */ static void init(struct fmt_main * self) { char * tmp_value; char * task = "$JOHN/sha256_kernel.cl"; opencl_init_dev(ocl_gpu_id, platform_id); source_in_use = device_info[ocl_gpu_id]; if ((tmp_value = getenv("_TYPE"))) source_in_use = atoi(tmp_value); opencl_build_kernel(task, ocl_gpu_id); // create kernel(s) to execute crypt_kernel = clCreateKernel(program[ocl_gpu_id], "kernel_crypt", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?"); cmp_kernel = clCreateKernel(program[ocl_gpu_id], "kernel_cmp", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel_cmp. Double-check kernel name?"); global_work_size = get_task_max_size(); local_work_size = 0; if (source_in_use != device_info[ocl_gpu_id]) { device_info[ocl_gpu_id] = source_in_use; fprintf(stderr, "Selected runtime id %d, source (%s)\n", source_in_use, task); } if ((tmp_value = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, LWS_CONFIG))) local_work_size = atoi(tmp_value); if ((tmp_value = getenv("LWS"))) local_work_size = atoi(tmp_value); //Check if local_work_size is a valid number. if (local_work_size > get_task_max_work_group_size()){ fprintf(stderr, "Error: invalid local work size (LWS). Max value allowed is: %zd\n" , get_task_max_work_group_size()); local_work_size = 0; //Force find a valid number. } self->params.max_keys_per_crypt = global_work_size; if (!local_work_size) { local_work_size = get_task_max_work_group_size(); create_clobj(global_work_size, self); find_best_workgroup(self); release_clobj(); } if ((tmp_value = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, GWS_CONFIG))) global_work_size = atoi(tmp_value); if ((tmp_value = getenv("GWS"))) global_work_size = atoi(tmp_value); //Check if a valid multiple is used. global_work_size = get_multiple(global_work_size, local_work_size); if (global_work_size) create_clobj(global_work_size, self); else { //user chose to die of boredom global_work_size = get_task_max_size(); find_best_gws(self); } fprintf(stderr, "Local work size (LWS) %d, global work size (GWS) %zd\n", (int) local_work_size, global_work_size); self->params.max_keys_per_crypt = global_work_size; }
/* -- This function could be used to calculated the best num of keys per crypt for the given format -- */ static void find_best_gws(struct fmt_main * self) { size_t num = 0; cl_ulong run_time, min_time = CL_ULONG_MAX; int optimal_gws = local_work_size, step = STEP; int do_benchmark = 0; unsigned int SHAspeed, bestSHAspeed = 0; unsigned long long int max_run_time = 1000000000ULL; char *tmp_value; if ((tmp_value = getenv("STEP"))){ step = atoi(tmp_value); do_benchmark = 1; } step = get_multiple(step, local_work_size); if ((tmp_value = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, DUR_CONFIG))) max_run_time = atoi(tmp_value) * 1000000000UL; fprintf(stderr, "Calculating best global work size (GWS) for LWS=%zd and max. %llu s duration.\n\n", local_work_size, max_run_time / 1000000000ULL); if (do_benchmark) fprintf(stderr, "Raw speed figures including buffer transfers:\n"); for (num = get_step(num, step, 1); num; num = get_step(num, step, 0)) { //Check if hardware can handle the size we are going to try now. if (sizeof(sha256_password) * num * 1.2 > get_max_mem_alloc_size(ocl_gpu_id)) break; if (! (run_time = gws_test(num, self))) continue; if (!do_benchmark) advance_cursor(); SHAspeed = num / (run_time / 1000000000.); if (run_time < min_time) min_time = run_time; if (do_benchmark) { fprintf(stderr, "gws: %8zu\t%12lu c/s %8.3f ms per crypt_all()", num, (long) (num / (run_time / 1000000000.)), (float) run_time / 1000000.); if (run_time > max_run_time) { fprintf(stderr, " - too slow\n"); break; } } else { if (run_time > min_time * 20 || run_time > max_run_time) break; } if (((long) SHAspeed - bestSHAspeed) > 10000) { if (do_benchmark) fprintf(stderr, "+"); bestSHAspeed = SHAspeed; optimal_gws = num; } if (do_benchmark) fprintf(stderr, "\n"); } fprintf(stderr, "Optimal global work size %d\n", optimal_gws); fprintf(stderr, "(to avoid this test on next run, put \"" GWS_CONFIG " = %d\" in john.conf, section [" SECTION_OPTIONS SUBSECTION_OPENCL "])\n", optimal_gws); global_work_size = optimal_gws; create_clobj(optimal_gws, self); }
static void john_init(char *name, int argc, char **argv) { int make_check = (argc == 2 && !strcmp(argv[1], "--make_check")); if (make_check) argv[1] = "--test=0"; CPU_detect_or_fallback(argv, make_check); status_init(NULL, 1); if (argc < 2) john_register_all(); /* for printing by opt_init() */ opt_init(name, argc, argv); if (options.listconf && !strcasecmp(options.listconf, "?")) { puts("inc-modes, rules, externals, ext-filters, ext-filters-only,"); puts("ext-modes, build-info, hidden-options, <conf section name>"); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "hidden-options")) { puts("--list=NAME list configuration, rules, etc"); puts("--mkpc=N force a lower max. keys per crypt"); exit(0); } if (!make_check) { #if defined(_OPENMP) && OMP_FALLBACK #if defined(__DJGPP__) || defined(__CYGWIN32__) #error OMP_FALLBACK is incompatible with the current DOS and Win32 code #endif if (!getenv("JOHN_NO_OMP_FALLBACK") && omp_get_max_threads() <= 1) { #define OMP_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" OMP_FALLBACK_BINARY execv(OMP_FALLBACK_PATHNAME, argv); perror("execv: " OMP_FALLBACK_PATHNAME); } #endif path_init(argv); if (options.listconf && !strcasecmp(options.listconf, "build-info")) { puts("Version: " JOHN_VERSION); puts("Build: " JOHN_BLD _MP_VERSION); printf("Arch: %d-bit %s\n", ARCH_BITS, ARCH_LITTLE_ENDIAN ? "LE" : "BE"); #if JOHN_SYSTEMWIDE puts("System-wide exec: " JOHN_SYSTEMWIDE_EXEC); puts("System-wide home: " JOHN_SYSTEMWIDE_HOME); puts("Private home: " JOHN_PRIVATE_HOME); #endif printf("$JOHN is %s\n", path_expand("$JOHN/")); puts("Rec file version: " RECOVERY_V); printf("CHARSET_MIN: %d (0x%02x)\n", CHARSET_MIN, CHARSET_MIN); printf("CHARSET_MAX: %d (0x%02x)\n", CHARSET_MAX, CHARSET_MAX); printf("CHARSET_LENGTH: %d\n", CHARSET_LENGTH); #ifdef __GNUC__ printf("gcc version: %d.%d.%d\n", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); #endif #ifdef __ICC printf("icc version: %d\n", __ICC); #endif exit(0); } if (options.flags & FLG_CONFIG_CLI) { path_init_ex(options.config); cfg_init(options.config, 1); cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } else { #if JOHN_SYSTEMWIDE cfg_init(CFG_PRIVATE_FULL_NAME, 1); cfg_init(CFG_PRIVATE_ALT_NAME, 1); #endif cfg_init(CFG_FULL_NAME, 1); cfg_init(CFG_ALT_NAME, 0); } } if (options.subformat && !strcasecmp(options.subformat, "list")) { dynamic_DISPLAY_ALL_FORMATS(); /* NOTE if we have other 'generics', like sha1, sha2, rc4, ... * then EACH of them should have a DISPLAY_ALL_FORMATS() * function and we can call them here. */ exit(0); } if (options.listconf && !strcasecmp(options.listconf, "inc-modes")) { cfg_print_subsections("Incremental", NULL, NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "rules")) { cfg_print_subsections("List.Rules", NULL, NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "externals")) { cfg_print_subsections("List.External", NULL, NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters")) { cfg_print_subsections("List.External", "filter", NULL); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-filters-only")) { cfg_print_subsections("List.External", "filter", "generate"); exit(0); } if (options.listconf && !strcasecmp(options.listconf, "ext-modes")) { cfg_print_subsections("List.External", "generate", NULL); exit(0); } /* Catch-all for any other john.conf section name :-) */ if (options.listconf) { cfg_print_subsections(options.listconf, NULL, NULL); exit(0); } initUnicode(UNICODE_UNICODE); /* Init the unicode system */ john_register_all(); /* maybe restricted to one format by options */ common_init(); sig_init(); john_load(); if (options.encodingStr && options.encodingStr[0]) log_event("- %s input encoding enabled", options.encodingStr); #ifdef CL_VERSION_1_0 if (!options.ocl_platform) if ((options.ocl_platform = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Platform"))) platform_id = atoi(options.ocl_platform); if (!options.ocl_device) if ((options.ocl_device = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Device"))) gpu_id = atoi(options.ocl_device); #endif }
/* ------- Initialization ------- */ static void init(struct fmt_main * self) { char * tmp_value; char * task = "$JOHN/cryptsha512_kernel_DEFAULT.cl"; uint64_t startTime, runtime; opencl_init_dev(ocl_gpu_id, platform_id); startTime = (unsigned long) time(NULL); source_in_use = device_info[ocl_gpu_id]; if ((tmp_value = getenv("_TYPE"))) source_in_use = atoi(tmp_value); if ((tmp_value = getenv("_FAST"))) fast_mode = TRUE; if (use_local(source_in_use)) task = "$JOHN/cryptsha512_kernel_LOCAL.cl"; else if (gpu(source_in_use)) { fprintf(stderr, "Building the kernel, this could take a while\n"); task = "$JOHN/cryptsha512_kernel_GPU.cl"; } fflush(stdout); opencl_build_kernel(task, ocl_gpu_id); if ((runtime = (unsigned long) (time(NULL) - startTime)) > 2UL) fprintf(stderr, "Elapsed time: %lu seconds\n", runtime); fflush(stdout); // create kernel(s) to execute crypt_kernel = clCreateKernel(program[ocl_gpu_id], "kernel_crypt", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?"); if (gpu(source_in_use) || use_local(source_in_use)) { prepare_kernel = clCreateKernel(program[ocl_gpu_id], "kernel_prepare", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel_prepare. Double-check kernel name?"); final_kernel = clCreateKernel(program[ocl_gpu_id], "kernel_final", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel_final. Double-check kernel name?"); } global_work_size = get_task_max_size(); local_work_size = get_default_workgroup(); if (source_in_use != device_info[ocl_gpu_id]) fprintf(stderr, "Selected runtime id %d, source (%s)\n", source_in_use, task); if ((tmp_value = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, LWS_CONFIG))) local_work_size = atoi(tmp_value); if ((tmp_value = getenv("LWS"))) local_work_size = atoi(tmp_value); //Check if local_work_size is a valid number. if (local_work_size > get_task_max_work_group_size()){ local_work_size = 0; //Force find a valid number. } self->params.max_keys_per_crypt = global_work_size; if (!local_work_size) { local_work_size = get_task_max_work_group_size(); create_clobj(global_work_size, self); find_best_workgroup(self); release_clobj(); } if ((tmp_value = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, GWS_CONFIG))) global_work_size = atoi(tmp_value); if ((tmp_value = getenv("GWS"))) global_work_size = atoi(tmp_value); //Check if a valid multiple is used. global_work_size = get_multiple(global_work_size, local_work_size); if (global_work_size) create_clobj(global_work_size, self); else { //user chose to die of boredom global_work_size = get_task_max_size(); find_best_gws(self); } fprintf(stderr, "Local work size (LWS) %d, global work size (GWS) %zd\n", (int) local_work_size, global_work_size); self->params.max_keys_per_crypt = global_work_size; }
static void init(struct fmt_main *self) { #ifdef CL_VERSION_1_0 char *temp; cl_ulong maxsize; global_work_size = 0; opencl_init("$JOHN/rar_kernel.cl", ocl_gpu_id, platform_id); // create kernel to execute crypt_kernel = clCreateKernel(program[ocl_gpu_id], "SetCryptKeys", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?"); /* We mimic the lengths of cRARk for comparisons */ if (get_device_type(ocl_gpu_id) == CL_DEVICE_TYPE_GPU) { #ifndef DEBUG self->params.benchmark_comment = " (6 characters)"; #endif self->params.tests = gpu_tests; #if defined(DEBUG) && !defined(ALWAYS_OPENCL) fprintf(stderr, "Note: will use CPU for some self-tests, and Single mode.\n"); #endif } if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, LWS_CONFIG))) local_work_size = atoi(temp); if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, GWS_CONFIG))) global_work_size = atoi(temp); if ((temp = getenv("LWS"))) local_work_size = atoi(temp); if ((temp = getenv("GWS"))) global_work_size = atoi(temp); /* Note: we ask for this kernel's max size, not the device's! */ HANDLE_CLERROR(clGetKernelWorkGroupInfo(crypt_kernel, devices[ocl_gpu_id], CL_KERNEL_WORK_GROUP_SIZE, sizeof(maxsize), &maxsize, NULL), "Query max work group size"); #ifdef DEBUG fprintf(stderr, "Max allowed local work size %d\n", (int)maxsize); #endif if (!local_work_size) { if (get_device_type(ocl_gpu_id) == CL_DEVICE_TYPE_CPU) { if (get_platform_vendor_id(platform_id) == INTEL) local_work_size = 8; else local_work_size = 1; } else { local_work_size = 64; } } if (local_work_size > maxsize) { fprintf(stderr, "LWS %d is too large for this GPU. Max allowed is %d, using that.\n", (int)local_work_size, (int)maxsize); local_work_size = maxsize; } if (!global_work_size) find_best_gws(temp == NULL ? 0 : 1); if (global_work_size < local_work_size) global_work_size = local_work_size; fprintf(stderr, "Local worksize (LWS) %d, Global worksize (GWS) %d\n", (int)local_work_size, (int)global_work_size); create_clobj(global_work_size); #ifdef DEBUG { cl_ulong loc_mem_size; HANDLE_CLERROR(clGetKernelWorkGroupInfo(crypt_kernel, devices[ocl_gpu_id], CL_KERNEL_LOCAL_MEM_SIZE, sizeof(loc_mem_size), &loc_mem_size, NULL), "Query local memory usage"); fprintf(stderr, "Kernel using %lu bytes of local memory out of %lu available\n", loc_mem_size, get_local_memory_size(ocl_gpu_id)); } #endif atexit(release_clobj); *mkpc = VF * global_work_size; #endif /* OpenCL */ #if defined (_OPENMP) omp_t = omp_get_max_threads(); self->params.min_keys_per_crypt *= omp_t; #ifndef CL_VERSION_1_0 /* OpenCL gets to decide */ *mkpc = omp_t * OMP_SCALE * MAX_KEYS_PER_CRYPT; #endif init_locks(); #endif /* _OPENMP */ if (options.utf8) self->params.plaintext_length = PLAINTEXT_LENGTH * 3; unpack_data = mem_calloc_tiny(sizeof(unpack_data_t) * omp_t, MEM_ALIGN_WORD); cracked = mem_calloc_tiny(sizeof(*cracked) * *mkpc, MEM_ALIGN_WORD); #ifndef CL_VERSION_1_0 saved_key = mem_calloc_tiny(UNICODE_LENGTH * *mkpc, MEM_ALIGN_NONE); saved_len = mem_calloc_tiny(sizeof(*saved_len) * *mkpc, MEM_ALIGN_WORD); saved_salt = mem_calloc_tiny(8, MEM_ALIGN_NONE); aes_key = mem_calloc_tiny(16 * *mkpc, MEM_ALIGN_NONE); aes_iv = mem_calloc_tiny(16 * *mkpc, MEM_ALIGN_NONE); #endif /* OpenSSL init */ init_aesni(); SSL_load_error_strings(); SSL_library_init(); OpenSSL_add_all_algorithms(); #ifndef __APPLE__ atexit(openssl_cleanup); #endif /* CRC-32 table init, do it before we start multithreading */ { CRC32_t crc; CRC32_Init(&crc); } }