From ff376ce112281af2d0b2e5d8ef77322b1d3f100f Mon Sep 17 00:00:00 2001 From: jsteube Date: Mon, 5 Sep 2016 14:12:31 +0200 Subject: [PATCH] Moved bit operations out of shared.[hc] and created bitops.[hc] based on https://github.com/hashcat/hashcat/pull/485/commits/1aafa13e09973568ae58e4a539ce1d7772bd7e0b --- include/bitops.h | 18 ++++++++++++++++ include/shared.h | 10 --------- src/Makefile | 10 ++++----- src/bitops.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ src/hashcat.c | 13 ++++++------ src/shared.c | 53 +++--------------------------------------------- 6 files changed, 84 insertions(+), 71 deletions(-) create mode 100644 include/bitops.h create mode 100644 src/bitops.c diff --git a/include/bitops.h b/include/bitops.h new file mode 100644 index 000000000..8f40ee408 --- /dev/null +++ b/include/bitops.h @@ -0,0 +1,18 @@ +/** + * Authors.....: Jens Steube + * License.....: MIT + */ + +#pragma once + +#include "common.h" + +u32 is_power_of_2 (const u32 v); + +u32 rotl32 (const u32 a, const u32 n); +u32 rotr32 (const u32 a, const u32 n); +u64 rotl64 (const u64 a, const u64 n); +u64 rotr64 (const u64 a, const u64 n); + +u32 byte_swap_32 (const u32 n); +u64 byte_swap_64 (const u64 n); diff --git a/include/shared.h b/include/shared.h index 471f14bd6..76baef51a 100644 --- a/include/shared.h +++ b/include/shared.h @@ -1400,16 +1400,6 @@ typedef enum kern_run_mp * functions */ -u32 is_power_of_2(u32 v); - -u32 rotl32 (const u32 a, const u32 n); -u32 rotr32 (const u32 a, const u32 n); -u64 rotl64 (const u64 a, const u64 n); -u64 rotr64 (const u64 a, const u64 n); - -u32 byte_swap_32 (const u32 n); -u64 byte_swap_64 (const u64 n); - u8 hex_convert (const u8 c); u8 hex_to_u8 (const u8 hex[2]); u32 hex_to_u32 (const u8 hex[8]); diff --git a/src/Makefile b/src/Makefile index afc13285b..ed1a84d5b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -165,7 +165,7 @@ LFLAGS_CROSS_WIN := -lpsapi ## Objects ## -NATIVE_OBJS := obj/ext_OpenCL.NATIVE.o obj/shared.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o +NATIVE_OBJS := obj/bitops.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/shared.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o ifeq ($(UNAME),Linux) NATIVE_OBJS += obj/ext_ADL.NATIVE.o @@ -174,8 +174,8 @@ NATIVE_OBJS += obj/ext_nvml.NATIVE.o NATIVE_OBJS += obj/ext_xnvctrl.NATIVE.o endif -LINUX_32_OBJS := obj/ext_OpenCL.LINUX.32.o obj/shared.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o -LINUX_64_OBJS := obj/ext_OpenCL.LINUX.64.o obj/shared.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o +LINUX_32_OBJS := obj/bitops.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/shared.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o +LINUX_64_OBJS := obj/bitops.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/shared.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o # Windows CRT file globbing: @@ -185,8 +185,8 @@ CRT_GLOB_INCLUDE_FOLDER := $(dir $(lastword $(MAKEFILE_LIST))) include $(CRT_GLOB_INCLUDE_FOLDER)/win_file_globbing.mk -WIN_32_OBJS := obj/ext_OpenCL.WIN.32.o obj/shared.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_xnvctrl.WIN.32.o $(CRT_GLOB_32) -WIN_64_OBJS := obj/ext_OpenCL.WIN.64.o obj/shared.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_xnvctrl.WIN.64.o $(CRT_GLOB_64) +WIN_32_OBJS := obj/bitops.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/shared.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_xnvctrl.WIN.32.o $(CRT_GLOB_32) +WIN_64_OBJS := obj/bitops.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/shared.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_xnvctrl.WIN.64.o $(CRT_GLOB_64) ## ## Targets: Global diff --git a/src/bitops.c b/src/bitops.c new file mode 100644 index 000000000..0f2537916 --- /dev/null +++ b/src/bitops.c @@ -0,0 +1,51 @@ +/** + * Authors.....: Jens Steube + * License.....: MIT + */ + +#include "bitops.h" + +u32 is_power_of_2 (const u32 v) +{ + return (v && !(v & (v - 1))); +} + +u32 rotl32 (const u32 a, const u32 n) +{ + return ((a << n) | (a >> (32 - n))); +} + +u32 rotr32 (const u32 a, const u32 n) +{ + return ((a >> n) | (a << (32 - n))); +} + +u64 rotl64 (const u64 a, const u64 n) +{ + return ((a << n) | (a >> (64 - n))); +} + +u64 rotr64 (const u64 a, const u64 n) +{ + return ((a >> n) | (a << (64 - n))); +} + +u32 byte_swap_32 (const u32 n) +{ + return (n & 0xff000000) >> 24 + | (n & 0x00ff0000) >> 8 + | (n & 0x0000ff00) << 8 + | (n & 0x000000ff) << 24; +} + +u64 byte_swap_64 (const u64 n) +{ + return (n & 0xff00000000000000ULL) >> 56 + | (n & 0x00ff000000000000ULL) >> 40 + | (n & 0x0000ff0000000000ULL) >> 24 + | (n & 0x000000ff00000000ULL) >> 8 + | (n & 0x00000000ff000000ULL) << 8 + | (n & 0x0000000000ff0000ULL) << 24 + | (n & 0x000000000000ff00ULL) << 40 + | (n & 0x00000000000000ffULL) << 56; +} diff --git a/src/hashcat.c b/src/hashcat.c index d9966f6f7..7f0b41998 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -14,17 +14,18 @@ #include #endif -#include -#include -#include -#include +#include "common.h" +#include "bitops.h" +#include "shared.h" +#include "rp_kernel_on_cpu.h" +#include "getopt.h" -static const char *PROGNAME = "hashcat"; +static const char *PROGNAME = "hashcat"; const uint VERSION_BIN = 310; const uint RESTORE_MIN = 300; -static double TARGET_MS_PROFILE[4] = { 2, 12, 96, 480 }; +static double TARGET_MS_PROFILE[4] = { 2, 12, 96, 480 }; #define INCR_RULES 10000 #define INCR_SALTS 100000 diff --git a/src/shared.c b/src/shared.c index 90eaf4a83..0058eb201 100644 --- a/src/shared.c +++ b/src/shared.c @@ -15,58 +15,11 @@ #include #endif -#include +#include "shared.h" +#include "bitops.h" + #include -/** - * basic bit handling - */ - -u32 is_power_of_2(u32 v) -{ - return (v && !(v & (v - 1))); -} - -u32 rotl32 (const u32 a, const u32 n) -{ - return ((a << n) | (a >> (32 - n))); -} - -u32 rotr32 (const u32 a, const u32 n) -{ - return ((a >> n) | (a << (32 - n))); -} - -u64 rotl64 (const u64 a, const u64 n) -{ - return ((a << n) | (a >> (64 - n))); -} - -u64 rotr64 (const u64 a, const u64 n) -{ - return ((a >> n) | (a << (64 - n))); -} - -u32 byte_swap_32 (const u32 n) -{ - return (n & 0xff000000) >> 24 - | (n & 0x00ff0000) >> 8 - | (n & 0x0000ff00) << 8 - | (n & 0x000000ff) << 24; -} - -u64 byte_swap_64 (const u64 n) -{ - return (n & 0xff00000000000000ULL) >> 56 - | (n & 0x00ff000000000000ULL) >> 40 - | (n & 0x0000ff0000000000ULL) >> 24 - | (n & 0x000000ff00000000ULL) >> 8 - | (n & 0x00000000ff000000ULL) << 8 - | (n & 0x0000000000ff0000ULL) << 24 - | (n & 0x000000000000ff00ULL) << 40 - | (n & 0x00000000000000ffULL) << 56; -} - /** * ciphers for use on cpu */