1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-23 00:28:11 +00:00

Move more functions out of shared.c

This commit is contained in:
jsteube 2016-09-07 16:04:42 +02:00
parent 8dd57b715b
commit 80d7dce9b5
5 changed files with 154 additions and 160 deletions

View File

@ -9,6 +9,7 @@
#define _OPENCL_H
#include <stdio.h>
#include <errno.h>
static const char CL_VENDOR_AMD[] = "Advanced Micro Devices, Inc.";
static const char CL_VENDOR_AMD_USE_INTEL[] = "GenuineIntel";
@ -217,3 +218,6 @@ struct __hc_device_param
uint setup_opencl_platforms_filter (char *opencl_platforms);
u32 setup_devices_filter (char *opencl_devices);
cl_device_type setup_device_types_filter (char *opencl_device_types);
void load_kernel (const char *kernel_file, int num_devices, size_t *kernel_lengths, const u8 **kernel_sources);
void writeProgramBin (char *dst, u8 *binary, size_t binary_size);

View File

@ -69,37 +69,8 @@ extern const char *PROMPT;
extern hc_thread_mutex_t mux_display;
static const char OPTI_STR_ZERO_BYTE[] = "Zero-Byte";
static const char OPTI_STR_PRECOMPUTE_INIT[] = "Precompute-Init";
static const char OPTI_STR_PRECOMPUTE_MERKLE[] = "Precompute-Merkle-Demgard";
static const char OPTI_STR_PRECOMPUTE_PERMUT[] = "Precompute-Final-Permutation";
static const char OPTI_STR_MEET_IN_MIDDLE[] = "Meet-In-The-Middle";
static const char OPTI_STR_EARLY_SKIP[] = "Early-Skip";
static const char OPTI_STR_NOT_SALTED[] = "Not-Salted";
static const char OPTI_STR_NOT_ITERATED[] = "Not-Iterated";
static const char OPTI_STR_PREPENDED_SALT[] = "Prepended-Salt";
static const char OPTI_STR_APPENDED_SALT[] = "Appended-Salt";
static const char OPTI_STR_SINGLE_HASH[] = "Single-Hash";
static const char OPTI_STR_SINGLE_SALT[] = "Single-Salt";
static const char OPTI_STR_BRUTE_FORCE[] = "Brute-Force";
static const char OPTI_STR_RAW_HASH[] = "Raw-Hash";
static const char OPTI_STR_SLOW_HASH_SIMD[] = "Slow-Hash-SIMD";
static const char OPTI_STR_USES_BITS_8[] = "Uses-8-Bit";
static const char OPTI_STR_USES_BITS_16[] = "Uses-16-Bit";
static const char OPTI_STR_USES_BITS_32[] = "Uses-32-Bit";
static const char OPTI_STR_USES_BITS_64[] = "Uses-64-Bit";
static const char ST_0000[] = "Initializing";
static const char ST_0001[] = "Starting";
static const char ST_0002[] = "Running";
static const char ST_0003[] = "Paused";
static const char ST_0004[] = "Exhausted";
static const char ST_0005[] = "Cracked";
static const char ST_0006[] = "Aborted";
static const char ST_0007[] = "Quit";
static const char ST_0008[] = "Bypass";
static const char ST_0009[] = "Running (stop at checkpoint)";
static const char ST_0010[] = "Autotuning";
/*
@ -155,8 +126,6 @@ void format_speed_display (double val, char *buf, size_t len);
void format_timer_display (struct tm *tm, char *buf, size_t len);
char *stroptitype (const uint opti_type);
char *strstatus (const uint threads_status);
void status ();
@ -169,8 +138,6 @@ void myquit (void);
void naive_replace (char *s, const u8 key_char, const u8 replace_char);
void naive_escape (char *s, size_t s_max, const u8 key_char, const u8 escape_char);
void load_kernel (const char *kernel_file, int num_devices, size_t *kernel_lengths, const u8 **kernel_sources);
void writeProgramBin (char *dst, u8 *binary, size_t binary_size);
u64 get_lowest_words_done (void);

View File

@ -240,6 +240,39 @@ typedef enum kern_run_mp
} kern_run_mp_t;
static const char OPTI_STR_ZERO_BYTE[] = "Zero-Byte";
static const char OPTI_STR_PRECOMPUTE_INIT[] = "Precompute-Init";
static const char OPTI_STR_PRECOMPUTE_MERKLE[] = "Precompute-Merkle-Demgard";
static const char OPTI_STR_PRECOMPUTE_PERMUT[] = "Precompute-Final-Permutation";
static const char OPTI_STR_MEET_IN_MIDDLE[] = "Meet-In-The-Middle";
static const char OPTI_STR_EARLY_SKIP[] = "Early-Skip";
static const char OPTI_STR_NOT_SALTED[] = "Not-Salted";
static const char OPTI_STR_NOT_ITERATED[] = "Not-Iterated";
static const char OPTI_STR_PREPENDED_SALT[] = "Prepended-Salt";
static const char OPTI_STR_APPENDED_SALT[] = "Appended-Salt";
static const char OPTI_STR_SINGLE_HASH[] = "Single-Hash";
static const char OPTI_STR_SINGLE_SALT[] = "Single-Salt";
static const char OPTI_STR_BRUTE_FORCE[] = "Brute-Force";
static const char OPTI_STR_RAW_HASH[] = "Raw-Hash";
static const char OPTI_STR_SLOW_HASH_SIMD[] = "Slow-Hash-SIMD";
static const char OPTI_STR_USES_BITS_8[] = "Uses-8-Bit";
static const char OPTI_STR_USES_BITS_16[] = "Uses-16-Bit";
static const char OPTI_STR_USES_BITS_32[] = "Uses-32-Bit";
static const char OPTI_STR_USES_BITS_64[] = "Uses-64-Bit";
static const char ST_0000[] = "Initializing";
static const char ST_0001[] = "Starting";
static const char ST_0002[] = "Running";
static const char ST_0003[] = "Paused";
static const char ST_0004[] = "Exhausted";
static const char ST_0005[] = "Cracked";
static const char ST_0006[] = "Aborted";
static const char ST_0007[] = "Quit";
static const char ST_0008[] = "Bypass";
static const char ST_0009[] = "Running (stop at checkpoint)";
static const char ST_0010[] = "Autotuning";
#ifdef _WIN
#define mkdir(name,mode) mkdir (name)
#endif
@ -447,6 +480,54 @@ const char *PROMPT = "[s]tatus [p]ause [r]esume [b]ypass [c]heckpoint [q]uit =>
* hashcat specific functions
*/
char *strstatus (const uint devices_status)
{
switch (devices_status)
{
case STATUS_INIT: return ((char *) ST_0000);
case STATUS_STARTING: return ((char *) ST_0001);
case STATUS_RUNNING: return ((char *) ST_0002);
case STATUS_PAUSED: return ((char *) ST_0003);
case STATUS_EXHAUSTED: return ((char *) ST_0004);
case STATUS_CRACKED: return ((char *) ST_0005);
case STATUS_ABORTED: return ((char *) ST_0006);
case STATUS_QUIT: return ((char *) ST_0007);
case STATUS_BYPASS: return ((char *) ST_0008);
case STATUS_STOP_AT_CHECKPOINT: return ((char *) ST_0009);
case STATUS_AUTOTUNE: return ((char *) ST_0010);
}
return ((char *) "Unknown");
}
char *stroptitype (const uint opti_type)
{
switch (opti_type)
{
case OPTI_TYPE_ZERO_BYTE: return ((char *) OPTI_STR_ZERO_BYTE);
case OPTI_TYPE_PRECOMPUTE_INIT: return ((char *) OPTI_STR_PRECOMPUTE_INIT);
case OPTI_TYPE_PRECOMPUTE_MERKLE: return ((char *) OPTI_STR_PRECOMPUTE_MERKLE);
case OPTI_TYPE_PRECOMPUTE_PERMUT: return ((char *) OPTI_STR_PRECOMPUTE_PERMUT);
case OPTI_TYPE_MEET_IN_MIDDLE: return ((char *) OPTI_STR_MEET_IN_MIDDLE);
case OPTI_TYPE_EARLY_SKIP: return ((char *) OPTI_STR_EARLY_SKIP);
case OPTI_TYPE_NOT_SALTED: return ((char *) OPTI_STR_NOT_SALTED);
case OPTI_TYPE_NOT_ITERATED: return ((char *) OPTI_STR_NOT_ITERATED);
case OPTI_TYPE_PREPENDED_SALT: return ((char *) OPTI_STR_PREPENDED_SALT);
case OPTI_TYPE_APPENDED_SALT: return ((char *) OPTI_STR_APPENDED_SALT);
case OPTI_TYPE_SINGLE_HASH: return ((char *) OPTI_STR_SINGLE_HASH);
case OPTI_TYPE_SINGLE_SALT: return ((char *) OPTI_STR_SINGLE_SALT);
case OPTI_TYPE_BRUTE_FORCE: return ((char *) OPTI_STR_BRUTE_FORCE);
case OPTI_TYPE_RAW_HASH: return ((char *) OPTI_STR_RAW_HASH);
case OPTI_TYPE_SLOW_HASH_SIMD: return ((char *) OPTI_STR_SLOW_HASH_SIMD);
case OPTI_TYPE_USES_BITS_8: return ((char *) OPTI_STR_USES_BITS_8);
case OPTI_TYPE_USES_BITS_16: return ((char *) OPTI_STR_USES_BITS_16);
case OPTI_TYPE_USES_BITS_32: return ((char *) OPTI_STR_USES_BITS_32);
case OPTI_TYPE_USES_BITS_64: return ((char *) OPTI_STR_USES_BITS_64);
}
return (NULL);
}
static double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_entries)
{
int exec_pos = (int) device_param->exec_pos - last_num_entries;

View File

@ -10,6 +10,7 @@
#include "types.h"
#include "memory.h"
#include "logging.h"
#include "locking.h"
#include "ext_OpenCL.h"
#include "timer.h"
#include "opencl.h"
@ -121,3 +122,61 @@ cl_device_type setup_device_types_filter (char *opencl_device_types)
return device_types_filter;
}
void load_kernel (const char *kernel_file, int num_devices, size_t *kernel_lengths, const u8 **kernel_sources)
{
FILE *fp = fopen (kernel_file, "rb");
if (fp != NULL)
{
struct stat st;
memset (&st, 0, sizeof (st));
stat (kernel_file, &st);
u8 *buf = (u8 *) mymalloc (st.st_size + 1);
size_t num_read = fread (buf, sizeof (u8), st.st_size, fp);
if (num_read != (size_t) st.st_size)
{
log_error ("ERROR: %s: %s", kernel_file, strerror (errno));
exit (-1);
}
fclose (fp);
buf[st.st_size] = 0;
for (int i = 0; i < num_devices; i++)
{
kernel_lengths[i] = (size_t) st.st_size;
kernel_sources[i] = buf;
}
}
else
{
log_error ("ERROR: %s: %s", kernel_file, strerror (errno));
exit (-1);
}
return;
}
void writeProgramBin (char *dst, u8 *binary, size_t binary_size)
{
if (binary_size > 0)
{
FILE *fp = fopen (dst, "wb");
lock_file (fp);
fwrite (binary, sizeof (u8), binary_size, fp);
fflush (fp);
fclose (fp);
}
}

View File

@ -35,28 +35,6 @@
extern hc_global_data_t data;
/**
* system
*/
#ifdef WIN
static void fsync (int fd)
{
HANDLE h = (HANDLE) _get_osfhandle (fd);
FlushFileBuffers (h);
}
#endif
/**
* mixed shared functions
*/
void *rulefind (const void *key, void *base, int nmemb, size_t size, int (*compar) (const void *, const void *))
{
char *element, *end;
@ -1008,53 +986,6 @@ void format_speed_display (double val, char *buf, size_t len)
char *stroptitype (const uint opti_type)
{
switch (opti_type)
{
case OPTI_TYPE_ZERO_BYTE: return ((char *) OPTI_STR_ZERO_BYTE);
case OPTI_TYPE_PRECOMPUTE_INIT: return ((char *) OPTI_STR_PRECOMPUTE_INIT);
case OPTI_TYPE_PRECOMPUTE_MERKLE: return ((char *) OPTI_STR_PRECOMPUTE_MERKLE);
case OPTI_TYPE_PRECOMPUTE_PERMUT: return ((char *) OPTI_STR_PRECOMPUTE_PERMUT);
case OPTI_TYPE_MEET_IN_MIDDLE: return ((char *) OPTI_STR_MEET_IN_MIDDLE);
case OPTI_TYPE_EARLY_SKIP: return ((char *) OPTI_STR_EARLY_SKIP);
case OPTI_TYPE_NOT_SALTED: return ((char *) OPTI_STR_NOT_SALTED);
case OPTI_TYPE_NOT_ITERATED: return ((char *) OPTI_STR_NOT_ITERATED);
case OPTI_TYPE_PREPENDED_SALT: return ((char *) OPTI_STR_PREPENDED_SALT);
case OPTI_TYPE_APPENDED_SALT: return ((char *) OPTI_STR_APPENDED_SALT);
case OPTI_TYPE_SINGLE_HASH: return ((char *) OPTI_STR_SINGLE_HASH);
case OPTI_TYPE_SINGLE_SALT: return ((char *) OPTI_STR_SINGLE_SALT);
case OPTI_TYPE_BRUTE_FORCE: return ((char *) OPTI_STR_BRUTE_FORCE);
case OPTI_TYPE_RAW_HASH: return ((char *) OPTI_STR_RAW_HASH);
case OPTI_TYPE_SLOW_HASH_SIMD: return ((char *) OPTI_STR_SLOW_HASH_SIMD);
case OPTI_TYPE_USES_BITS_8: return ((char *) OPTI_STR_USES_BITS_8);
case OPTI_TYPE_USES_BITS_16: return ((char *) OPTI_STR_USES_BITS_16);
case OPTI_TYPE_USES_BITS_32: return ((char *) OPTI_STR_USES_BITS_32);
case OPTI_TYPE_USES_BITS_64: return ((char *) OPTI_STR_USES_BITS_64);
}
return (NULL);
}
char *strstatus (const uint devices_status)
{
switch (devices_status)
{
case STATUS_INIT: return ((char *) ST_0000);
case STATUS_STARTING: return ((char *) ST_0001);
case STATUS_RUNNING: return ((char *) ST_0002);
case STATUS_PAUSED: return ((char *) ST_0003);
case STATUS_EXHAUSTED: return ((char *) ST_0004);
case STATUS_CRACKED: return ((char *) ST_0005);
case STATUS_ABORTED: return ((char *) ST_0006);
case STATUS_QUIT: return ((char *) ST_0007);
case STATUS_BYPASS: return ((char *) ST_0008);
case STATUS_STOP_AT_CHECKPOINT: return ((char *) ST_0009);
case STATUS_AUTOTUNE: return ((char *) ST_0010);
}
return ((char *) "Unknown");
}
static void SuspendThreads ()
{
@ -1181,63 +1112,6 @@ void naive_escape (char *s, size_t s_max, const u8 key_char, const u8 escape_cha
strncpy (s, s_escaped, s_max - 1);
}
void load_kernel (const char *kernel_file, int num_devices, size_t *kernel_lengths, const u8 **kernel_sources)
{
FILE *fp = fopen (kernel_file, "rb");
if (fp != NULL)
{
struct stat st;
memset (&st, 0, sizeof (st));
stat (kernel_file, &st);
u8 *buf = (u8 *) mymalloc (st.st_size + 1);
size_t num_read = fread (buf, sizeof (u8), st.st_size, fp);
if (num_read != (size_t) st.st_size)
{
log_error ("ERROR: %s: %s", kernel_file, strerror (errno));
exit (-1);
}
fclose (fp);
buf[st.st_size] = 0;
for (int i = 0; i < num_devices; i++)
{
kernel_lengths[i] = (size_t) st.st_size;
kernel_sources[i] = buf;
}
}
else
{
log_error ("ERROR: %s: %s", kernel_file, strerror (errno));
exit (-1);
}
return;
}
void writeProgramBin (char *dst, u8 *binary, size_t binary_size)
{
if (binary_size > 0)
{
FILE *fp = fopen (dst, "wb");
lock_file (fp);
fwrite (binary, sizeof (u8), binary_size, fp);
fflush (fp);
fclose (fp);
}
}
/**
* restore
@ -1442,6 +1316,15 @@ u64 get_lowest_words_done ()
return words_cur;
}
#ifdef _WIN
static void fsync (int fd)
{
HANDLE h = (HANDLE) _get_osfhandle (fd);
FlushFileBuffers (h);
}
#endif
void write_restore (const char *new_restore_file, restore_data_t *rd)
{
u64 words_cur = get_lowest_words_done ();