diff --git a/include/bitops.h b/include/bitops.h index 17811091c..ef68f0f4c 100644 --- a/include/bitops.h +++ b/include/bitops.h @@ -15,4 +15,14 @@ u16 byte_swap_16 (const u16 n); u32 byte_swap_32 (const u32 n); u64 byte_swap_64 (const u64 n); +// Conditional byte swap macros for endianness conversion +// These convert between native byte order and big-endian byte order +#if HC_BIG_ENDIAN +#define byte_swap_32_to_be(n) (n) +#define byte_swap_64_to_be(n) (n) +#else +#define byte_swap_32_to_be(n) byte_swap_32(n) +#define byte_swap_64_to_be(n) byte_swap_64(n) +#endif + #endif // HC_BITOPS_H diff --git a/include/common.h b/include/common.h index a744d532a..0325ca705 100644 --- a/include/common.h +++ b/include/common.h @@ -16,10 +16,10 @@ #error Your Operating System is not supported or detected #endif -#if defined (__BYTE_ORDER__) && defined (__ORDER_BIG_ENDIAN__) -#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -#error "compiling for big-endian architecture not supported" -#endif +#if defined (__BYTE_ORDER__) && defined (__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#define HC_BIG_ENDIAN 1 +#else +#define HC_BIG_ENDIAN 0 #endif #ifndef _GNU_SOURCE diff --git a/src/mpsp.c b/src/mpsp.c index 7585b4447..222fb3314 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -809,14 +809,14 @@ static int sp_setup_tbl (hashcat_ctx_t *hashcat_ctx) hcfree (outbuf); /** - * switch endianess + * switch endianness (hcstat file stores data in big-endian format) */ - v = byte_swap_64 (v); - z = byte_swap_64 (z); + v = byte_swap_64_to_be (v); + z = byte_swap_64_to_be (z); - for (int i = 0; i < SP_ROOT_CNT; i++) root_stats_buf[i] = byte_swap_64 (root_stats_buf[i]); - for (int i = 0; i < SP_MARKOV_CNT; i++) markov_stats_buf[i] = byte_swap_64 (markov_stats_buf[i]); + for (int i = 0; i < SP_ROOT_CNT; i++) root_stats_buf[i] = byte_swap_64_to_be (root_stats_buf[i]); + for (int i = 0; i < SP_MARKOV_CNT; i++) markov_stats_buf[i] = byte_swap_64_to_be (markov_stats_buf[i]); /** * markov inverse: https://github.com/hashcat/hashcat/issues/1058 diff --git a/src/selftest.c b/src/selftest.c index 4cba3d940..9770b95eb 100644 --- a/src/selftest.c +++ b/src/selftest.c @@ -325,7 +325,7 @@ static int selftest_init (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_ if (hashconfig->opts_type & OPTS_TYPE_PT_GENERATE_BE) { - bf.i = byte_swap_32 (bf.i); + bf.i = byte_swap_32_to_be (bf.i); } if (device_param->is_cuda == true) @@ -431,7 +431,7 @@ static int selftest_init (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_ if (hashconfig->opts_type & OPTS_TYPE_PT_GENERATE_BE) { - for (int i = 0; i < 14; i++) pw.i[i] = byte_swap_32 (pw.i[i]); + for (int i = 0; i < 14; i++) pw.i[i] = byte_swap_32_to_be (pw.i[i]); } if (device_param->is_cuda == true) diff --git a/src/wordlist.c b/src/wordlist.c index 19cec3ed5..44f9f4f53 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -494,7 +494,7 @@ int count_words (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, const char *dictfile, u for (size_t i = 0, j = 0; i < dictfile_len; i += 4, j += 1) { - dictfile_padded[j] = byte_swap_32 (dictfile_padded[j]); + dictfile_padded[j] = byte_swap_32_to_be (dictfile_padded[j]); } sha1_ctx_t sha1_ctx; @@ -502,11 +502,11 @@ int count_words (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, const char *dictfile, u sha1_update (&sha1_ctx, dictfile_padded, dictfile_len); sha1_final (&sha1_ctx); - sha1_ctx.h[0] = byte_swap_32 (sha1_ctx.h[0]); - sha1_ctx.h[1] = byte_swap_32 (sha1_ctx.h[1]); - sha1_ctx.h[2] = byte_swap_32 (sha1_ctx.h[2]); - sha1_ctx.h[3] = byte_swap_32 (sha1_ctx.h[3]); - sha1_ctx.h[4] = byte_swap_32 (sha1_ctx.h[4]); + sha1_ctx.h[0] = byte_swap_32_to_be (sha1_ctx.h[0]); + sha1_ctx.h[1] = byte_swap_32_to_be (sha1_ctx.h[1]); + sha1_ctx.h[2] = byte_swap_32_to_be (sha1_ctx.h[2]); + sha1_ctx.h[3] = byte_swap_32_to_be (sha1_ctx.h[3]); + sha1_ctx.h[4] = byte_swap_32_to_be (sha1_ctx.h[4]); hcfree (dictfile_padded); --- a/src/backend.c +++ b/src/backend.c @@ -7467,9 +7467,9 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) if (device_endian_little == CL_FALSE) { - event_log_error (hashcat_ctx, "* Device #%u: This device is not little-endian.", device_id + 1); + event_log_warning (hashcat_ctx, "* Device #%u: This device is big-endian. Experimental support - results may be incorrect.", device_id + 1); - device_param->skipped = true; + // Continue anyway - experimental big-endian support } // device_available