From 97249ba1cac4393aa0dc198477b44bcf8d5d2a7c Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Thu, 21 Mar 2019 20:18:39 +0100 Subject: [PATCH 01/19] added pkzip kernels 17200, 17210, 17220 and 17230 --- OpenCL/inc_zip_inflate.cl | 1067 ++++++++++++++++++++++++++++++++++++ OpenCL/m17200_a0-pure.cl | 967 ++++++++++++++++++++++++++++++++ OpenCL/m17200_a1-pure.cl | 967 ++++++++++++++++++++++++++++++++ OpenCL/m17200_a3-pure.cl | 979 +++++++++++++++++++++++++++++++++ OpenCL/m17210_a0-pure.cl | 551 +++++++++++++++++++ OpenCL/m17210_a1-pure.cl | 553 +++++++++++++++++++ OpenCL/m17210_a3-pure.cl | 565 +++++++++++++++++++ OpenCL/m17220_a0-pure.cl | 1003 +++++++++++++++++++++++++++++++++ OpenCL/m17220_a1-pure.cl | 1005 +++++++++++++++++++++++++++++++++ OpenCL/m17220_a3-pure.cl | 1012 ++++++++++++++++++++++++++++++++++ OpenCL/m17230_a0-pure.cl | 539 ++++++++++++++++++ OpenCL/m17230_a1-pure.cl | 544 ++++++++++++++++++ OpenCL/m17230_a3-pure.cl | 555 +++++++++++++++++++ docs/changes.txt | 1 + src/modules/module_17200.c | 398 ++++++++++++++ src/modules/module_17210.c | 400 ++++++++++++++ src/modules/module_17220.c | 404 ++++++++++++++ src/modules/module_17230.c | 404 ++++++++++++++ 18 files changed, 11914 insertions(+) create mode 100644 OpenCL/inc_zip_inflate.cl create mode 100644 OpenCL/m17200_a0-pure.cl create mode 100644 OpenCL/m17200_a1-pure.cl create mode 100644 OpenCL/m17200_a3-pure.cl create mode 100644 OpenCL/m17210_a0-pure.cl create mode 100644 OpenCL/m17210_a1-pure.cl create mode 100644 OpenCL/m17210_a3-pure.cl create mode 100644 OpenCL/m17220_a0-pure.cl create mode 100644 OpenCL/m17220_a1-pure.cl create mode 100644 OpenCL/m17220_a3-pure.cl create mode 100644 OpenCL/m17230_a0-pure.cl create mode 100644 OpenCL/m17230_a1-pure.cl create mode 100644 OpenCL/m17230_a3-pure.cl create mode 100644 src/modules/module_17200.c create mode 100644 src/modules/module_17210.c create mode 100644 src/modules/module_17220.c create mode 100644 src/modules/module_17230.c diff --git a/OpenCL/inc_zip_inflate.cl b/OpenCL/inc_zip_inflate.cl new file mode 100644 index 000000000..0009f8e3f --- /dev/null +++ b/OpenCL/inc_zip_inflate.cl @@ -0,0 +1,1067 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +*/ + +#include "inc_vendor.cl" +#include "inc_hash_constants.h" +#include "inc_hash_functions.cl" +#include "inc_types.cl" +#include "inc_common.cl" +#include "inc_simd.cl" + +enum{ + MZ_OK = 0, + MZ_STREAM_END = 1, + MZ_NEED_DICT = 2, + MZ_ERRNO = -1, + MZ_STREAM_ERROR = -2, + MZ_DATA_ERROR = -3, + MZ_MEM_ERROR = -4, + MZ_BUF_ERROR = -5, + MZ_VERSION_ERROR = -6, + MZ_PARAM_ERROR = -10000 +}; +typedef unsigned long mz_ulong; + +#ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES +typedef unsigned char Byte; +typedef unsigned int uInt; +typedef mz_ulong uLong; +typedef Byte Bytef; +typedef uInt uIntf; +typedef char charf; +typedef int intf; +typedef void *voidpf; +typedef uLong uLongf; +typedef void *voidp; +typedef void *const voidpc; +#define Z_NULL 0 +#define Z_NO_FLUSH MZ_NO_FLUSH +#define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH +#define Z_SYNC_FLUSH MZ_SYNC_FLUSH +#define Z_FULL_FLUSH MZ_FULL_FLUSH +#define Z_FINISH MZ_FINISH +#define Z_BLOCK MZ_BLOCK +#define Z_OK MZ_OK +#define Z_STREAM_END MZ_STREAM_END +#define Z_NEED_DICT MZ_NEED_DICT +#define Z_ERRNO MZ_ERRNO +#define Z_STREAM_ERROR MZ_STREAM_ERROR +#define Z_DATA_ERROR MZ_DATA_ERROR +#define Z_MEM_ERROR MZ_MEM_ERROR +#define Z_BUF_ERROR MZ_BUF_ERROR +#define Z_VERSION_ERROR MZ_VERSION_ERROR +#define Z_PARAM_ERROR MZ_PARAM_ERROR +#define Z_NO_COMPRESSION MZ_NO_COMPRESSION +#define Z_BEST_SPEED MZ_BEST_SPEED +#define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION +#define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION +#define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY +#define Z_FILTERED MZ_FILTERED +#define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY +#define Z_RLE MZ_RLE +#define Z_FIXED MZ_FIXED +#define Z_DEFLATED MZ_DEFLATED +#define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS +#define z_stream mz_stream +#define deflateInit mz_deflateInit +#define deflateInit2 mz_deflateInit2 +#define deflateReset mz_deflateReset +#define deflate mz_deflate +#define deflateEnd mz_deflateEnd +#define deflateBound mz_deflateBound +#define compress mz_compress +#define compress2 mz_compress2 +#define compressBound mz_compressBound +#define inflateInit mz_inflateInit +#define inflateInit2 mz_inflateInit2 +#define inflate mz_inflate +#define inflateEnd mz_inflateEnd +#define uncompress mz_uncompress +#define adler32 mz_adler32 +#define MAX_WBITS 15 +#define MAX_MEM_LEVEL 9 +#define ZLIB_VERSION MZ_VERSION +#define ZLIB_VERNUM MZ_VERNUM +#define ZLIB_VER_MAJOR MZ_VER_MAJOR +#define ZLIB_VER_MINOR MZ_VER_MINOR +#define ZLIB_VER_REVISION MZ_VER_REVISION +#define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION +#define zlibVersion mz_version +#define zlib_version mz_version() +#endif /* #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES */ + +#define MZ_MACRO_END while (0) + +#define tinfl_init(r) \ + do \ + { \ + (r)->m_state = 0; \ + } \ + MZ_MACRO_END + +enum +{ + TINFL_FLAG_PARSE_ZLIB_HEADER = 1, + TINFL_FLAG_HAS_MORE_INPUT = 2, + TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4, + TINFL_FLAG_COMPUTE_ADLER32 = 8 +}; + +enum +{ + TINFL_MAX_HUFF_TABLES = 3, + TINFL_MAX_HUFF_SYMBOLS_0 = 288, + TINFL_MAX_HUFF_SYMBOLS_1 = 32, + TINFL_MAX_HUFF_SYMBOLS_2 = 19, + TINFL_FAST_LOOKUP_BITS = 10, + TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS +}; + +typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size); +typedef void (*mz_free_func)(void *opaque, void *address); +typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size); + + +typedef unsigned char mz_uint8; +typedef signed short mz_int16; +typedef unsigned short mz_uint16; +typedef unsigned int mz_uint32; +typedef unsigned int mz_uint; +typedef u64 mz_uint64; +typedef int mz_bool; + +typedef mz_uint64 tinfl_bit_buf_t; + +void memcpy(void *dest, const void *src, size_t n){ + char *csrc = (char *)src; + char *cdest = (char *)dest; + for (int i=0; i 0) { + *dst = (u8) c; + dst++; + len--; + } + return s; +} + + +#define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MZ_DEFAULT_WINDOW_BITS 15 +#define TINFL_LZ_DICT_SIZE 32768 +#define TINFL_MEMCPY(d, s, l) memcpy(d, s, l) +#define TINFL_MEMSET(p, c, l) memset(p, c, l) +#define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj)) + +#define TINFL_CR_FINISH } +#define TINFL_CR_BEGIN \ + switch (r->m_state) \ + { \ + case 0: + +enum +{ + MZ_NO_FLUSH = 0, + MZ_PARTIAL_FLUSH = 1, + MZ_SYNC_FLUSH = 2, + MZ_FULL_FLUSH = 3, + MZ_FINISH = 4, + MZ_BLOCK = 5 +}; + +#define MZ_READ_LE16(p) *((const mz_uint16 *)(p)) +//#define MZ_READ_LE32(p) *((const mz_uint32 *)(p)) +#define MZ_READ_LE32(p) *((mz_uint32 *)(p)) + +#define TINFL_NEED_BITS(state_index, n) \ + do \ + { \ + mz_uint c; \ + TINFL_GET_BYTE(state_index, c); \ + bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); \ + num_bits += 8; \ + } while (num_bits < (mz_uint)(n)) + +#define TINFL_SKIP_BITS(state_index, n) \ + do \ + { \ + if (num_bits < (mz_uint)(n)) \ + { \ + TINFL_NEED_BITS(state_index, n); \ + } \ + bit_buf >>= (n); \ + num_bits -= (n); \ + } \ + MZ_MACRO_END + +#define TINFL_GET_BITS(state_index, b, n) \ + do \ + { \ + if (num_bits < (mz_uint)(n)) \ + { \ + TINFL_NEED_BITS(state_index, n); \ + } \ + b = bit_buf & ((1 << (n)) - 1); \ + bit_buf >>= (n); \ + num_bits -= (n); \ + } \ + MZ_MACRO_END + +//case state_index:; +#define TINFL_CR_RETURN(state_index, result) \ + do \ + { \ + status = result; \ + r->m_state = state_index; \ + goto common_exit; \ + } \ + MZ_MACRO_END + +#define TINFL_CR_RETURN_FOREVER(state_index, result) \ + do \ + { \ + for (;;) \ + { \ + TINFL_CR_RETURN(state_index, result); \ + } \ + } \ + MZ_MACRO_END + +#define TINFL_GET_BYTE(state_index, c) \ + do \ + { \ + while (pIn_buf_cur >= pIn_buf_end) \ + { \ + TINFL_CR_RETURN(state_index, (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) ? TINFL_STATUS_NEEDS_MORE_INPUT : TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS); \ + } \ + c = *pIn_buf_cur++; \ + } \ + MZ_MACRO_END + +#define TINFL_HUFF_DECODE(state_index, sym, pHuff) \ + do \ + { \ + int temp; \ + mz_uint code_len, c; \ + if (num_bits < 15) \ + { \ + if ((pIn_buf_end - pIn_buf_cur) < 2) \ + { \ + TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \ + } \ + else \ + { \ + bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); \ + pIn_buf_cur += 2; \ + num_bits += 16; \ + } \ + } \ + if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \ + code_len = temp >> 9, temp &= 511; \ + else \ + { \ + code_len = TINFL_FAST_LOOKUP_BITS; \ + do \ + { \ + temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \ + } while (temp < 0); \ + } \ + sym = temp; \ + bit_buf >>= code_len; \ + num_bits -= code_len; \ + } \ + MZ_MACRO_END + +#define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \ + do \ + { \ + temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \ + if (temp >= 0) \ + { \ + code_len = temp >> 9; \ + if ((code_len) && (num_bits >= code_len)) \ + break; \ + } \ + else if (num_bits > TINFL_FAST_LOOKUP_BITS) \ + { \ + code_len = TINFL_FAST_LOOKUP_BITS; \ + do \ + { \ + temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \ + } while ((temp < 0) && (num_bits >= (code_len + 1))); \ + if (temp >= 0) \ + break; \ + } \ + TINFL_GET_BYTE(state_index, c); \ + bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); \ + num_bits += 8; \ + } while (num_bits < 15); + +typedef struct +{ + mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0]; + mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2]; +} tinfl_huff_table; + +typedef enum { + /* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is indicating that no more are available. The compressed data */ + /* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input but this is a BAD sign (either the data is corrupted or you called it incorrectly). */ + /* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */ + TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS = -4, + + /* This flag indicates that one or more of the input parameters was obviously bogus. (You can try calling it again, but if you get this error the calling code is wrong.) */ + TINFL_STATUS_BAD_PARAM = -3, + + /* This flags indicate the inflator is finished but the adler32 check of the uncompressed data didn't match. If you call it again it'll return TINFL_STATUS_DONE. */ + TINFL_STATUS_ADLER32_MISMATCH = -2, + + /* This flags indicate the inflator has somehow failed (bad code, corrupted input, etc.). If you call it again without resetting via tinfl_init() it it'll just keep on returning the same status failure code. */ + TINFL_STATUS_FAILED = -1, + + /* Any status code less than TINFL_STATUS_DONE must indicate a failure. */ + + /* This flag indicates the inflator has returned every byte of uncompressed data that it can, has consumed every byte that it needed, has successfully reached the end of the deflate stream, and */ + /* if zlib headers and adler32 checking enabled that it has successfully checked the uncompressed data's adler32. If you call it again you'll just get TINFL_STATUS_DONE over and over again. */ + TINFL_STATUS_DONE = 0, + + /* This flag indicates the inflator MUST have more input data (even 1 byte) before it can make any more forward progress, or you need to clear the TINFL_FLAG_HAS_MORE_INPUT */ + /* flag on the next call if you don't have any more source data. If the source data was somehow corrupted it's also possible (but unlikely) for the inflator to keep on demanding input to */ + /* proceed, so be sure to properly set the TINFL_FLAG_HAS_MORE_INPUT flag. */ + TINFL_STATUS_NEEDS_MORE_INPUT = 1, + + /* This flag indicates the inflator definitely has 1 or more bytes of uncompressed data available, but it cannot write this data into the output buffer. */ + /* Note if the source compressed data was corrupted it's possible for the inflator to return a lot of uncompressed data to the caller. I've been assuming you know how much uncompressed data to expect */ + /* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure streaming scenarios where you have no idea how many bytes to expect this may not be possible */ + /* so I may need to add some code to address this. */ + TINFL_STATUS_HAS_MORE_OUTPUT = 2 +} tinfl_status; + +#define tinfl_get_adler32(r) (r)->m_check_adler32 + + + +struct tinfl_decompressor_tag +{ + mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES]; + tinfl_bit_buf_t m_bit_buf; + size_t m_dist_from_out_buf_start; + tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES]; + mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137]; +}; +typedef struct tinfl_decompressor_tag tinfl_decompressor; + +typedef struct +{ + tinfl_decompressor m_decomp; + mz_uint m_dict_ofs, m_dict_avail, m_first_call, m_has_flushed; + int m_window_bits; + mz_uint8 m_dict[TINFL_LZ_DICT_SIZE]; + tinfl_status m_last_status; +} inflate_state; + +typedef struct mz_stream_s +{ + const unsigned char *next_in; /* pointer to next byte to read */ + unsigned int avail_in; /* number of bytes available at next_in */ + mz_ulong total_in; /* total number of bytes consumed so far */ + + unsigned char *next_out; /* pointer to next byte to write */ + unsigned int avail_out; /* number of bytes that can be written to next_out */ + mz_ulong total_out; /* total number of bytes produced so far */ + + char *msg; /* error msg (unused) */ + struct inflate_state *state; /* internal state, allocated by zalloc/zfree */ + + mz_alloc_func zalloc; /* optional heap allocation function (defaults to malloc) */ + mz_free_func zfree; /* optional heap free function (defaults to free) */ + void *opaque; /* heap alloc function user pointer */ + + int data_type; /* data_type (unused) */ + mz_ulong adler; /* adler32 of the source or uncompressed data */ + mz_ulong reserved; /* not used */ +} mz_stream; + +typedef mz_stream *mz_streamp; + + +void miniz_def_free_func(void *opaque, void *address); +void *miniz_def_alloc_func(void *opaque, size_t items, size_t size); +int mz_inflate(mz_streamp pStream, int flush); +int mz_inflateEnd(mz_streamp pStream); + + + +int mz_inflateInit2(mz_streamp pStream, int window_bits, inflate_state*); + + + + +tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags) +{ + + const int s_length_base[31] = { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 }; + const int s_length_extra[31] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0 }; + const int s_dist_base[32] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577, 0, 0 }; + const int s_dist_extra[32] = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 }; + const mz_uint8 s_length_dezigzag[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; + const int s_min_table_sizes[3] = { 257, 1, 4 }; + + tinfl_status status = TINFL_STATUS_FAILED; + mz_uint32 num_bits, dist, counter, num_extra; + tinfl_bit_buf_t bit_buf; + const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size; + mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size; + size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start; + + /* Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter). */ + if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) + { + *pIn_buf_size = *pOut_buf_size = 0; + return TINFL_STATUS_BAD_PARAM; + } + + num_bits = r->m_num_bits; + bit_buf = r->m_bit_buf; + dist = r->m_dist; + counter = r->m_counter; + num_extra = r->m_num_extra; + dist_from_out_buf_start = r->m_dist_from_out_buf_start; + TINFL_CR_BEGIN + + bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; + r->m_z_adler32 = r->m_check_adler32 = 1; + if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) + { + TINFL_GET_BYTE(1, r->m_zhdr0); + TINFL_GET_BYTE(2, r->m_zhdr1); + counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8)); + if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) + counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4))))); + if (counter) + { + TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); + } + } + + do + { + TINFL_GET_BITS(3, r->m_final, 3); + r->m_type = r->m_final >> 1; + if (r->m_type == 0) + { + TINFL_SKIP_BITS(5, num_bits & 7); + for (counter = 0; counter < 4; ++counter) + { + if (num_bits) + TINFL_GET_BITS(6, r->m_raw_header[counter], 8); + else + TINFL_GET_BYTE(7, r->m_raw_header[counter]); + } + if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) + { + TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); + } + while ((counter) && (num_bits)) + { + TINFL_GET_BITS(51, dist, 8); + while (pOut_buf_cur >= pOut_buf_end) + { + TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); + } + *pOut_buf_cur++ = (mz_uint8)dist; + counter--; + } + while (counter) + { + size_t n; + while (pOut_buf_cur >= pOut_buf_end) + { + TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); + } + while (pIn_buf_cur >= pIn_buf_end) + { + TINFL_CR_RETURN(38, (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) ? TINFL_STATUS_NEEDS_MORE_INPUT : TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS); + } + n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter); + TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); + pIn_buf_cur += n; + pOut_buf_cur += n; + counter -= (mz_uint)n; + } + } + else if (r->m_type == 3) + { + TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED); + } + else + { + if (r->m_type == 1) + { + mz_uint8 *p = r->m_tables[0].m_code_size; + mz_uint i; + r->m_table_sizes[0] = 288; + r->m_table_sizes[1] = 32; + TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32); + for (i = 0; i <= 143; ++i) + *p++ = 8; + for (; i <= 255; ++i) + *p++ = 9; + for (; i <= 279; ++i) + *p++ = 7; + for (; i <= 287; ++i) + *p++ = 8; + } + else + { + for (counter = 0; counter < 3; counter++) + { + TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); + r->m_table_sizes[counter] += s_min_table_sizes[counter]; + } + MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); + for (counter = 0; counter < r->m_table_sizes[2]; counter++) + { + mz_uint s; + TINFL_GET_BITS(14, s, 3); + r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; + } + r->m_table_sizes[2] = 19; + } + for (; (int)r->m_type >= 0; r->m_type--) + { + int tree_next, tree_cur; + tinfl_huff_table *pTable; + mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; + pTable = &r->m_tables[r->m_type]; + MZ_CLEAR_OBJ(total_syms); + MZ_CLEAR_OBJ(pTable->m_look_up); + MZ_CLEAR_OBJ(pTable->m_tree); + for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) + total_syms[pTable->m_code_size[i]]++; + used_syms = 0, total = 0; + next_code[0] = next_code[1] = 0; + for (i = 1; i <= 15; ++i) + { + used_syms += total_syms[i]; + next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); + } + if ((65536 != total) && (used_syms > 1)) + { + TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED); + } + for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index) + { + mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; + if (!code_size) + continue; + cur_code = next_code[code_size]++; + for (l = code_size; l > 0; l--, cur_code >>= 1) + rev_code = (rev_code << 1) | (cur_code & 1); + if (code_size <= TINFL_FAST_LOOKUP_BITS) + { + mz_int16 k = (mz_int16)((code_size << 9) | sym_index); + while (rev_code < TINFL_FAST_LOOKUP_SIZE) + { + pTable->m_look_up[rev_code] = k; + rev_code += (1 << code_size); + } + continue; + } + if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) + { + pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; + tree_cur = tree_next; + tree_next -= 2; + } + rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1); + for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--) + { + tree_cur -= ((rev_code >>= 1) & 1); + if (!pTable->m_tree[-tree_cur - 1]) + { + pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; + tree_cur = tree_next; + tree_next -= 2; + } + else + tree_cur = pTable->m_tree[-tree_cur - 1]; + } + tree_cur -= ((rev_code >>= 1) & 1); + pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index; + } + if (r->m_type == 2) + { + for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]);) + { + mz_uint s; + TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); + if (dist < 16) + { + r->m_len_codes[counter++] = (mz_uint8)dist; + continue; + } + if ((dist == 16) && (!counter)) + { + TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED); + } + num_extra = "\02\03\07"[dist - 16]; + TINFL_GET_BITS(18, s, num_extra); + s += "\03\03\013"[dist - 16]; + TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); + counter += s; + } + if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter) + { + TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED); + } + TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); + TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]); + } + } + for (;;) + { + mz_uint8 *pSrc; + for (;;) + { + if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2)) + { + TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]); + if (counter >= 256) + break; + while (pOut_buf_cur >= pOut_buf_end) + { + TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); + } + *pOut_buf_cur++ = (mz_uint8)counter; + } + else + { + int sym2; + mz_uint code_len; + if (num_bits < 30) + { + u32 num = *pIn_buf_cur; + pIn_buf_cur++; + for(int i=1;i<4;i++){ + num |= (*pIn_buf_cur) << 8*i; + pIn_buf_cur++; + } + //bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); + bit_buf |= ((tinfl_bit_buf_t)num) << num_bits; + //pIn_buf_cur += 4; + num_bits += 32; + } + if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) + code_len = sym2 >> 9; + else + { + code_len = TINFL_FAST_LOOKUP_BITS; + do + { + sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; + } while (sym2 < 0); + } + counter = sym2; + bit_buf >>= code_len; + num_bits -= code_len; + if (counter & 256) + break; + + if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) + code_len = sym2 >> 9; + else + { + code_len = TINFL_FAST_LOOKUP_BITS; + do + { + sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; + } while (sym2 < 0); + } + bit_buf >>= code_len; + num_bits -= code_len; + + pOut_buf_cur[0] = (mz_uint8)counter; + if (sym2 & 256) + { + pOut_buf_cur++; + counter = sym2; + break; + } + pOut_buf_cur[1] = (mz_uint8)sym2; + pOut_buf_cur += 2; + } + } + if ((counter &= 511) == 256) + break; + + num_extra = s_length_extra[counter - 257]; + counter = s_length_base[counter - 257]; + if (num_extra) + { + mz_uint extra_bits; + TINFL_GET_BITS(25, extra_bits, num_extra); + counter += extra_bits; + } + + TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]); + num_extra = s_dist_extra[dist]; + dist = s_dist_base[dist]; + if (num_extra) + { + mz_uint extra_bits; + TINFL_GET_BITS(27, extra_bits, num_extra); + dist += extra_bits; + } + + dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start; + if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) + { + TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED); + } + + pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask); + + if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end) + { + while (counter--) + { + while (pOut_buf_cur >= pOut_buf_end) + { + TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); + } + *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask]; + } + continue; + } + else if ((counter >= 9) && (counter <= dist)) + { + const mz_uint8 *pSrc_end = pSrc + (counter & ~7); + do + { + //((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0]; + //((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1]; + + for(int i=0;i<8;i++){ + pOut_buf_cur[i] = pSrc[i]; + } + + pOut_buf_cur += 8; + } while ((pSrc += 8) < pSrc_end); + if ((counter &= 7) < 3) + { + if (counter) + { + pOut_buf_cur[0] = pSrc[0]; + if (counter > 1) + pOut_buf_cur[1] = pSrc[1]; + pOut_buf_cur += counter; + } + continue; + } + } + while(counter>2) + { + pOut_buf_cur[0] = pSrc[0]; + pOut_buf_cur[1] = pSrc[1]; + pOut_buf_cur[2] = pSrc[2]; + pOut_buf_cur += 3; + pSrc += 3; + counter -= 3; + } + if (counter > 0) + { + pOut_buf_cur[0] = pSrc[0]; + if (counter > 1) + pOut_buf_cur[1] = pSrc[1]; + pOut_buf_cur += counter; + } + } + } + } while (!(r->m_final & 1)); + + /* Ensure byte alignment and put back any bytes from the bitbuf if we've looked ahead too far on gzip, or other Deflate streams followed by arbitrary data. */ + /* I'm being super conservative here. A number of simplifications can be made to the byte alignment part, and the Adler32 check shouldn't ever need to worry about reading from the bitbuf now. */ + TINFL_SKIP_BITS(32, num_bits & 7); + while ((pIn_buf_cur > pIn_buf_next) && (num_bits >= 8)) + { + --pIn_buf_cur; + num_bits -= 8; + } + bit_buf &= (tinfl_bit_buf_t)((((mz_uint64)1) << num_bits) - (mz_uint64)1); + + + if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) + { + for (counter = 0; counter < 4; ++counter) + { + mz_uint s; + if (num_bits) + TINFL_GET_BITS(41, s, 8); + else + TINFL_GET_BYTE(42, s); + r->m_z_adler32 = (r->m_z_adler32 << 8) | s; + } + } + TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE); + + TINFL_CR_FINISH + +common_exit: + /* As long as we aren't telling the caller that we NEED more input to make forward progress: */ + /* Put back any bytes from the bitbuf in case we've looked ahead too far on gzip, or other Deflate streams followed by arbitrary data. */ + /* We need to be very careful here to NOT push back any bytes we definitely know we need to make forward progress, though, or we'll lock the caller up into an inf loop. */ + if ((status != TINFL_STATUS_NEEDS_MORE_INPUT) && (status != TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS)) + { + while ((pIn_buf_cur > pIn_buf_next) && (num_bits >= 8)) + { + --pIn_buf_cur; + num_bits -= 8; + } + } + r->m_num_bits = num_bits; + r->m_bit_buf = bit_buf & (tinfl_bit_buf_t)((((mz_uint64)1) << num_bits) - (mz_uint64)1); + r->m_dist = dist; + r->m_counter = counter; + r->m_num_extra = num_extra; + r->m_dist_from_out_buf_start = dist_from_out_buf_start; + *pIn_buf_size = pIn_buf_cur - pIn_buf_next; + *pOut_buf_size = pOut_buf_cur - pOut_buf_next; + if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0)) + { + const mz_uint8 *ptr = pOut_buf_next; + size_t buf_len = *pOut_buf_size; + mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; + size_t block_len = buf_len % 5552; + while (buf_len) + { + for (i = 0; i + 7 < block_len; i += 8, ptr += 8) + { + s1 += ptr[0], s2 += s1; + s1 += ptr[1], s2 += s1; + s1 += ptr[2], s2 += s1; + s1 += ptr[3], s2 += s1; + s1 += ptr[4], s2 += s1; + s1 += ptr[5], s2 += s1; + s1 += ptr[6], s2 += s1; + s1 += ptr[7], s2 += s1; + } + for (; i < block_len; ++i) + s1 += *ptr++, s2 += s1; + s1 %= 65521U, s2 %= 65521U; + buf_len -= block_len; + block_len = 5552; + } + r->m_check_adler32 = (s2 << 16) + s1; + if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) + status = TINFL_STATUS_ADLER32_MISMATCH; + } + return status; +} + + +int mz_inflateInit2(mz_streamp pStream, int window_bits, inflate_state *pDecomp) +{ + if (pStream == 0) + return MZ_STREAM_ERROR; + if ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS)) + return MZ_PARAM_ERROR; + + pStream->data_type = 0; + pStream->adler = 0; + pStream->msg = Z_NULL; + pStream->total_in = 0; + pStream->total_out = 0; + pStream->reserved = 0; + + //pStream->state = (struct mz_internal_state *)pDecomp; + pStream->state = (struct inflate_state *) pDecomp; + + tinfl_init(&pDecomp->m_decomp); + pDecomp->m_dict_ofs = 0; + pDecomp->m_dict_avail = 0; + pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT; + pDecomp->m_first_call = 1; + pDecomp->m_has_flushed = 0; + pDecomp->m_window_bits = window_bits; + + return MZ_OK; +} + +int mz_inflate(mz_streamp pStream, int flush) +{ + inflate_state *pState; + mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32; + size_t in_bytes, out_bytes, orig_avail_in; + tinfl_status status; + + if ((pStream == 0) || (pStream->state == 0)) + return MZ_STREAM_ERROR; + if (flush == MZ_PARTIAL_FLUSH) + flush = MZ_SYNC_FLUSH; + if ((flush) && (flush != MZ_SYNC_FLUSH) && (flush != MZ_FINISH)) + return MZ_STREAM_ERROR; + + pState = (inflate_state *)pStream->state; + if (pState->m_window_bits > 0) + decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER; + orig_avail_in = pStream->avail_in; + + first_call = pState->m_first_call; + pState->m_first_call = 0; + if (pState->m_last_status < 0) + return MZ_DATA_ERROR; + + if (pState->m_has_flushed && (flush != MZ_FINISH)) + return MZ_STREAM_ERROR; + pState->m_has_flushed |= (flush == MZ_FINISH); + + if ((flush == MZ_FINISH) && (first_call)) + { + /* MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file. */ + decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF; + in_bytes = pStream->avail_in; + out_bytes = pStream->avail_out; + status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags); + pState->m_last_status = status; + pStream->next_in += (mz_uint)in_bytes; + pStream->avail_in -= (mz_uint)in_bytes; + pStream->total_in += (mz_uint)in_bytes; + pStream->adler = tinfl_get_adler32(&pState->m_decomp); + pStream->next_out += (mz_uint)out_bytes; + pStream->avail_out -= (mz_uint)out_bytes; + pStream->total_out += (mz_uint)out_bytes; + + if (status < 0) + return MZ_DATA_ERROR; + else if (status != TINFL_STATUS_DONE) + { + pState->m_last_status = TINFL_STATUS_FAILED; + return MZ_BUF_ERROR; + } + return MZ_STREAM_END; + } + /* flush != MZ_FINISH then we must assume there's more input. */ + if (flush != MZ_FINISH) + decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT; + + if (pState->m_dict_avail) + { + n = MZ_MIN(pState->m_dict_avail, pStream->avail_out); + memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n); + pStream->next_out += n; + pStream->avail_out -= n; + pStream->total_out += n; + pState->m_dict_avail -= n; + pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1); + return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK; + } + + + for (;;) + { + in_bytes = pStream->avail_in; + out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs; + + status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags); + pState->m_last_status = status; + + pStream->next_in += (mz_uint)in_bytes; + pStream->avail_in -= (mz_uint)in_bytes; + pStream->total_in += (mz_uint)in_bytes; + pStream->adler = tinfl_get_adler32(&pState->m_decomp); + + pState->m_dict_avail = (mz_uint)out_bytes; + + n = MZ_MIN(pState->m_dict_avail, pStream->avail_out); + memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n); + pStream->next_out += n; + pStream->avail_out -= n; + pStream->total_out += n; + pState->m_dict_avail -= n; + pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1); + + if (status < 0) + return MZ_DATA_ERROR; /* Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well). */ + else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in)) + return MZ_BUF_ERROR; /* Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH. */ + else if (flush == MZ_FINISH) + { + /* The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH. */ + if (status == TINFL_STATUS_DONE) + return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END; + /* status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong. */ + else if (!pStream->avail_out) + return MZ_BUF_ERROR; + } + else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail)) + break; + } + + return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK; +} diff --git a/OpenCL/m17200_a0-pure.cl b/OpenCL/m17200_a0-pure.cl new file mode 100644 index 000000000..1328d458c --- /dev/null +++ b/OpenCL/m17200_a0-pure.cl @@ -0,0 +1,967 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "inc_zip_inflate.cl" +#include "inc_rp.h" +#include "inc_rp.cl" + +#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) +#define MSB(x) ((x)>>24) +#define CONST 0x08088405 +#define POLYNOMIAL 0xEDB88320 + +#define MAX_COMPRESSED_LENGTH 2048 +#define MAX_UNCOMPRESSED_LENGTH 4096 + +typedef struct { + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ +} code; + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_COMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hash; +} pkzip_t; + +__constant code lenfix[512] = { + {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, + {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, + {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, + {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, + {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, + {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, + {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, + {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, + {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, + {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, + {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, + {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, + {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, + {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, + {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, + {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, + {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, + {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, + {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, + {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, + {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, + {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, + {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, + {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, + {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, + {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, + {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, + {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, + {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, + {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, + {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, + {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, + {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, + {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, + {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, + {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, + {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, + {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, + {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, + {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, + {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, + {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, + {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, + {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, + {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, + {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, + {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, + {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, + {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, + {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, + {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, + {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, + {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, + {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, + {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, + {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, + {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, + {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, + {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, + {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, + {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, + {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, + {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, + {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, + {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, + {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, + {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, + {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, + {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, + {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, + {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, + {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, + {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, + {0,9,255} +}; + +__constant code distfix[32] = { + {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, + {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, + {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, + {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, + {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, + {22,5,193},{64,5,0} +}; + +DECLSPEC int check_inflate_code2 (u8 *next) +{ + u32 bits, hold, thisget, have, i; + int left; + u32 ncode; + u32 ncount[2]; // ends up being an array of 8 u8 count values. But we can clear it, and later 'check' it with 2 u32 instructions. + u8 *count; // this will point to ncount array. NOTE, this is alignment required 'safe' for Sparc systems or others requiring alignment. + hold = *next + (((u32)next[1])<<8) + (((u32)next[2])<<16) + (((u32)next[3])<<24); + next += 3; // we pre-increment when pulling it in the loop, thus we need to be 1 byte back. + hold >>= 3; // we already processed 3 bits + count = (u8*)ncount; + + if (257+(hold&0x1F) > 286) + { + return 0; // nlen, but we do not use it. + } + hold >>= 5; + if (1+(hold&0x1F) > 30) + { + return 0; // ndist, but we do not use it. + } + hold >>= 5; + ncode = 4+(hold&0xF); + hold >>= 4; + + // we have 15 bits left. + hold += ((u32)(*++next)) << 15; + hold += ((u32)(*++next)) << 23; + // we now have 31 bits. We need to know this for the loop below. + bits = 31; + + // We have 31 bits now, in accum. If we are processing 19 codes, we do 7, then have 10 bits. + // Add 16 more and have 26, then use 21, have 5. Then load 16 more, then eat 15 of them. + have = 0; + + ncount[0] = ncount[1] = 0; + for (;;) + { + if (have+7>ncode) + { + thisget = ncode-have; + } + else + { + thisget = 7; + } + have += thisget; + bits -= thisget*3; + while (thisget--) + { + ++count[hold&7]; + hold>>=3; + } + if (have == ncode) + { + break; + } + hold += ((u32)(*++next)) << bits; + bits += 8; + hold += ((u32)(*++next)) << bits; + bits += 8; + } + count[0] = 0; + if (!ncount[0] && !ncount[1]) + { + return 0; + } + + left = 1; + for (i = 1; i <= 7; ++i) + { + left <<= 1; + left -= count[i]; + if (left < 0) + { + return 0; + } + } + if (left > 0) + { + return 0; + } + + return 1; +} + + +DECLSPEC int check_inflate_code1 (u8 *next, int left){ + u32 whave = 0, op, bits, hold,len; + code here1; + + hold = *next + (((u32)next[1])<<8) + (((u32)next[2])<<16) + (((u32)next[3])<<24); + next += 3; // we pre-increment when pulling it in the loop, thus we need to be 1 byte back. + left -= 4; + hold >>= 3; // we already processed 3 bits + bits = 32-3; + for (;;) + { + if (bits < 15) + { + if (left < 2) + { + return 1; // we are out of bytes. Return we had no error. + } + left -= 2; + hold += (u32)(*++next) << bits; + bits += 8; + hold += (u32)(*++next) << bits; + bits += 8; + } + here1=lenfix[hold & 0x1FF]; + op = (unsigned)(here1.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here1.op); + if (op == 0) + { + ++whave; + } + else if (op & 16) + { + len = (unsigned)(here1.val); + op &= 15; + if (op) + { + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + } + len += (unsigned)hold & ((1U << op) - 1); + hold >>= op; + bits -= op; + } + if (bits < 15) + { + if (left < 2) + { + return 1; + } + left -= 2; + hold += (u32)(*++next) << bits; + bits += 8; + hold += (u32)(*++next) << bits; + bits += 8; + } + code here2 = distfix[hold & 0x1F]; + op = (unsigned)(here2.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here2.op); + if (op & 16) /* distance base */ + { + u32 dist = (unsigned)(here2.val); + op &= 15; + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + } + } + dist += (unsigned)hold & ((1U << op) - 1); + if (dist > whave) + { + return 0; + } + hold >>= op; + bits -= op; + + whave += len; + } + else + { + return 0; + } + } + else if (op & 32) + { + if (left == 0) + { + return 1; + } + return 0; + } + else + { + return 0; + } + } +} + +__kernel void m17200_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + /** + * loop + */ + + u32x key0, key1, key2; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + key0 = 0x12345678; + key1 = 0x23456789; + key2 = 0x34567890; + + for (u8 i = 0; i < tmp.pw_len; i++) + { + key0 = CRC32 (key0, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + } + + u8 compressed[MAX_COMPRESSED_LENGTH]; + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + { + continue; + } + + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) + { + continue; + } + + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + continue; + } + + compressed[0] = plain; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + for (unsigned int i = 13; i < 36; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + compressed[i - 12] = plain; + } + + if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) + { + abort=1; + } + if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) + { + abort=1; + } + + if (abort) + { + continue; + } + + for (unsigned int i = 36; i < esalt_bufs[digests_offset].hash.data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + compressed[i - 12] = plain; + } + + unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + mz_stream infstream; + inflate_state pStream; + infstream.zalloc = Z_NULL; + infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; + infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input + infstream.next_in = (Bytef *) compressed; // input char array + infstream.avail_out = 2048; // size of output + infstream.next_out = (Bytef *) inflated; // output char array + + // inflateinit2 is needed because otherwise it checks for headers by default + mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); + + const int ret = mz_inflate (&infstream, Z_NO_FLUSH); + if (ret < 0) + { + continue; // failed to inflate + } + + // check CRC + u32x crc = 0xffffffff; + for (unsigned int k = 0; k < infstream.total_out; ++k) + { + crc = CRC32 (crc, inflated[k]); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hash.crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } +} + +__kernel void m17200_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + /** + * loop + */ + + u32x key0, key1, key2; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + key0 = 0x12345678; + key1 = 0x23456789; + key2 = 0x34567890; + + for (u8 i = 0; i < tmp.pw_len; i++) + { + key0 = CRC32 (key0, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + } + + u8 compressed[MAX_COMPRESSED_LENGTH]; + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + { + continue; + } + + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) + { + continue; + } + + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + continue; + } + + compressed[0] = plain; + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + for (unsigned int i = 13; i < 36; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + compressed[i - 12] = plain; + } + + if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) + { + abort=1; + } + if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) + { + abort=1; + } + + if (abort) + { + continue; + } + + for (unsigned int i = 36; i < esalt_bufs[digests_offset].hash.data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32 (key0, plain); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32 (key2, MSB(key1)); + + compressed[i - 12] = plain; + } + + unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + mz_stream infstream; + inflate_state pStream; + infstream.zalloc = Z_NULL; + infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; + infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input + infstream.next_in = (Bytef *) compressed; // input char array + infstream.avail_out = 2048; // size of output + infstream.next_out = (Bytef *) inflated; // output char array + + // inflateinit2 is needed because otherwise it checks for headers by default + mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); + + const int ret = mz_inflate (&infstream, Z_NO_FLUSH); + if (ret < 0) + { + continue; // failed to inflate + } + + // check CRC + u32x crc = 0xffffffff; + for (unsigned int k = 0; k < infstream.total_out; ++k) + { + crc = CRC32 (crc, inflated[k]); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hash.crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } +} \ No newline at end of file diff --git a/OpenCL/m17200_a1-pure.cl b/OpenCL/m17200_a1-pure.cl new file mode 100644 index 000000000..0a481bd83 --- /dev/null +++ b/OpenCL/m17200_a1-pure.cl @@ -0,0 +1,967 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "inc_zip_inflate.cl" + +#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) +#define MSB(x) ((x)>>24) +#define CONST 0x08088405 +#define POLYNOMIAL 0xEDB88320 + +#define MAX_COMPRESSED_LENGTH 2048 +#define MAX_UNCOMPRESSED_LENGTH 4096 + +typedef struct { + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ +} code; + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_COMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hash; +} pkzip_t; + +__constant code lenfix[512] = { + {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, + {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, + {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, + {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, + {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, + {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, + {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, + {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, + {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, + {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, + {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, + {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, + {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, + {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, + {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, + {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, + {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, + {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, + {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, + {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, + {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, + {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, + {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, + {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, + {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, + {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, + {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, + {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, + {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, + {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, + {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, + {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, + {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, + {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, + {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, + {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, + {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, + {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, + {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, + {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, + {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, + {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, + {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, + {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, + {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, + {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, + {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, + {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, + {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, + {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, + {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, + {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, + {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, + {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, + {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, + {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, + {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, + {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, + {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, + {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, + {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, + {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, + {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, + {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, + {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, + {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, + {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, + {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, + {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, + {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, + {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, + {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, + {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, + {0,9,255} +}; + +__constant code distfix[32] = { + {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, + {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, + {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, + {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, + {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, + {22,5,193},{64,5,0} +}; + +DECLSPEC int check_inflate_code2 (u8 *next) +{ + u32 bits, hold, thisget, have, i; + int left; + u32 ncode; + u32 ncount[2]; // ends up being an array of 8 u8 count values. But we can clear it, and later 'check' it with 2 u32 instructions. + u8 *count; // this will point to ncount array. NOTE, this is alignment required 'safe' for Sparc systems or others requiring alignment. + hold = *next + (((u32)next[1])<<8) + (((u32)next[2])<<16) + (((u32)next[3])<<24); + next += 3; // we pre-increment when pulling it in the loop, thus we need to be 1 byte back. + hold >>= 3; // we already processed 3 bits + count = (u8*)ncount; + + if (257+(hold&0x1F) > 286) + { + return 0; // nlen, but we do not use it. + } + hold >>= 5; + if (1+(hold&0x1F) > 30) + { + return 0; // ndist, but we do not use it. + } + hold >>= 5; + ncode = 4+(hold&0xF); + hold >>= 4; + + // we have 15 bits left. + hold += ((u32)(*++next)) << 15; + hold += ((u32)(*++next)) << 23; + // we now have 31 bits. We need to know this for the loop below. + bits = 31; + + // We have 31 bits now, in accum. If we are processing 19 codes, we do 7, then have 10 bits. + // Add 16 more and have 26, then use 21, have 5. Then load 16 more, then eat 15 of them. + have = 0; + + ncount[0] = ncount[1] = 0; + for (;;) + { + if (have+7>ncode) + { + thisget = ncode-have; + } + else + { + thisget = 7; + } + have += thisget; + bits -= thisget*3; + while (thisget--) + { + ++count[hold&7]; + hold>>=3; + } + if (have == ncode) + { + break; + } + hold += ((u32)(*++next)) << bits; + bits += 8; + hold += ((u32)(*++next)) << bits; + bits += 8; + } + count[0] = 0; + if (!ncount[0] && !ncount[1]) + { + return 0; + } + + left = 1; + for (i = 1; i <= 7; ++i) + { + left <<= 1; + left -= count[i]; + if (left < 0) + { + return 0; + } + } + if (left > 0) + { + return 0; + } + + return 1; +} + + +DECLSPEC int check_inflate_code1 (u8 *next, int left){ + u32 whave = 0, op, bits, hold,len; + code here1; + + hold = *next + (((u32)next[1])<<8) + (((u32)next[2])<<16) + (((u32)next[3])<<24); + next += 3; // we pre-increment when pulling it in the loop, thus we need to be 1 byte back. + left -= 4; + hold >>= 3; // we already processed 3 bits + bits = 32-3; + for (;;) + { + if (bits < 15) + { + if (left < 2) + { + return 1; // we are out of bytes. Return we had no error. + } + left -= 2; + hold += (u32)(*++next) << bits; + bits += 8; + hold += (u32)(*++next) << bits; + bits += 8; + } + here1=lenfix[hold & 0x1FF]; + op = (unsigned)(here1.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here1.op); + if (op == 0) + { + ++whave; + } + else if (op & 16) + { + len = (unsigned)(here1.val); + op &= 15; + if (op) + { + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + } + len += (unsigned)hold & ((1U << op) - 1); + hold >>= op; + bits -= op; + } + if (bits < 15) + { + if (left < 2) + { + return 1; + } + left -= 2; + hold += (u32)(*++next) << bits; + bits += 8; + hold += (u32)(*++next) << bits; + bits += 8; + } + code here2 = distfix[hold & 0x1F]; + op = (unsigned)(here2.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here2.op); + if (op & 16) /* distance base */ + { + u32 dist = (unsigned)(here2.val); + op &= 15; + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + } + } + dist += (unsigned)hold & ((1U << op) - 1); + if (dist > whave) + { + return 0; + } + hold >>= op; + bits -= op; + + whave += len; + } + else + { + return 0; + } + } + else if (op & 32) + { + if (left == 0) + { + return 1; + } + return 0; + } + else + { + return 0; + } + } +} + +__kernel void m17200_sxx (KERN_ATTR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < pws[gid].pw_len; i++) + { + key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + key0 = key0init; + key1 = key1init; + key2 = key2init; + + for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + { + key0 = CRC32( key0, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + } + + u8 compressed[MAX_COMPRESSED_LENGTH]; + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + continue; + } + + compressed[0] = plain; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + for (unsigned int i = 13; i < 36; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i-12] = plain; + } + + if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) + { + abort=1; + } + if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) + { + abort=1; + } + + if (abort) + { + continue; + } + + for (unsigned int i = 36; i < esalt_bufs[digests_offset].hash.data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + mz_stream infstream; + inflate_state pStream; + infstream.zalloc = Z_NULL; + infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; + infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input + infstream.next_in = (Bytef *)compressed; // input char array + infstream.avail_out = 2048; // size of output + infstream.next_out = (Bytef *)inflated; // output char array + + // inflateinit2 is needed because otherwise it checks for headers by default + mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); + int ret = mz_inflate(&infstream, Z_NO_FLUSH); + if (ret < 0) + { + continue; // failed to inflate + } + + // check CRC + u32x crc = 0xffffffff; + for (unsigned int k = 0; k < infstream.total_out; ++k) + { + crc = CRC32(crc, inflated[k]); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hash.crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } +} + +__kernel void m17200_mxx (KERN_ATTR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for(u8 i = 0; i < pws[gid].pw_len; i++) + { + key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + key0 = key0init; + key1 = key1init; + key2 = key2init; + + for(u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + { + key0 = CRC32( key0, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + } + + u8 compressed[MAX_COMPRESSED_LENGTH]; + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + continue; + } + + compressed[0] = plain; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + for (unsigned int i = 13; i < 36; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i-12] = plain; + } + + if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) + { + abort=1; + } + if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) + { + abort=1; + } + + if (abort) + { + continue; + } + + for (unsigned int i = 36; i < esalt_bufs[digests_offset].hash.data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + mz_stream infstream; + inflate_state pStream; + infstream.zalloc = Z_NULL; + infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; + infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input + infstream.next_in = (Bytef *)compressed; // input char array + infstream.avail_out = 2048; // size of output + infstream.next_out = (Bytef *)inflated; // output char array + + // inflateinit2 is needed because otherwise it checks for headers by default + mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); + int ret = mz_inflate(&infstream, Z_NO_FLUSH); + if (ret < 0) + { + continue; // failed to inflate + } + + // check CRC + u32x crc = 0xffffffff; + for (unsigned int k = 0; k < infstream.total_out; ++k) + { + crc = CRC32(crc, inflated[k]); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hash.crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } +} \ No newline at end of file diff --git a/OpenCL/m17200_a3-pure.cl b/OpenCL/m17200_a3-pure.cl new file mode 100644 index 000000000..cfe13900c --- /dev/null +++ b/OpenCL/m17200_a3-pure.cl @@ -0,0 +1,979 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "inc_zip_inflate.cl" + +#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) +#define MSB(x) ((x)>>24) +#define CONST 0x08088405 +#define POLYNOMIAL 0xEDB88320 + +#define MAX_COMPRESSED_LENGTH 2048 +#define MAX_UNCOMPRESSED_LENGTH 4096 + +typedef struct { + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ +} code; + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_COMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hash; +} pkzip_t; + +__constant code lenfix[512] = { + {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, + {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, + {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, + {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, + {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, + {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, + {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, + {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, + {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, + {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, + {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, + {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, + {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, + {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, + {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, + {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, + {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, + {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, + {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, + {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, + {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, + {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, + {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, + {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, + {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, + {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, + {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, + {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, + {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, + {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, + {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, + {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, + {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, + {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, + {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, + {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, + {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, + {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, + {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, + {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, + {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, + {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, + {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, + {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, + {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, + {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, + {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, + {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, + {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, + {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, + {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, + {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, + {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, + {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, + {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, + {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, + {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, + {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, + {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, + {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, + {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, + {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, + {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, + {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, + {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, + {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, + {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, + {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, + {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, + {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, + {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, + {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, + {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, + {0,9,255} +}; + +__constant code distfix[32] = { + {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, + {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, + {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, + {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, + {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, + {22,5,193},{64,5,0} +}; + +DECLSPEC int check_inflate_code2(u8 *next) +{ + u32 bits, hold, thisget, have, i; + int left; + u32 ncode; + u32 ncount[2]; // ends up being an array of 8 u8 count values. But we can clear it, and later 'check' it with 2 u32 instructions. + u8 *count; // this will point to ncount array. NOTE, this is alignment required 'safe' for Sparc systems or others requiring alignment. + hold = *next + (((u32)next[1])<<8) + (((u32)next[2])<<16) + (((u32)next[3])<<24); + next += 3; // we pre-increment when pulling it in the loop, thus we need to be 1 byte back. + hold >>= 3; // we already processed 3 bits + count = (u8*)ncount; + + if (257+(hold&0x1F) > 286) + { + return 0; // nlen, but we do not use it. + } + hold >>= 5; + if (1+(hold&0x1F) > 30) + { + return 0; // ndist, but we do not use it. + } + hold >>= 5; + ncode = 4+(hold&0xF); + hold >>= 4; + + // we have 15 bits left. + hold += ((u32)(*++next)) << 15; + hold += ((u32)(*++next)) << 23; + // we now have 31 bits. We need to know this for the loop below. + bits = 31; + + // We have 31 bits now, in accum. If we are processing 19 codes, we do 7, then have 10 bits. + // Add 16 more and have 26, then use 21, have 5. Then load 16 more, then eat 15 of them. + have = 0; + + ncount[0] = ncount[1] = 0; + for (;;) + { + if (have+7>ncode) + { + thisget = ncode-have; + } + else + { + thisget = 7; + } + have += thisget; + bits -= thisget*3; + while (thisget--) + { + ++count[hold&7]; + hold>>=3; + } + if (have == ncode) + { + break; + } + hold += ((u32)(*++next)) << bits; + bits += 8; + hold += ((u32)(*++next)) << bits; + bits += 8; + } + count[0] = 0; + if (!ncount[0] && !ncount[1]) + { + return 0; + } + + left = 1; + for (i = 1; i <= 7; ++i) + { + left <<= 1; + left -= count[i]; + if (left < 0) + { + return 0; + } + } + if (left > 0) + { + return 0; + } + + return 1; +} + + +DECLSPEC int check_inflate_code1(u8 *next, int left){ + u32 whave = 0, op, bits, hold,len; + code here1; + + hold = *next + (((u32)next[1])<<8) + (((u32)next[2])<<16) + (((u32)next[3])<<24); + next += 3; // we pre-increment when pulling it in the loop, thus we need to be 1 byte back. + left -= 4; + hold >>= 3; // we already processed 3 bits + bits = 32-3; + for (;;) + { + if (bits < 15) + { + if (left < 2) + { + return 1; // we are out of bytes. Return we had no error. + } + left -= 2; + hold += (u32)(*++next) << bits; + bits += 8; + hold += (u32)(*++next) << bits; + bits += 8; + } + here1=lenfix[hold & 0x1FF]; + op = (unsigned)(here1.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here1.op); + if (op == 0) + { + ++whave; + } + else if (op & 16) + { + len = (unsigned)(here1.val); + op &= 15; + if (op) + { + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + } + len += (unsigned)hold & ((1U << op) - 1); + hold >>= op; + bits -= op; + } + if (bits < 15) + { + if (left < 2) + { + return 1; + } + left -= 2; + hold += (u32)(*++next) << bits; + bits += 8; + hold += (u32)(*++next) << bits; + bits += 8; + } + code here2 = distfix[hold & 0x1F]; + op = (unsigned)(here2.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here2.op); + if (op & 16) /* distance base */ + { + u32 dist = (unsigned)(here2.val); + op &= 15; + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + } + } + dist += (unsigned)hold & ((1U << op) - 1); + if (dist > whave) + { + return 0; + } + hold >>= op; + bits -= op; + + whave += len; + } + else + { + return 0; + } + } + else if (op & 32) + { + if (left == 0) + { + return 1; + } + return 0; + } + else + { + return 0; + } + } +} + +__kernel void m17200_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (int i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + /** + * loop + */ + + u32x key0, key1, key2; + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; + w[0] = w0; + + key0 = 0x12345678; + key1 = 0x23456789; + key2 = 0x34567890; + + for (u8 i = 0; i < pw_len; i++) + { + key0 = CRC32( key0, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + } + + u8 compressed[MAX_COMPRESSED_LENGTH]; + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + continue; + } + + compressed[0] = plain; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + for (unsigned int i = 13; i < 36; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i-12] = plain; + } + + if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) + { + abort=1; + } + if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) + { + abort=1; + } + + if (abort) + { + continue; + } + + for (unsigned int i = 36; i < esalt_bufs[digests_offset].hash.data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + mz_stream infstream; + inflate_state pStream; + infstream.zalloc = Z_NULL; + infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; + infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input + infstream.next_in = (Bytef *)compressed; // input char array + infstream.avail_out = 2048; // size of output + infstream.next_out = (Bytef *)inflated; // output char array + + // inflateinit2 is needed because otherwise it checks for headers by default + mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); + int ret = mz_inflate(&infstream, Z_NO_FLUSH); + if (ret < 0) + { + continue; // failed to inflate + } + + // check CRC + u32x crc = 0xffffffff; + for (unsigned int k = 0; k < infstream.total_out; ++k) + { + crc = CRC32(crc, inflated[k]); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hash.crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } +} + +__kernel void m17200_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (int i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + /** + * loop + */ + + u32x key0, key1, key2; + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; + w[0] = w0; + + key0 = 0x12345678; + key1 = 0x23456789; + key2 = 0x34567890; + + for(u8 i = 0; i < pw_len; i++) + { + key0 = CRC32( key0, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + } + + u8 compressed[MAX_COMPRESSED_LENGTH]; + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + continue; + } + + compressed[0] = plain; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + for (unsigned int i = 13; i < 36; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i-12] = plain; + } + + if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) + { + abort=1; + } + if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) + { + abort=1; + } + + if (abort) + { + continue; + } + + for (unsigned int i = 36; i < esalt_bufs[digests_offset].hash.data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + mz_stream infstream; + inflate_state pStream; + infstream.zalloc = Z_NULL; + infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; + infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input + infstream.next_in = (Bytef *)compressed; // input char array + infstream.avail_out = 2048; // size of output + infstream.next_out = (Bytef *)inflated; // output char array + + // inflateinit2 is needed because otherwise it checks for headers by default + mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); + int ret = mz_inflate(&infstream, Z_NO_FLUSH); + if (ret < 0) + { + continue; // failed to inflate + } + + // check CRC + u32x crc = 0xffffffff; + for (unsigned int k = 0; k < infstream.total_out; ++k) + { + crc = CRC32(crc, inflated[k]); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hash.crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } +} \ No newline at end of file diff --git a/OpenCL/m17210_a0-pure.cl b/OpenCL/m17210_a0-pure.cl new file mode 100644 index 000000000..d78df3280 --- /dev/null +++ b/OpenCL/m17210_a0-pure.cl @@ -0,0 +1,551 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "inc_vendor.cl" +#include "inc_hash_constants.h" +#include "inc_hash_functions.cl" +#include "inc_types.cl" +#include "inc_common.cl" +#include "inc_simd.cl" +#include "inc_rp.h" +#include "inc_rp.cl" + +#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) +#define MSB(x) ((x)>>24) +#define CONST 0x08088405 +#define POLYNOMIAL 0xEDB88320 + +#define MAX_UNCOMPRESSED_LENGTH 4096 + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_UNCOMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hash; +} pkzip_t; + +__kernel void m17210_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + /** + * loop + */ + + u32x key0, key1, key2; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + key0 = 0x12345678; + key1 = 0x23456789; + key2 = 0x34567890; + + for (u8 i = 0; i < tmp.pw_len; i++) + { + key0 = CRC32( key0, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + } + + u8 plain; + u8 key3; + u16 temp; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp^1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + u32x crc = 0xffffffff; + crc = CRC32(crc, plain); + + for (unsigned int i = 13; i < esalt_bufs[digests_offset].hash.data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + crc = CRC32(crc, plain); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hash.crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } +} + +__kernel void m17210_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + /** + * loop + */ + + u32x key0, key1, key2; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + key0 = 0x12345678; + key1 = 0x23456789; + key2 = 0x34567890; + + for (u8 i = 0; i < tmp.pw_len; i++) + { + key0 = CRC32( key0, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + } + + u8 plain; + u8 key3; + u16 temp; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp^1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + u32x crc = 0xffffffff; + crc = CRC32(crc, plain); + + for (unsigned int i = 13; i < esalt_bufs[digests_offset].hash.data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + crc = CRC32(crc, plain); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hash.crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } +} \ No newline at end of file diff --git a/OpenCL/m17210_a1-pure.cl b/OpenCL/m17210_a1-pure.cl new file mode 100644 index 000000000..6e49d74d5 --- /dev/null +++ b/OpenCL/m17210_a1-pure.cl @@ -0,0 +1,553 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "inc_vendor.cl" +#include "inc_hash_constants.h" +#include "inc_hash_functions.cl" +#include "inc_types.cl" +#include "inc_common.cl" +#include "inc_simd.cl" + +#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) +#define MSB(x) ((x)>>24) +#define CONST 0x08088405 +#define POLYNOMIAL 0xEDB88320 + +#define MAX_UNCOMPRESSED_LENGTH 4096 + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_UNCOMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hash; +} pkzip_t; + +__kernel void m17210_sxx (KERN_ATTR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < pws[gid].pw_len; i++) + { + key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + key0 = key0init; + key1 = key1init; + key2 = key2init; + + for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + { + key0 = CRC32( key0, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + } + + u8 plain; + u8 key3; + u16 temp; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp^1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + u32x crc = 0xffffffff; + crc = CRC32(crc, plain); + + for (unsigned int i = 13; i < esalt_bufs[digests_offset].hash.data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + crc = CRC32(crc, plain); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hash.crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } +} + +__kernel void m17210_mxx (KERN_ATTR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < pws[gid].pw_len; i++) + { + key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + key0 = key0init; + key1 = key1init; + key2 = key2init; + + for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + { + key0 = CRC32( key0, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + } + + u8 plain; + u8 key3; + u16 temp; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp^1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + u32x crc = 0xffffffff; + crc = CRC32(crc, plain); + + for (unsigned int i = 13; i < esalt_bufs[digests_offset].hash.data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + crc = CRC32(crc, plain); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hash.crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } +} \ No newline at end of file diff --git a/OpenCL/m17210_a3-pure.cl b/OpenCL/m17210_a3-pure.cl new file mode 100644 index 000000000..a56146cca --- /dev/null +++ b/OpenCL/m17210_a3-pure.cl @@ -0,0 +1,565 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "inc_vendor.cl" +#include "inc_hash_constants.h" +#include "inc_hash_functions.cl" +#include "inc_types.cl" +#include "inc_common.cl" +#include "inc_simd.cl" + +#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) +#define MSB(x) ((x)>>24) +#define CONST 0x08088405 +#define POLYNOMIAL 0xEDB88320 + +#define MAX_UNCOMPRESSED_LENGTH 4096 + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_UNCOMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hash; +} pkzip_t; + +__kernel void m17210_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (int i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + /** + * loop + */ + + u32x key0, key1, key2; + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; + w[0] = w0; + + key0 = 0x12345678; + key1 = 0x23456789; + key2 = 0x34567890; + + for (u8 i = 0; i < pw_len; i++) + { + key0 = CRC32( key0, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + } + + u8 plain; + u8 key3; + u16 temp; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp^1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + u32x crc = 0xffffffff; + crc = CRC32(crc, plain); + + for (unsigned int i = 13; i < esalt_bufs[digests_offset].hash.data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + crc = CRC32(crc, plain); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hash.crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } +} + +__kernel void m17210_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (int i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + /** + * loop + */ + + u32x key0, key1, key2; + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; + w[0] = w0; + + key0 = 0x12345678; + key1 = 0x23456789; + key2 = 0x34567890; + + for (u8 i = 0; i < pw_len; i++) + { + key0 = CRC32( key0, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + } + + u8 plain; + u8 key3; + u16 temp; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp^1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) + { + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + u32x crc = 0xffffffff; + crc = CRC32(crc, plain); + + for (unsigned int i = 13; i < esalt_bufs[digests_offset].hash.data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + crc = CRC32(crc, plain); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hash.crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } +} \ No newline at end of file diff --git a/OpenCL/m17220_a0-pure.cl b/OpenCL/m17220_a0-pure.cl new file mode 100644 index 000000000..828ca77e2 --- /dev/null +++ b/OpenCL/m17220_a0-pure.cl @@ -0,0 +1,1003 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "inc_zip_inflate.cl" +#include "inc_rp.h" +#include "inc_rp.cl" + +#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) +#define MSB(x) ((x)>>24) +#define CONST 0x08088405 +#define POLYNOMIAL 0xEDB88320 + +#define MAX_COMPRESSED_LENGTH 2048 +#define MAX_UNCOMPRESSED_LENGTH 4096 + +typedef struct { + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ +} code; + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_COMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hashes[8]; +} pkzip_t; + +__constant code lenfix[512] = { + {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, + {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, + {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, + {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, + {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, + {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, + {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, + {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, + {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, + {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, + {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, + {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, + {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, + {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, + {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, + {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, + {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, + {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, + {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, + {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, + {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, + {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, + {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, + {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, + {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, + {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, + {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, + {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, + {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, + {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, + {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, + {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, + {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, + {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, + {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, + {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, + {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, + {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, + {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, + {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, + {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, + {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, + {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, + {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, + {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, + {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, + {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, + {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, + {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, + {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, + {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, + {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, + {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, + {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, + {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, + {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, + {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, + {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, + {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, + {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, + {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, + {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, + {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, + {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, + {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, + {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, + {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, + {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, + {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, + {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, + {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, + {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, + {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, + {0,9,255} +}; + +__constant code distfix[32] = { + {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, + {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, + {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, + {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, + {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, + {22,5,193},{64,5,0} +}; + +DECLSPEC int check_inflate_code2(u8 *next) +{ + u32 bits, hold, thisget, have, i; + int left; + u32 ncode; + u32 ncount[2]; // ends up being an array of 8 u8 count values. But we can clear it, and later 'check' it with 2 u32 instructions. + u8 *count; // this will point to ncount array. NOTE, this is alignment required 'safe' for Sparc systems or others requiring alignment. + hold = *next + (((u32)next[1])<<8) + (((u32)next[2])<<16) + (((u32)next[3])<<24); + next += 3; // we pre-increment when pulling it in the loop, thus we need to be 1 byte back. + hold >>= 3; // we already processed 3 bits + count = (u8*)ncount; + + if (257+(hold&0x1F) > 286) + { + return 0; // nlen, but we do not use it. + } + hold >>= 5; + if (1+(hold&0x1F) > 30) + { + return 0; // ndist, but we do not use it. + } + hold >>= 5; + ncode = 4+(hold&0xF); + hold >>= 4; + + // we have 15 bits left. + hold += ((u32)(*++next)) << 15; + hold += ((u32)(*++next)) << 23; + // we now have 31 bits. We need to know this for the loop below. + bits = 31; + + // We have 31 bits now, in accum. If we are processing 19 codes, we do 7, then have 10 bits. + // Add 16 more and have 26, then use 21, have 5. Then load 16 more, then eat 15 of them. + have = 0; + + ncount[0] = ncount[1] = 0; + for (;;) + { + if (have+7>ncode) + { + thisget = ncode-have; + } + else + { + thisget = 7; + } + have += thisget; + bits -= thisget*3; + while (thisget--) + { + ++count[hold&7]; + hold>>=3; + } + if (have == ncode) + { + break; + } + hold += ((u32)(*++next)) << bits; + bits += 8; + hold += ((u32)(*++next)) << bits; + bits += 8; + } + count[0] = 0; + if (!ncount[0] && !ncount[1]) + { + return 0; + } + + left = 1; + for (i = 1; i <= 7; ++i) + { + left <<= 1; + left -= count[i]; + if (left < 0) + { + return 0; + } + } + if (left > 0) + { + return 0; + } + + return 1; +} + + +DECLSPEC int check_inflate_code1(u8 *next, int left){ + u32 whave = 0, op, bits, hold,len; + code here1; + + hold = *next + (((u32)next[1])<<8) + (((u32)next[2])<<16) + (((u32)next[3])<<24); + next += 3; // we pre-increment when pulling it in the loop, thus we need to be 1 byte back. + left -= 4; + hold >>= 3; // we already processed 3 bits + bits = 32-3; + for (;;) + { + if (bits < 15) + { + if (left < 2) + { + return 1; // we are out of bytes. Return we had no error. + } + left -= 2; + hold += (u32)(*++next) << bits; + bits += 8; + hold += (u32)(*++next) << bits; + bits += 8; + } + here1=lenfix[hold & 0x1FF]; + op = (unsigned)(here1.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here1.op); + if (op == 0) + { + ++whave; + } + else if (op & 16) + { + len = (unsigned)(here1.val); + op &= 15; + if (op) + { + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + } + len += (unsigned)hold & ((1U << op) - 1); + hold >>= op; + bits -= op; + } + if (bits < 15) + { + if (left < 2) + { + return 1; + } + left -= 2; + hold += (u32)(*++next) << bits; + bits += 8; + hold += (u32)(*++next) << bits; + bits += 8; + } + code here2 = distfix[hold & 0x1F]; + op = (unsigned)(here2.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here2.op); + if (op & 16) /* distance base */ + { + u32 dist = (unsigned)(here2.val); + op &= 15; + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + } + } + dist += (unsigned)hold & ((1U << op) - 1); + if (dist > whave) + { + return 0; + } + hold >>= op; + bits -= op; + + whave += len; + } + else + { + return 0; + } + } + else if (op & 32) + { + if (left == 0) + { + return 1; + } + return 0; + } + else + { + return 0; + } + } +} + +__kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < tmp.pw_len; i++) + { + key0init = CRC32( key0init, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + u8 compressed[MAX_COMPRESSED_LENGTH]; + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + { + key0 = key0init; + key1 = key1init; + key2 = key2init; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + idx = 0xfe; + continue; + } + + compressed[0] = plain; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + for (unsigned int i = 13; i < 36; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) + { + abort=1; + } + if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) + { + abort=1; + } + + if (abort) + { + idx = 0xfe; + continue; + } + + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) + { + continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one + } + + for (unsigned int i = 36; i < esalt_bufs[digests_offset].hashes[idx].data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + mz_stream infstream; + inflate_state pStream; + infstream.zalloc = Z_NULL; + infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; + infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input + infstream.next_in = (Bytef *)compressed; // input char array + infstream.avail_out = 2048; // size of output + infstream.next_out = (Bytef *)inflated; // output char array + + // inflateinit2 is needed because otherwise it checks for headers by default + mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); + int ret = mz_inflate(&infstream, Z_NO_FLUSH); + if (ret < 0) + { + idx = 0xfe; + continue; // failed to inflate + } + + // check CRC + u32x crc = 0xffffffff; + for (unsigned int k = 0; k < infstream.total_out; ++k) + { + crc = CRC32(crc, inflated[k]); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hashes[idx].crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + idx = 0xfe; + } + } +} + +__kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < tmp.pw_len; i++) + { + key0init = CRC32( key0init, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + u8 compressed[MAX_COMPRESSED_LENGTH]; + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + { + key0 = key0init; + key1 = key1init; + key2 = key2init; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + idx = 0xfe; + continue; + } + + compressed[0] = plain; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + for (unsigned int i = 13; i < 36; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i-12] = plain; + } + + if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) + { + abort=1; + } + if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) + { + abort=1; + } + + if (abort) + { + idx = 0xfe; + continue; + } + + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) + { + continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one + } + + for (unsigned int i = 36; i < esalt_bufs[digests_offset].hashes[idx].data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + mz_stream infstream; + inflate_state pStream; + infstream.zalloc = Z_NULL; + infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; + infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input + infstream.next_in = (Bytef *)compressed; // input char array + infstream.avail_out = 2048; // size of output + infstream.next_out = (Bytef *)inflated; // output char array + + // inflateinit2 is needed because otherwise it checks for headers by default + mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); + int ret = mz_inflate(&infstream, Z_NO_FLUSH); + if (ret < 0) + { + idx = 0xfe; + continue; // failed to inflate + } + + // check CRC + u32x crc = 0xffffffff; + for (unsigned int k = 0; k < infstream.total_out; ++k) + { + crc = CRC32(crc, inflated[k]); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hashes[idx].crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + idx = 0xfe; + } + } +} \ No newline at end of file diff --git a/OpenCL/m17220_a1-pure.cl b/OpenCL/m17220_a1-pure.cl new file mode 100644 index 000000000..f1dfc2e50 --- /dev/null +++ b/OpenCL/m17220_a1-pure.cl @@ -0,0 +1,1005 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "inc_zip_inflate.cl" + +#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) +#define MSB(x) ((x)>>24) +#define CONST 0x08088405 +#define POLYNOMIAL 0xEDB88320 + +#define MAX_COMPRESSED_LENGTH 2048 +#define MAX_UNCOMPRESSED_LENGTH 4096 + +typedef struct { + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ +} code; + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_COMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hashes[8]; +} pkzip_t; + +__constant code lenfix[512] = { + {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, + {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, + {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, + {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, + {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, + {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, + {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, + {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, + {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, + {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, + {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, + {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, + {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, + {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, + {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, + {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, + {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, + {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, + {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, + {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, + {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, + {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, + {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, + {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, + {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, + {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, + {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, + {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, + {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, + {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, + {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, + {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, + {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, + {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, + {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, + {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, + {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, + {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, + {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, + {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, + {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, + {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, + {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, + {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, + {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, + {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, + {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, + {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, + {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, + {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, + {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, + {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, + {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, + {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, + {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, + {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, + {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, + {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, + {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, + {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, + {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, + {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, + {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, + {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, + {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, + {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, + {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, + {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, + {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, + {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, + {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, + {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, + {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, + {0,9,255} +}; + +__constant code distfix[32] = { + {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, + {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, + {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, + {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, + {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, + {22,5,193},{64,5,0} +}; + +DECLSPEC int check_inflate_code2(u8 *next) +{ + u32 bits, hold, thisget, have, i; + int left; + u32 ncode; + u32 ncount[2]; // ends up being an array of 8 u8 count values. But we can clear it, and later 'check' it with 2 u32 instructions. + u8 *count; // this will point to ncount array. NOTE, this is alignment required 'safe' for Sparc systems or others requiring alignment. + hold = *next + (((u32)next[1])<<8) + (((u32)next[2])<<16) + (((u32)next[3])<<24); + next += 3; // we pre-increment when pulling it in the loop, thus we need to be 1 byte back. + hold >>= 3; // we already processed 3 bits + count = (u8*)ncount; + + if (257+(hold&0x1F) > 286) + { + return 0; // nlen, but we do not use it. + } + hold >>= 5; + if (1+(hold&0x1F) > 30) + { + return 0; // ndist, but we do not use it. + } + hold >>= 5; + ncode = 4+(hold&0xF); + hold >>= 4; + + // we have 15 bits left. + hold += ((u32)(*++next)) << 15; + hold += ((u32)(*++next)) << 23; + // we now have 31 bits. We need to know this for the loop below. + bits = 31; + + // We have 31 bits now, in accum. If we are processing 19 codes, we do 7, then have 10 bits. + // Add 16 more and have 26, then use 21, have 5. Then load 16 more, then eat 15 of them. + have = 0; + + ncount[0] = ncount[1] = 0; + for (;;) + { + if (have+7>ncode) + { + thisget = ncode-have; + } + else + { + thisget = 7; + } + have += thisget; + bits -= thisget*3; + while (thisget--) + { + ++count[hold&7]; + hold>>=3; + } + if (have == ncode) + { + break; + } + hold += ((u32)(*++next)) << bits; + bits += 8; + hold += ((u32)(*++next)) << bits; + bits += 8; + } + count[0] = 0; + if (!ncount[0] && !ncount[1]) + { + return 0; + } + + left = 1; + for (i = 1; i <= 7; ++i) + { + left <<= 1; + left -= count[i]; + if (left < 0) + { + return 0; + } + } + if (left > 0) + { + return 0; + } + + return 1; +} + + +DECLSPEC int check_inflate_code1(u8 *next, int left){ + u32 whave = 0, op, bits, hold,len; + code here1; + + hold = *next + (((u32)next[1])<<8) + (((u32)next[2])<<16) + (((u32)next[3])<<24); + next += 3; // we pre-increment when pulling it in the loop, thus we need to be 1 byte back. + left -= 4; + hold >>= 3; // we already processed 3 bits + bits = 32-3; + for (;;) + { + if (bits < 15) + { + if (left < 2) + { + return 1; // we are out of bytes. Return we had no error. + } + left -= 2; + hold += (u32)(*++next) << bits; + bits += 8; + hold += (u32)(*++next) << bits; + bits += 8; + } + here1=lenfix[hold & 0x1FF]; + op = (unsigned)(here1.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here1.op); + if (op == 0) + { + ++whave; + } + else if (op & 16) + { + len = (unsigned)(here1.val); + op &= 15; + if (op) + { + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + } + len += (unsigned)hold & ((1U << op) - 1); + hold >>= op; + bits -= op; + } + if (bits < 15) + { + if (left < 2) + { + return 1; + } + left -= 2; + hold += (u32)(*++next) << bits; + bits += 8; + hold += (u32)(*++next) << bits; + bits += 8; + } + code here2 = distfix[hold & 0x1F]; + op = (unsigned)(here2.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here2.op); + if (op & 16) /* distance base */ + { + u32 dist = (unsigned)(here2.val); + op &= 15; + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + } + } + dist += (unsigned)hold & ((1U << op) - 1); + if (dist > whave) + { + return 0; + } + hold >>= op; + bits -= op; + + whave += len; + } + else + { + return 0; + } + } + else if (op & 32) + { + if (left == 0) + { + return 1; + } + return 0; + } + else + { + return 0; + } + } +} + +__kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + u32x key0init2, key1init2, key2init2; + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < pws[gid].pw_len; i++) + { + key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + key0init2 = key0init; + key1init2 = key1init; + key2init2 = key2init; + + for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + { + key0init2 = CRC32( key0init2, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init2 = (key1init2 + (key0init2 & 0xff)) * CONST + 1; + key2init2 = CRC32( key2init2, MSB(key1init2) ); + } + + u8 compressed[MAX_COMPRESSED_LENGTH]; + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + { + key0 = key0init2; + key1 = key1init2; + key2 = key2init2; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + idx = 0xfe; + continue; + } + + compressed[0] = plain; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + for (unsigned int i = 13; i < 36; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) + { + abort = 1; + } + if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) + { + abort = 1; + } + + if (abort) + { + idx = 0xfe; + continue; + } + + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) + { + continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one + } + + for (unsigned int i = 36; i < esalt_bufs[digests_offset].hashes[idx].data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + mz_stream infstream; + inflate_state pStream; + infstream.zalloc = Z_NULL; + infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; + infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input + infstream.next_in = (Bytef *)compressed; // input char array + infstream.avail_out = 2048; // size of output + infstream.next_out = (Bytef *)inflated; // output char array + + // inflateinit2 is needed because otherwise it checks for headers by default + mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); + int ret = mz_inflate(&infstream, Z_NO_FLUSH); + if (ret < 0) + { + idx = 0xfe; + continue; // failed to inflate + } + + // check CRC + u32x crc = 0xffffffff; + for (unsigned int k = 0; k < infstream.total_out; ++k) + { + crc = CRC32(crc, inflated[k]); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hashes[idx].crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + idx = 0xfe; + } + } +} + +__kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + u32x key0init2, key1init2, key2init2; + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < pws[gid].pw_len; i++) + { + key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + key0init2 = key0init; + key1init2 = key1init; + key2init2 = key2init; + + for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + { + key0init2 = CRC32( key0init2, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init2 = (key1init2 + (key0init2 & 0xff)) * CONST + 1; + key2init2 = CRC32( key2init2, MSB(key1init2) ); + } + + u8 compressed[MAX_COMPRESSED_LENGTH]; + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + { + key0 = key0init2; + key1 = key1init2; + key2 = key2init2; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + idx = 0xfe; + continue; + } + + compressed[0] = plain; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + for (unsigned int i = 13; i < 36; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) + { + abort = 1; + } + if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) + { + abort = 1; + } + + if (abort) + { + idx = 0xfe; + continue; + } + + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) + { + continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one + } + + for (unsigned int i = 36; i < esalt_bufs[digests_offset].hashes[idx].data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + mz_stream infstream; + inflate_state pStream; + infstream.zalloc = Z_NULL; + infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; + infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input + infstream.next_in = (Bytef *)compressed; // input char array + infstream.avail_out = 2048; // size of output + infstream.next_out = (Bytef *)inflated; // output char array + + // inflateinit2 is needed because otherwise it checks for headers by default + mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); + int ret = mz_inflate(&infstream, Z_NO_FLUSH); + if (ret < 0) + { + idx = 0xfe; + continue; // failed to inflate + } + + // check CRC + u32x crc = 0xffffffff; + for (unsigned int k = 0; k < infstream.total_out; ++k) + { + crc = CRC32(crc, inflated[k]); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hashes[idx].crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + idx = 0xfe; + } + } +} \ No newline at end of file diff --git a/OpenCL/m17220_a3-pure.cl b/OpenCL/m17220_a3-pure.cl new file mode 100644 index 000000000..0dc5e38fc --- /dev/null +++ b/OpenCL/m17220_a3-pure.cl @@ -0,0 +1,1012 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "inc_zip_inflate.cl" + +#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) +#define MSB(x) ((x)>>24) +#define CONST 0x08088405 +#define POLYNOMIAL 0xEDB88320 + +#define MAX_COMPRESSED_LENGTH 2048 +#define MAX_UNCOMPRESSED_LENGTH 4096 + +typedef struct { + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ +} code; + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_COMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hashes[8]; +} pkzip_t; + +__constant code lenfix[512] = { + {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, + {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, + {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, + {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, + {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, + {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, + {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, + {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, + {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, + {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, + {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, + {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, + {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, + {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, + {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, + {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, + {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, + {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, + {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, + {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, + {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, + {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, + {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, + {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, + {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, + {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, + {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, + {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, + {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, + {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, + {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, + {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, + {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, + {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, + {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, + {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, + {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, + {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, + {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, + {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, + {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, + {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, + {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, + {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, + {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, + {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, + {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, + {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, + {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, + {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, + {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, + {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, + {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, + {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, + {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, + {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, + {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, + {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, + {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, + {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, + {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, + {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, + {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, + {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, + {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, + {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, + {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, + {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, + {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, + {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, + {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, + {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, + {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, + {0,9,255} +}; + +__constant code distfix[32] = { + {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, + {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, + {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, + {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, + {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, + {22,5,193},{64,5,0} +}; + +DECLSPEC int check_inflate_code2(u8 *next) +{ + u32 bits, hold, thisget, have, i; + int left; + u32 ncode; + u32 ncount[2]; // ends up being an array of 8 u8 count values. But we can clear it, and later 'check' it with 2 u32 instructions. + u8 *count; // this will point to ncount array. NOTE, this is alignment required 'safe' for Sparc systems or others requiring alignment. + hold = *next + (((u32)next[1])<<8) + (((u32)next[2])<<16) + (((u32)next[3])<<24); + next += 3; // we pre-increment when pulling it in the loop, thus we need to be 1 byte back. + hold >>= 3; // we already processed 3 bits + count = (u8*)ncount; + + if (257+(hold&0x1F) > 286) + { + return 0; // nlen, but we do not use it. + } + hold >>= 5; + if (1+(hold&0x1F) > 30) + { + return 0; // ndist, but we do not use it. + } + hold >>= 5; + ncode = 4+(hold&0xF); + hold >>= 4; + + // we have 15 bits left. + hold += ((u32)(*++next)) << 15; + hold += ((u32)(*++next)) << 23; + // we now have 31 bits. We need to know this for the loop below. + bits = 31; + + // We have 31 bits now, in accum. If we are processing 19 codes, we do 7, then have 10 bits. + // Add 16 more and have 26, then use 21, have 5. Then load 16 more, then eat 15 of them. + have = 0; + + ncount[0] = ncount[1] = 0; + for (;;) + { + if (have+7>ncode) + { + thisget = ncode-have; + } + else + { + thisget = 7; + } + have += thisget; + bits -= thisget*3; + while (thisget--) + { + ++count[hold&7]; + hold>>=3; + } + if (have == ncode) + { + break; + } + hold += ((u32)(*++next)) << bits; + bits += 8; + hold += ((u32)(*++next)) << bits; + bits += 8; + } + count[0] = 0; + if (!ncount[0] && !ncount[1]) + { + return 0; + } + + left = 1; + for (i = 1; i <= 7; ++i) + { + left <<= 1; + left -= count[i]; + if (left < 0) + { + return 0; + } + } + if (left > 0) + { + return 0; + } + + return 1; +} + + +DECLSPEC int check_inflate_code1(u8 *next, int left){ + u32 whave = 0, op, bits, hold,len; + code here1; + + hold = *next + (((u32)next[1])<<8) + (((u32)next[2])<<16) + (((u32)next[3])<<24); + next += 3; // we pre-increment when pulling it in the loop, thus we need to be 1 byte back. + left -= 4; + hold >>= 3; // we already processed 3 bits + bits = 32-3; + for (;;) + { + if (bits < 15) + { + if (left < 2) + { + return 1; // we are out of bytes. Return we had no error. + } + left -= 2; + hold += (u32)(*++next) << bits; + bits += 8; + hold += (u32)(*++next) << bits; + bits += 8; + } + here1=lenfix[hold & 0x1FF]; + op = (unsigned)(here1.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here1.op); + if (op == 0) + { + ++whave; + } + else if (op & 16) + { + len = (unsigned)(here1.val); + op &= 15; + if (op) + { + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + } + len += (unsigned)hold & ((1U << op) - 1); + hold >>= op; + bits -= op; + } + if (bits < 15) + { + if (left < 2) + { + return 1; + } + left -= 2; + hold += (u32)(*++next) << bits; + bits += 8; + hold += (u32)(*++next) << bits; + bits += 8; + } + code here2 = distfix[hold & 0x1F]; + op = (unsigned)(here2.bits); + hold >>= op; + bits -= op; + op = (unsigned)(here2.op); + if (op & 16) /* distance base */ + { + u32 dist = (unsigned)(here2.val); + op &= 15; + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + if (bits < op) + { + if (!left) + { + return 1; + } + --left; + hold += (u32)(*++next) << bits; + bits += 8; + } + } + dist += (unsigned)hold & ((1U << op) - 1); + if (dist > whave) + { + return 0; + } + hold >>= op; + bits -= op; + + whave += len; + } + else + { + return 0; + } + } + else if (op & 32) + { + if (left == 0) + { + return 1; + } + return 0; + } + else + { + return 0; + } + } +} + +__kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (int i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; + w[0] = w0; + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < pw_len; i++) + { + key0init = CRC32( key0init, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + u8 compressed[MAX_COMPRESSED_LENGTH]; + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + { + key0 = key0init; + key1 = key1init; + key2 = key2init; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + idx = 0xfe; + continue; + } + + compressed[0] = plain; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + for (unsigned int i = 13; i < 36; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i-12] = plain; + } + + if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) + { + abort=1; + } + if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) + { + abort=1; + } + if (abort) + { + idx = 0xfe; + continue; + } + + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1){ + continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one + } + + for (unsigned int i = 36; i < esalt_bufs[digests_offset].hashes[idx].data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + mz_stream infstream; + inflate_state pStream; + infstream.zalloc = Z_NULL; + infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; + infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input + infstream.next_in = (Bytef *)compressed; // input char array + infstream.avail_out = 2048; // size of output + infstream.next_out = (Bytef *)inflated; // output char array + + // inflateinit2 is needed because otherwise it checks for headers by default + mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); + int ret = mz_inflate(&infstream, Z_NO_FLUSH); + if (ret < 0) + { + idx = 0xfe; + continue; // failed to inflate + } + + // check CRC + u32x crc = 0xffffffff; + for (unsigned int k = 0; k < infstream.total_out; ++k) + { + crc = CRC32(crc, inflated[k]); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hashes[idx].crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + idx = 0xfe; + } + } +} + +__kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (int i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; + w[0] = w0; + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < pw_len; i++) + { + key0init = CRC32( key0init, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + u8 compressed[MAX_COMPRESSED_LENGTH]; + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + { + key0 = key0init; + key1 = key1init; + key2 = key2init; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; + + if(esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) + { + idx = 0xfe; + continue; + } + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + idx = 0xfe; + continue; + } + + compressed[0] = plain; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + for (unsigned int i = 13; i < 36; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i-12] = plain; + } + + if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) + { + abort=1; + } + if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) + { + abort=1; + } + if (abort) + { + idx = 0xfe; + continue; + } + + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1){ + continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one + } + + for (unsigned int i = 36; i < esalt_bufs[digests_offset].hashes[idx].data_length; i++) + { + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + compressed[i - 12] = plain; + } + + unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + mz_stream infstream; + inflate_state pStream; + infstream.zalloc = Z_NULL; + infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; + infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input + infstream.next_in = (Bytef *)compressed; // input char array + infstream.avail_out = 2048; // size of output + infstream.next_out = (Bytef *)inflated; // output char array + + // inflateinit2 is needed because otherwise it checks for headers by default + mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); + int ret = mz_inflate(&infstream, Z_NO_FLUSH); + if (ret < 0) + { + idx = 0xfe; + continue; // failed to inflate + } + + // check CRC + u32x crc = 0xffffffff; + for (unsigned int k = 0; k < infstream.total_out; ++k) + { + crc = CRC32(crc, inflated[k]); + } + crc = ~crc; + + if (crc == esalt_bufs[digests_offset].hashes[idx].crc32) + { + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + idx = 0xfe; + } + } +} \ No newline at end of file diff --git a/OpenCL/m17230_a0-pure.cl b/OpenCL/m17230_a0-pure.cl new file mode 100644 index 000000000..9d3607604 --- /dev/null +++ b/OpenCL/m17230_a0-pure.cl @@ -0,0 +1,539 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "inc_vendor.cl" +#include "inc_hash_constants.h" +#include "inc_hash_functions.cl" +#include "inc_types.cl" +#include "inc_common.cl" +#include "inc_simd.cl" +#include "inc_rp.h" +#include "inc_rp.cl" + +#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) +#define MSB(x) ((x)>>24) +#define CONST 0x08088405 +#define POLYNOMIAL 0xEDB88320 + +#define MAX_COMPRESSED_LENGTH 2048 + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_COMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hashes[8]; +} pkzip_t; + +__kernel void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < tmp.pw_len; i++) + { + key0init = CRC32( key0init, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + u8 plain; + u8 key3; + u16 temp; + + for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + { + key0 = key0init; + key1 = key1init; + key2 = key2init; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + idx = 0xfe; + continue; + } + + if (idx + 1 == esalt_bufs[digests_offset].hash_count){ \ + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } + } +} + +__kernel void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + COPY_PW (pws[gid]); + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + pw_t tmp = PASTE_PW; + + tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < tmp.pw_len; i++) + { + key0init = CRC32( key0init, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + u8 plain; + u8 key3; + u16 temp; + + for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + { + key0 = key0init; + key1 = key1init; + key2 = key2init; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + idx = 0xfe; + continue; + } + + if (idx + 1 == esalt_bufs[digests_offset].hash_count){ \ + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } + } +} \ No newline at end of file diff --git a/OpenCL/m17230_a1-pure.cl b/OpenCL/m17230_a1-pure.cl new file mode 100644 index 000000000..f882801fe --- /dev/null +++ b/OpenCL/m17230_a1-pure.cl @@ -0,0 +1,544 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "inc_zip_inflate.cl" + +#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) +#define MSB(x) ((x)>>24) +#define CONST 0x08088405 +#define POLYNOMIAL 0xEDB88320 + +#define MAX_COMPRESSED_LENGTH 2048 + +typedef struct { + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ +} code; + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_COMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hashes[8]; +} pkzip_t; + +__kernel void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + u32x key0init2, key1init2, key2init2; + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < pws[gid].pw_len; i++) + { + key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + key0init2 = key0init; + key1init2 = key1init; + key2init2 = key2init; + + for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + { + key0init2 = CRC32( key0init2, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init2 = (key1init2 + (key0init2 & 0xff)) * CONST + 1; + key2init2 = CRC32( key2init2, MSB(key1init2) ); + } + + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + { + key0 = key0init2; + key1 = key1init2; + key2 = key2init2; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + idx = 0xfe; + continue; + } + + if (idx + 1 == esalt_bufs[digests_offset].hash_count){ \ + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } + } +} + +__kernel void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + u32x key0init2, key1init2, key2init2; + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < pws[gid].pw_len; i++) + { + key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) + { + key0init2 = key0init; + key1init2 = key1init; + key2init2 = key2init; + + for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + { + key0init2 = CRC32( key0init2, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init2 = (key1init2 + (key0init2 & 0xff)) * CONST + 1; + key2init2 = CRC32( key2init2, MSB(key1init2) ); + } + + u8 abort = 0; + u8 plain; + u8 key3; + u16 temp; + + for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + { + key0 = key0init2; + key1 = key1init2; + key2 = key2init2; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + idx = 0xfe; + continue; + } + + if (idx + 1 == esalt_bufs[digests_offset].hash_count){ \ + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } + } +} \ No newline at end of file diff --git a/OpenCL/m17230_a3-pure.cl b/OpenCL/m17230_a3-pure.cl new file mode 100644 index 000000000..4fd5ffbd4 --- /dev/null +++ b/OpenCL/m17230_a3-pure.cl @@ -0,0 +1,555 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "inc_vendor.cl" +#include "inc_hash_constants.h" +#include "inc_hash_functions.cl" +#include "inc_types.cl" +#include "inc_common.cl" +#include "inc_simd.cl" +#include "inc_rp.h" +#include "inc_rp.cl" + +#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) +#define MSB(x) ((x)>>24) +#define CONST 0x08088405 +#define POLYNOMIAL 0xEDB88320 + +#define MAX_COMPRESSED_LENGTH 2048 + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_COMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hashes[8]; +} pkzip_t; + +__kernel void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (int i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; + w[0] = w0; + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < pw_len; i++) + { + key0init = CRC32( key0init, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + u8 plain; + u8 key3; + u16 temp; + + for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + { + key0 = key0init; + key1 = key1init; + key2 = key2init; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + idx = 0xfe; + continue; + } + + if (idx + 1 == esalt_bufs[digests_offset].hash_count){ \ + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } + } +} + +__kernel void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +{ + /** + * modifier + */ + + const u64 lid = get_local_id (0); + const u64 gid = get_global_id (0); + + __local u32 l_crc32tab[0x100]; + + u32 remainder; + u32 b = 0; + u8 set = 0; + for (u32 b = 0; b < 256; b++) + { + remainder = b; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; + else remainder >>= 1; + + l_crc32tab[b] = remainder; + } + + barrier (CLK_LOCAL_MEM_FENCE); + + if (gid >= gid_max) return; + + /** + * base + */ + + const u32 pw_len = pws[gid].pw_len; + + u32x w[64] = { 0 }; + + for (int i = 0, idx = 0; i < pw_len; i += 4, idx += 1) + { + w[idx] = pws[gid].i[idx]; + } + + /** + * loop + */ + + u32x key0, key1, key2; + u32x key0init, key1init, key2init; + u32 w0l = w[0]; + + for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) + { + const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; + w[0] = w0; + + key0init = 0x12345678; + key1init = 0x23456789; + key2init = 0x34567890; + + for (u8 i = 0; i < pw_len; i++) + { + key0init = CRC32( key0init, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); + key1init = (key1init + (key0init & 0xff)) * CONST + 1; + key2init = CRC32( key2init, MSB(key1init) ); + } + + u8 plain; + u8 key3; + u16 temp; + + for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + { + key0 = key0init; + key1 = key1init; + key2 = key2init; + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; + + if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + + if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) + { + idx = 0xfe; + continue; + } + + key0 = CRC32( key0, plain ); + key1 = (key1 + (key0 & 0xff)) * CONST + 1; + key2 = CRC32( key2, MSB(key1) ); + + temp = (key2 & 0xffff) | 3; + key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; + plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + + if ((plain & 6) == 0 || (plain & 6) == 6) + { + idx = 0xfe; + continue; + } + + if (idx + 1 == esalt_bufs[digests_offset].hash_count){ \ + if (atomic_inc (&hashes_shown[digests_offset]) == 0) + { + mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + } + } + } + } +} \ No newline at end of file diff --git a/docs/changes.txt b/docs/changes.txt index 3dba99e54..b9f74762b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -24,6 +24,7 @@ - Added hash-mode: sha1(md5(md5($pass))) - Added hash-mode: sha1($salt1.$pass.$salt2) - Added hash-mode: Ruby on Rails Restful-Authentication +- Added hash-mode: PKZIP archive encryption ## ## Bugs diff --git a/src/modules/module_17200.c b/src/modules/module_17200.c new file mode 100644 index 000000000..605f47f00 --- /dev/null +++ b/src/modules/module_17200.c @@ -0,0 +1,398 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "common.h" +#include "types.h" +#include "modules.h" +#include "bitops.h" +#include "convert.h" +#include "shared.h" +#include "inc_hash_constants.h" + +static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; +static const u32 DGST_POS0 = 1; +static const u32 DGST_POS1 = 2; +static const u32 DGST_POS2 = 3; +static const u32 DGST_POS3 = 4; +static const u32 DGST_SIZE = DGST_SIZE_4_4; +static const u32 HASH_CATEGORY = HASH_CATEGORY_ARCHIVE; +static const char *HASH_NAME = "PKZIP (Compressed)"; +static const u64 KERN_TYPE = 17200; +static const u32 OPTI_TYPE = 0; +static const u64 OPTS_TYPE = 0; +static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; +static const char *ST_PASS = "hashcat"; +static const char *ST_HASH = "$pkzip2$1*1*2*0*e3*1c5*eda7a8de*0*28*8*e3*eda7*5096*a9fc1f4e951c8fb3031a6f903e5f4e3211c8fdc4671547bf77f6f682afbfcc7475d83898985621a7af9bccd1349d1976500a68c48f630b7f22d7a0955524d768e34868880461335417ddd149c65a917c0eb0a4bf7224e24a1e04cf4ace5eef52205f4452e66ded937db9545f843a68b1e84a2e933cc05fb36d3db90e6c5faf1bee2249fdd06a7307849902a8bb24ec7e8a0886a4544ca47979a9dfeefe034bdfc5bd593904cfe9a5309dd199d337d3183f307c2cb39622549a5b9b8b485b7949a4803f63f67ca427a0640ad3793a519b2476c52198488e3e2e04cac202d624fb7d13c2*$/pkzip2$"; + +static const char *SIGNATURE_PKZIP_V1 = "$pkzip$"; +static const char *SIGNATURE_PKZIP_V2 = "$pkzip2$"; + +#define MAX_COMPRESSED_LENGTH 2048 +#define MAX_UNCOMPRESSED_LENGTH 4096 + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_COMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hash; +} pkzip_t; + +u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) +{ + const u64 esalt_size = (const u64) sizeof (pkzip_t); + + return esalt_size; +} + +void hex_to_binary (const char *source, int len, char* out) +{ + const char *pos = source; + for (size_t count = 0; count < (size_t) len/2; count++) { + sscanf(pos, "%2hhx", &out[count]); + pos += 2; + } +} + +int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len) +{ + pkzip_t *pkzip = (pkzip_t *) esalt_buf; + + u32 *digest = (u32 *) digest_buf; + + char input[line_len + 1]; + input[line_len] = '\0'; + memcpy(&input, line_buf, line_len); + + char *p = strtok(input, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + if (strncmp(p, SIGNATURE_PKZIP_V1, 7) != 0 && strncmp(p, SIGNATURE_PKZIP_V2, 8) != 0) return PARSER_HASH_LENGTH; + + pkzip->version = 1; + if(strlen(p) == 9) pkzip->version = 2; + + char sub[2]; + sub[0] = p[strlen(p) - 1]; + sub[1] = '\0'; + pkzip->hash_count = atoi(sub); + + // check here that the hash_count is valid for the attack type + if(pkzip->hash_count != 1) return PARSER_HASH_VALUE; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->checksum_size = atoi(p); + if (pkzip->checksum_size != 1 && pkzip->checksum_size != 2) return PARSER_HASH_LENGTH; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.data_type_enum = atoi(p); + if (pkzip->hash.data_type_enum > 3) return PARSER_HASH_LENGTH; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.magic_type_enum = atoi(p); + + if(pkzip->hash.data_type_enum > 1) + { + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.compressed_length = strtoul(p, NULL, 16); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.uncompressed_length = strtoul(p, NULL, 16); + if (pkzip->hash.compressed_length > MAX_COMPRESSED_LENGTH || pkzip->hash.uncompressed_length > MAX_UNCOMPRESSED_LENGTH) + { + return PARSER_TOKEN_LENGTH; + } + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + sscanf(p, "%x", &(pkzip->hash.crc32)); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.offset = strtoul(p, NULL, 16); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.additional_offset = strtoul(p, NULL, 16); + } + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.compression_type = atoi(p); + if (pkzip->hash.compression_type != 8) return PARSER_HASH_VALUE; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.data_length = strtoul(p, NULL, 16); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + sscanf(p, "%hx", &(pkzip->hash.checksum_from_crc)); + if(pkzip->version == 2) + { + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + sscanf(p, "%hx", &(pkzip->hash.checksum_from_timestamp)); + } + else + { + pkzip->hash.checksum_from_timestamp = pkzip->hash.checksum_from_crc; + } + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + + hex_to_binary(p, strlen(p) * 2, (char *) &(pkzip->hash.data)); + + // fake salt + salt->salt_buf[0] = pkzip->hash.data[ 3] << 24 | pkzip->hash.data[ 2] << 16 | pkzip->hash.data[ 1] << 8 | pkzip->hash.data[ 0]; + salt->salt_buf[1] = pkzip->hash.data[ 7] << 24 | pkzip->hash.data[ 6] << 16 | pkzip->hash.data[ 5] << 8 | pkzip->hash.data[ 4]; + salt->salt_buf[2] = pkzip->hash.data[11] << 24 | pkzip->hash.data[10] << 16 | pkzip->hash.data[ 9] << 8 | pkzip->hash.data[ 8]; + salt->salt_buf[3] = pkzip->hash.data[15] << 24 | pkzip->hash.data[14] << 16 | pkzip->hash.data[13] << 8 | pkzip->hash.data[ 12]; + + salt->salt_len = 16; + + // fake hash + digest[0] = pkzip->hash.data[ 0] << 24 | pkzip->hash.data[ 1] << 16 | pkzip->hash.data[ 2] << 8 | pkzip->hash.data[ 3]; + digest[1] = pkzip->hash.data[ 4] << 24 | pkzip->hash.data[ 5] << 16 | pkzip->hash.data[ 6] << 8 | pkzip->hash.data[ 7]; + digest[2] = pkzip->hash.data[ 8] << 24 | pkzip->hash.data[ 9] << 16 | pkzip->hash.data[10] << 8 | pkzip->hash.data[11]; + digest[3] = pkzip->hash.data[12] << 24 | pkzip->hash.data[13] << 16 | pkzip->hash.data[14] << 8 | pkzip->hash.data[15]; + + return (PARSER_OK); +} + +int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) +{ + const u32 *digest = (const u32 *) digest_buf; + + const pkzip_t *pkzip = (const pkzip_t *) esalt_buf; + + int out_len = 0; + + if (pkzip->version == 1) + { + sprintf (line_buf, "%s", SIGNATURE_PKZIP_V1); + out_len += 7; + } + else + { + sprintf (line_buf, "%s", SIGNATURE_PKZIP_V2); + out_len += 8; + } + out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hash_count, pkzip->checksum_size); + + out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hash.data_type_enum, pkzip->hash.magic_type_enum); + if (pkzip->hash.data_type_enum > 1) + { + out_len += sprintf (line_buf + out_len, "%x*%x*%x*%x*%x*", pkzip->hash.compressed_length, pkzip->hash.uncompressed_length, pkzip->hash.crc32, pkzip->hash.offset, pkzip->hash.additional_offset); + } + + out_len += sprintf (line_buf + out_len, "%i*%x*%x*", pkzip->hash.compression_type, pkzip->hash.data_length, pkzip->hash.checksum_from_crc); + if (pkzip->version == 2) + { + out_len += sprintf (line_buf + out_len, "%x*", pkzip->hash.checksum_from_timestamp); + } + + for (u32 i = 0; i < pkzip->hash.data_length; i++) + { + out_len += sprintf (line_buf + out_len, "%02x", pkzip->hash.data[i]); + } + + if (pkzip->version == 1) + { + out_len += sprintf (line_buf + out_len, "*$/pkzip$"); + } + else + { + out_len += sprintf (line_buf + out_len, "*$/pkzip2$"); + } + + return out_len; +} + +void module_init (module_ctx_t *module_ctx) +{ + module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; + module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; + + module_ctx->module_attack_exec = module_attack_exec; + module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_salt = MODULE_DEFAULT; + module_ctx->module_build_plain_postprocess = MODULE_DEFAULT; + module_ctx->module_deep_comp_kernel = MODULE_DEFAULT; + module_ctx->module_dgst_pos0 = module_dgst_pos0; + module_ctx->module_dgst_pos1 = module_dgst_pos1; + module_ctx->module_dgst_pos2 = module_dgst_pos2; + module_ctx->module_dgst_pos3 = module_dgst_pos3; + module_ctx->module_dgst_size = module_dgst_size; + module_ctx->module_dictstat_disable = MODULE_DEFAULT; + module_ctx->module_esalt_size = module_esalt_size; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_forced_outfile_format = MODULE_DEFAULT; + module_ctx->module_hash_binary_count = MODULE_DEFAULT; + module_ctx->module_hash_binary_parse = MODULE_DEFAULT; + module_ctx->module_hash_binary_save = MODULE_DEFAULT; + module_ctx->module_hash_decode_outfile = MODULE_DEFAULT; + module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT; + module_ctx->module_hash_decode = module_hash_decode; + module_ctx->module_hash_encode_status = MODULE_DEFAULT; + module_ctx->module_hash_encode = module_hash_encode; + module_ctx->module_hash_init_selftest = MODULE_DEFAULT; + module_ctx->module_hash_mode = MODULE_DEFAULT; + module_ctx->module_hash_category = module_hash_category; + module_ctx->module_hash_name = module_hash_name; + module_ctx->module_hlfmt_disable = MODULE_DEFAULT; + module_ctx->module_hook12 = MODULE_DEFAULT; + module_ctx->module_hook23 = MODULE_DEFAULT; + module_ctx->module_hook_salt_size = MODULE_DEFAULT; + module_ctx->module_hook_size = MODULE_DEFAULT; + module_ctx->module_jit_build_options = MODULE_DEFAULT; + module_ctx->module_jit_cache_disable = MODULE_DEFAULT; + module_ctx->module_kernel_accel_max = MODULE_DEFAULT; + module_ctx->module_kernel_accel_min = MODULE_DEFAULT; + module_ctx->module_kernel_loops_max = MODULE_DEFAULT; + module_ctx->module_kernel_loops_min = MODULE_DEFAULT; + module_ctx->module_kernel_threads_max = MODULE_DEFAULT; + module_ctx->module_kernel_threads_min = MODULE_DEFAULT; + module_ctx->module_kern_type = module_kern_type; + module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; + module_ctx->module_opti_type = module_opti_type; + module_ctx->module_opts_type = module_opts_type; + module_ctx->module_outfile_check_disable = MODULE_DEFAULT; + module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_disable = MODULE_DEFAULT; + module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; + module_ctx->module_pwdump_column = MODULE_DEFAULT; + module_ctx->module_pw_max = MODULE_DEFAULT; + module_ctx->module_pw_min = MODULE_DEFAULT; + module_ctx->module_salt_max = MODULE_DEFAULT; + module_ctx->module_salt_min = MODULE_DEFAULT; + module_ctx->module_salt_type = module_salt_type; + module_ctx->module_separator = MODULE_DEFAULT; + module_ctx->module_st_hash = module_st_hash; + module_ctx->module_st_pass = module_st_pass; + module_ctx->module_tmp_size = MODULE_DEFAULT; + module_ctx->module_unstable_warning = MODULE_DEFAULT; + module_ctx->module_warmup_disable = MODULE_DEFAULT; +} diff --git a/src/modules/module_17210.c b/src/modules/module_17210.c new file mode 100644 index 000000000..ac7947e5d --- /dev/null +++ b/src/modules/module_17210.c @@ -0,0 +1,400 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "common.h" +#include "types.h" +#include "modules.h" +#include "bitops.h" +#include "convert.h" +#include "shared.h" +#include "inc_hash_constants.h" + +static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; +static const u32 DGST_POS0 = 1; +static const u32 DGST_POS1 = 2; +static const u32 DGST_POS2 = 3; +static const u32 DGST_POS3 = 4; +static const u32 DGST_SIZE = DGST_SIZE_4_4; +static const u32 HASH_CATEGORY = HASH_CATEGORY_ARCHIVE; +static const char *HASH_NAME = "PKZIP (Uncompressed)"; +static const u64 KERN_TYPE = 17210; +static const u32 OPTI_TYPE = 0; +static const u64 OPTS_TYPE = OPTS_TYPE_PT_NEVERCRACK; +static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; +static const char *ST_PASS = "hashcat"; +static const char *ST_HASH = "$pkzip2$1*1*2*0*1d1*1c5*eda7a8de*0*28*0*1d1*eda7*5096*1dea673da43d9fc7e2be1a1f4f664269fceb6cb88723a97408ae1fe07f774d31d1442ea8485081e63f919851ca0b7588d5e3442317fff19fe547a4ef97492ed75417c427eea3c4e146e16c100a2f8b6abd7e5988dc967e5a0e51f641401605d673630ea52ebb04da4b388489901656532c9aa474ca090dbac7cf8a21428d57b42a71da5f3d83fed927361e5d385ca8e480a6d42dea5b4bf497d3a24e79fc7be37c8d1721238cbe9e1ea3ae1eb91fc02aabdf33070d718d5105b70b3d7f3d2c28b3edd822e89a5abc0c8fee117c7fbfbfd4b4c8e130977b75cb0b1da080bfe1c0859e6483c42f459c8069d45a76220e046e6c2a2417392fd87e4aa4a2559eaab3baf78a77a1b94d8c8af16a977b4bb45e3da211838ad044f209428dba82666bf3d54d4eed82c64a9b3444a44746b9e398d0516a2596d84243b4a1d7e87d9843f38e45b6be67fd980107f3ad7b8453d87300e6c51ac9f5e3f6c3b702654440c543b1d808b62f7a313a83b31a6faaeedc2620de7057cd0df80f70346fe2d4dccc318f0b5ed128bcf0643e63d754bb05f53afb2b0fa90b34b538b2ad3648209dff587df4fa18698e4fa6d858ad44aa55d2bba3b08dfdedd3e28b8b7caf394d5d9d95e452c2ab1c836b9d74538c2f0d24b9b577*$/pkzip2$"; + +static const char *SIGNATURE_PKZIP_V1 = "$pkzip$"; +static const char *SIGNATURE_PKZIP_V2 = "$pkzip2$"; + +#define MAX_UNCOMPRESSED_LENGTH 4096 + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_UNCOMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hash; +} pkzip_t; + +u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) +{ + const u64 esalt_size = (const u64) sizeof (pkzip_t); + + return esalt_size; +} + +void hex_to_binary (const char *source, int len, char* out) +{ + const char *pos = source; + for (size_t count = 0; count < (size_t) len/2; count++) { + sscanf(pos, "%2hhx", &out[count]); + pos += 2; + } +} + +int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len) +{ + pkzip_t *pkzip = (pkzip_t *) esalt_buf; + + u32 *digest = (u32 *) digest_buf; + + char input[line_len + 1]; + input[line_len] = '\0'; + memcpy(&input, line_buf, line_len); + + char *p = strtok(input, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + if (strncmp(p, SIGNATURE_PKZIP_V1, 7) != 0 && strncmp(p, SIGNATURE_PKZIP_V2, 8) != 0) return PARSER_HASH_LENGTH; + + pkzip->version = 1; + if(strlen(p) == 9) pkzip->version = 2; + + char sub[2]; + sub[0] = p[strlen(p) - 1]; + sub[1] = '\0'; + pkzip->hash_count = atoi(sub); + + // check here that the hash_count is valid for the attack type + if(pkzip->hash_count != 1) return PARSER_HASH_VALUE; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->checksum_size = atoi(p); + if (pkzip->checksum_size != 1 && pkzip->checksum_size != 2) return PARSER_HASH_LENGTH; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.data_type_enum = atoi(p); + if (pkzip->hash.data_type_enum > 3) return PARSER_HASH_LENGTH; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.magic_type_enum = atoi(p); + + if(pkzip->hash.data_type_enum > 1) + { + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.compressed_length = strtoul(p, NULL, 16); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.uncompressed_length = strtoul(p, NULL, 16); + if (pkzip->hash.uncompressed_length > MAX_UNCOMPRESSED_LENGTH) + { + return PARSER_TOKEN_LENGTH; + } + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + sscanf(p, "%x", &(pkzip->hash.crc32)); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.offset = strtoul(p, NULL, 16); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.additional_offset = strtoul(p, NULL, 16); + } + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.compression_type = atoi(p); + if (pkzip->hash.compression_type != 0) return PARSER_HASH_VALUE; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hash.data_length = strtoul(p, NULL, 16); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + sscanf(p, "%hx", &(pkzip->hash.checksum_from_crc)); + if(pkzip->version == 2) + { + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + sscanf(p, "%hx", &(pkzip->hash.checksum_from_timestamp)); + } + else + { + pkzip->hash.checksum_from_timestamp = pkzip->hash.checksum_from_crc; + } + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + + hex_to_binary(p, strlen(p) * 2, (char *) &(pkzip->hash.data)); + + // fake salt + salt->salt_buf[0] = pkzip->hash.data[ 3] << 24 | pkzip->hash.data[ 2] << 16 | pkzip->hash.data[ 1] << 8 | pkzip->hash.data[ 0]; + salt->salt_buf[1] = pkzip->hash.data[ 7] << 24 | pkzip->hash.data[ 6] << 16 | pkzip->hash.data[ 5] << 8 | pkzip->hash.data[ 4]; + salt->salt_buf[2] = pkzip->hash.data[11] << 24 | pkzip->hash.data[10] << 16 | pkzip->hash.data[ 9] << 8 | pkzip->hash.data[ 8]; + salt->salt_buf[3] = pkzip->hash.data[15] << 24 | pkzip->hash.data[14] << 16 | pkzip->hash.data[13] << 8 | pkzip->hash.data[ 12]; + + salt->salt_len = 16; + + // fake hash + digest[0] = pkzip->hash.data[ 0] << 24 | pkzip->hash.data[ 1] << 16 | pkzip->hash.data[ 2] << 8 | pkzip->hash.data[ 3]; + digest[1] = pkzip->hash.data[ 4] << 24 | pkzip->hash.data[ 5] << 16 | pkzip->hash.data[ 6] << 8 | pkzip->hash.data[ 7]; + digest[2] = pkzip->hash.data[ 8] << 24 | pkzip->hash.data[ 9] << 16 | pkzip->hash.data[10] << 8 | pkzip->hash.data[11]; + digest[3] = pkzip->hash.data[12] << 24 | pkzip->hash.data[13] << 16 | pkzip->hash.data[14] << 8 | pkzip->hash.data[15]; + + return (PARSER_OK); +} + +int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) +{ + const u32 *digest = (const u32 *) digest_buf; + + const pkzip_t *pkzip = (const pkzip_t *) esalt_buf; + + int out_len = 0; + + if (pkzip->version == 1) + { + sprintf (line_buf, "%s", SIGNATURE_PKZIP_V1); + out_len += 7; + } + else + { + sprintf (line_buf, "%s", SIGNATURE_PKZIP_V2); + out_len += 8; + } + out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hash_count, pkzip->checksum_size); + + for (int cnt = 0; cnt < pkzip->hash_count; cnt++) + { + out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hash.data_type_enum, pkzip->hash.magic_type_enum); + if (pkzip->hash.data_type_enum > 1) + { + out_len += sprintf (line_buf + out_len, "%x*%x*%x*%x*%x*", pkzip->hash.compressed_length, pkzip->hash.uncompressed_length, pkzip->hash.crc32, pkzip->hash.offset, pkzip->hash.additional_offset); + } + + out_len += sprintf (line_buf + out_len, "%i*%x*%x*", pkzip->hash.compression_type, pkzip->hash.data_length, pkzip->hash.checksum_from_crc); + if (pkzip->version == 2) + { + out_len += sprintf (line_buf + out_len, "%x*", pkzip->hash.checksum_from_timestamp); + } + + for (u32 i = 0; i < pkzip->hash.data_length; i++) + { + out_len += sprintf (line_buf + out_len, "%02x", pkzip->hash.data[i]); + } + } + + if (pkzip->version == 1) + { + out_len += sprintf (line_buf + out_len, "*$/pkzip$"); + } + else + { + out_len += sprintf (line_buf + out_len, "*$/pkzip2$"); + } + + return out_len; +} + +void module_init (module_ctx_t *module_ctx) +{ + module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; + module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; + + module_ctx->module_attack_exec = module_attack_exec; + module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_salt = MODULE_DEFAULT; + module_ctx->module_build_plain_postprocess = MODULE_DEFAULT; + module_ctx->module_deep_comp_kernel = MODULE_DEFAULT; + module_ctx->module_dgst_pos0 = module_dgst_pos0; + module_ctx->module_dgst_pos1 = module_dgst_pos1; + module_ctx->module_dgst_pos2 = module_dgst_pos2; + module_ctx->module_dgst_pos3 = module_dgst_pos3; + module_ctx->module_dgst_size = module_dgst_size; + module_ctx->module_dictstat_disable = MODULE_DEFAULT; + module_ctx->module_esalt_size = module_esalt_size; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_forced_outfile_format = MODULE_DEFAULT; + module_ctx->module_hash_binary_count = MODULE_DEFAULT; + module_ctx->module_hash_binary_parse = MODULE_DEFAULT; + module_ctx->module_hash_binary_save = MODULE_DEFAULT; + module_ctx->module_hash_decode_outfile = MODULE_DEFAULT; + module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT; + module_ctx->module_hash_decode = module_hash_decode; + module_ctx->module_hash_encode_status = MODULE_DEFAULT; + module_ctx->module_hash_encode = module_hash_encode; + module_ctx->module_hash_init_selftest = MODULE_DEFAULT; + module_ctx->module_hash_mode = MODULE_DEFAULT; + module_ctx->module_hash_category = module_hash_category; + module_ctx->module_hash_name = module_hash_name; + module_ctx->module_hlfmt_disable = MODULE_DEFAULT; + module_ctx->module_hook12 = MODULE_DEFAULT; + module_ctx->module_hook23 = MODULE_DEFAULT; + module_ctx->module_hook_salt_size = MODULE_DEFAULT; + module_ctx->module_hook_size = MODULE_DEFAULT; + module_ctx->module_jit_build_options = MODULE_DEFAULT; + module_ctx->module_jit_cache_disable = MODULE_DEFAULT; + module_ctx->module_kernel_accel_max = MODULE_DEFAULT; + module_ctx->module_kernel_accel_min = MODULE_DEFAULT; + module_ctx->module_kernel_loops_max = MODULE_DEFAULT; + module_ctx->module_kernel_loops_min = MODULE_DEFAULT; + module_ctx->module_kernel_threads_max = MODULE_DEFAULT; + module_ctx->module_kernel_threads_min = MODULE_DEFAULT; + module_ctx->module_kern_type = module_kern_type; + module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; + module_ctx->module_opti_type = module_opti_type; + module_ctx->module_opts_type = module_opts_type; + module_ctx->module_outfile_check_disable = MODULE_DEFAULT; + module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_disable = MODULE_DEFAULT; + module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; + module_ctx->module_pwdump_column = MODULE_DEFAULT; + module_ctx->module_pw_max = MODULE_DEFAULT; + module_ctx->module_pw_min = MODULE_DEFAULT; + module_ctx->module_salt_max = MODULE_DEFAULT; + module_ctx->module_salt_min = MODULE_DEFAULT; + module_ctx->module_salt_type = module_salt_type; + module_ctx->module_separator = MODULE_DEFAULT; + module_ctx->module_st_hash = module_st_hash; + module_ctx->module_st_pass = module_st_pass; + module_ctx->module_tmp_size = MODULE_DEFAULT; + module_ctx->module_unstable_warning = MODULE_DEFAULT; + module_ctx->module_warmup_disable = MODULE_DEFAULT; +} diff --git a/src/modules/module_17220.c b/src/modules/module_17220.c new file mode 100644 index 000000000..c896e783f --- /dev/null +++ b/src/modules/module_17220.c @@ -0,0 +1,404 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "common.h" +#include "types.h" +#include "modules.h" +#include "bitops.h" +#include "convert.h" +#include "shared.h" +#include "inc_hash_constants.h" + +static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; +static const u32 DGST_POS0 = 1; +static const u32 DGST_POS1 = 2; +static const u32 DGST_POS2 = 3; +static const u32 DGST_POS3 = 4; +static const u32 DGST_SIZE = DGST_SIZE_4_4; +static const u32 HASH_CATEGORY = HASH_CATEGORY_ARCHIVE; +static const char *HASH_NAME = "PKZIP (Compressed Multi-File)"; +static const u64 KERN_TYPE = 17220; +static const u32 OPTI_TYPE = 0; +static const u64 OPTS_TYPE = 0; +static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; +static const char *ST_PASS = "hashcat"; +static const char *ST_HASH = "$pkzip2$3*1*1*0*8*24*a425*8827*d1730095cd829e245df04ebba6c52c0573d49d3bbeab6cb385b7fa8a28dcccd3098bfdd7*1*0*8*24*2a74*882a*51281ac874a60baedc375ca645888d29780e20d4076edd1e7154a99bde982152a736311f*2*0*e3*1c5*eda7a8de*0*29*8*e3*eda7*5096*1455781b59707f5151139e018bdcfeebfc89bc37e372883a7ec0670a5eafc622feb338f9b021b6601a674094898a91beac70e41e675f77702834ca6156111a1bf7361bc9f3715d77dfcdd626634c68354c6f2e5e0a7b1e1ce84a44e632d0f6e36019feeab92fb7eac9dda8df436e287aafece95d042059a1b27d533c5eab62c1c559af220dc432f2eb1a38a70f29e8f3cb5a207704274d1e305d7402180fd47e026522792f5113c52a116d5bb25b67074ffd6f4926b221555234aabddc69775335d592d5c7d22462b75de1259e8342a9ba71cb06223d13c7f51f13be2ad76352c3b8ed*$/pkzip2$"; + +static const char *SIGNATURE_PKZIP_V1 = "$pkzip$"; +static const char *SIGNATURE_PKZIP_V2 = "$pkzip2$"; + +#define MAX_COMPRESSED_LENGTH 2048 +#define MAX_UNCOMPRESSED_LENGTH 4096 + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_COMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hashes[8]; +} pkzip_t; + +u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) +{ + const u64 esalt_size = (const u64) sizeof (pkzip_t); + + return esalt_size; +} + +void hex_to_binary (const char *source, int len, char* out) +{ + const char *pos = source; + for (size_t count = 0; count < (size_t) len/2; count++) { + sscanf(pos, "%2hhx", &out[count]); + pos += 2; + } +} + +int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len) +{ + pkzip_t *pkzip = (pkzip_t *) esalt_buf; + + u32 *digest = (u32 *) digest_buf; + + char input[line_len + 1]; + input[line_len] = '\0'; + memcpy(&input, line_buf, line_len); + + char *p = strtok(input, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + if (strncmp(p, SIGNATURE_PKZIP_V1, 7) != 0 && strncmp(p, SIGNATURE_PKZIP_V2, 8) != 0) return PARSER_HASH_LENGTH; + + pkzip->version = 1; + if(strlen(p) == 9) pkzip->version = 2; + + char sub[2]; + sub[0] = p[strlen(p) - 1]; + sub[1] = '\0'; + pkzip->hash_count = atoi(sub); + + // check here that the hash_count is valid for the attack type + if(pkzip->hash_count > 8) return PARSER_HASH_VALUE; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->checksum_size = atoi(p); + if (pkzip->checksum_size != 1 && pkzip->checksum_size != 2) return PARSER_HASH_LENGTH; + + for(int i = 0; i < pkzip->hash_count; i++) + { + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].data_type_enum = atoi(p); + if (pkzip->hashes[i].data_type_enum > 3) return PARSER_HASH_LENGTH; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].magic_type_enum = atoi(p); + + if(pkzip->hashes[i].data_type_enum > 1) + { + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].compressed_length = strtoul(p, NULL, 16); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].uncompressed_length = strtoul(p, NULL, 16); + if (pkzip->hashes[i].compressed_length > MAX_COMPRESSED_LENGTH || pkzip->hashes[i].uncompressed_length > MAX_UNCOMPRESSED_LENGTH) + { + return PARSER_TOKEN_LENGTH; + } + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + sscanf(p, "%x", &(pkzip->hashes[i].crc32)); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].offset = strtoul(p, NULL, 16); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].additional_offset = strtoul(p, NULL, 16); + } + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].compression_type = atoi(p); + if (pkzip->hashes[i].compression_type != 8) return PARSER_HASH_VALUE; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].data_length = strtoul(p, NULL, 16); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + sscanf(p, "%hx", &(pkzip->hashes[i].checksum_from_crc)); + if(pkzip->version == 2) + { + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + sscanf(p, "%hx", &(pkzip->hashes[i].checksum_from_timestamp)); + } + else + { + pkzip->hashes[i].checksum_from_timestamp = pkzip->hashes[i].checksum_from_crc; + } + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + + hex_to_binary(p, strlen(p) * 2, (char *) &(pkzip->hashes[i].data)); + + // fake salt + salt->salt_buf[0] ^= pkzip->hashes[i].data[ 3] << 24 | pkzip->hashes[i].data[ 2] << 16 | pkzip->hashes[i].data[ 1] << 8 | pkzip->hashes[i].data[ 0]; + salt->salt_buf[1] ^= pkzip->hashes[i].data[ 7] << 24 | pkzip->hashes[i].data[ 6] << 16 | pkzip->hashes[i].data[ 5] << 8 | pkzip->hashes[i].data[ 4]; + salt->salt_buf[2] ^= pkzip->hashes[i].data[11] << 24 | pkzip->hashes[i].data[10] << 16 | pkzip->hashes[i].data[ 9] << 8 | pkzip->hashes[i].data[ 8]; + salt->salt_buf[3] ^= pkzip->hashes[i].data[15] << 24 | pkzip->hashes[i].data[14] << 16 | pkzip->hashes[i].data[13] << 8 | pkzip->hashes[i].data[ 12]; + + salt->salt_len = 16; + + // fake hash + digest[0] ^= pkzip->hashes[i].data[ 0] << 24 | pkzip->hashes[i].data[ 1] << 16 | pkzip->hashes[i].data[ 2] << 8 | pkzip->hashes[i].data[ 3]; + digest[1] ^= pkzip->hashes[i].data[ 4] << 24 | pkzip->hashes[i].data[ 5] << 16 | pkzip->hashes[i].data[ 6] << 8 | pkzip->hashes[i].data[ 7]; + digest[2] ^= pkzip->hashes[i].data[ 8] << 24 | pkzip->hashes[i].data[ 9] << 16 | pkzip->hashes[i].data[10] << 8 | pkzip->hashes[i].data[11]; + digest[3] ^= pkzip->hashes[i].data[12] << 24 | pkzip->hashes[i].data[13] << 16 | pkzip->hashes[i].data[14] << 8 | pkzip->hashes[i].data[15]; + } + + return (PARSER_OK); +} + +int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) +{ + const u32 *digest = (const u32 *) digest_buf; + + const pkzip_t *pkzip = (const pkzip_t *) esalt_buf; + + int out_len = 0; + + if (pkzip->version == 1) + { + sprintf (line_buf, "%s", SIGNATURE_PKZIP_V1); + out_len += 7; + } + else + { + sprintf (line_buf, "%s", SIGNATURE_PKZIP_V2); + out_len += 8; + } + out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hash_count, pkzip->checksum_size); + + for (int cnt = 0; cnt < pkzip->hash_count; cnt++) + { + out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hashes[cnt].data_type_enum, pkzip->hashes[cnt].magic_type_enum); + if (pkzip->hashes[cnt].data_type_enum > 1) + { + out_len += sprintf (line_buf + out_len, "%x*%x*%x*%x*%x*", pkzip->hashes[cnt].compressed_length, pkzip->hashes[cnt].uncompressed_length, pkzip->hashes[cnt].crc32, pkzip->hashes[cnt].offset, pkzip->hashes[cnt].additional_offset); + } + + out_len += sprintf (line_buf + out_len, "%i*%x*%x*", pkzip->hashes[cnt].compression_type, pkzip->hashes[cnt].data_length, pkzip->hashes[cnt].checksum_from_crc); + if (pkzip->version == 2) + { + out_len += sprintf (line_buf + out_len, "%x*", pkzip->hashes[cnt].checksum_from_timestamp); + } + + for (u32 i = 0; i < pkzip->hashes[cnt].data_length; i++) + { + out_len += sprintf (line_buf + out_len, "%02x", pkzip->hashes[cnt].data[i]); + } + } + + if (pkzip->version == 1) + { + out_len += sprintf (line_buf + out_len, "*$/pkzip$"); + } + else + { + out_len += sprintf (line_buf + out_len, "*$/pkzip2$"); + } + + return out_len; +} + +void module_init (module_ctx_t *module_ctx) +{ + module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; + module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; + + module_ctx->module_attack_exec = module_attack_exec; + module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_salt = MODULE_DEFAULT; + module_ctx->module_build_plain_postprocess = MODULE_DEFAULT; + module_ctx->module_deep_comp_kernel = MODULE_DEFAULT; + module_ctx->module_dgst_pos0 = module_dgst_pos0; + module_ctx->module_dgst_pos1 = module_dgst_pos1; + module_ctx->module_dgst_pos2 = module_dgst_pos2; + module_ctx->module_dgst_pos3 = module_dgst_pos3; + module_ctx->module_dgst_size = module_dgst_size; + module_ctx->module_dictstat_disable = MODULE_DEFAULT; + module_ctx->module_esalt_size = module_esalt_size; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_forced_outfile_format = MODULE_DEFAULT; + module_ctx->module_hash_binary_count = MODULE_DEFAULT; + module_ctx->module_hash_binary_parse = MODULE_DEFAULT; + module_ctx->module_hash_binary_save = MODULE_DEFAULT; + module_ctx->module_hash_decode_outfile = MODULE_DEFAULT; + module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT; + module_ctx->module_hash_decode = module_hash_decode; + module_ctx->module_hash_encode_status = MODULE_DEFAULT; + module_ctx->module_hash_encode = module_hash_encode; + module_ctx->module_hash_init_selftest = MODULE_DEFAULT; + module_ctx->module_hash_mode = MODULE_DEFAULT; + module_ctx->module_hash_category = module_hash_category; + module_ctx->module_hash_name = module_hash_name; + module_ctx->module_hlfmt_disable = MODULE_DEFAULT; + module_ctx->module_hook12 = MODULE_DEFAULT; + module_ctx->module_hook23 = MODULE_DEFAULT; + module_ctx->module_hook_salt_size = MODULE_DEFAULT; + module_ctx->module_hook_size = MODULE_DEFAULT; + module_ctx->module_jit_build_options = MODULE_DEFAULT; + module_ctx->module_jit_cache_disable = MODULE_DEFAULT; + module_ctx->module_kernel_accel_max = MODULE_DEFAULT; + module_ctx->module_kernel_accel_min = MODULE_DEFAULT; + module_ctx->module_kernel_loops_max = MODULE_DEFAULT; + module_ctx->module_kernel_loops_min = MODULE_DEFAULT; + module_ctx->module_kernel_threads_max = MODULE_DEFAULT; + module_ctx->module_kernel_threads_min = MODULE_DEFAULT; + module_ctx->module_kern_type = module_kern_type; + module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; + module_ctx->module_opti_type = module_opti_type; + module_ctx->module_opts_type = module_opts_type; + module_ctx->module_outfile_check_disable = MODULE_DEFAULT; + module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_disable = MODULE_DEFAULT; + module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; + module_ctx->module_pwdump_column = MODULE_DEFAULT; + module_ctx->module_pw_max = MODULE_DEFAULT; + module_ctx->module_pw_min = MODULE_DEFAULT; + module_ctx->module_salt_max = MODULE_DEFAULT; + module_ctx->module_salt_min = MODULE_DEFAULT; + module_ctx->module_salt_type = module_salt_type; + module_ctx->module_separator = MODULE_DEFAULT; + module_ctx->module_st_hash = module_st_hash; + module_ctx->module_st_pass = module_st_pass; + module_ctx->module_tmp_size = MODULE_DEFAULT; + module_ctx->module_unstable_warning = MODULE_DEFAULT; + module_ctx->module_warmup_disable = MODULE_DEFAULT; +} diff --git a/src/modules/module_17230.c b/src/modules/module_17230.c new file mode 100644 index 000000000..afd855693 --- /dev/null +++ b/src/modules/module_17230.c @@ -0,0 +1,404 @@ +/* + +PKZIP Kernels for Hashcat (c) 2018, European Union + +PKZIP Kernels for Hashcat has been developed by the Joint Research Centre of the European Commission. +It is released as open source software under the MIT License. + +PKZIP Kernels for Hashcat makes use of two primary external components, which continue to be subject +to the terms and conditions stipulated in the respective licences they have been released under. These +external components include, but are not necessarily limited to, the following: + +----- + +1. Hashcat: MIT License + +Copyright (c) 2015-2018 Jens Steube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +2. Miniz: MIT License + +Copyright 2013-2014 RAD Game Tools and Valve Software +Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +----- + +The European Union disclaims all liability related to or arising out of the use made by third parties of +any external components and dependencies which may be included with PKZIP Kernels for Hashcat. + +----- + +The MIT License + +Copyright (c) 2018, EUROPEAN UNION + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the Software without restriction, including without +limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Author: Sein Coray + +*/ + +#include "common.h" +#include "types.h" +#include "modules.h" +#include "bitops.h" +#include "convert.h" +#include "shared.h" +#include "inc_hash_constants.h" + +static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; +static const u32 DGST_POS0 = 1; +static const u32 DGST_POS1 = 2; +static const u32 DGST_POS2 = 3; +static const u32 DGST_POS3 = 4; +static const u32 DGST_SIZE = DGST_SIZE_4_4; +static const u32 HASH_CATEGORY = HASH_CATEGORY_ARCHIVE; +static const char *HASH_NAME = "PKZIP (Compressed Multi-File Checksum-Only)"; +static const u64 KERN_TYPE = 17230; +static const u32 OPTI_TYPE = 0; +static const u64 OPTS_TYPE = 0; +static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; +static const char *ST_PASS = "hashcat"; +static const char *ST_HASH = "$pkzip2$8*1*1*0*8*24*a425*8827*3bd479d541019c2f32395046b8fbca7e1dca218b9b5414975be49942c3536298e9cc939e*1*0*8*24*2a74*882a*537af57c30fd9fd4b3eefa9ce55b6bff3bbfada237a7c1dace8ebf3bb0de107426211da3*1*0*8*24*2a74*882a*5f406b4858d3489fd4a6a6788798ac9b924b5d0ca8b8e5a6371739c9edcfd28c82f75316*1*0*8*24*2a74*882a*1843aca546b2ea68bd844d1e99d4f74d86417248eb48dd5e956270e42a331c18ea13f5ed*1*0*8*24*2a74*882a*aca3d16543bbfb2e5d2659f63802e0fa5b33e0a1f8ae47334019b4f0b6045d3d8eda3af1*1*0*8*24*2a74*882a*fbe0efc9e10ae1fc9b169bd060470bf3e39f09f8d83bebecd5216de02b81e35fe7e7b2f2*1*0*8*24*2a74*882a*537886dbabffbb7cac77deb01dc84760894524e6966183b4478a4ef56f0c657375a235a1*1*0*8*24*eda7*5096*40eb30ef1ddd9b77b894ed46abf199b480f1e5614fde510855f92ae7b8026a11f80e4d5f*$/pkzip2$"; + +static const char *SIGNATURE_PKZIP_V1 = "$pkzip$"; +static const char *SIGNATURE_PKZIP_V2 = "$pkzip2$"; + +#define MAX_COMPRESSED_LENGTH 2048 + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } + +typedef struct pkzip_hash +{ + u8 data_type_enum; + u8 magic_type_enum; + u32 compressed_length; + u32 uncompressed_length; + u32 crc32; + u8 offset; + u8 additional_offset; + u8 compression_type; + u32 data_length; + u16 checksum_from_crc; + u16 checksum_from_timestamp; + u8 data[MAX_COMPRESSED_LENGTH]; +} pkzip_hash_t; + +typedef struct pkzip +{ + u8 hash_count; + u8 checksum_size; + u8 version; + pkzip_hash_t hashes[8]; +} pkzip_t; + +u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) +{ + const u64 esalt_size = (const u64) sizeof (pkzip_t); + + return esalt_size; +} + +void hex_to_binary (const char *source, int len, char* out) +{ + const char *pos = source; + for (size_t count = 0; count < (size_t) len/2; count++) { + sscanf(pos, "%2hhx", &out[count]); + pos += 2; + } +} + +int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED void *digest_buf, MAYBE_UNUSED salt_t *salt, MAYBE_UNUSED void *esalt_buf, MAYBE_UNUSED void *hook_salt_buf, MAYBE_UNUSED hashinfo_t *hash_info, const char *line_buf, MAYBE_UNUSED const int line_len) +{ + pkzip_t *pkzip = (pkzip_t *) esalt_buf; + + u32 *digest = (u32 *) digest_buf; + + char input[line_len + 1]; + input[line_len] = '\0'; + memcpy(&input, line_buf, line_len); + + char *p = strtok(input, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + if (strncmp(p, SIGNATURE_PKZIP_V1, 7) != 0 && strncmp(p, SIGNATURE_PKZIP_V2, 8) != 0) return PARSER_HASH_LENGTH; + + pkzip->version = 1; + if(strlen(p) == 9) pkzip->version = 2; + + char sub[2]; + sub[0] = p[strlen(p) - 1]; + sub[1] = '\0'; + pkzip->hash_count = atoi(sub); + + // check here that the hash_count is valid for the attack type + if(pkzip->hash_count > 8) return PARSER_HASH_VALUE; + if(pkzip->hash_count < 3) return PARSER_HASH_VALUE; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->checksum_size = atoi(p); + if (pkzip->checksum_size != 1 && pkzip->checksum_size != 2) return PARSER_HASH_LENGTH; + + for(int i = 0; i < pkzip->hash_count; i++) + { + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].data_type_enum = atoi(p); + if (pkzip->hashes[i].data_type_enum > 3) return PARSER_HASH_LENGTH; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].magic_type_enum = atoi(p); + + if(pkzip->hashes[i].data_type_enum > 1) + { + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].compressed_length = strtoul(p, NULL, 16); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].uncompressed_length = strtoul(p, NULL, 16); + if (pkzip->hashes[i].compressed_length > MAX_COMPRESSED_LENGTH) + { + return PARSER_TOKEN_LENGTH; + } + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + sscanf(p, "%x", &(pkzip->hashes[i].crc32)); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].offset = strtoul(p, NULL, 16); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].additional_offset = strtoul(p, NULL, 16); + } + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].compression_type = atoi(p); + if (pkzip->hashes[i].compression_type != 8) return PARSER_HASH_VALUE; + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + pkzip->hashes[i].data_length = strtoul(p, NULL, 16); + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + sscanf(p, "%hx", &(pkzip->hashes[i].checksum_from_crc)); + if(pkzip->version == 2) + { + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + sscanf(p, "%hx", &(pkzip->hashes[i].checksum_from_timestamp)); + } + else + { + pkzip->hashes[i].checksum_from_timestamp = pkzip->hashes[i].checksum_from_crc; + } + + p = strtok(NULL, "*"); + if (p == NULL) return PARSER_HASH_LENGTH; + + hex_to_binary(p, strlen(p) * 2, (char *) &(pkzip->hashes[i].data)); + + // fake salt + salt->salt_buf[0] ^= pkzip->hashes[i].data[ 3] << 24 | pkzip->hashes[i].data[ 2] << 16 | pkzip->hashes[i].data[ 1] << 8 | pkzip->hashes[i].data[ 0]; + salt->salt_buf[1] ^= pkzip->hashes[i].data[ 7] << 24 | pkzip->hashes[i].data[ 6] << 16 | pkzip->hashes[i].data[ 5] << 8 | pkzip->hashes[i].data[ 4]; + salt->salt_buf[2] ^= pkzip->hashes[i].data[11] << 24 | pkzip->hashes[i].data[10] << 16 | pkzip->hashes[i].data[ 9] << 8 | pkzip->hashes[i].data[ 8]; + salt->salt_buf[3] ^= pkzip->hashes[i].data[15] << 24 | pkzip->hashes[i].data[14] << 16 | pkzip->hashes[i].data[13] << 8 | pkzip->hashes[i].data[ 12]; + + salt->salt_len = 16; + + // fake hash + digest[0] ^= pkzip->hashes[i].data[ 0] << 24 | pkzip->hashes[i].data[ 1] << 16 | pkzip->hashes[i].data[ 2] << 8 | pkzip->hashes[i].data[ 3]; + digest[1] ^= pkzip->hashes[i].data[ 4] << 24 | pkzip->hashes[i].data[ 5] << 16 | pkzip->hashes[i].data[ 6] << 8 | pkzip->hashes[i].data[ 7]; + digest[2] ^= pkzip->hashes[i].data[ 8] << 24 | pkzip->hashes[i].data[ 9] << 16 | pkzip->hashes[i].data[10] << 8 | pkzip->hashes[i].data[11]; + digest[3] ^= pkzip->hashes[i].data[12] << 24 | pkzip->hashes[i].data[13] << 16 | pkzip->hashes[i].data[14] << 8 | pkzip->hashes[i].data[15]; + } + + return (PARSER_OK); +} + +int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) +{ + const u32 *digest = (const u32 *) digest_buf; + + const pkzip_t *pkzip = (const pkzip_t *) esalt_buf; + + int out_len = 0; + + if (pkzip->version == 1) + { + sprintf (line_buf, "%s", SIGNATURE_PKZIP_V1); + out_len += 7; + } + else + { + sprintf (line_buf, "%s", SIGNATURE_PKZIP_V2); + out_len += 8; + } + out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hash_count, pkzip->checksum_size); + + for (int cnt = 0; cnt < pkzip->hash_count; cnt++) + { + out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hashes[cnt].data_type_enum, pkzip->hashes[cnt].magic_type_enum); + if (pkzip->hashes[cnt].data_type_enum > 1) + { + out_len += sprintf (line_buf + out_len, "%x*%x*%x*%x*%x*", pkzip->hashes[cnt].compressed_length, pkzip->hashes[cnt].uncompressed_length, pkzip->hashes[cnt].crc32, pkzip->hashes[cnt].offset, pkzip->hashes[cnt].additional_offset); + } + + out_len += sprintf (line_buf + out_len, "%i*%x*%x*", pkzip->hashes[cnt].compression_type, pkzip->hashes[cnt].data_length, pkzip->hashes[cnt].checksum_from_crc); + if (pkzip->version == 2) + { + out_len += sprintf (line_buf + out_len, "%x*", pkzip->hashes[cnt].checksum_from_timestamp); + } + + for (u32 i = 0; i < pkzip->hashes[cnt].data_length; i++) + { + out_len += sprintf (line_buf + out_len, "%02x", pkzip->hashes[cnt].data[i]); + } + } + + if (pkzip->version == 1) + { + out_len += sprintf (line_buf + out_len, "*$/pkzip$"); + } + else + { + out_len += sprintf (line_buf + out_len, "*$/pkzip2$"); + } + + return out_len; +} + +void module_init (module_ctx_t *module_ctx) +{ + module_ctx->module_context_size = MODULE_CONTEXT_SIZE_CURRENT; + module_ctx->module_interface_version = MODULE_INTERFACE_VERSION_CURRENT; + + module_ctx->module_attack_exec = module_attack_exec; + module_ctx->module_benchmark_esalt = MODULE_DEFAULT; + module_ctx->module_benchmark_hook_salt = MODULE_DEFAULT; + module_ctx->module_benchmark_mask = MODULE_DEFAULT; + module_ctx->module_benchmark_salt = MODULE_DEFAULT; + module_ctx->module_build_plain_postprocess = MODULE_DEFAULT; + module_ctx->module_deep_comp_kernel = MODULE_DEFAULT; + module_ctx->module_dgst_pos0 = module_dgst_pos0; + module_ctx->module_dgst_pos1 = module_dgst_pos1; + module_ctx->module_dgst_pos2 = module_dgst_pos2; + module_ctx->module_dgst_pos3 = module_dgst_pos3; + module_ctx->module_dgst_size = module_dgst_size; + module_ctx->module_dictstat_disable = MODULE_DEFAULT; + module_ctx->module_esalt_size = module_esalt_size; + module_ctx->module_extra_buffer_size = MODULE_DEFAULT; + module_ctx->module_extra_tmp_size = MODULE_DEFAULT; + module_ctx->module_forced_outfile_format = MODULE_DEFAULT; + module_ctx->module_hash_binary_count = MODULE_DEFAULT; + module_ctx->module_hash_binary_parse = MODULE_DEFAULT; + module_ctx->module_hash_binary_save = MODULE_DEFAULT; + module_ctx->module_hash_decode_outfile = MODULE_DEFAULT; + module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT; + module_ctx->module_hash_decode = module_hash_decode; + module_ctx->module_hash_encode_status = MODULE_DEFAULT; + module_ctx->module_hash_encode = module_hash_encode; + module_ctx->module_hash_init_selftest = MODULE_DEFAULT; + module_ctx->module_hash_mode = MODULE_DEFAULT; + module_ctx->module_hash_category = module_hash_category; + module_ctx->module_hash_name = module_hash_name; + module_ctx->module_hlfmt_disable = MODULE_DEFAULT; + module_ctx->module_hook12 = MODULE_DEFAULT; + module_ctx->module_hook23 = MODULE_DEFAULT; + module_ctx->module_hook_salt_size = MODULE_DEFAULT; + module_ctx->module_hook_size = MODULE_DEFAULT; + module_ctx->module_jit_build_options = MODULE_DEFAULT; + module_ctx->module_jit_cache_disable = MODULE_DEFAULT; + module_ctx->module_kernel_accel_max = MODULE_DEFAULT; + module_ctx->module_kernel_accel_min = MODULE_DEFAULT; + module_ctx->module_kernel_loops_max = MODULE_DEFAULT; + module_ctx->module_kernel_loops_min = MODULE_DEFAULT; + module_ctx->module_kernel_threads_max = MODULE_DEFAULT; + module_ctx->module_kernel_threads_min = MODULE_DEFAULT; + module_ctx->module_kern_type = module_kern_type; + module_ctx->module_kern_type_dynamic = MODULE_DEFAULT; + module_ctx->module_opti_type = module_opti_type; + module_ctx->module_opts_type = module_opts_type; + module_ctx->module_outfile_check_disable = MODULE_DEFAULT; + module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_disable = MODULE_DEFAULT; + module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; + module_ctx->module_pwdump_column = MODULE_DEFAULT; + module_ctx->module_pw_max = MODULE_DEFAULT; + module_ctx->module_pw_min = MODULE_DEFAULT; + module_ctx->module_salt_max = MODULE_DEFAULT; + module_ctx->module_salt_min = MODULE_DEFAULT; + module_ctx->module_salt_type = module_salt_type; + module_ctx->module_separator = MODULE_DEFAULT; + module_ctx->module_st_hash = module_st_hash; + module_ctx->module_st_pass = module_st_pass; + module_ctx->module_tmp_size = MODULE_DEFAULT; + module_ctx->module_unstable_warning = MODULE_DEFAULT; + module_ctx->module_warmup_disable = MODULE_DEFAULT; +} From 2da33ab0ba82ea5e2930179a9c17b350ccb2d092 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Thu, 21 Mar 2019 21:12:18 +0100 Subject: [PATCH 02/19] fixed issue with converting more than needed and using too much memory --- src/modules/module_17200.c | 2 +- src/modules/module_17210.c | 2 +- src/modules/module_17220.c | 2 +- src/modules/module_17230.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/module_17200.c b/src/modules/module_17200.c index 605f47f00..1be17645f 100644 --- a/src/modules/module_17200.c +++ b/src/modules/module_17200.c @@ -260,7 +260,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE p = strtok(NULL, "*"); if (p == NULL) return PARSER_HASH_LENGTH; - hex_to_binary(p, strlen(p) * 2, (char *) &(pkzip->hash.data)); + hex_to_binary(p, strlen(p), (char *) &(pkzip->hash.data)); // fake salt salt->salt_buf[0] = pkzip->hash.data[ 3] << 24 | pkzip->hash.data[ 2] << 16 | pkzip->hash.data[ 1] << 8 | pkzip->hash.data[ 0]; diff --git a/src/modules/module_17210.c b/src/modules/module_17210.c index ac7947e5d..d4ac412fb 100644 --- a/src/modules/module_17210.c +++ b/src/modules/module_17210.c @@ -259,7 +259,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE p = strtok(NULL, "*"); if (p == NULL) return PARSER_HASH_LENGTH; - hex_to_binary(p, strlen(p) * 2, (char *) &(pkzip->hash.data)); + hex_to_binary(p, strlen(p), (char *) &(pkzip->hash.data)); // fake salt salt->salt_buf[0] = pkzip->hash.data[ 3] << 24 | pkzip->hash.data[ 2] << 16 | pkzip->hash.data[ 1] << 8 | pkzip->hash.data[ 0]; diff --git a/src/modules/module_17220.c b/src/modules/module_17220.c index c896e783f..faec23a38 100644 --- a/src/modules/module_17220.c +++ b/src/modules/module_17220.c @@ -262,7 +262,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE p = strtok(NULL, "*"); if (p == NULL) return PARSER_HASH_LENGTH; - hex_to_binary(p, strlen(p) * 2, (char *) &(pkzip->hashes[i].data)); + hex_to_binary(p, strlen(p), (char *) &(pkzip->hashes[i].data)); // fake salt salt->salt_buf[0] ^= pkzip->hashes[i].data[ 3] << 24 | pkzip->hashes[i].data[ 2] << 16 | pkzip->hashes[i].data[ 1] << 8 | pkzip->hashes[i].data[ 0]; diff --git a/src/modules/module_17230.c b/src/modules/module_17230.c index afd855693..1e744863c 100644 --- a/src/modules/module_17230.c +++ b/src/modules/module_17230.c @@ -262,7 +262,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE p = strtok(NULL, "*"); if (p == NULL) return PARSER_HASH_LENGTH; - hex_to_binary(p, strlen(p) * 2, (char *) &(pkzip->hashes[i].data)); + hex_to_binary(p, strlen(p), (char *) &(pkzip->hashes[i].data)); // fake salt salt->salt_buf[0] ^= pkzip->hashes[i].data[ 3] << 24 | pkzip->hashes[i].data[ 2] << 16 | pkzip->hashes[i].data[ 1] << 8 | pkzip->hashes[i].data[ 0]; From c768073f6072381c068ad13398964307c7826abc Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Thu, 21 Mar 2019 21:37:24 +0100 Subject: [PATCH 03/19] fixed static limit for uncompress output to length defined --- OpenCL/m17200_a0-pure.cl | 4 ++-- OpenCL/m17200_a1-pure.cl | 4 ++-- OpenCL/m17200_a3-pure.cl | 4 ++-- OpenCL/m17220_a0-pure.cl | 4 ++-- OpenCL/m17220_a1-pure.cl | 4 ++-- OpenCL/m17220_a3-pure.cl | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/OpenCL/m17200_a0-pure.cl b/OpenCL/m17200_a0-pure.cl index 1328d458c..8fab34e48 100644 --- a/OpenCL/m17200_a0-pure.cl +++ b/OpenCL/m17200_a0-pure.cl @@ -664,7 +664,7 @@ __kernel void m17200_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input infstream.next_in = (Bytef *) compressed; // input char array - infstream.avail_out = 2048; // size of output + infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output infstream.next_out = (Bytef *) inflated; // output char array // inflateinit2 is needed because otherwise it checks for headers by default @@ -936,7 +936,7 @@ __kernel void m17200_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input infstream.next_in = (Bytef *) compressed; // input char array - infstream.avail_out = 2048; // size of output + infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output infstream.next_out = (Bytef *) inflated; // output char array // inflateinit2 is needed because otherwise it checks for headers by default diff --git a/OpenCL/m17200_a1-pure.cl b/OpenCL/m17200_a1-pure.cl index 0a481bd83..1ab9916f8 100644 --- a/OpenCL/m17200_a1-pure.cl +++ b/OpenCL/m17200_a1-pure.cl @@ -664,7 +664,7 @@ __kernel void m17200_sxx (KERN_ATTR_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = 2048; // size of output + infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output infstream.next_out = (Bytef *)inflated; // output char array // inflateinit2 is needed because otherwise it checks for headers by default @@ -937,7 +937,7 @@ __kernel void m17200_mxx (KERN_ATTR_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = 2048; // size of output + infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output infstream.next_out = (Bytef *)inflated; // output char array // inflateinit2 is needed because otherwise it checks for headers by default diff --git a/OpenCL/m17200_a3-pure.cl b/OpenCL/m17200_a3-pure.cl index cfe13900c..fb65d2438 100644 --- a/OpenCL/m17200_a3-pure.cl +++ b/OpenCL/m17200_a3-pure.cl @@ -670,7 +670,7 @@ __kernel void m17200_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = 2048; // size of output + infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output infstream.next_out = (Bytef *)inflated; // output char array // inflateinit2 is needed because otherwise it checks for headers by default @@ -949,7 +949,7 @@ __kernel void m17200_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = 2048; // size of output + infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output infstream.next_out = (Bytef *)inflated; // output char array // inflateinit2 is needed because otherwise it checks for headers by default diff --git a/OpenCL/m17220_a0-pure.cl b/OpenCL/m17220_a0-pure.cl index 828ca77e2..0a6dcf202 100644 --- a/OpenCL/m17220_a0-pure.cl +++ b/OpenCL/m17220_a0-pure.cl @@ -680,7 +680,7 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = 2048; // size of output + infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output infstream.next_out = (Bytef *)inflated; // output char array // inflateinit2 is needed because otherwise it checks for headers by default @@ -970,7 +970,7 @@ __kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = 2048; // size of output + infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output infstream.next_out = (Bytef *)inflated; // output char array // inflateinit2 is needed because otherwise it checks for headers by default diff --git a/OpenCL/m17220_a1-pure.cl b/OpenCL/m17220_a1-pure.cl index f1dfc2e50..c11a2ca08 100644 --- a/OpenCL/m17220_a1-pure.cl +++ b/OpenCL/m17220_a1-pure.cl @@ -680,7 +680,7 @@ __kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = 2048; // size of output + infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output infstream.next_out = (Bytef *)inflated; // output char array // inflateinit2 is needed because otherwise it checks for headers by default @@ -972,7 +972,7 @@ __kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = 2048; // size of output + infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output infstream.next_out = (Bytef *)inflated; // output char array // inflateinit2 is needed because otherwise it checks for headers by default diff --git a/OpenCL/m17220_a3-pure.cl b/OpenCL/m17220_a3-pure.cl index 0dc5e38fc..98c20276c 100644 --- a/OpenCL/m17220_a3-pure.cl +++ b/OpenCL/m17220_a3-pure.cl @@ -684,7 +684,7 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = 2048; // size of output + infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output infstream.next_out = (Bytef *)inflated; // output char array // inflateinit2 is needed because otherwise it checks for headers by default @@ -979,7 +979,7 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = 2048; // size of output + infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output infstream.next_out = (Bytef *)inflated; // output char array // inflateinit2 is needed because otherwise it checks for headers by default From 67994fc177810d6df649712cd502eac1be9eaacb Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Fri, 22 Mar 2019 21:09:38 +0100 Subject: [PATCH 04/19] removed unecessary parts causing build on some Intel OpenCLs to fail --- OpenCL/inc_zip_inflate.cl | 7 ------- OpenCL/m17200_a0-pure.cl | 6 +----- OpenCL/m17200_a1-pure.cl | 6 +----- OpenCL/m17200_a3-pure.cl | 6 +----- OpenCL/m17220_a0-pure.cl | 4 +--- OpenCL/m17220_a1-pure.cl | 6 +----- OpenCL/m17220_a3-pure.cl | 6 +----- 7 files changed, 6 insertions(+), 35 deletions(-) diff --git a/OpenCL/inc_zip_inflate.cl b/OpenCL/inc_zip_inflate.cl index 0009f8e3f..24633fe30 100644 --- a/OpenCL/inc_zip_inflate.cl +++ b/OpenCL/inc_zip_inflate.cl @@ -177,11 +177,6 @@ enum TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS }; -typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size); -typedef void (*mz_free_func)(void *opaque, void *address); -typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size); - - typedef unsigned char mz_uint8; typedef signed short mz_int16; typedef unsigned short mz_uint16; @@ -438,8 +433,6 @@ typedef struct mz_stream_s char *msg; /* error msg (unused) */ struct inflate_state *state; /* internal state, allocated by zalloc/zfree */ - mz_alloc_func zalloc; /* optional heap allocation function (defaults to malloc) */ - mz_free_func zfree; /* optional heap free function (defaults to free) */ void *opaque; /* heap alloc function user pointer */ int data_type; /* data_type (unused) */ diff --git a/OpenCL/m17200_a0-pure.cl b/OpenCL/m17200_a0-pure.cl index 8fab34e48..276353245 100644 --- a/OpenCL/m17200_a0-pure.cl +++ b/OpenCL/m17200_a0-pure.cl @@ -659,8 +659,6 @@ __kernel void m17200_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; inflate_state pStream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input infstream.next_in = (Bytef *) compressed; // input char array @@ -931,8 +929,6 @@ __kernel void m17200_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; inflate_state pStream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input infstream.next_in = (Bytef *) compressed; // input char array @@ -964,4 +960,4 @@ __kernel void m17200_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) } } } -} \ No newline at end of file +} diff --git a/OpenCL/m17200_a1-pure.cl b/OpenCL/m17200_a1-pure.cl index 1ab9916f8..7d2ec0eb8 100644 --- a/OpenCL/m17200_a1-pure.cl +++ b/OpenCL/m17200_a1-pure.cl @@ -659,8 +659,6 @@ __kernel void m17200_sxx (KERN_ATTR_ESALT (pkzip_t)) unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; inflate_state pStream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array @@ -932,8 +930,6 @@ __kernel void m17200_mxx (KERN_ATTR_ESALT (pkzip_t)) unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; inflate_state pStream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array @@ -964,4 +960,4 @@ __kernel void m17200_mxx (KERN_ATTR_ESALT (pkzip_t)) } } } -} \ No newline at end of file +} diff --git a/OpenCL/m17200_a3-pure.cl b/OpenCL/m17200_a3-pure.cl index fb65d2438..b739ce6df 100644 --- a/OpenCL/m17200_a3-pure.cl +++ b/OpenCL/m17200_a3-pure.cl @@ -665,8 +665,6 @@ __kernel void m17200_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; inflate_state pStream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array @@ -944,8 +942,6 @@ __kernel void m17200_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; inflate_state pStream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array @@ -976,4 +972,4 @@ __kernel void m17200_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) } } } -} \ No newline at end of file +} diff --git a/OpenCL/m17220_a0-pure.cl b/OpenCL/m17220_a0-pure.cl index 0a6dcf202..0b02e2b17 100644 --- a/OpenCL/m17220_a0-pure.cl +++ b/OpenCL/m17220_a0-pure.cl @@ -675,8 +675,6 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; inflate_state pStream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array @@ -1000,4 +998,4 @@ __kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) idx = 0xfe; } } -} \ No newline at end of file +} diff --git a/OpenCL/m17220_a1-pure.cl b/OpenCL/m17220_a1-pure.cl index c11a2ca08..d3717aa74 100644 --- a/OpenCL/m17220_a1-pure.cl +++ b/OpenCL/m17220_a1-pure.cl @@ -675,8 +675,6 @@ __kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; inflate_state pStream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array @@ -967,8 +965,6 @@ __kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; inflate_state pStream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array @@ -1002,4 +998,4 @@ __kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) idx = 0xfe; } } -} \ No newline at end of file +} diff --git a/OpenCL/m17220_a3-pure.cl b/OpenCL/m17220_a3-pure.cl index 98c20276c..a919df7e4 100644 --- a/OpenCL/m17220_a3-pure.cl +++ b/OpenCL/m17220_a3-pure.cl @@ -679,8 +679,6 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; inflate_state pStream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array @@ -974,8 +972,6 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; inflate_state pStream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input infstream.next_in = (Bytef *)compressed; // input char array @@ -1009,4 +1005,4 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) idx = 0xfe; } } -} \ No newline at end of file +} From 3ad7d00380d87ba101aebf84b5cd04ba7b363a54 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Fri, 22 Mar 2019 21:18:02 +0100 Subject: [PATCH 05/19] removed hash constants include --- src/modules/module_17200.c | 1 - src/modules/module_17210.c | 1 - src/modules/module_17220.c | 1 - src/modules/module_17230.c | 1 - 4 files changed, 4 deletions(-) diff --git a/src/modules/module_17200.c b/src/modules/module_17200.c index 1be17645f..4b2526037 100644 --- a/src/modules/module_17200.c +++ b/src/modules/module_17200.c @@ -90,7 +90,6 @@ Author: Sein Coray #include "bitops.h" #include "convert.h" #include "shared.h" -#include "inc_hash_constants.h" static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; static const u32 DGST_POS0 = 1; diff --git a/src/modules/module_17210.c b/src/modules/module_17210.c index d4ac412fb..8c235fe67 100644 --- a/src/modules/module_17210.c +++ b/src/modules/module_17210.c @@ -90,7 +90,6 @@ Author: Sein Coray #include "bitops.h" #include "convert.h" #include "shared.h" -#include "inc_hash_constants.h" static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; static const u32 DGST_POS0 = 1; diff --git a/src/modules/module_17220.c b/src/modules/module_17220.c index faec23a38..2ce885473 100644 --- a/src/modules/module_17220.c +++ b/src/modules/module_17220.c @@ -90,7 +90,6 @@ Author: Sein Coray #include "bitops.h" #include "convert.h" #include "shared.h" -#include "inc_hash_constants.h" static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; static const u32 DGST_POS0 = 1; diff --git a/src/modules/module_17230.c b/src/modules/module_17230.c index 1e744863c..9e82c3c6d 100644 --- a/src/modules/module_17230.c +++ b/src/modules/module_17230.c @@ -90,7 +90,6 @@ Author: Sein Coray #include "bitops.h" #include "convert.h" #include "shared.h" -#include "inc_hash_constants.h" static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; static const u32 DGST_POS0 = 1; From 798f026e3a9dbfbfe71e15e591dcfed04defa7e1 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Mon, 25 Mar 2019 10:57:18 +0100 Subject: [PATCH 06/19] adjusted kernels to newest refactoring --- OpenCL/inc_zip_inflate.cl | 6 ++---- OpenCL/m17210_a0-pure.cl | 8 +++----- OpenCL/m17210_a1-pure.cl | 8 +++----- OpenCL/m17210_a3-pure.cl | 8 +++----- OpenCL/m17230_a0-pure.cl | 8 +++----- OpenCL/m17230_a1-pure.cl | 9 +++++++-- OpenCL/m17230_a3-pure.cl | 8 +++----- 7 files changed, 24 insertions(+), 31 deletions(-) diff --git a/OpenCL/inc_zip_inflate.cl b/OpenCL/inc_zip_inflate.cl index 24633fe30..7e1fdb77c 100644 --- a/OpenCL/inc_zip_inflate.cl +++ b/OpenCL/inc_zip_inflate.cl @@ -61,10 +61,8 @@ any external components and dependencies which may be included with PKZIP Kernel */ -#include "inc_vendor.cl" -#include "inc_hash_constants.h" -#include "inc_hash_functions.cl" -#include "inc_types.cl" +#include "inc_vendor.h" +#include "inc_types.h" #include "inc_common.cl" #include "inc_simd.cl" diff --git a/OpenCL/m17210_a0-pure.cl b/OpenCL/m17210_a0-pure.cl index d78df3280..6002a3b95 100644 --- a/OpenCL/m17210_a0-pure.cl +++ b/OpenCL/m17210_a0-pure.cl @@ -84,10 +84,8 @@ Author: Sein Coray */ -#include "inc_vendor.cl" -#include "inc_hash_constants.h" -#include "inc_hash_functions.cl" -#include "inc_types.cl" +#include "inc_vendor.h" +#include "inc_types.h" #include "inc_common.cl" #include "inc_simd.cl" #include "inc_rp.h" @@ -548,4 +546,4 @@ __kernel void m17210_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) } } } -} \ No newline at end of file +} diff --git a/OpenCL/m17210_a1-pure.cl b/OpenCL/m17210_a1-pure.cl index 6e49d74d5..992a1b439 100644 --- a/OpenCL/m17210_a1-pure.cl +++ b/OpenCL/m17210_a1-pure.cl @@ -84,10 +84,8 @@ Author: Sein Coray */ -#include "inc_vendor.cl" -#include "inc_hash_constants.h" -#include "inc_hash_functions.cl" -#include "inc_types.cl" +#include "inc_vendor.h" +#include "inc_types.h" #include "inc_common.cl" #include "inc_simd.cl" @@ -550,4 +548,4 @@ __kernel void m17210_mxx (KERN_ATTR_ESALT (pkzip_t)) } } } -} \ No newline at end of file +} diff --git a/OpenCL/m17210_a3-pure.cl b/OpenCL/m17210_a3-pure.cl index a56146cca..ebbc5142f 100644 --- a/OpenCL/m17210_a3-pure.cl +++ b/OpenCL/m17210_a3-pure.cl @@ -84,10 +84,8 @@ Author: Sein Coray */ -#include "inc_vendor.cl" -#include "inc_hash_constants.h" -#include "inc_hash_functions.cl" -#include "inc_types.cl" +#include "inc_vendor.h" +#include "inc_types.h" #include "inc_common.cl" #include "inc_simd.cl" @@ -562,4 +560,4 @@ __kernel void m17210_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) } } } -} \ No newline at end of file +} diff --git a/OpenCL/m17230_a0-pure.cl b/OpenCL/m17230_a0-pure.cl index 9d3607604..b914e4dc6 100644 --- a/OpenCL/m17230_a0-pure.cl +++ b/OpenCL/m17230_a0-pure.cl @@ -84,10 +84,8 @@ Author: Sein Coray */ -#include "inc_vendor.cl" -#include "inc_hash_constants.h" -#include "inc_hash_functions.cl" -#include "inc_types.cl" +#include "inc_vendor.h" +#include "inc_types.h" #include "inc_common.cl" #include "inc_simd.cl" #include "inc_rp.h" @@ -536,4 +534,4 @@ __kernel void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) } } } -} \ No newline at end of file +} diff --git a/OpenCL/m17230_a1-pure.cl b/OpenCL/m17230_a1-pure.cl index f882801fe..735d42850 100644 --- a/OpenCL/m17230_a1-pure.cl +++ b/OpenCL/m17230_a1-pure.cl @@ -84,7 +84,12 @@ Author: Sein Coray */ -#include "inc_zip_inflate.cl" +#include "inc_vendor.h" +#include "inc_types.h" +#include "inc_common.cl" +#include "inc_simd.cl" +#include "inc_rp.h" +#include "inc_rp.cl" #define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) #define MSB(x) ((x)>>24) @@ -541,4 +546,4 @@ __kernel void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) } } } -} \ No newline at end of file +} diff --git a/OpenCL/m17230_a3-pure.cl b/OpenCL/m17230_a3-pure.cl index 4fd5ffbd4..dcf6d4047 100644 --- a/OpenCL/m17230_a3-pure.cl +++ b/OpenCL/m17230_a3-pure.cl @@ -84,10 +84,8 @@ Author: Sein Coray */ -#include "inc_vendor.cl" -#include "inc_hash_constants.h" -#include "inc_hash_functions.cl" -#include "inc_types.cl" +#include "inc_vendor.h" +#include "inc_types.h" #include "inc_common.cl" #include "inc_simd.cl" #include "inc_rp.h" @@ -552,4 +550,4 @@ __kernel void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) } } } -} \ No newline at end of file +} From 371991e0795fcf119945a2114549637163fcbe61 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Fri, 10 May 2019 12:50:03 +0200 Subject: [PATCH 07/19] included speed improvements and feedback from atom applied to all 172xx kernel variants --- OpenCL/inc_zip_inflate.cl | 88 +++- OpenCL/m17200_a0-pure.cl | 879 ++++++++++++++++++---------------- OpenCL/m17200_a1-pure.cl | 913 ++++++++++++++++++----------------- OpenCL/m17200_a3-pure.cl | 902 +++++++++++++++++++---------------- OpenCL/m17210_a0-pure.cl | 722 ++++++++++++++++------------ OpenCL/m17210_a1-pure.cl | 754 ++++++++++++++++------------- OpenCL/m17210_a3-pure.cl | 734 ++++++++++++++++------------ OpenCL/m17220_a0-pure.cl | 925 ++++++++++++++++++----------------- OpenCL/m17220_a1-pure.cl | 955 +++++++++++++++++++------------------ OpenCL/m17220_a3-pure.cl | 939 +++++++++++++++++++----------------- OpenCL/m17230_a0-pure.cl | 642 +++++++++++++------------ OpenCL/m17230_a1-pure.cl | 682 +++++++++++++------------- OpenCL/m17230_a3-pure.cl | 656 ++++++++++++------------- src/modules/module_17200.c | 97 ++-- src/modules/module_17210.c | 96 ++-- src/modules/module_17220.c | 97 ++-- src/modules/module_17230.c | 96 ++-- 17 files changed, 5400 insertions(+), 4777 deletions(-) diff --git a/OpenCL/inc_zip_inflate.cl b/OpenCL/inc_zip_inflate.cl index 7e1fdb77c..9f0b86d0e 100644 --- a/OpenCL/inc_zip_inflate.cl +++ b/OpenCL/inc_zip_inflate.cl @@ -61,11 +61,6 @@ any external components and dependencies which may be included with PKZIP Kernel */ -#include "inc_vendor.h" -#include "inc_types.h" -#include "inc_common.cl" -#include "inc_simd.cl" - enum{ MZ_OK = 0, MZ_STREAM_END = 1, @@ -193,6 +188,7 @@ void memcpy(void *dest, const void *src, size_t n){ } } + void *memset(void *s, int c, u32 len){ u8 *dst = s; while (len > 0) { @@ -209,6 +205,7 @@ void *memset(void *s, int c, u32 len){ #define MZ_DEFAULT_WINDOW_BITS 15 #define TINFL_LZ_DICT_SIZE 32768 #define TINFL_MEMCPY(d, s, l) memcpy(d, s, l) +#define TINFL_MEMCPY_G(d, s, l, p) memcpy_g(d, s, l, p) #define TINFL_MEMSET(p, c, l) memset(p, c, l) #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj)) @@ -293,7 +290,7 @@ enum { \ TINFL_CR_RETURN(state_index, (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) ? TINFL_STATUS_NEEDS_MORE_INPUT : TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS); \ } \ - c = *pIn_buf_cur++; \ + c = pIn_xor_byte (*pIn_buf_cur++, pStream); \ } \ MZ_MACRO_END @@ -310,7 +307,7 @@ enum } \ else \ { \ - bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); \ + bit_buf |= (((tinfl_bit_buf_t) pIn_xor_byte (pIn_buf_cur[0], pStream)) << num_bits) | (((tinfl_bit_buf_t) pIn_xor_byte (pIn_buf_cur[1], pStream)) << (num_bits + 8)); \ pIn_buf_cur += 2; \ num_bits += 16; \ } \ @@ -416,11 +413,12 @@ typedef struct int m_window_bits; mz_uint8 m_dict[TINFL_LZ_DICT_SIZE]; tinfl_status m_last_status; + } inflate_state; typedef struct mz_stream_s { - const unsigned char *next_in; /* pointer to next byte to read */ + __global const unsigned char *next_in; /* pointer to next byte to read */ unsigned int avail_in; /* number of bytes available at next_in */ mz_ulong total_in; /* total number of bytes consumed so far */ @@ -436,6 +434,15 @@ typedef struct mz_stream_s int data_type; /* data_type (unused) */ mz_ulong adler; /* adler32 of the source or uncompressed data */ mz_ulong reserved; /* not used */ + + #ifdef CRC32_IN_INFLATE + u32 key0; + u32 key1; + u32 key2; + u32 crc32; + LOCAL_AS u32 *crc32tab; + #endif + } mz_stream; typedef mz_stream *mz_streamp; @@ -451,9 +458,29 @@ int mz_inflateEnd(mz_streamp pStream); int mz_inflateInit2(mz_streamp pStream, int window_bits, inflate_state*); +const mz_uint8 pIn_xor_byte (const mz_uint8 c, mz_streamp pStream) +{ + mz_uint8 r = c; + + u32 key3; + + update_key3 (pStream->key2, key3); + u32 plain = c ^ key3; + update_key012 (pStream->key0, pStream->key1, pStream->key2, plain, pStream->crc32tab); + + return (mz_uint8) plain; +} -tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags) +void memcpy_g(void *dest, __global const void *src, size_t n, mz_streamp pStream){ + __global char *csrc = (__global char *)src; + char *cdest = (char *)dest; + for (int i=0; iavail_in; out_bytes = pStream->avail_out; - status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags); + status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags, pStream); + + for (int i = 0; i < out_bytes; i++) + { + pStream->crc32 = CRC32 (pStream->crc32, pStream->next_out[i], pStream->crc32tab); + } + pState->m_last_status = status; pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; pStream->total_in += (mz_uint)in_bytes; pStream->adler = tinfl_get_adler32(&pState->m_decomp); - pStream->next_out += (mz_uint)out_bytes; - pStream->avail_out -= (mz_uint)out_bytes; + //pStream->next_out += (mz_uint)out_bytes; + //pStream->avail_out -= (mz_uint)out_bytes; pStream->total_out += (mz_uint)out_bytes; if (status < 0) @@ -1005,8 +1039,14 @@ int mz_inflate(mz_streamp pStream, int flush) { n = MZ_MIN(pState->m_dict_avail, pStream->avail_out); memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n); - pStream->next_out += n; - pStream->avail_out -= n; + + for (int i = 0; i < n; i++) + { + pStream->crc32 = CRC32 (pStream->crc32, pStream->next_out[i], pStream->crc32tab); + } + + //pStream->next_out += n; + //pStream->avail_out -= n; pStream->total_out += n; pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1); @@ -1019,7 +1059,7 @@ int mz_inflate(mz_streamp pStream, int flush) in_bytes = pStream->avail_in; out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs; - status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags); + status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags, pStream); pState->m_last_status = status; pStream->next_in += (mz_uint)in_bytes; @@ -1031,8 +1071,14 @@ int mz_inflate(mz_streamp pStream, int flush) n = MZ_MIN(pState->m_dict_avail, pStream->avail_out); memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n); - pStream->next_out += n; - pStream->avail_out -= n; + + for (int i = 0; i < n; i++) + { + pStream->crc32 = CRC32 (pStream->crc32, pStream->next_out[i], pStream->crc32tab); + } + + //pStream->next_out += n; + //pStream->avail_out -= n; pStream->total_out += n; pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1); diff --git a/OpenCL/m17200_a0-pure.cl b/OpenCL/m17200_a0-pure.cl index 276353245..84b1c85d7 100644 --- a/OpenCL/m17200_a0-pure.cl +++ b/OpenCL/m17200_a0-pure.cl @@ -80,29 +80,45 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ -#include "inc_zip_inflate.cl" +#include "inc_vendor.h" +#include "inc_types.h" +#include "inc_common.cl" +#include "inc_simd.cl" #include "inc_rp.h" #include "inc_rp.cl" -#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) -#define MSB(x) ((x)>>24) -#define CONST 0x08088405 -#define POLYNOMIAL 0xEDB88320 +#define MAX_LOCAL 512 // too much leaves no room for compiler optimizations, simply benchmark to find a good trade-off - make it as big as possible +#define TMPSIZ 32 -#define MAX_COMPRESSED_LENGTH 2048 -#define MAX_UNCOMPRESSED_LENGTH 4096 +#define CRC32(x,c,t) (((x) >> 8) ^ (t)[((x) ^ (c)) & 0xff]) +#define MSB(x) ((x) >> 24) +#define CONST 0x08088405 -typedef struct { - u8 op; /* operation, extra bits, table bits */ - u8 bits; /* bits in this part of the code */ - u16 val; /* offset in table or code value */ -} code; +#define MAX_DATA (16 * 1024 * 1024) -typedef struct pkzip_hash +#define update_key012(k0,k1,k2,c,t) \ +{ \ + (k0) = CRC32 ((k0), c, (t)); \ + (k1) = ((k1) + ((k0) & 0xff)) * CONST + 1; \ + (k2) = CRC32 ((k2), MSB (k1), (t)); \ +} + +#define update_key3(k2,k3) \ +{ \ + const u32 temp = ((k2) & 0xffff) | 3; \ + \ + (k3) = ((temp * (temp ^ 1)) >> 8) & 0xff; \ +} + +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) + +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -115,18 +131,107 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_COMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; + +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; -typedef struct pkzip +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hash; -} pkzip_t; -__constant code lenfix[512] = { +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +CONSTANT_AS u32a crc32tab[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +#define CRC32_IN_INFLATE + +#include "inc_zip_inflate.cl" + +typedef struct +{ + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ + +} code; + +CONSTANT_AS code lenfix[512] = { {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, @@ -203,7 +308,7 @@ __constant code lenfix[512] = { {0,9,255} }; -__constant code distfix[32] = { +CONSTANT_AS code distfix[32] = { {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, @@ -299,7 +404,8 @@ DECLSPEC int check_inflate_code2 (u8 *next) } -DECLSPEC int check_inflate_code1 (u8 *next, int left){ +DECLSPEC int check_inflate_code1 (u8 *next, int left) +{ u32 whave = 0, op, bits, hold,len; code here1; @@ -428,48 +534,55 @@ __kernel void m17200_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; + /** + * sbox, kbox + */ - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; + LOCAL_AS u32 l_crc32tab[256]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_data[MAX_LOCAL]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = data_ptr[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + if (gid >= gid_max) return; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * digest + */ - l_crc32tab[b] = remainder; - } + const u32 search[4] = + { + digests_buf[digests_offset].digest_buf[DGST_R0], + digests_buf[digests_offset].digest_buf[DGST_R1], + digests_buf[digests_offset].digest_buf[DGST_R2], + digests_buf[digests_offset].digest_buf[DGST_R3] + }; - barrier (CLK_LOCAL_MEM_FENCE); + /** + * prefetch from global memory + */ - if (gid >= gid_max) return; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 checksum_from_crc = esalt_bufs[digests_offset].hash.checksum_from_crc; + const u32 checksum_from_timestamp = esalt_bufs[digests_offset].hash.checksum_from_timestamp; /** * base @@ -481,214 +594,177 @@ __kernel void m17200_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * loop */ - u32x key0, key1, key2; - for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - pw_t tmp = PASTE_PW; + pw_t t = PASTE_PW; - tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + t.pw_len = apply_rules (rules_buf[il_pos].cmds, t.i, t.pw_len); - key0 = 0x12345678; - key1 = 0x23456789; - key2 = 0x34567890; + u32x key0 = 0x12345678; + u32x key1 = 0x23456789; + u32x key2 = 0x34567890; - for (u8 i = 0; i < tmp.pw_len; i++) + for (u32 i = 0, j = 0; i < t.pw_len; i += 4, j += 1) { - key0 = CRC32 (key0, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); + if (t.pw_len >= (i + 1)) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (t.i[j]), l_crc32tab); + if (t.pw_len >= (i + 2)) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (t.i[j]), l_crc32tab); + if (t.pw_len >= (i + 3)) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (t.i[j]), l_crc32tab); + if (t.pw_len >= (i + 4)) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (t.i[j]), l_crc32tab); } - u8 compressed[MAX_COMPRESSED_LENGTH]; - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) - { - continue; - } + u32 plain; + u32 key3; + u32 next; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); + next = l_data[0]; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) - { - continue; - } + next = l_data[1]; - compressed[0] = plain; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - for (unsigned int i = 13; i < 36; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i - 12] = plain; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) - { - abort=1; - } - if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) - { - abort=1; - } + next = l_data[2]; - if (abort) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((checksum_from_crc & 0xff) != plain) && ((checksum_from_timestamp & 0xff) != plain)) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (checksum_from_crc >> 8)) && (plain != (checksum_from_timestamp >> 8))) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + const u32 key0_sav = key0; + const u32 key1_sav = key1; + const u32 key2_sav = key2; + + u8 tmp[TMPSIZ]; + + next = l_data[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) continue; + tmp[0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - for (unsigned int i = 36; i < esalt_bufs[digests_offset].hash.data_length; i++) + for (int i = 16; i < 36; i += 4) { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + next = l_data[i / 4]; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + tmp[i - 12 + 0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i - 12] = plain; + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[i - 12 + 1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[i - 12 + 2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[i - 12 + 3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); } - unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) continue; + if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) continue; + mz_stream infstream; + inflate_state pStream; + infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input - infstream.next_in = (Bytef *) compressed; // input char array - infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output - infstream.next_out = (Bytef *) inflated; // output char array + infstream.next_in = esalt_bufs[digests_offset].hash.data + 12; // input char array + infstream.avail_out = TMPSIZ; // size of output + infstream.next_out = tmp; // output char array + + #ifdef CRC32_IN_INFLATE + infstream.key0 = key0_sav; + infstream.key1 = key1_sav; + infstream.key2 = key2_sav; + infstream.crc32 = 0xffffffff; + infstream.crc32tab = l_crc32tab; + #endif // inflateinit2 is needed because otherwise it checks for headers by default mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); - const int ret = mz_inflate (&infstream, Z_NO_FLUSH); - if (ret < 0) - { - continue; // failed to inflate - } + int ret = mz_inflate (&infstream, Z_SYNC_FLUSH); - // check CRC - u32x crc = 0xffffffff; - for (unsigned int k = 0; k < infstream.total_out; ++k) + while (ret == MZ_OK) { - crc = CRC32 (crc, inflated[k]); + ret = mz_inflate (&infstream, Z_SYNC_FLUSH); } - crc = ~crc; - if (crc == esalt_bufs[digests_offset].hash.crc32) - { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) - { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); - } - } + if (ret != MZ_STREAM_END) continue; // failed to inflate + + const u32 r0 = ~infstream.crc32; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); } } @@ -698,49 +774,44 @@ __kernel void m17200_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_data[MAX_LOCAL]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = data_ptr[i]; } barrier (CLK_LOCAL_MEM_FENCE); if (gid >= gid_max) return; + /** + * prefetch from global memory + */ + + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 checksum_from_crc = esalt_bufs[digests_offset].hash.checksum_from_crc; + const u32 checksum_from_timestamp = esalt_bufs[digests_offset].hash.checksum_from_timestamp; + /** * base */ @@ -751,213 +822,185 @@ __kernel void m17200_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * loop */ - u32x key0, key1, key2; - for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - pw_t tmp = PASTE_PW; + pw_t t = PASTE_PW; - tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); + t.pw_len = apply_rules (rules_buf[il_pos].cmds, t.i, t.pw_len); - key0 = 0x12345678; - key1 = 0x23456789; - key2 = 0x34567890; + u32x key0 = 0x12345678; + u32x key1 = 0x23456789; + u32x key2 = 0x34567890; - for (u8 i = 0; i < tmp.pw_len; i++) + for (u32 i = 0, j = 0; i < t.pw_len; i += 4, j += 1) { - key0 = CRC32 (key0, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); + if (t.pw_len >= (i + 1)) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (t.i[j]), l_crc32tab); + if (t.pw_len >= (i + 2)) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (t.i[j]), l_crc32tab); + if (t.pw_len >= (i + 3)) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (t.i[j]), l_crc32tab); + if (t.pw_len >= (i + 4)) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (t.i[j]), l_crc32tab); } - u8 compressed[MAX_COMPRESSED_LENGTH]; - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) - { - continue; - } + u32 plain; + u32 key3; + u32 next; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); + next = l_data[0]; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) - { - continue; - } + next = l_data[1]; - compressed[0] = plain; - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - for (unsigned int i = 13; i < 36; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i - 12] = plain; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) - { - abort=1; - } - if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) - { - abort=1; - } + next = l_data[2]; - if (abort) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((checksum_from_crc & 0xff) != plain) && ((checksum_from_timestamp & 0xff) != plain)) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (checksum_from_crc >> 8)) && (plain != (checksum_from_timestamp >> 8))) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + const u32 key0_sav = key0; + const u32 key1_sav = key1; + const u32 key2_sav = key2; + + u8 tmp[TMPSIZ]; + + next = l_data[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) continue; + tmp[0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - for (unsigned int i = 36; i < esalt_bufs[digests_offset].hash.data_length; i++) + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + for (int i = 16; i < 36; i += 4) { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + next = l_data[i / 4]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + tmp[i - 12 + 0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[i - 12 + 1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32 (key0, plain); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32 (key2, MSB(key1)); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[i - 12 + 2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i - 12] = plain; + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[i - 12 + 3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); } - unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) continue; + if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) continue; + mz_stream infstream; + inflate_state pStream; + infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input - infstream.next_in = (Bytef *) compressed; // input char array - infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output - infstream.next_out = (Bytef *) inflated; // output char array + infstream.next_in = esalt_bufs[digests_offset].hash.data + 12; // input char array + infstream.avail_out = TMPSIZ; // size of output + infstream.next_out = tmp; // output char array + + #ifdef CRC32_IN_INFLATE + infstream.key0 = key0_sav; + infstream.key1 = key1_sav; + infstream.key2 = key2_sav; + infstream.crc32 = 0xffffffff; + infstream.crc32tab = l_crc32tab; + #endif // inflateinit2 is needed because otherwise it checks for headers by default mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); - const int ret = mz_inflate (&infstream, Z_NO_FLUSH); - if (ret < 0) - { - continue; // failed to inflate - } + int ret = mz_inflate (&infstream, Z_SYNC_FLUSH); - // check CRC - u32x crc = 0xffffffff; - for (unsigned int k = 0; k < infstream.total_out; ++k) + while (ret == MZ_OK) { - crc = CRC32 (crc, inflated[k]); + ret = mz_inflate (&infstream, Z_SYNC_FLUSH); } - crc = ~crc; - if (crc == esalt_bufs[digests_offset].hash.crc32) - { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) - { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); - } - } + if (ret != MZ_STREAM_END) continue; // failed to inflate + + const u32 r0 = ~infstream.crc32; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_M_SIMD (r0, r1, r2, r3); } } + +#undef MAX_LOCAL +#undef TMPSIZ +#undef CRC32 +#undef MSB +#undef CONST +#undef MAX_DATA +#undef update_key012 +#undef update_key3 diff --git a/OpenCL/m17200_a1-pure.cl b/OpenCL/m17200_a1-pure.cl index 7d2ec0eb8..3d8aaf662 100644 --- a/OpenCL/m17200_a1-pure.cl +++ b/OpenCL/m17200_a1-pure.cl @@ -80,27 +80,43 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ -#include "inc_zip_inflate.cl" +#include "inc_vendor.h" +#include "inc_types.h" +#include "inc_common.cl" +#include "inc_simd.cl" -#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) -#define MSB(x) ((x)>>24) -#define CONST 0x08088405 -#define POLYNOMIAL 0xEDB88320 +#define MAX_LOCAL 512 // too much leaves no room for compiler optimizations, simply benchmark to find a good trade-off - make it as big as possible +#define TMPSIZ 32 -#define MAX_COMPRESSED_LENGTH 2048 -#define MAX_UNCOMPRESSED_LENGTH 4096 +#define CRC32(x,c,t) (((x) >> 8) ^ (t)[((x) ^ (c)) & 0xff]) +#define MSB(x) ((x) >> 24) +#define CONST 0x08088405 -typedef struct { - u8 op; /* operation, extra bits, table bits */ - u8 bits; /* bits in this part of the code */ - u16 val; /* offset in table or code value */ -} code; +#define MAX_DATA (16 * 1024 * 1024) -typedef struct pkzip_hash +#define update_key012(k0,k1,k2,c,t) \ +{ \ + (k0) = CRC32 ((k0), c, (t)); \ + (k1) = ((k1) + ((k0) & 0xff)) * CONST + 1; \ + (k2) = CRC32 ((k2), MSB (k1), (t)); \ +} + +#define update_key3(k2,k3) \ +{ \ + const u32 temp = ((k2) & 0xffff) | 3; \ + \ + (k3) = ((temp * (temp ^ 1)) >> 8) & 0xff; \ +} + +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) + +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -113,18 +129,107 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_COMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; + +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; -typedef struct pkzip +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hash; -} pkzip_t; -__constant code lenfix[512] = { +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +CONSTANT_AS u32a crc32tab[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +#define CRC32_IN_INFLATE + +#include "inc_zip_inflate.cl" + +typedef struct +{ + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ + +} code; + +CONSTANT_AS code lenfix[512] = { {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, @@ -201,7 +306,7 @@ __constant code lenfix[512] = { {0,9,255} }; -__constant code distfix[32] = { +CONSTANT_AS code distfix[32] = { {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, @@ -297,7 +402,8 @@ DECLSPEC int check_inflate_code2 (u8 *next) } -DECLSPEC int check_inflate_code1 (u8 *next, int left){ +DECLSPEC int check_inflate_code1 (u8 *next, int left) +{ u32 whave = 0, op, bits, hold,len; code here1; @@ -426,268 +532,241 @@ __kernel void m17200_sxx (KERN_ATTR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; + /** + * sbox, kbox + */ - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; + LOCAL_AS u32 l_crc32tab[256]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_data[MAX_LOCAL]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = data_ptr[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + if (gid >= gid_max) return; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * digest + */ - l_crc32tab[b] = remainder; - } + const u32 search[4] = + { + digests_buf[digests_offset].digest_buf[DGST_R0], + digests_buf[digests_offset].digest_buf[DGST_R1], + digests_buf[digests_offset].digest_buf[DGST_R2], + digests_buf[digests_offset].digest_buf[DGST_R3] + }; - barrier (CLK_LOCAL_MEM_FENCE); + /** + * prefetch from global memory + */ - if (gid >= gid_max) return; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 checksum_from_crc = esalt_bufs[digests_offset].hash.checksum_from_crc; + const u32 checksum_from_timestamp = esalt_bufs[digests_offset].hash.checksum_from_timestamp; + const u32 crc32_final = esalt_bufs[digests_offset].hash.crc32; + const u32 data_length = esalt_bufs[digests_offset].hash.data_length; /** * loop */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; - - for (u8 i = 0; i < pws[gid].pw_len; i++) + for (u32 i = 0, j = 0; i < pws[gid].pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (pws[gid].pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (pws[gid].i[j]), l_crc32tab); } for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - key0 = key0init; - key1 = key1init; - key2 = key2init; + u32x key0 = key0init; + u32x key1 = key1init; + u32x key2 = key2init; - for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + for (u32 i = 0, j = 0; i < combs_buf[il_pos].pw_len; i += 4, j += 1) { - key0 = CRC32( key0, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (combs_buf[il_pos].pw_len >= (i + 1)) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 2)) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 3)) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 4)) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); } - u8 compressed[MAX_COMPRESSED_LENGTH]; - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) - { - continue; - } + u32 plain; + u32 key3; + u32 next; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = l_data[0]; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) - { - continue; - } + next = l_data[1]; - compressed[0] = plain; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - for (unsigned int i = 13; i < 36; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i-12] = plain; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) - { - abort=1; - } - if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) - { - abort=1; - } + next = l_data[2]; - if (abort) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((checksum_from_crc & 0xff) != plain) && ((checksum_from_timestamp & 0xff) != plain)) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (checksum_from_crc >> 8)) && (plain != (checksum_from_timestamp >> 8))) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); - for (unsigned int i = 36; i < esalt_bufs[digests_offset].hash.data_length; i++) + const u32 key0_sav = key0; + const u32 key1_sav = key1; + const u32 key2_sav = key2; + + u8 tmp[TMPSIZ]; + + next = l_data[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) continue; + tmp[0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + for (int i = 16; i < 36; i += 4) { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + next = l_data[i / 4]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + tmp[i - 12 + 0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[i - 12 + 1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i - 12] = plain; + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[i - 12 + 2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[i - 12 + 3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); } - unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) continue; + if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) continue; + mz_stream infstream; + inflate_state pStream; + infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input - infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output - infstream.next_out = (Bytef *)inflated; // output char array + infstream.next_in = esalt_bufs[digests_offset].hash.data + 12; // input char array + infstream.avail_out = TMPSIZ; // size of output + infstream.next_out = tmp; // output char array + + #ifdef CRC32_IN_INFLATE + infstream.key0 = key0_sav; + infstream.key1 = key1_sav; + infstream.key2 = key2_sav; + infstream.crc32 = 0xffffffff; + infstream.crc32tab = l_crc32tab; + #endif // inflateinit2 is needed because otherwise it checks for headers by default - mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); - int ret = mz_inflate(&infstream, Z_NO_FLUSH); - if (ret < 0) - { - continue; // failed to inflate - } + mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); - // check CRC - u32x crc = 0xffffffff; - for (unsigned int k = 0; k < infstream.total_out; ++k) - { - crc = CRC32(crc, inflated[k]); - } - crc = ~crc; + int ret = mz_inflate (&infstream, Z_SYNC_FLUSH); - if (crc == esalt_bufs[digests_offset].hash.crc32) + while (ret == MZ_OK) { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) - { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); - } + ret = mz_inflate (&infstream, Z_SYNC_FLUSH); } + + if (ret != MZ_STREAM_END) continue; // failed to inflate + + const u32 r0 = ~infstream.crc32; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); } } @@ -697,43 +776,30 @@ __kernel void m17200_mxx (KERN_ATTR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_data[MAX_LOCAL]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = data_ptr[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -741,223 +807,206 @@ __kernel void m17200_mxx (KERN_ATTR_ESALT (pkzip_t)) if (gid >= gid_max) return; /** - * loop + * prefetch from global memory */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 checksum_from_crc = esalt_bufs[digests_offset].hash.checksum_from_crc; + const u32 checksum_from_timestamp = esalt_bufs[digests_offset].hash.checksum_from_timestamp; + const u32 crc32_final = esalt_bufs[digests_offset].hash.crc32; + const u32 data_length = esalt_bufs[digests_offset].hash.data_length; - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + /** + * loop + */ + + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - for(u8 i = 0; i < pws[gid].pw_len; i++) + for (u32 i = 0, j = 0; i < pws[gid].pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (pws[gid].pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (pws[gid].i[j]), l_crc32tab); } for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - key0 = key0init; - key1 = key1init; - key2 = key2init; + u32x key0 = key0init; + u32x key1 = key1init; + u32x key2 = key2init; - for(u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + for (u32 i = 0, j = 0; i < combs_buf[il_pos].pw_len; i += 4, j += 1) { - key0 = CRC32( key0, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (combs_buf[il_pos].pw_len >= (i + 1)) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 2)) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 3)) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 4)) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); } - u8 compressed[MAX_COMPRESSED_LENGTH]; - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) - { - continue; - } + u32 plain; + u32 key3; + u32 next; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = l_data[0]; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) - { - continue; - } + next = l_data[1]; - compressed[0] = plain; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - for (unsigned int i = 13; i < 36; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i-12] = plain; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) - { - abort=1; - } - if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) - { - abort=1; - } + next = l_data[2]; - if (abort) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((checksum_from_crc & 0xff) != plain) && ((checksum_from_timestamp & 0xff) != plain)) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (checksum_from_crc >> 8)) && (plain != (checksum_from_timestamp >> 8))) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + const u32 key0_sav = key0; + const u32 key1_sav = key1; + const u32 key2_sav = key2; + + u8 tmp[TMPSIZ]; + + next = l_data[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) continue; + tmp[0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - for (unsigned int i = 36; i < esalt_bufs[digests_offset].hash.data_length; i++) + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + for (int i = 16; i < 36; i += 4) { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + next = l_data[i / 4]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + tmp[i - 12 + 0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[i - 12 + 1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i - 12] = plain; + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[i - 12 + 2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[i - 12 + 3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); } - unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) continue; + if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) continue; + mz_stream infstream; + inflate_state pStream; + infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input - infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output - infstream.next_out = (Bytef *)inflated; // output char array + infstream.next_in = esalt_bufs[digests_offset].hash.data + 12; // input char array + infstream.avail_out = TMPSIZ; // size of output + infstream.next_out = tmp; // output char array + + #ifdef CRC32_IN_INFLATE + infstream.key0 = key0_sav; + infstream.key1 = key1_sav; + infstream.key2 = key2_sav; + infstream.crc32 = 0xffffffff; + infstream.crc32tab = l_crc32tab; + #endif // inflateinit2 is needed because otherwise it checks for headers by default - mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); - int ret = mz_inflate(&infstream, Z_NO_FLUSH); - if (ret < 0) - { - continue; // failed to inflate - } + mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); - // check CRC - u32x crc = 0xffffffff; - for (unsigned int k = 0; k < infstream.total_out; ++k) - { - crc = CRC32(crc, inflated[k]); - } - crc = ~crc; + int ret = mz_inflate (&infstream, Z_SYNC_FLUSH); - if (crc == esalt_bufs[digests_offset].hash.crc32) + while (ret == MZ_OK) { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) - { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); - } + ret = mz_inflate (&infstream, Z_SYNC_FLUSH); } + + if (ret != MZ_STREAM_END) continue; // failed to inflate + + const u32 r0 = ~infstream.crc32; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_M_SIMD (r0, r1, r2, r3); } } + +#undef MAX_LOCAL +#undef TMPSIZ +#undef CRC32 +#undef MSB +#undef CONST +#undef MAX_DATA +#undef update_key012 +#undef update_key3 diff --git a/OpenCL/m17200_a3-pure.cl b/OpenCL/m17200_a3-pure.cl index b739ce6df..4f0c278a3 100644 --- a/OpenCL/m17200_a3-pure.cl +++ b/OpenCL/m17200_a3-pure.cl @@ -80,27 +80,43 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ -#include "inc_zip_inflate.cl" +#include "inc_vendor.h" +#include "inc_types.h" +#include "inc_common.cl" +#include "inc_simd.cl" -#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) -#define MSB(x) ((x)>>24) -#define CONST 0x08088405 -#define POLYNOMIAL 0xEDB88320 +#define MAX_LOCAL 512 // too much leaves no room for compiler optimizations, simply benchmark to find a good trade-off - make it as big as possible +#define TMPSIZ 32 -#define MAX_COMPRESSED_LENGTH 2048 -#define MAX_UNCOMPRESSED_LENGTH 4096 +#define CRC32(x,c,t) (((x) >> 8) ^ (t)[((x) ^ (c)) & 0xff]) +#define MSB(x) ((x) >> 24) +#define CONST 0x08088405 -typedef struct { - u8 op; /* operation, extra bits, table bits */ - u8 bits; /* bits in this part of the code */ - u16 val; /* offset in table or code value */ -} code; +#define MAX_DATA (16 * 1024 * 1024) -typedef struct pkzip_hash +#define update_key012(k0,k1,k2,c,t) \ +{ \ + (k0) = CRC32 ((k0), c, (t)); \ + (k1) = ((k1) + ((k0) & 0xff)) * CONST + 1; \ + (k2) = CRC32 ((k2), MSB (k1), (t)); \ +} + +#define update_key3(k2,k3) \ +{ \ + const u32 temp = ((k2) & 0xffff) | 3; \ + \ + (k3) = ((temp * (temp ^ 1)) >> 8) & 0xff; \ +} + +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) + +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -113,18 +129,108 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_COMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; + +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; -typedef struct pkzip +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hash; -} pkzip_t; -__constant code lenfix[512] = { +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +CONSTANT_AS u32a crc32tab[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +#define CRC32_IN_INFLATE + +#include "inc_zip_inflate.cl" + +typedef struct +{ + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ + +} code; + +CONSTANT_AS code lenfix[512] = +{ {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, @@ -201,7 +307,8 @@ __constant code lenfix[512] = { {0,9,255} }; -__constant code distfix[32] = { +CONSTANT_AS code distfix[32] = +{ {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, @@ -210,7 +317,7 @@ __constant code distfix[32] = { {22,5,193},{64,5,0} }; -DECLSPEC int check_inflate_code2(u8 *next) +DECLSPEC int check_inflate_code2 (u8 *next) { u32 bits, hold, thisget, have, i; int left; @@ -296,8 +403,8 @@ DECLSPEC int check_inflate_code2(u8 *next) return 1; } - -DECLSPEC int check_inflate_code1(u8 *next, int left){ +DECLSPEC int check_inflate_code1 (u8 *next, int left) +{ u32 whave = 0, op, bits, hold,len; code here1; @@ -426,48 +533,57 @@ __kernel void m17200_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; + /** + * sbox, kbox + */ - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; + LOCAL_AS u32 l_crc32tab[256]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_data[MAX_LOCAL]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = data_ptr[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + if (gid >= gid_max) return; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * digest + */ - l_crc32tab[b] = remainder; - } + const u32 search[4] = + { + digests_buf[digests_offset].digest_buf[DGST_R0], + digests_buf[digests_offset].digest_buf[DGST_R1], + digests_buf[digests_offset].digest_buf[DGST_R2], + digests_buf[digests_offset].digest_buf[DGST_R3] + }; - barrier (CLK_LOCAL_MEM_FENCE); + /** + * prefetch from global memory + */ - if (gid >= gid_max) return; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 checksum_from_crc = esalt_bufs[digests_offset].hash.checksum_from_crc; + const u32 checksum_from_timestamp = esalt_bufs[digests_offset].hash.checksum_from_timestamp; + const u32 crc32_final = esalt_bufs[digests_offset].hash.crc32; + const u32 data_length = esalt_bufs[digests_offset].hash.data_length; /** * base @@ -486,214 +602,184 @@ __kernel void m17200_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * loop */ - u32x key0, key1, key2; u32 w0l = w[0]; for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) { const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; - w[0] = w0; - key0 = 0x12345678; - key1 = 0x23456789; - key2 = 0x34567890; + u32x key0 = 0x12345678; + u32x key1 = 0x23456789; + u32x key2 = 0x34567890; - for (u8 i = 0; i < pw_len; i++) - { - key0 = CRC32( key0, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - } + if (pw_len >= 1) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (w0), l_crc32tab); + if (pw_len >= 2) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (w0), l_crc32tab); + if (pw_len >= 3) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (w0), l_crc32tab); + if (pw_len >= 4) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (w0), l_crc32tab); - u8 compressed[MAX_COMPRESSED_LENGTH]; - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + for (u32 i = 4, j = 1; i < pw_len; i += 4, j += 1) { - continue; + if (pw_len >= (i + 1)) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 2)) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 3)) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 4)) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (w[j]), l_crc32tab); } - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32 plain; + u32 key3; + u32 next; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + next = l_data[0]; - if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[0] = plain; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = l_data[1]; - for (unsigned int i = 13; i < 36; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i-12] = plain; - } + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) - { - abort=1; - } - if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) - { - abort=1; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (abort) - { - continue; - } + next = l_data[2]; - for (unsigned int i = 36; i < esalt_bufs[digests_offset].hash.data_length; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((checksum_from_crc & 0xff) != plain) && ((checksum_from_timestamp & 0xff) != plain)) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (checksum_from_crc >> 8)) && (plain != (checksum_from_timestamp >> 8))) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + const u32 key0_sav = key0; + const u32 key1_sav = key1; + const u32 key2_sav = key2; + + u8 tmp[TMPSIZ]; + + next = l_data[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) continue; + tmp[0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i - 12] = plain; + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + for (int i = 16; i < 36; i += 4) + { + next = l_data[i / 4]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + tmp[i - 12 + 0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[i - 12 + 1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[i - 12 + 2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[i - 12 + 3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); } - unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) continue; + if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) continue; + mz_stream infstream; + inflate_state pStream; + infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input - infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output - infstream.next_out = (Bytef *)inflated; // output char array + infstream.next_in = esalt_bufs[digests_offset].hash.data + 12; // input char array + infstream.avail_out = TMPSIZ; // size of output + infstream.next_out = tmp; // output char array + + #ifdef CRC32_IN_INFLATE + infstream.key0 = key0_sav; + infstream.key1 = key1_sav; + infstream.key2 = key2_sav; + infstream.crc32 = 0xffffffff; + infstream.crc32tab = l_crc32tab; + #endif // inflateinit2 is needed because otherwise it checks for headers by default - mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); - int ret = mz_inflate(&infstream, Z_NO_FLUSH); - if (ret < 0) - { - continue; // failed to inflate - } + mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); - // check CRC - u32x crc = 0xffffffff; - for (unsigned int k = 0; k < infstream.total_out; ++k) - { - crc = CRC32(crc, inflated[k]); - } - crc = ~crc; + int ret = mz_inflate (&infstream, Z_SYNC_FLUSH); - if (crc == esalt_bufs[digests_offset].hash.crc32) + while (ret == MZ_OK) { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) - { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); - } + ret = mz_inflate (&infstream, Z_SYNC_FLUSH); } + + if (ret != MZ_STREAM_END) continue; // failed to inflate + + const u32 r0 = ~infstream.crc32; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); } } @@ -703,49 +789,46 @@ __kernel void m17200_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_data[MAX_LOCAL]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = data_ptr[i]; } barrier (CLK_LOCAL_MEM_FENCE); if (gid >= gid_max) return; + /** + * prefetch from global memory + */ + + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 checksum_from_crc = esalt_bufs[digests_offset].hash.checksum_from_crc; + const u32 checksum_from_timestamp = esalt_bufs[digests_offset].hash.checksum_from_timestamp; + const u32 crc32_final = esalt_bufs[digests_offset].hash.crc32; + const u32 data_length = esalt_bufs[digests_offset].hash.data_length; + /** * base */ @@ -763,213 +846,192 @@ __kernel void m17200_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * loop */ - u32x key0, key1, key2; u32 w0l = w[0]; for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) { const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; - w[0] = w0; - key0 = 0x12345678; - key1 = 0x23456789; - key2 = 0x34567890; + u32x key0 = 0x12345678; + u32x key1 = 0x23456789; + u32x key2 = 0x34567890; - for(u8 i = 0; i < pw_len; i++) - { - key0 = CRC32( key0, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - } + if (pw_len >= 1) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (w0), l_crc32tab); + if (pw_len >= 2) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (w0), l_crc32tab); + if (pw_len >= 3) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (w0), l_crc32tab); + if (pw_len >= 4) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (w0), l_crc32tab); - u8 compressed[MAX_COMPRESSED_LENGTH]; - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + for (u32 i = 4, j = 1; i < pw_len; i += 4, j += 1) { - continue; + if (pw_len >= (i + 1)) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 2)) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 3)) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 4)) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (w[j]), l_crc32tab); } - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32 plain; + u32 key3; + u32 next; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + next = l_data[0]; - if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[0] = plain; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = l_data[1]; - for (unsigned int i = 13; i < 36; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i-12] = plain; - } + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) - { - abort=1; - } - if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) - { - abort=1; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (abort) - { - continue; - } + next = l_data[2]; - for (unsigned int i = 36; i < esalt_bufs[digests_offset].hash.data_length; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((checksum_from_crc & 0xff) != plain) && ((checksum_from_timestamp & 0xff) != plain)) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (checksum_from_crc >> 8)) && (plain != (checksum_from_timestamp >> 8))) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + const u32 key0_sav = key0; + const u32 key1_sav = key1; + const u32 key2_sav = key2; + + u8 tmp[TMPSIZ]; + + next = l_data[3]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) continue; + tmp[0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i - 12] = plain; + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + for (int i = 16; i < 36; i += 4) + { + next = l_data[i / 4]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + tmp[i - 12 + 0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[i - 12 + 1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[i - 12 + 2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[i - 12 + 3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); } - unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) continue; + if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) continue; + mz_stream infstream; + inflate_state pStream; + infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input - infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output - infstream.next_out = (Bytef *)inflated; // output char array + infstream.next_in = esalt_bufs[digests_offset].hash.data + 12; // input char array + infstream.avail_out = TMPSIZ; // size of output + infstream.next_out = tmp; // output char array + + #ifdef CRC32_IN_INFLATE + infstream.key0 = key0_sav; + infstream.key1 = key1_sav; + infstream.key2 = key2_sav; + infstream.crc32 = 0xffffffff; + infstream.crc32tab = l_crc32tab; + #endif // inflateinit2 is needed because otherwise it checks for headers by default - mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); - int ret = mz_inflate(&infstream, Z_NO_FLUSH); - if (ret < 0) - { - continue; // failed to inflate - } + mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); - // check CRC - u32x crc = 0xffffffff; - for (unsigned int k = 0; k < infstream.total_out; ++k) - { - crc = CRC32(crc, inflated[k]); - } - crc = ~crc; + int ret = mz_inflate (&infstream, Z_SYNC_FLUSH); - if (crc == esalt_bufs[digests_offset].hash.crc32) + while (ret == MZ_OK) { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) - { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); - } + ret = mz_inflate (&infstream, Z_SYNC_FLUSH); } + + if (ret != MZ_STREAM_END) continue; // failed to inflate + + const u32 r0 = ~infstream.crc32; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_M_SIMD (r0, r1, r2, r3); } } + +#undef MAX_LOCAL +#undef TMPSIZ +#undef CRC32 +#undef MSB +#undef CONST +#undef MAX_DATA +#undef update_key012 +#undef update_key3 diff --git a/OpenCL/m17210_a0-pure.cl b/OpenCL/m17210_a0-pure.cl index 6002a3b95..8308d10ef 100644 --- a/OpenCL/m17210_a0-pure.cl +++ b/OpenCL/m17210_a0-pure.cl @@ -80,7 +80,8 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ @@ -91,14 +92,33 @@ Author: Sein Coray #include "inc_rp.h" #include "inc_rp.cl" -#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) -#define MSB(x) ((x)>>24) -#define CONST 0x08088405 -#define POLYNOMIAL 0xEDB88320 +#define MAX_LOCAL 512 // too much leaves no room for compiler optimizations, simply benchmark to find a good trade-off - make it as big as possible +#define TMPSIZ 32 -#define MAX_UNCOMPRESSED_LENGTH 4096 +#define CRC32(x,c,t) (((x) >> 8) ^ (t)[((x) ^ (c)) & 0xff]) +#define MSB(x) ((x) >> 24) +#define CONST 0x08088405 -typedef struct pkzip_hash +#define MAX_DATA (16 * 1024 * 1024) + +#define update_key012(k0,k1,k2,c,t) \ +{ \ + (k0) = CRC32 ((k0), c, (t)); \ + (k1) = ((k1) + ((k0) & 0xff)) * CONST + 1; \ + (k2) = CRC32 ((k2), MSB (k1), (t)); \ +} + +#define update_key3(k2,k3) \ +{ \ + const u32 temp = ((k2) & 0xffff) | 3; \ + \ + (k3) = ((temp * (temp ^ 1)) >> 8) & 0xff; \ +} + +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) + +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -111,16 +131,93 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_UNCOMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; + +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; -typedef struct pkzip +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hash; -} pkzip_t; + +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +CONSTANT_AS u32a crc32tab[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; __kernel void m17210_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) { @@ -128,48 +225,57 @@ __kernel void m17210_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; + /** + * sbox, kbox + */ - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; + LOCAL_AS u32 l_crc32tab[256]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_data[MAX_LOCAL]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = data_ptr[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + if (gid >= gid_max) return; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * digest + */ - l_crc32tab[b] = remainder; - } + const u32 search[4] = + { + digests_buf[digests_offset].digest_buf[DGST_R0], + digests_buf[digests_offset].digest_buf[DGST_R1], + digests_buf[digests_offset].digest_buf[DGST_R2], + digests_buf[digests_offset].digest_buf[DGST_R3] + }; - barrier (CLK_LOCAL_MEM_FENCE); + /** + * prefetch from global memory + */ - if (gid >= gid_max) return; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 checksum_from_crc = esalt_bufs[digests_offset].hash.checksum_from_crc; + const u32 checksum_from_timestamp = esalt_bufs[digests_offset].hash.checksum_from_timestamp; + const u32 crc32_final = esalt_bufs[digests_offset].hash.crc32; + const u32 data_length = esalt_bufs[digests_offset].hash.data_length; /** * base @@ -181,157 +287,144 @@ __kernel void m17210_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * loop */ - u32x key0, key1, key2; - for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { pw_t tmp = PASTE_PW; tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); - key0 = 0x12345678; - key1 = 0x23456789; - key2 = 0x34567890; + u32x key0 = 0x12345678; + u32x key1 = 0x23456789; + u32x key2 = 0x34567890; - for (u8 i = 0; i < tmp.pw_len; i++) + for (u32 i = 0, j = 0; i < tmp.pw_len; i += 4, j += 1) { - key0 = CRC32( key0, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (tmp.pw_len >= (i + 1)) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 2)) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 3)) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 4)) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (tmp.i[j]), l_crc32tab); } - u8 plain; - u8 key3; - u16 temp; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) - { - continue; - } + u32 plain; + u32 key3; + u32 next; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = l_data[0]; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp^1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = l_data[1]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = l_data[2]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((checksum_from_crc & 0xff) != plain) && ((checksum_from_timestamp & 0xff) != plain)) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (checksum_from_crc >> 8)) && (plain != (checksum_from_timestamp >> 8))) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); u32x crc = 0xffffffff; - crc = CRC32(crc, plain); - for (unsigned int i = 13; i < esalt_bufs[digests_offset].hash.data_length; i++) + for (u32 i = 12, j = 3; i < data_length && j < MAX_LOCAL; i += 4, j += 1) { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + next = l_data[j]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (data_length >= (i + 1)) + { + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - crc = CRC32(crc, plain); - } - crc = ~crc; + crc = CRC32 (crc, plain, l_crc32tab); + } - if (crc == esalt_bufs[digests_offset].hash.crc32) - { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + if (data_length >= (i + 2)) { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + if (data_length >= (i + 3)) + { + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + if (data_length >= (i + 4)) + { + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); } } + + // global memory from here + + for (u32 i = MAX_LOCAL * 4; i < data_length; i++) + { + update_key3 (key2, key3); + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + const u32 r0 = ~crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); } } @@ -341,49 +434,46 @@ __kernel void m17210_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_data[MAX_LOCAL]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = data_ptr[i]; } barrier (CLK_LOCAL_MEM_FENCE); if (gid >= gid_max) return; + /** + * prefetch from global memory + */ + + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 checksum_from_crc = esalt_bufs[digests_offset].hash.checksum_from_crc; + const u32 checksum_from_timestamp = esalt_bufs[digests_offset].hash.checksum_from_timestamp; + const u32 crc32_final = esalt_bufs[digests_offset].hash.crc32; + const u32 data_length = esalt_bufs[digests_offset].hash.data_length; + /** * base */ @@ -394,156 +484,152 @@ __kernel void m17210_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * loop */ - u32x key0, key1, key2; - for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { pw_t tmp = PASTE_PW; tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); - key0 = 0x12345678; - key1 = 0x23456789; - key2 = 0x34567890; + u32x key0 = 0x12345678; + u32x key1 = 0x23456789; + u32x key2 = 0x34567890; - for (u8 i = 0; i < tmp.pw_len; i++) + for (u32 i = 0, j = 0; i < tmp.pw_len; i += 4, j += 1) { - key0 = CRC32( key0, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (tmp.pw_len >= (i + 1)) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 2)) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 3)) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 4)) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (tmp.i[j]), l_crc32tab); } - u8 plain; - u8 key3; - u16 temp; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) - { - continue; - } + u32 plain; + u32 key3; + u32 next; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = l_data[0]; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp^1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + next = l_data[1]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = l_data[2]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((checksum_from_crc & 0xff) != plain) && ((checksum_from_timestamp & 0xff) != plain)) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (checksum_from_crc >> 8)) && (plain != (checksum_from_timestamp >> 8))) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); u32x crc = 0xffffffff; - crc = CRC32(crc, plain); - for (unsigned int i = 13; i < esalt_bufs[digests_offset].hash.data_length; i++) + for (u32 i = 12, j = 3; i < data_length && j < MAX_LOCAL; i += 4, j += 1) { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + next = l_data[j]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (data_length >= (i + 1)) + { + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - crc = CRC32(crc, plain); - } - crc = ~crc; + crc = CRC32 (crc, plain, l_crc32tab); + } - if (crc == esalt_bufs[digests_offset].hash.crc32) - { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + if (data_length >= (i + 2)) { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + if (data_length >= (i + 3)) + { + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + if (data_length >= (i + 4)) + { + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); } } + + // global memory from here + + for (u32 i = MAX_LOCAL * 4; i < data_length; i++) + { + update_key3 (key2, key3); + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + const u32 r0 = ~crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_M_SIMD (r0, r1, r2, r3); } } + +#undef MAX_LOCAL +#undef TMPSIZ +#undef CRC32 +#undef MSB +#undef CONST +#undef MAX_DATA +#undef update_key012 +#undef update_key3 diff --git a/OpenCL/m17210_a1-pure.cl b/OpenCL/m17210_a1-pure.cl index 992a1b439..4e726f759 100644 --- a/OpenCL/m17210_a1-pure.cl +++ b/OpenCL/m17210_a1-pure.cl @@ -80,7 +80,8 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ @@ -89,14 +90,33 @@ Author: Sein Coray #include "inc_common.cl" #include "inc_simd.cl" -#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) -#define MSB(x) ((x)>>24) -#define CONST 0x08088405 -#define POLYNOMIAL 0xEDB88320 +#define MAX_LOCAL 512 // too much leaves no room for compiler optimizations, simply benchmark to find a good trade-off - make it as big as possible +#define TMPSIZ 32 -#define MAX_UNCOMPRESSED_LENGTH 4096 +#define CRC32(x,c,t) (((x) >> 8) ^ (t)[((x) ^ (c)) & 0xff]) +#define MSB(x) ((x) >> 24) +#define CONST 0x08088405 -typedef struct pkzip_hash +#define MAX_DATA (16 * 1024 * 1024) + +#define update_key012(k0,k1,k2,c,t) \ +{ \ + (k0) = CRC32 ((k0), c, (t)); \ + (k1) = ((k1) + ((k0) & 0xff)) * CONST + 1; \ + (k2) = CRC32 ((k2), MSB (k1), (t)); \ +} + +#define update_key3(k2,k3) \ +{ \ + const u32 temp = ((k2) & 0xffff) | 3; \ + \ + (k3) = ((temp * (temp ^ 1)) >> 8) & 0xff; \ +} + +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) + +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -109,16 +129,93 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_UNCOMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; + +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; -typedef struct pkzip +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hash; -} pkzip_t; + +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +CONSTANT_AS u32a crc32tab[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; __kernel void m17210_sxx (KERN_ATTR_ESALT (pkzip_t)) { @@ -126,212 +223,208 @@ __kernel void m17210_sxx (KERN_ATTR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; + /** + * sbox, kbox + */ - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; + LOCAL_AS u32 l_crc32tab[256]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_data[MAX_LOCAL]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = data_ptr[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + if (gid >= gid_max) return; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * digest + */ - l_crc32tab[b] = remainder; - } + const u32 search[4] = + { + digests_buf[digests_offset].digest_buf[DGST_R0], + digests_buf[digests_offset].digest_buf[DGST_R1], + digests_buf[digests_offset].digest_buf[DGST_R2], + digests_buf[digests_offset].digest_buf[DGST_R3] + }; - barrier (CLK_LOCAL_MEM_FENCE); + /** + * prefetch from global memory + */ - if (gid >= gid_max) return; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 checksum_from_crc = esalt_bufs[digests_offset].hash.checksum_from_crc; + const u32 checksum_from_timestamp = esalt_bufs[digests_offset].hash.checksum_from_timestamp; + const u32 crc32_final = esalt_bufs[digests_offset].hash.crc32; + const u32 data_length = esalt_bufs[digests_offset].hash.data_length; /** * loop */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; - - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - for (u8 i = 0; i < pws[gid].pw_len; i++) + for (u32 i = 0, j = 0; i < pws[gid].pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (pws[gid].pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (pws[gid].i[j]), l_crc32tab); } for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - key0 = key0init; - key1 = key1init; - key2 = key2init; + u32x key0 = key0init; + u32x key1 = key1init; + u32x key2 = key2init; - for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + for (u32 i = 0, j = 0; i < combs_buf[il_pos].pw_len; i += 4, j += 1) { - key0 = CRC32( key0, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (combs_buf[il_pos].pw_len >= (i + 1)) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 2)) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 3)) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 4)) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); } - u8 plain; - u8 key3; - u16 temp; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) - { - continue; - } + u32 plain; + u32 key3; + u32 next; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = l_data[0]; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp^1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = l_data[1]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = l_data[2]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((checksum_from_crc & 0xff) != plain) && ((checksum_from_timestamp & 0xff) != plain)) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (checksum_from_crc >> 8)) && (plain != (checksum_from_timestamp >> 8))) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); u32x crc = 0xffffffff; - crc = CRC32(crc, plain); - for (unsigned int i = 13; i < esalt_bufs[digests_offset].hash.data_length; i++) + for (u32 i = 12, j = 3; i < data_length && j < MAX_LOCAL; i += 4, j += 1) { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + next = l_data[j]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (data_length >= (i + 1)) + { + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - crc = CRC32(crc, plain); - } - crc = ~crc; + crc = CRC32 (crc, plain, l_crc32tab); + } - if (crc == esalt_bufs[digests_offset].hash.crc32) - { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + if (data_length >= (i + 2)) { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + if (data_length >= (i + 3)) + { + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + if (data_length >= (i + 4)) + { + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); } } + + // global memory from here + + for (u32 i = MAX_LOCAL * 4; i < data_length; i++) + { + update_key3 (key2, key3); + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + const u32 r0 = ~crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); } } @@ -341,43 +434,30 @@ __kernel void m17210_mxx (KERN_ATTR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_data[MAX_LOCAL]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = data_ptr[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -385,167 +465,173 @@ __kernel void m17210_mxx (KERN_ATTR_ESALT (pkzip_t)) if (gid >= gid_max) return; /** - * loop + * prefetch from global memory */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 checksum_from_crc = esalt_bufs[digests_offset].hash.checksum_from_crc; + const u32 checksum_from_timestamp = esalt_bufs[digests_offset].hash.checksum_from_timestamp; + const u32 crc32_final = esalt_bufs[digests_offset].hash.crc32; + const u32 data_length = esalt_bufs[digests_offset].hash.data_length; - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + /** + * loop + */ + + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - for (u8 i = 0; i < pws[gid].pw_len; i++) + for (u32 i = 0, j = 0; i < pws[gid].pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (pws[gid].pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (pws[gid].i[j]), l_crc32tab); } for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - key0 = key0init; - key1 = key1init; - key2 = key2init; + u32x key0 = key0init; + u32x key1 = key1init; + u32x key2 = key2init; - for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + for (u32 i = 0, j = 0; i < combs_buf[il_pos].pw_len; i += 4, j += 1) { - key0 = CRC32( key0, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (combs_buf[il_pos].pw_len >= (i + 1)) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 2)) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 3)) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 4)) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); } - u8 plain; - u8 key3; - u16 temp; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) - { - continue; - } + u32 plain; + u32 key3; + u32 next; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = l_data[0]; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp^1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + next = l_data[1]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = l_data[2]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((checksum_from_crc & 0xff) != plain) && ((checksum_from_timestamp & 0xff) != plain)) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (checksum_from_crc >> 8)) && (plain != (checksum_from_timestamp >> 8))) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); u32x crc = 0xffffffff; - crc = CRC32(crc, plain); - for (unsigned int i = 13; i < esalt_bufs[digests_offset].hash.data_length; i++) + for (u32 i = 12, j = 3; i < data_length && j < MAX_LOCAL; i += 4, j += 1) { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + next = l_data[j]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (data_length >= (i + 1)) + { + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - crc = CRC32(crc, plain); - } - crc = ~crc; + crc = CRC32 (crc, plain, l_crc32tab); + } - if (crc == esalt_bufs[digests_offset].hash.crc32) - { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + if (data_length >= (i + 2)) { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + if (data_length >= (i + 3)) + { + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + if (data_length >= (i + 4)) + { + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); } } + + // global memory from here + + for (u32 i = MAX_LOCAL * 4; i < data_length; i++) + { + update_key3 (key2, key3); + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + const u32 r0 = ~crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_M_SIMD (r0, r1, r2, r3); } } + +#undef MAX_LOCAL +#undef TMPSIZ +#undef CRC32 +#undef MSB +#undef CONST +#undef MAX_DATA +#undef update_key012 +#undef update_key3 diff --git a/OpenCL/m17210_a3-pure.cl b/OpenCL/m17210_a3-pure.cl index ebbc5142f..c15fb57db 100644 --- a/OpenCL/m17210_a3-pure.cl +++ b/OpenCL/m17210_a3-pure.cl @@ -80,7 +80,8 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ @@ -89,14 +90,33 @@ Author: Sein Coray #include "inc_common.cl" #include "inc_simd.cl" -#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) -#define MSB(x) ((x)>>24) -#define CONST 0x08088405 -#define POLYNOMIAL 0xEDB88320 +#define MAX_LOCAL 512 // too much leaves no room for compiler optimizations, simply benchmark to find a good trade-off - make it as big as possible +#define TMPSIZ 32 -#define MAX_UNCOMPRESSED_LENGTH 4096 +#define CRC32(x,c,t) (((x) >> 8) ^ (t)[((x) ^ (c)) & 0xff]) +#define MSB(x) ((x) >> 24) +#define CONST 0x08088405 -typedef struct pkzip_hash +#define MAX_DATA (16 * 1024 * 1024) + +#define update_key012(k0,k1,k2,c,t) \ +{ \ + (k0) = CRC32 ((k0), c, (t)); \ + (k1) = ((k1) + ((k0) & 0xff)) * CONST + 1; \ + (k2) = CRC32 ((k2), MSB (k1), (t)); \ +} + +#define update_key3(k2,k3) \ +{ \ + const u32 temp = ((k2) & 0xffff) | 3; \ + \ + (k3) = ((temp * (temp ^ 1)) >> 8) & 0xff; \ +} + +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) + +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -109,16 +129,93 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_UNCOMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; + +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; -typedef struct pkzip +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hash; -} pkzip_t; + +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +CONSTANT_AS u32a crc32tab[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; __kernel void m17210_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) { @@ -126,48 +223,57 @@ __kernel void m17210_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; + /** + * sbox, kbox + */ - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; + LOCAL_AS u32 l_crc32tab[256]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_data[MAX_LOCAL]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = data_ptr[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + if (gid >= gid_max) return; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * digest + */ - l_crc32tab[b] = remainder; - } + const u32 search[4] = + { + digests_buf[digests_offset].digest_buf[DGST_R0], + digests_buf[digests_offset].digest_buf[DGST_R1], + digests_buf[digests_offset].digest_buf[DGST_R2], + digests_buf[digests_offset].digest_buf[DGST_R3] + }; - barrier (CLK_LOCAL_MEM_FENCE); + /** + * prefetch from global memory + */ - if (gid >= gid_max) return; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 checksum_from_crc = esalt_bufs[digests_offset].hash.checksum_from_crc; + const u32 checksum_from_timestamp = esalt_bufs[digests_offset].hash.checksum_from_timestamp; + const u32 crc32_final = esalt_bufs[digests_offset].hash.crc32; + const u32 data_length = esalt_bufs[digests_offset].hash.data_length; /** * base @@ -186,158 +292,151 @@ __kernel void m17210_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * loop */ - u32x key0, key1, key2; u32 w0l = w[0]; for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) { const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; - w[0] = w0; - key0 = 0x12345678; - key1 = 0x23456789; - key2 = 0x34567890; + u32x key0 = 0x12345678; + u32x key1 = 0x23456789; + u32x key2 = 0x34567890; - for (u8 i = 0; i < pw_len; i++) - { - key0 = CRC32( key0, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - } + if (pw_len >= 1) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (w0), l_crc32tab); + if (pw_len >= 2) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (w0), l_crc32tab); + if (pw_len >= 3) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (w0), l_crc32tab); + if (pw_len >= 4) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (w0), l_crc32tab); - u8 plain; - u8 key3; - u16 temp; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + for (u32 i = 4, j = 1; i < pw_len; i += 4, j += 1) { - continue; + if (pw_len >= (i + 1)) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 2)) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 3)) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 4)) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (w[j]), l_crc32tab); } - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32 plain; + u32 key3; + u32 next; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp^1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + next = l_data[0]; - if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = l_data[1]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = l_data[2]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((checksum_from_crc & 0xff) != plain) && ((checksum_from_timestamp & 0xff) != plain)) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (checksum_from_crc >> 8)) && (plain != (checksum_from_timestamp >> 8))) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); u32x crc = 0xffffffff; - crc = CRC32(crc, plain); - for (unsigned int i = 13; i < esalt_bufs[digests_offset].hash.data_length; i++) + for (u32 i = 12, j = 3; i < data_length && j < MAX_LOCAL; i += 4, j += 1) { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + next = l_data[j]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (data_length >= (i + 1)) + { + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - crc = CRC32(crc, plain); - } - crc = ~crc; + crc = CRC32 (crc, plain, l_crc32tab); + } - if (crc == esalt_bufs[digests_offset].hash.crc32) - { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + if (data_length >= (i + 2)) { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + if (data_length >= (i + 3)) + { + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + if (data_length >= (i + 4)) + { + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); } } + + // global memory from here + + for (u32 i = MAX_LOCAL * 4; i < data_length; i++) + { + update_key3 (key2, key3); + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + const u32 r0 = ~crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); } } @@ -347,49 +446,46 @@ __kernel void m17210_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; + } - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + barrier (CLK_LOCAL_MEM_FENCE); - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_data[MAX_LOCAL]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = data_ptr[i]; } barrier (CLK_LOCAL_MEM_FENCE); if (gid >= gid_max) return; + /** + * prefetch from global memory + */ + + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 checksum_from_crc = esalt_bufs[digests_offset].hash.checksum_from_crc; + const u32 checksum_from_timestamp = esalt_bufs[digests_offset].hash.checksum_from_timestamp; + const u32 crc32_final = esalt_bufs[digests_offset].hash.crc32; + const u32 data_length = esalt_bufs[digests_offset].hash.data_length; + /** * base */ @@ -407,157 +503,159 @@ __kernel void m17210_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * loop */ - u32x key0, key1, key2; u32 w0l = w[0]; for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) { const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; - w[0] = w0; - key0 = 0x12345678; - key1 = 0x23456789; - key2 = 0x34567890; + u32x key0 = 0x12345678; + u32x key1 = 0x23456789; + u32x key2 = 0x34567890; - for (u8 i = 0; i < pw_len; i++) - { - key0 = CRC32( key0, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - } + if (pw_len >= 1) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (w0), l_crc32tab); + if (pw_len >= 2) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (w0), l_crc32tab); + if (pw_len >= 3) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (w0), l_crc32tab); + if (pw_len >= 4) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (w0), l_crc32tab); - u8 plain; - u8 key3; - u16 temp; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hash.checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp & 0xff)) + for (u32 i = 4, j = 1; i < pw_len; i += 4, j += 1) { - continue; + if (pw_len >= (i + 1)) update_key012 (key0, key1, key2, unpack_v8a_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 2)) update_key012 (key0, key1, key2, unpack_v8b_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 3)) update_key012 (key0, key1, key2, unpack_v8c_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 4)) update_key012 (key0, key1, key2, unpack_v8d_from_v32_S (w[j]), l_crc32tab); } - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32 plain; + u32 key3; + u32 next; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp^1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[11] ^ key3; + next = l_data[0]; - if (plain != (esalt_bufs[digests_offset].hash.checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hash.checksum_from_timestamp >> 8)) - { - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[12] ^ key3; + next = l_data[1]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = l_data[2]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((checksum_from_crc & 0xff) != plain) && ((checksum_from_timestamp & 0xff) != plain)) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (checksum_from_crc >> 8)) && (plain != (checksum_from_timestamp >> 8))) continue; + update_key012 (key0, key1, key2, plain, l_crc32tab); u32x crc = 0xffffffff; - crc = CRC32(crc, plain); - for (unsigned int i = 13; i < esalt_bufs[digests_offset].hash.data_length; i++) + for (u32 i = 12, j = 3; i < data_length && j < MAX_LOCAL; i += 4, j += 1) { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + next = l_data[j]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (data_length >= (i + 1)) + { + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - crc = CRC32(crc, plain); - } - crc = ~crc; + crc = CRC32 (crc, plain, l_crc32tab); + } - if (crc == esalt_bufs[digests_offset].hash.crc32) - { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + if (data_length >= (i + 2)) { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + if (data_length >= (i + 3)) + { + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + if (data_length >= (i + 4)) + { + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); } } + + // global memory from here + + for (u32 i = MAX_LOCAL * 4; i < data_length; i++) + { + update_key3 (key2, key3); + plain = esalt_bufs[digests_offset].hash.data[i] ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + crc = CRC32 (crc, plain, l_crc32tab); + } + + const u32 r0 = ~crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_M_SIMD (r0, r1, r2, r3); } } + +#undef MAX_LOCAL +#undef TMPSIZ +#undef CRC32 +#undef MSB +#undef CONST +#undef MAX_DATA +#undef update_key012 +#undef update_key3 diff --git a/OpenCL/m17220_a0-pure.cl b/OpenCL/m17220_a0-pure.cl index 0b02e2b17..13bfbe70e 100644 --- a/OpenCL/m17220_a0-pure.cl +++ b/OpenCL/m17220_a0-pure.cl @@ -80,29 +80,45 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ -#include "inc_zip_inflate.cl" +#include "inc_vendor.h" +#include "inc_types.h" +#include "inc_common.cl" +#include "inc_simd.cl" #include "inc_rp.h" #include "inc_rp.cl" -#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) -#define MSB(x) ((x)>>24) -#define CONST 0x08088405 -#define POLYNOMIAL 0xEDB88320 +#define MAX_LOCAL 512 // too much leaves no room for compiler optimizations, simply benchmark to find a good trade-off - make it as big as possible +#define TMPSIZ 32 -#define MAX_COMPRESSED_LENGTH 2048 -#define MAX_UNCOMPRESSED_LENGTH 4096 +#define CRC32(x,c,t) (((x) >> 8) ^ (t)[((x) ^ (c)) & 0xff]) +#define MSB(x) ((x) >> 24) +#define CONST 0x08088405 -typedef struct { - u8 op; /* operation, extra bits, table bits */ - u8 bits; /* bits in this part of the code */ - u16 val; /* offset in table or code value */ -} code; +#define MAX_DATA (16 * 1024 * 1024) + +#define update_key012(k0,k1,k2,c,t) \ +{ \ + (k0) = CRC32 ((k0), c, (t)); \ + (k1) = ((k1) + ((k0) & 0xff)) * CONST + 1; \ + (k2) = CRC32 ((k2), MSB (k1), (t)); \ +} + +#define update_key3(k2,k3) \ +{ \ + const u32 temp = ((k2) & 0xffff) | 3; \ + \ + (k3) = ((temp * (temp ^ 1)) >> 8) & 0xff; \ +} -typedef struct pkzip_hash +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) + +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -115,18 +131,105 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_COMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; + +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; -typedef struct pkzip +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hashes[8]; -} pkzip_t; -__constant code lenfix[512] = { +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +CONSTANT_AS u32a crc32tab[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +#define CRC32_IN_INFLATE + +#include "inc_zip_inflate.cl" + +typedef struct { + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ +} code; + +CONSTANT_AS code lenfix[512] = { {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, @@ -203,7 +306,7 @@ __constant code lenfix[512] = { {0,9,255} }; -__constant code distfix[32] = { +CONSTANT_AS code distfix[32] = { {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, @@ -212,7 +315,7 @@ __constant code distfix[32] = { {22,5,193},{64,5,0} }; -DECLSPEC int check_inflate_code2(u8 *next) +DECLSPEC int check_inflate_code2 (u8 *next) { u32 bits, hold, thisget, have, i; int left; @@ -299,7 +402,8 @@ DECLSPEC int check_inflate_code2(u8 *next) } -DECLSPEC int check_inflate_code1(u8 *next, int left){ +DECLSPEC int check_inflate_code1 (u8 *next, int left) +{ u32 whave = 0, op, bits, hold,len; code here1; @@ -428,43 +532,19 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -478,11 +558,15 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) COPY_PW (pws[gid]); /** - * loop + * prefetch from global memory */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 hash_count = esalt_bufs[digests_offset].hash_count; + + /** + * loop + */ for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { @@ -490,222 +574,207 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - for (u8 i = 0; i < tmp.pw_len; i++) + for (u32 i = 0, j = 0; i < tmp.pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (tmp.pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (tmp.i[j]), l_crc32tab); } - u8 compressed[MAX_COMPRESSED_LENGTH]; - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; + u32 plain; + u32 key3; + u32 next; - for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + for (u32 idx = 0; idx < hash_count; idx++) { - key0 = key0init; - key1 = key1init; - key2 = key2init; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) - { - idx = 0xfe; - continue; - } + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32x key0 = key0init; + u32x key1 = key1init; + u32x key2 = key2init; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + next = data_ptr[0]; - if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[0] = plain; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = data_ptr[1]; - for (unsigned int i = 13; i < 36; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i - 12] = plain; - } + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) - { - abort=1; - } - if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) - { - abort=1; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[2]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) != plain) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff) != plain)) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (abort) + const u32 key0_sav = key0; + const u32 key1_sav = key1; + const u32 key2_sav = key2; + + u8 tmp[TMPSIZ]; + + next = data_ptr[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) break; + tmp[0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + for (int i = 16; i < 36; i += 4) { - idx = 0xfe; - continue; + next = data_ptr[i / 4]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + tmp[i - 12 + 0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[i - 12 + 1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[i - 12 + 2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[i - 12 + 3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); } + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; + if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) { continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one } - for (unsigned int i = 36; i < esalt_bufs[digests_offset].hashes[idx].data_length; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; - - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - compressed[i - 12] = plain; - } - - unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; + inflate_state pStream; + infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output - infstream.next_out = (Bytef *)inflated; // output char array + infstream.next_in = esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.avail_out = TMPSIZ; // size of output + infstream.next_out = tmp; // output char array + + #ifdef CRC32_IN_INFLATE + infstream.key0 = key0_sav; + infstream.key1 = key1_sav; + infstream.key2 = key2_sav; + infstream.crc32 = 0xffffffff; + infstream.crc32tab = l_crc32tab; + #endif // inflateinit2 is needed because otherwise it checks for headers by default - mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); - int ret = mz_inflate(&infstream, Z_NO_FLUSH); - if (ret < 0) - { - idx = 0xfe; - continue; // failed to inflate - } + mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); - // check CRC - u32x crc = 0xffffffff; - for (unsigned int k = 0; k < infstream.total_out; ++k) + int ret = mz_inflate (&infstream, Z_SYNC_FLUSH); + + while (ret == MZ_OK) { - crc = CRC32(crc, inflated[k]); + ret = mz_inflate (&infstream, Z_SYNC_FLUSH); } - crc = ~crc; - if (crc == esalt_bufs[digests_offset].hashes[idx].crc32) + if (ret != MZ_STREAM_END) break; // failed to inflate + + // we check the crc32, but it might not necessarily be the last one (depending how strict + if ((~infstream.crc32) == esalt_bufs[digests_offset].hashes[idx].crc32) { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + if (idx + 1 == hash_count) { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + /** + * digest for last hash + */ + + const u32 search[4] = + { + digests_buf[digests_offset].digest_buf[0], + 0, + 0, + 0 + }; + + const u32 r0 = esalt_bufs[digests_offset].hashes[0].checksum_from_crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); } } - idx = 0xfe; + else + { + break; + } } } } @@ -716,43 +785,19 @@ __kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -766,11 +811,15 @@ __kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) COPY_PW (pws[gid]); /** - * loop + * prefetch from global memory */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 hash_count = esalt_bufs[digests_offset].hash_count; + + /** + * loop + */ for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { @@ -778,224 +827,204 @@ __kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - for (u8 i = 0; i < tmp.pw_len; i++) + for (u32 i = 0, j = 0; i < tmp.pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (tmp.pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (tmp.i[j]), l_crc32tab); } - u8 compressed[MAX_COMPRESSED_LENGTH]; - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; + u32 plain; + u32 key3; + u32 next; - for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + for (u32 idx = 0; idx < hash_count; idx++) { - key0 = key0init; - key1 = key1init; - key2 = key2init; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) - { - idx = 0xfe; - continue; - } + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32x key0 = key0init; + u32x key1 = key1init; + u32x key2 = key2init; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + next = data_ptr[0]; - if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[0] = plain; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = data_ptr[1]; - for (unsigned int i = 13; i < 36; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i-12] = plain; - } + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) - { - abort=1; - } - if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) - { - abort=1; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[2]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) != plain) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff) != plain)) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + const u32 key0_sav = key0; + const u32 key1_sav = key1; + const u32 key2_sav = key2; + + u8 tmp[TMPSIZ]; + + next = data_ptr[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) break; + tmp[0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (abort) + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + for (int i = 16; i < 36; i += 4) { - idx = 0xfe; - continue; + next = data_ptr[i / 4]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + tmp[i - 12 + 0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[i - 12 + 1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[i - 12 + 2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[i - 12 + 3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); } + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; + if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) { continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one } - for (unsigned int i = 36; i < esalt_bufs[digests_offset].hashes[idx].data_length; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; - - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - compressed[i - 12] = plain; - } - - unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; + inflate_state pStream; - infstream.zalloc = Z_NULL; - infstream.zfree = Z_NULL; + infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output - infstream.next_out = (Bytef *)inflated; // output char array + infstream.next_in = esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.avail_out = TMPSIZ; // size of output + infstream.next_out = tmp; // output char array + + #ifdef CRC32_IN_INFLATE + infstream.key0 = key0_sav; + infstream.key1 = key1_sav; + infstream.key2 = key2_sav; + infstream.crc32 = 0xffffffff; + infstream.crc32tab = l_crc32tab; + #endif // inflateinit2 is needed because otherwise it checks for headers by default - mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); - int ret = mz_inflate(&infstream, Z_NO_FLUSH); - if (ret < 0) - { - idx = 0xfe; - continue; // failed to inflate - } + mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); + + int ret = mz_inflate (&infstream, Z_SYNC_FLUSH); - // check CRC - u32x crc = 0xffffffff; - for (unsigned int k = 0; k < infstream.total_out; ++k) + while (ret == MZ_OK) { - crc = CRC32(crc, inflated[k]); + ret = mz_inflate (&infstream, Z_SYNC_FLUSH); } - crc = ~crc; - if (crc == esalt_bufs[digests_offset].hashes[idx].crc32) + if (ret != MZ_STREAM_END) break; // failed to inflate + + // we check the crc32, but it might not necessarily be the last one (depending how strict + if ((~infstream.crc32) == esalt_bufs[digests_offset].hashes[idx].crc32) { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + if (idx + 1 == hash_count) { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + const u32 r0 = esalt_bufs[digests_offset].hashes[0].checksum_from_crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_M_SIMD (r0, r1, r2, r3); } } - idx = 0xfe; + else + { + break; + } } } } + +#undef MAX_LOCAL +#undef TMPSIZ +#undef CRC32 +#undef MSB +#undef CONST +#undef MAX_DATA +#undef update_key012 +#undef update_key3 diff --git a/OpenCL/m17220_a1-pure.cl b/OpenCL/m17220_a1-pure.cl index d3717aa74..68c3c2f7c 100644 --- a/OpenCL/m17220_a1-pure.cl +++ b/OpenCL/m17220_a1-pure.cl @@ -80,27 +80,43 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ -#include "inc_zip_inflate.cl" +#include "inc_vendor.h" +#include "inc_types.h" +#include "inc_common.cl" +#include "inc_simd.cl" -#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) -#define MSB(x) ((x)>>24) -#define CONST 0x08088405 -#define POLYNOMIAL 0xEDB88320 +#define MAX_LOCAL 512 // too much leaves no room for compiler optimizations, simply benchmark to find a good trade-off - make it as big as possible +#define TMPSIZ 32 -#define MAX_COMPRESSED_LENGTH 2048 -#define MAX_UNCOMPRESSED_LENGTH 4096 +#define CRC32(x,c,t) (((x) >> 8) ^ (t)[((x) ^ (c)) & 0xff]) +#define MSB(x) ((x) >> 24) +#define CONST 0x08088405 -typedef struct { - u8 op; /* operation, extra bits, table bits */ - u8 bits; /* bits in this part of the code */ - u16 val; /* offset in table or code value */ -} code; +#define MAX_DATA (16 * 1024 * 1024) + +#define update_key012(k0,k1,k2,c,t) \ +{ \ + (k0) = CRC32 ((k0), c, (t)); \ + (k1) = ((k1) + ((k0) & 0xff)) * CONST + 1; \ + (k2) = CRC32 ((k2), MSB (k1), (t)); \ +} + +#define update_key3(k2,k3) \ +{ \ + const u32 temp = ((k2) & 0xffff) | 3; \ + \ + (k3) = ((temp * (temp ^ 1)) >> 8) & 0xff; \ +} -typedef struct pkzip_hash +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) + +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -113,18 +129,105 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_COMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; + +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; -typedef struct pkzip +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hashes[8]; -} pkzip_t; -__constant code lenfix[512] = { +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +CONSTANT_AS u32a crc32tab[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +#define CRC32_IN_INFLATE + +#include "inc_zip_inflate.cl" + +typedef struct { + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ +} code; + +CONSTANT_AS code lenfix[512] = { {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, @@ -201,7 +304,7 @@ __constant code lenfix[512] = { {0,9,255} }; -__constant code distfix[32] = { +CONSTANT_AS code distfix[32] = { {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, @@ -210,7 +313,7 @@ __constant code distfix[32] = { {22,5,193},{64,5,0} }; -DECLSPEC int check_inflate_code2(u8 *next) +DECLSPEC int check_inflate_code2 (u8 *next) { u32 bits, hold, thisget, have, i; int left; @@ -297,7 +400,8 @@ DECLSPEC int check_inflate_code2(u8 *next) } -DECLSPEC int check_inflate_code1(u8 *next, int left){ +DECLSPEC int check_inflate_code1 (u8 *next, int left) +{ u32 whave = 0, op, bits, hold,len; code here1; @@ -426,43 +530,19 @@ __kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -470,242 +550,231 @@ __kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) if (gid >= gid_max) return; /** - * loop + * prefetch from global memory */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; - u32x key0init2, key1init2, key2init2; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 hash_count = esalt_bufs[digests_offset].hash_count; - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + /** + * loop + */ - for (u8 i = 0; i < pws[gid].pw_len; i++) + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; + + for (u32 i = 0, j = 0; i < pws[gid].pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (pws[gid].pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (pws[gid].i[j]), l_crc32tab); } for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - key0init2 = key0init; - key1init2 = key1init; - key2init2 = key2init; + u32x key0init2 = key0init; + u32x key1init2 = key1init; + u32x key2init2 = key2init; - for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + for (u32 i = 0, j = 0; i < combs_buf[il_pos].pw_len; i += 4, j += 1) { - key0init2 = CRC32( key0init2, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init2 = (key1init2 + (key0init2 & 0xff)) * CONST + 1; - key2init2 = CRC32( key2init2, MSB(key1init2) ); + if (combs_buf[il_pos].pw_len >= (i + 1)) update_key012 (key0init2, key1init2, key2init2, unpack_v8a_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 2)) update_key012 (key0init2, key1init2, key2init2, unpack_v8b_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 3)) update_key012 (key0init2, key1init2, key2init2, unpack_v8c_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 4)) update_key012 (key0init2, key1init2, key2init2, unpack_v8d_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); } - u8 compressed[MAX_COMPRESSED_LENGTH]; - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; + u32 plain; + u32 key3; + u32 next; - for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + for (u32 idx = 0; idx < hash_count; idx++) { - key0 = key0init2; - key1 = key1init2; - key2 = key2init2; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) - { - idx = 0xfe; - continue; - } + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32x key0 = key0init2; + u32x key1 = key1init2; + u32x key2 = key2init2; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + next = data_ptr[0]; - if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[0] = plain; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = data_ptr[1]; - for (unsigned int i = 13; i < 36; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i - 12] = plain; - } + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) - { - abort = 1; - } - if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) - { - abort = 1; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[2]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) != plain) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff) != plain)) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (abort) + const u32 key0_sav = key0; + const u32 key1_sav = key1; + const u32 key2_sav = key2; + + u8 tmp[TMPSIZ]; + + next = data_ptr[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) break; + tmp[0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + for (int i = 16; i < 36; i += 4) { - idx = 0xfe; - continue; + next = data_ptr[i / 4]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + tmp[i - 12 + 0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[i - 12 + 1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[i - 12 + 2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[i - 12 + 3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); } + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; + if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) { continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one } - for (unsigned int i = 36; i < esalt_bufs[digests_offset].hashes[idx].data_length; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; - - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - compressed[i - 12] = plain; - } - - unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; + inflate_state pStream; + infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output - infstream.next_out = (Bytef *)inflated; // output char array + infstream.next_in = esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.avail_out = TMPSIZ; // size of output + infstream.next_out = tmp; // output char array + + #ifdef CRC32_IN_INFLATE + infstream.key0 = key0_sav; + infstream.key1 = key1_sav; + infstream.key2 = key2_sav; + infstream.crc32 = 0xffffffff; + infstream.crc32tab = l_crc32tab; + #endif // inflateinit2 is needed because otherwise it checks for headers by default - mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); - int ret = mz_inflate(&infstream, Z_NO_FLUSH); - if (ret < 0) - { - idx = 0xfe; - continue; // failed to inflate - } + mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); - // check CRC - u32x crc = 0xffffffff; - for (unsigned int k = 0; k < infstream.total_out; ++k) + int ret = mz_inflate (&infstream, Z_SYNC_FLUSH); + + while (ret == MZ_OK) { - crc = CRC32(crc, inflated[k]); + ret = mz_inflate (&infstream, Z_SYNC_FLUSH); } - crc = ~crc; - if (crc == esalt_bufs[digests_offset].hashes[idx].crc32) + if (ret != MZ_STREAM_END) break; // failed to inflate + + // we check the crc32, but it might not necessarily be the last one (depending how strict + if ((~infstream.crc32) == esalt_bufs[digests_offset].hashes[idx].crc32) { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + if (idx + 1 == hash_count) { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + /** + * digest for last hash + */ + + const u32 search[4] = + { + digests_buf[digests_offset].digest_buf[0], + 0, + 0, + 0 + }; + + const u32 r0 = esalt_bufs[digests_offset].hashes[0].checksum_from_crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); } } - idx = 0xfe; + else + { + break; + } } } } @@ -716,43 +785,19 @@ __kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -760,242 +805,228 @@ __kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) if (gid >= gid_max) return; /** - * loop + * prefetch from global memory */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; - u32x key0init2, key1init2, key2init2; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 hash_count = esalt_bufs[digests_offset].hash_count; + + /** + * loop + */ - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - for (u8 i = 0; i < pws[gid].pw_len; i++) + for (u32 i = 0, j = 0; i < pws[gid].pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (pws[gid].pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (pws[gid].i[j]), l_crc32tab); } for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - key0init2 = key0init; - key1init2 = key1init; - key2init2 = key2init; + u32x key0init2 = key0init; + u32x key1init2 = key1init; + u32x key2init2 = key2init; - for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + for (u32 i = 0, j = 0; i < combs_buf[il_pos].pw_len; i += 4, j += 1) { - key0init2 = CRC32( key0init2, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init2 = (key1init2 + (key0init2 & 0xff)) * CONST + 1; - key2init2 = CRC32( key2init2, MSB(key1init2) ); + if (combs_buf[il_pos].pw_len >= (i + 1)) update_key012 (key0init2, key1init2, key2init2, unpack_v8a_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 2)) update_key012 (key0init2, key1init2, key2init2, unpack_v8b_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 3)) update_key012 (key0init2, key1init2, key2init2, unpack_v8c_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 4)) update_key012 (key0init2, key1init2, key2init2, unpack_v8d_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); } - u8 compressed[MAX_COMPRESSED_LENGTH]; - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; + u32 plain; + u32 key3; + u32 next; - for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + for (u32 idx = 0; idx < hash_count; idx++) { - key0 = key0init2; - key1 = key1init2; - key2 = key2init2; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) - { - idx = 0xfe; - continue; - } + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32x key0 = key0init2; + u32x key1 = key1init2; + u32x key2 = key2init2; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + next = data_ptr[0]; - if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[0] = plain; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = data_ptr[1]; - for (unsigned int i = 13; i < 36; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i - 12] = plain; - } + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) - { - abort = 1; - } - if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) - { - abort = 1; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[2]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) != plain) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff) != plain)) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + const u32 key0_sav = key0; + const u32 key1_sav = key1; + const u32 key2_sav = key2; + + u8 tmp[TMPSIZ]; + + next = data_ptr[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) break; + tmp[0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (abort) + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + for (int i = 16; i < 36; i += 4) { - idx = 0xfe; - continue; + next = data_ptr[i / 4]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + tmp[i - 12 + 0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[i - 12 + 1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[i - 12 + 2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[i - 12 + 3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); } + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; + if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) { continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one } - for (unsigned int i = 36; i < esalt_bufs[digests_offset].hashes[idx].data_length; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; - - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - compressed[i - 12] = plain; - } - - unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; + inflate_state pStream; + infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output - infstream.next_out = (Bytef *)inflated; // output char array + infstream.next_in = esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.avail_out = TMPSIZ; // size of output + infstream.next_out = tmp; // output char array + + #ifdef CRC32_IN_INFLATE + infstream.key0 = key0_sav; + infstream.key1 = key1_sav; + infstream.key2 = key2_sav; + infstream.crc32 = 0xffffffff; + infstream.crc32tab = l_crc32tab; + #endif // inflateinit2 is needed because otherwise it checks for headers by default - mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); - int ret = mz_inflate(&infstream, Z_NO_FLUSH); - if (ret < 0) - { - idx = 0xfe; - continue; // failed to inflate - } + mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); + + int ret = mz_inflate (&infstream, Z_SYNC_FLUSH); - // check CRC - u32x crc = 0xffffffff; - for (unsigned int k = 0; k < infstream.total_out; ++k) + while (ret == MZ_OK) { - crc = CRC32(crc, inflated[k]); + ret = mz_inflate (&infstream, Z_SYNC_FLUSH); } - crc = ~crc; - if (crc == esalt_bufs[digests_offset].hashes[idx].crc32) + if (ret != MZ_STREAM_END) break; // failed to inflate + + // we check the crc32, but it might not necessarily be the last one (depending how strict + if ((~infstream.crc32) == esalt_bufs[digests_offset].hashes[idx].crc32) { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + if (idx + 1 == hash_count) { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + const u32 r0 = esalt_bufs[digests_offset].hashes[0].checksum_from_crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_M_SIMD (r0, r1, r2, r3); } } - idx = 0xfe; + else + { + break; + } } } } + +#undef MAX_LOCAL +#undef TMPSIZ +#undef CRC32 +#undef MSB +#undef CONST +#undef MAX_DATA +#undef update_key012 +#undef update_key3 diff --git a/OpenCL/m17220_a3-pure.cl b/OpenCL/m17220_a3-pure.cl index a919df7e4..682d5562b 100644 --- a/OpenCL/m17220_a3-pure.cl +++ b/OpenCL/m17220_a3-pure.cl @@ -80,27 +80,43 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ -#include "inc_zip_inflate.cl" +#include "inc_vendor.h" +#include "inc_types.h" +#include "inc_common.cl" +#include "inc_simd.cl" -#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) -#define MSB(x) ((x)>>24) -#define CONST 0x08088405 -#define POLYNOMIAL 0xEDB88320 +#define MAX_LOCAL 512 // too much leaves no room for compiler optimizations, simply benchmark to find a good trade-off - make it as big as possible +#define TMPSIZ 32 -#define MAX_COMPRESSED_LENGTH 2048 -#define MAX_UNCOMPRESSED_LENGTH 4096 +#define CRC32(x,c,t) (((x) >> 8) ^ (t)[((x) ^ (c)) & 0xff]) +#define MSB(x) ((x) >> 24) +#define CONST 0x08088405 -typedef struct { - u8 op; /* operation, extra bits, table bits */ - u8 bits; /* bits in this part of the code */ - u16 val; /* offset in table or code value */ -} code; +#define MAX_DATA (16 * 1024 * 1024) + +#define update_key012(k0,k1,k2,c,t) \ +{ \ + (k0) = CRC32 ((k0), c, (t)); \ + (k1) = ((k1) + ((k0) & 0xff)) * CONST + 1; \ + (k2) = CRC32 ((k2), MSB (k1), (t)); \ +} + +#define update_key3(k2,k3) \ +{ \ + const u32 temp = ((k2) & 0xffff) | 3; \ + \ + (k3) = ((temp * (temp ^ 1)) >> 8) & 0xff; \ +} -typedef struct pkzip_hash +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) + +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -113,18 +129,105 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_COMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; + +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; -typedef struct pkzip +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hashes[8]; -} pkzip_t; -__constant code lenfix[512] = { +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +CONSTANT_AS u32a crc32tab[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; + +#define CRC32_IN_INFLATE + +#include "inc_zip_inflate.cl" + +typedef struct { + u8 op; /* operation, extra bits, table bits */ + u8 bits; /* bits in this part of the code */ + u16 val; /* offset in table or code value */ +} code; + +CONSTANT_AS code lenfix[512] = { {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, @@ -201,7 +304,7 @@ __constant code lenfix[512] = { {0,9,255} }; -__constant code distfix[32] = { +CONSTANT_AS code distfix[32] = { {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, @@ -210,7 +313,7 @@ __constant code distfix[32] = { {22,5,193},{64,5,0} }; -DECLSPEC int check_inflate_code2(u8 *next) +DECLSPEC int check_inflate_code2 (u8 *next) { u32 bits, hold, thisget, have, i; int left; @@ -297,7 +400,8 @@ DECLSPEC int check_inflate_code2(u8 *next) } -DECLSPEC int check_inflate_code1(u8 *next, int left){ +DECLSPEC int check_inflate_code1 (u8 *next, int left) +{ u32 whave = 0, op, bits, hold,len; code here1; @@ -426,43 +530,19 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -482,234 +562,231 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) w[idx] = pws[gid].i[idx]; } + /** + * prefetch from global memory + */ + + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 hash_count = esalt_bufs[digests_offset].hash_count; + /** * loop */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; u32 w0l = w[0]; for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) { const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; - w[0] = w0; - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - for (u8 i = 0; i < pw_len; i++) + if (pw_len >= 1) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (w0), l_crc32tab); + if (pw_len >= 2) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (w0), l_crc32tab); + if (pw_len >= 3) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (w0), l_crc32tab); + if (pw_len >= 4) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (w0), l_crc32tab); + + for (u32 i = 4, j = 1; i < pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (w[j]), l_crc32tab); } - u8 compressed[MAX_COMPRESSED_LENGTH]; - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; + u32 plain; + u32 key3; + u32 next; - for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + for (u32 idx = 0; idx < hash_count; idx++) { - key0 = key0init; - key1 = key1init; - key2 = key2init; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) - { - idx = 0xfe; - continue; - } + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32x key0 = key0init; + u32x key1 = key1init; + u32x key2 = key2init; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + next = data_ptr[0]; - if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[0] = plain; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = data_ptr[1]; - for (unsigned int i = 13; i < 36; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i-12] = plain; - } + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) - { - abort=1; - } - if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) - { - abort=1; - } - if (abort) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1){ - continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one - } + next = data_ptr[2]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) != plain) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff) != plain)) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + const u32 key0_sav = key0; + const u32 key1_sav = key1; + const u32 key2_sav = key2; + + u8 tmp[TMPSIZ]; + + next = data_ptr[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) break; + tmp[0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); - for (unsigned int i = 36; i < esalt_bufs[digests_offset].hashes[idx].data_length; i++) + for (int i = 16; i < 36; i += 4) { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + next = data_ptr[i / 4]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + tmp[i - 12 + 0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[i - 12 + 1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[i - 12 + 2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[i - 12 + 3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + } - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; + if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; - compressed[i - 12] = plain; + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) + { + continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one } - unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; + inflate_state pStream; + infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output - infstream.next_out = (Bytef *)inflated; // output char array + infstream.next_in = esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.avail_out = TMPSIZ; // size of output + infstream.next_out = tmp; // output char array + + #ifdef CRC32_IN_INFLATE + infstream.key0 = key0_sav; + infstream.key1 = key1_sav; + infstream.key2 = key2_sav; + infstream.crc32 = 0xffffffff; + infstream.crc32tab = l_crc32tab; + #endif // inflateinit2 is needed because otherwise it checks for headers by default - mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); - int ret = mz_inflate(&infstream, Z_NO_FLUSH); - if (ret < 0) - { - idx = 0xfe; - continue; // failed to inflate - } + mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); + + int ret = mz_inflate (&infstream, Z_SYNC_FLUSH); - // check CRC - u32x crc = 0xffffffff; - for (unsigned int k = 0; k < infstream.total_out; ++k) + while (ret == MZ_OK) { - crc = CRC32(crc, inflated[k]); + ret = mz_inflate (&infstream, Z_SYNC_FLUSH); } - crc = ~crc; - if (crc == esalt_bufs[digests_offset].hashes[idx].crc32) + if (ret != MZ_STREAM_END) break; // failed to inflate + + // we check the crc32, but it might not necessarily be the last one (depending how strict + if ((~infstream.crc32) == esalt_bufs[digests_offset].hashes[idx].crc32) { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + if (idx + 1 == hash_count) { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + /** + * digest for last hash + */ + + const u32 search[4] = + { + digests_buf[digests_offset].digest_buf[0], + 0, + 0, + 0 + }; + + const u32 r0 = esalt_bufs[digests_offset].hashes[0].checksum_from_crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); } } - idx = 0xfe; + else + { + break; + } } } } @@ -720,43 +797,19 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -776,233 +829,227 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) w[idx] = pws[gid].i[idx]; } + /** + * prefetch from global memory + */ + + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 hash_count = esalt_bufs[digests_offset].hash_count; + /** * loop */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; u32 w0l = w[0]; for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) { const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; - w[0] = w0; - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - for (u8 i = 0; i < pw_len; i++) + if (pw_len >= 1) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (w0), l_crc32tab); + if (pw_len >= 2) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (w0), l_crc32tab); + if (pw_len >= 3) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (w0), l_crc32tab); + if (pw_len >= 4) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (w0), l_crc32tab); + + for (u32 i = 4, j = 1; i < pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (w[j]), l_crc32tab); } - u8 compressed[MAX_COMPRESSED_LENGTH]; - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; + u32 plain; + u32 key3; + u32 next; - for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + for (u32 idx = 0; idx < hash_count; idx++) { - key0 = key0init; - key1 = key1init; - key2 = key2init; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; - - if(esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) - { - idx = 0xfe; - continue; - } - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + u32x key0 = key0init; + u32x key1 = key1init; + u32x key2 = key2init; - if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) - { - idx = 0xfe; - continue; - } + next = data_ptr[0]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[0] = plain; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - for (unsigned int i = 13; i < 36; i++) - { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + next = data_ptr[1]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - compressed[i-12] = plain; - } + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (((compressed[0]) & 6) == 2 && !check_inflate_code1 (compressed, 36)) - { - abort=1; - } - if (((compressed[0]) & 6) == 4 && !check_inflate_code2 (compressed)) - { - abort=1; - } - if (abort) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1){ - continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one - } + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[2]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) != plain) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff) != plain)) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + const u32 key0_sav = key0; + const u32 key1_sav = key1; + const u32 key2_sav = key2; + + u8 tmp[TMPSIZ]; - for (unsigned int i = 36; i < esalt_bufs[digests_offset].hashes[idx].data_length; i++) + next = data_ptr[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) break; + tmp[0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + for (int i = 16; i < 36; i += 4) { - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[i] ^ key3; + next = data_ptr[i / 4]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + tmp[i - 12 + 0] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + tmp[i - 12 + 1] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + tmp[i - 12 + 2] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + tmp[i - 12 + 3] = plain; + update_key012 (key0, key1, key2, plain, l_crc32tab); + } - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; + if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; - compressed[i - 12] = plain; + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1){ + continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one } - unsigned char inflated[MAX_UNCOMPRESSED_LENGTH]; mz_stream infstream; + inflate_state pStream; + infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = (Bytef *)compressed; // input char array - infstream.avail_out = MAX_UNCOMPRESSED_LENGTH; // size of output - infstream.next_out = (Bytef *)inflated; // output char array + infstream.next_in = esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.avail_out = TMPSIZ; // size of output + infstream.next_out = tmp; // output char array + + #ifdef CRC32_IN_INFLATE + infstream.key0 = key0_sav; + infstream.key1 = key1_sav; + infstream.key2 = key2_sav; + infstream.crc32 = 0xffffffff; + infstream.crc32tab = l_crc32tab; + #endif // inflateinit2 is needed because otherwise it checks for headers by default - mz_inflateInit2(&infstream, -MAX_WBITS, &pStream); - int ret = mz_inflate(&infstream, Z_NO_FLUSH); - if (ret < 0) - { - idx = 0xfe; - continue; // failed to inflate - } + mz_inflateInit2 (&infstream, -MAX_WBITS, &pStream); + + int ret = mz_inflate (&infstream, Z_SYNC_FLUSH); - // check CRC - u32x crc = 0xffffffff; - for (unsigned int k = 0; k < infstream.total_out; ++k) + while (ret == MZ_OK) { - crc = CRC32(crc, inflated[k]); + ret = mz_inflate (&infstream, Z_SYNC_FLUSH); } - crc = ~crc; - if (crc == esalt_bufs[digests_offset].hashes[idx].crc32) + if (ret != MZ_STREAM_END) break; // failed to inflate + + // we check the crc32, but it might not necessarily be the last one (depending how strict + if ((~infstream.crc32) == esalt_bufs[digests_offset].hashes[idx].crc32) { - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + if (idx + 1 == hash_count) { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); + const u32 r0 = esalt_bufs[digests_offset].hashes[0].checksum_from_crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_M_SIMD (r0, r1, r2, r3); } } - idx = 0xfe; + else + { + break; + } } } } + +#undef MAX_LOCAL +#undef TMPSIZ +#undef CRC32 +#undef MSB +#undef CONST +#undef MAX_DATA +#undef update_key012 +#undef update_key3 \ No newline at end of file diff --git a/OpenCL/m17230_a0-pure.cl b/OpenCL/m17230_a0-pure.cl index b914e4dc6..0d8428b5c 100644 --- a/OpenCL/m17230_a0-pure.cl +++ b/OpenCL/m17230_a0-pure.cl @@ -80,7 +80,8 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ @@ -91,14 +92,33 @@ Author: Sein Coray #include "inc_rp.h" #include "inc_rp.cl" -#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) -#define MSB(x) ((x)>>24) -#define CONST 0x08088405 -#define POLYNOMIAL 0xEDB88320 +#define MAX_LOCAL 512 // too much leaves no room for compiler optimizations, simply benchmark to find a good trade-off - make it as big as possible +#define TMPSIZ 32 -#define MAX_COMPRESSED_LENGTH 2048 +#define CRC32(x,c,t) (((x) >> 8) ^ (t)[((x) ^ (c)) & 0xff]) +#define MSB(x) ((x) >> 24) +#define CONST 0x08088405 -typedef struct pkzip_hash +#define MAX_DATA (16 * 1024 * 1024) + +#define update_key012(k0,k1,k2,c,t) \ +{ \ + (k0) = CRC32 ((k0), c, (t)); \ + (k1) = ((k1) + ((k0) & 0xff)) * CONST + 1; \ + (k2) = CRC32 ((k2), MSB (k1), (t)); \ +} + +#define update_key3(k2,k3) \ +{ \ + const u32 temp = ((k2) & 0xffff) | 3; \ + \ + (k3) = ((temp * (temp ^ 1)) >> 8) & 0xff; \ +} + +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) + +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -111,16 +131,93 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_COMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; -typedef struct pkzip +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; + +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hashes[8]; -} pkzip_t; + +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +CONSTANT_AS u32a crc32tab[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; __kernel void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) { @@ -128,43 +225,19 @@ __kernel void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -178,11 +251,15 @@ __kernel void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) COPY_PW (pws[gid]); /** - * loop + * prefetch from global memory */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 hash_count = esalt_bufs[digests_offset].hash_count; + + /** + * loop + */ for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { @@ -190,140 +267,112 @@ __kernel void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - for (u8 i = 0; i < tmp.pw_len; i++) + for (u32 i = 0, j = 0; i < tmp.pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (tmp.pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (tmp.i[j]), l_crc32tab); } - u8 plain; - u8 key3; - u16 temp; + u32 plain; + u32 key3; + u32 next; - for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + for (u32 idx = 0; idx < hash_count; idx++) { - key0 = key0init; - key1 = key1init; - key2 = key2init; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) - { - idx = 0xfe; - continue; - } + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32x key0 = key0init; + u32x key1 = key1init; + u32x key2 = key2init; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + next = data_ptr[0]; - if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[1]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = data_ptr[2]; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) != plain) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff) != plain)) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) break; + + if (idx + 1 == esalt_bufs[digests_offset].hash_count) { - idx = 0xfe; - continue; - } + /** + * digest + */ - if (idx + 1 == esalt_bufs[digests_offset].hash_count){ \ - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + const u32 search[4] = { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); - } + esalt_bufs[digests_offset].hashes[0].checksum_from_crc, + 0, + 0, + 0 + }; + + const u32 r0 = esalt_bufs[digests_offset].hashes[0].checksum_from_crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); } } } @@ -335,43 +384,19 @@ __kernel void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -385,11 +410,15 @@ __kernel void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) COPY_PW (pws[gid]); /** - * loop + * prefetch from global memory */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 hash_count = esalt_bufs[digests_offset].hash_count; + + /** + * loop + */ for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { @@ -397,141 +426,110 @@ __kernel void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) tmp.pw_len = apply_rules (rules_buf[il_pos].cmds, tmp.i, tmp.pw_len); - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - for (u8 i = 0; i < tmp.pw_len; i++) + for (u32 i = 0, j = 0; i < tmp.pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (tmp.i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (tmp.pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (tmp.i[j]), l_crc32tab); + if (tmp.pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (tmp.i[j]), l_crc32tab); } - u8 plain; - u8 key3; - u16 temp; + u32 plain; + u32 key3; + u32 next; - for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + for (u32 idx = 0; idx < hash_count; idx++) { - key0 = key0init; - key1 = key1init; - key2 = key2init; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) - { - idx = 0xfe; - continue; - } + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32x key0 = key0init; + u32x key1 = key1init; + u32x key2 = key2init; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + next = data_ptr[0]; - if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[1]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[2]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) != plain) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff) != plain)) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) break; + + if (idx + 1 == esalt_bufs[digests_offset].hash_count) { - idx = 0xfe; - continue; - } + const u32 r0 = esalt_bufs[digests_offset].hashes[0].checksum_from_crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; - if (idx + 1 == esalt_bufs[digests_offset].hash_count){ \ - if (atomic_inc (&hashes_shown[digests_offset]) == 0) - { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); - } + COMPARE_M_SIMD (r0, r1, r2, r3); } } } } + +#undef MAX_LOCAL +#undef TMPSIZ +#undef CRC32 +#undef MSB +#undef CONST +#undef MAX_DATA +#undef update_key012 +#undef update_key3 diff --git a/OpenCL/m17230_a1-pure.cl b/OpenCL/m17230_a1-pure.cl index 735d42850..327773f74 100644 --- a/OpenCL/m17230_a1-pure.cl +++ b/OpenCL/m17230_a1-pure.cl @@ -80,7 +80,8 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ @@ -88,23 +89,34 @@ Author: Sein Coray #include "inc_types.h" #include "inc_common.cl" #include "inc_simd.cl" -#include "inc_rp.h" -#include "inc_rp.cl" -#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) -#define MSB(x) ((x)>>24) -#define CONST 0x08088405 -#define POLYNOMIAL 0xEDB88320 +#define MAX_LOCAL 512 // too much leaves no room for compiler optimizations, simply benchmark to find a good trade-off - make it as big as possible +#define TMPSIZ 32 -#define MAX_COMPRESSED_LENGTH 2048 +#define CRC32(x,c,t) (((x) >> 8) ^ (t)[((x) ^ (c)) & 0xff]) +#define MSB(x) ((x) >> 24) +#define CONST 0x08088405 -typedef struct { - u8 op; /* operation, extra bits, table bits */ - u8 bits; /* bits in this part of the code */ - u16 val; /* offset in table or code value */ -} code; +#define MAX_DATA (16 * 1024 * 1024) -typedef struct pkzip_hash +#define update_key012(k0,k1,k2,c,t) \ +{ \ + (k0) = CRC32 ((k0), c, (t)); \ + (k1) = ((k1) + ((k0) & 0xff)) * CONST + 1; \ + (k2) = CRC32 ((k2), MSB (k1), (t)); \ +} + +#define update_key3(k2,k3) \ +{ \ + const u32 temp = ((k2) & 0xffff) | 3; \ + \ + (k3) = ((temp * (temp ^ 1)) >> 8) & 0xff; \ +} + +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) + +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -117,16 +129,93 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_COMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; + +} __attribute__((packed)); -typedef struct pkzip +typedef struct pkzip_hash pkzip_hash_t; + +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hashes[8]; -} pkzip_t; + +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +CONSTANT_AS u32a crc32tab[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; __kernel void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) { @@ -134,43 +223,19 @@ __kernel void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -178,161 +243,136 @@ __kernel void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) if (gid >= gid_max) return; /** - * loop + * prefetch from global memory */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; - u32x key0init2, key1init2, key2init2; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 hash_count = esalt_bufs[digests_offset].hash_count; - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + /** + * loop + */ + + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - for (u8 i = 0; i < pws[gid].pw_len; i++) + for (u32 i = 0, j = 0; i < pws[gid].pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (pws[gid].pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (pws[gid].i[j]), l_crc32tab); } for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - key0init2 = key0init; - key1init2 = key1init; - key2init2 = key2init; + u32x key0init2 = key0init; + u32x key1init2 = key1init; + u32x key2init2 = key2init; - for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + for (u32 i = 0, j = 0; i < combs_buf[il_pos].pw_len; i += 4, j += 1) { - key0init2 = CRC32( key0init2, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init2 = (key1init2 + (key0init2 & 0xff)) * CONST + 1; - key2init2 = CRC32( key2init2, MSB(key1init2) ); + if (combs_buf[il_pos].pw_len >= (i + 1)) update_key012 (key0init2, key1init2, key2init2, unpack_v8a_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 2)) update_key012 (key0init2, key1init2, key2init2, unpack_v8b_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 3)) update_key012 (key0init2, key1init2, key2init2, unpack_v8c_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 4)) update_key012 (key0init2, key1init2, key2init2, unpack_v8d_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); } - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; + u32 plain; + u32 key3; + u32 next; - for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + for (u32 idx = 0; idx < hash_count; idx++) { - key0 = key0init2; - key1 = key1init2; - key2 = key2init2; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) - { - idx = 0xfe; - continue; - } + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32x key0 = key0init2; + u32x key1 = key1init2; + u32x key2 = key2init2; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + next = data_ptr[0]; - if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[1]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[2]; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) != plain) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff) != plain)) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) break; + + if (idx + 1 == esalt_bufs[digests_offset].hash_count) { - idx = 0xfe; - continue; - } + /** + * digest + */ - if (idx + 1 == esalt_bufs[digests_offset].hash_count){ \ - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + const u32 search[4] = { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); - } + esalt_bufs[digests_offset].hashes[0].checksum_from_crc, + 0, + 0, + 0 + }; + + const u32 r0 = esalt_bufs[digests_offset].hashes[0].checksum_from_crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); } } } @@ -344,43 +384,19 @@ __kernel void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -388,162 +404,134 @@ __kernel void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) if (gid >= gid_max) return; /** - * loop + * prefetch from global memory */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; - u32x key0init2, key1init2, key2init2; + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 hash_count = esalt_bufs[digests_offset].hash_count; + + /** + * loop + */ - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; - for (u8 i = 0; i < pws[gid].pw_len; i++) + for (u32 i = 0, j = 0; i < pws[gid].pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (pws[gid].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (pws[gid].pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (pws[gid].i[j]), l_crc32tab); + if (pws[gid].pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (pws[gid].i[j]), l_crc32tab); } for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { - key0init2 = key0init; - key1init2 = key1init; - key2init2 = key2init; + u32x key0init2 = key0init; + u32x key1init2 = key1init; + u32x key2init2 = key2init; - for (u8 i = 0; i < combs_buf[il_pos].pw_len; i++) + for (u32 i = 0, j = 0; i < combs_buf[il_pos].pw_len; i += 4, j += 1) { - key0init2 = CRC32( key0init2, (combs_buf[il_pos].i[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init2 = (key1init2 + (key0init2 & 0xff)) * CONST + 1; - key2init2 = CRC32( key2init2, MSB(key1init2) ); + if (combs_buf[il_pos].pw_len >= (i + 1)) update_key012 (key0init2, key1init2, key2init2, unpack_v8a_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 2)) update_key012 (key0init2, key1init2, key2init2, unpack_v8b_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 3)) update_key012 (key0init2, key1init2, key2init2, unpack_v8c_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); + if (combs_buf[il_pos].pw_len >= (i + 4)) update_key012 (key0init2, key1init2, key2init2, unpack_v8d_from_v32_S (combs_buf[il_pos].i[j]), l_crc32tab); } - u8 abort = 0; - u8 plain; - u8 key3; - u16 temp; + u32 plain; + u32 key3; + u32 next; - for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + for (u32 idx = 0; idx < hash_count; idx++) { - key0 = key0init2; - key1 = key1init2; - key2 = key2init2; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) - { - idx = 0xfe; - continue; - } + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32x key0 = key0init2; + u32x key1 = key1init2; + u32x key2 = key2init2; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + next = data_ptr[0]; - if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[1]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[2]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) != plain) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff) != plain)) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) break; + + if (idx + 1 == esalt_bufs[digests_offset].hash_count) { - idx = 0xfe; - continue; - } + const u32 r0 = esalt_bufs[digests_offset].hashes[0].checksum_from_crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; - if (idx + 1 == esalt_bufs[digests_offset].hash_count){ \ - if (atomic_inc (&hashes_shown[digests_offset]) == 0) - { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); - } + COMPARE_M_SIMD (r0, r1, r2, r3); } } } } + +#undef MAX_LOCAL +#undef TMPSIZ +#undef CRC32 +#undef MSB +#undef CONST +#undef MAX_DATA +#undef update_key012 +#undef update_key3 diff --git a/OpenCL/m17230_a3-pure.cl b/OpenCL/m17230_a3-pure.cl index dcf6d4047..2ae2e3d3a 100644 --- a/OpenCL/m17230_a3-pure.cl +++ b/OpenCL/m17230_a3-pure.cl @@ -80,7 +80,8 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ @@ -88,17 +89,34 @@ Author: Sein Coray #include "inc_types.h" #include "inc_common.cl" #include "inc_simd.cl" -#include "inc_rp.h" -#include "inc_rp.cl" -#define CRC32(x,c) (((x)>>8)^l_crc32tab[((x)^(c))&0xff]) -#define MSB(x) ((x)>>24) -#define CONST 0x08088405 -#define POLYNOMIAL 0xEDB88320 +#define MAX_LOCAL 512 // too much leaves no room for compiler optimizations, simply benchmark to find a good trade-off - make it as big as possible +#define TMPSIZ 32 -#define MAX_COMPRESSED_LENGTH 2048 +#define CRC32(x,c,t) (((x) >> 8) ^ (t)[((x) ^ (c)) & 0xff]) +#define MSB(x) ((x) >> 24) +#define CONST 0x08088405 -typedef struct pkzip_hash +#define MAX_DATA (16 * 1024 * 1024) + +#define update_key012(k0,k1,k2,c,t) \ +{ \ + (k0) = CRC32 ((k0), c, (t)); \ + (k1) = ((k1) + ((k0) & 0xff)) * CONST + 1; \ + (k2) = CRC32 ((k2), MSB (k1), (t)); \ +} + +#define update_key3(k2,k3) \ +{ \ + const u32 temp = ((k2) & 0xffff) | 3; \ + \ + (k3) = ((temp * (temp ^ 1)) >> 8) & 0xff; \ +} + +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) + +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -111,16 +129,93 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_COMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; -typedef struct pkzip +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; + +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hashes[8]; -} pkzip_t; + +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +CONSTANT_AS u32a crc32tab[256] = +{ + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, + 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, + 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, + 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, + 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, + 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, + 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, + 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, + 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, + 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, + 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, + 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, + 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, + 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, + 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, + 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, + 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, + 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, + 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, + 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, + 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, + 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d +}; __kernel void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) { @@ -128,43 +223,19 @@ __kernel void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -184,154 +255,138 @@ __kernel void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) w[idx] = pws[gid].i[idx]; } + /** + * prefetch from global memory + */ + + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 hash_count = esalt_bufs[digests_offset].hash_count; + /** * loop */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; u32 w0l = w[0]; for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) { const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; + w[0] = w0; - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; + + if (pw_len >= 1) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (w0), l_crc32tab); + if (pw_len >= 2) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (w0), l_crc32tab); + if (pw_len >= 3) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (w0), l_crc32tab); + if (pw_len >= 4) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (w0), l_crc32tab); - for (u8 i = 0; i < pw_len; i++) + for (u32 i = 4, j = 1; i < pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (w[j]), l_crc32tab); } - u8 plain; - u8 key3; - u16 temp; + u32 plain; + u32 key3; + u32 next; - for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + for (u32 idx = 0; idx < hash_count; idx++) { - key0 = key0init; - key1 = key1init; - key2 = key2init; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) - { - idx = 0xfe; - continue; - } + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32x key0 = key0init; + u32x key1 = key1init; + u32x key2 = key2init; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + next = data_ptr[0]; - if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[1]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + next = data_ptr[2]; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) != plain) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff) != plain)) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) break; + + if (idx + 1 == esalt_bufs[digests_offset].hash_count) { - idx = 0xfe; - continue; - } + /** + * digest + */ - if (idx + 1 == esalt_bufs[digests_offset].hash_count){ \ - if (atomic_inc (&hashes_shown[digests_offset]) == 0) + const u32 search[4] = { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); - } + esalt_bufs[digests_offset].hashes[0].checksum_from_crc, + 0, + 0, + 0 + }; + + const u32 r0 = esalt_bufs[digests_offset].hashes[0].checksum_from_crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; + + COMPARE_S_SIMD (r0, r1, r2, r3); } } } @@ -343,43 +398,19 @@ __kernel void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * modifier */ - const u64 lid = get_local_id (0); const u64 gid = get_global_id (0); + const u64 lid = get_local_id (0); + const u64 lsz = get_local_size (0); - __local u32 l_crc32tab[0x100]; - - u32 remainder; - u32 b = 0; - u8 set = 0; - for (u32 b = 0; b < 256; b++) - { - remainder = b; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; - - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + /** + * sbox, kbox + */ - if (remainder & 1) remainder = (remainder >> 1) ^ POLYNOMIAL; - else remainder >>= 1; + LOCAL_AS u32 l_crc32tab[256]; - l_crc32tab[b] = remainder; + for (u64 i = lid; i < 256; i += lsz) + { + l_crc32tab[i] = crc32tab[i]; } barrier (CLK_LOCAL_MEM_FENCE); @@ -399,155 +430,136 @@ __kernel void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) w[idx] = pws[gid].i[idx]; } + /** + * prefetch from global memory + */ + + const u32 checksum_size = esalt_bufs[digests_offset].checksum_size; + const u32 hash_count = esalt_bufs[digests_offset].hash_count; + /** * loop */ - u32x key0, key1, key2; - u32x key0init, key1init, key2init; u32 w0l = w[0]; for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE) { const u32x w0r = words_buf_r[il_pos / VECT_SIZE]; + const u32x w0 = w0l | w0r; + w[0] = w0; - key0init = 0x12345678; - key1init = 0x23456789; - key2init = 0x34567890; + u32x key0init = 0x12345678; + u32x key1init = 0x23456789; + u32x key2init = 0x34567890; + + if (pw_len >= 1) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (w0), l_crc32tab); + if (pw_len >= 2) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (w0), l_crc32tab); + if (pw_len >= 3) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (w0), l_crc32tab); + if (pw_len >= 4) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (w0), l_crc32tab); - for (u8 i = 0; i < pw_len; i++) + for (u32 i = 4, j = 1; i < pw_len; i += 4, j += 1) { - key0init = CRC32( key0init, (w[i >> 2] >> ((i & 3) << 3)) & 0xff ); - key1init = (key1init + (key0init & 0xff)) * CONST + 1; - key2init = CRC32( key2init, MSB(key1init) ); + if (pw_len >= (i + 1)) update_key012 (key0init, key1init, key2init, unpack_v8a_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 2)) update_key012 (key0init, key1init, key2init, unpack_v8b_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 3)) update_key012 (key0init, key1init, key2init, unpack_v8c_from_v32_S (w[j]), l_crc32tab); + if (pw_len >= (i + 4)) update_key012 (key0init, key1init, key2init, unpack_v8d_from_v32_S (w[j]), l_crc32tab); } - u8 plain; - u8 key3; - u16 temp; + u32 plain; + u32 key3; + u32 next; - for (u8 idx = 0; idx < esalt_bufs[digests_offset].hash_count; idx++) + for (u32 idx = 0; idx < hash_count; idx++) { - key0 = key0init; - key1 = key1init; - key2 = key2init; - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[0] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[1] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[2] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[3] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[4] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[5] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[6] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[7] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[8] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[9] ^ key3; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); - - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[10] ^ key3; - - if (esalt_bufs[digests_offset].checksum_size == 2 && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff)) - { - idx = 0xfe; - continue; - } + __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + u32x key0 = key0init; + u32x key1 = key1init; + u32x key2 = key2init; - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[11] ^ key3; + next = data_ptr[0]; - if (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8) && plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8)) - { - idx = 0xfe; - continue; - } + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[1]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - key0 = CRC32( key0, plain ); - key1 = (key1 + (key0 & 0xff)) * CONST + 1; - key2 = CRC32( key2, MSB(key1) ); + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - temp = (key2 & 0xffff) | 3; - key3 = ((temp * (temp ^ 1)) >> 8) & 0xff; - plain = esalt_bufs[digests_offset].hashes[idx].data[12] ^ key3; + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); - if ((plain & 6) == 0 || (plain & 6) == 6) + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[2]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8b_from_v32_S (next) ^ key3; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8c_from_v32_S (next) ^ key3; + if ((checksum_size == 2) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_crc & 0xff) != plain) && ((esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp & 0xff) != plain)) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + update_key3 (key2, key3); + plain = unpack_v8d_from_v32_S (next) ^ key3; + if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; + update_key012 (key0, key1, key2, plain, l_crc32tab); + + next = data_ptr[3]; + + update_key3 (key2, key3); + plain = unpack_v8a_from_v32_S (next) ^ key3; + if ((plain & 6) == 0 || (plain & 6) == 6) break; + + if (idx + 1 == esalt_bufs[digests_offset].hash_count) { - idx = 0xfe; - continue; - } + const u32 r0 = esalt_bufs[digests_offset].hashes[0].checksum_from_crc; + const u32 r1 = 0; + const u32 r2 = 0; + const u32 r3 = 0; - if (idx + 1 == esalt_bufs[digests_offset].hash_count){ \ - if (atomic_inc (&hashes_shown[digests_offset]) == 0) - { - mark_hash (plains_buf, d_return_buf, salt_pos, digests_cnt, 0, digests_offset + 0, gid, il_pos, 0, 0); - } + COMPARE_M_SIMD (r0, r1, r2, r3); } } } } + +#undef MAX_LOCAL +#undef TMPSIZ +#undef CRC32 +#undef MSB +#undef CONST +#undef MAX_DATA +#undef update_key012 +#undef update_key3 diff --git a/src/modules/module_17200.c b/src/modules/module_17200.c index 4b2526037..516a7c9e5 100644 --- a/src/modules/module_17200.c +++ b/src/modules/module_17200.c @@ -80,7 +80,8 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ @@ -92,10 +93,10 @@ Author: Sein Coray #include "shared.h" static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; -static const u32 DGST_POS0 = 1; -static const u32 DGST_POS1 = 2; -static const u32 DGST_POS2 = 3; -static const u32 DGST_POS3 = 4; +static const u32 DGST_POS0 = 0; +static const u32 DGST_POS1 = 1; +static const u32 DGST_POS2 = 2; +static const u32 DGST_POS3 = 3; static const u32 DGST_SIZE = DGST_SIZE_4_4; static const u32 HASH_CATEGORY = HASH_CATEGORY_ARCHIVE; static const char *HASH_NAME = "PKZIP (Compressed)"; @@ -106,28 +107,12 @@ static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat"; static const char *ST_HASH = "$pkzip2$1*1*2*0*e3*1c5*eda7a8de*0*28*8*e3*eda7*5096*a9fc1f4e951c8fb3031a6f903e5f4e3211c8fdc4671547bf77f6f682afbfcc7475d83898985621a7af9bccd1349d1976500a68c48f630b7f22d7a0955524d768e34868880461335417ddd149c65a917c0eb0a4bf7224e24a1e04cf4ace5eef52205f4452e66ded937db9545f843a68b1e84a2e933cc05fb36d3db90e6c5faf1bee2249fdd06a7307849902a8bb24ec7e8a0886a4544ca47979a9dfeefe034bdfc5bd593904cfe9a5309dd199d337d3183f307c2cb39622549a5b9b8b485b7949a4803f63f67ca427a0640ad3793a519b2476c52198488e3e2e04cac202d624fb7d13c2*$/pkzip2$"; -static const char *SIGNATURE_PKZIP_V1 = "$pkzip$"; -static const char *SIGNATURE_PKZIP_V2 = "$pkzip2$"; - -#define MAX_COMPRESSED_LENGTH 2048 -#define MAX_UNCOMPRESSED_LENGTH 4096 +#define MAX_DATA (16 * 1024 * 1024) -u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } -u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } -u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } -u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } -u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } -u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } -u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } -const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } -u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } -u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } -u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } -u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } -const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } -const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) -typedef struct pkzip_hash +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -140,16 +125,43 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_COMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; -typedef struct pkzip +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; + +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hash; -} pkzip_t; + +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +static const char *SIGNATURE_PKZIP_V1 = "$pkzip$"; +static const char *SIGNATURE_PKZIP_V2 = "$pkzip2$"; + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { @@ -215,7 +227,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE p = strtok(NULL, "*"); if (p == NULL) return PARSER_HASH_LENGTH; pkzip->hash.uncompressed_length = strtoul(p, NULL, 16); - if (pkzip->hash.compressed_length > MAX_COMPRESSED_LENGTH || pkzip->hash.uncompressed_length > MAX_UNCOMPRESSED_LENGTH) + if (pkzip->hash.compressed_length > MAX_DATA) { return PARSER_TOKEN_LENGTH; } @@ -262,26 +274,25 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE hex_to_binary(p, strlen(p), (char *) &(pkzip->hash.data)); // fake salt - salt->salt_buf[0] = pkzip->hash.data[ 3] << 24 | pkzip->hash.data[ 2] << 16 | pkzip->hash.data[ 1] << 8 | pkzip->hash.data[ 0]; - salt->salt_buf[1] = pkzip->hash.data[ 7] << 24 | pkzip->hash.data[ 6] << 16 | pkzip->hash.data[ 5] << 8 | pkzip->hash.data[ 4]; - salt->salt_buf[2] = pkzip->hash.data[11] << 24 | pkzip->hash.data[10] << 16 | pkzip->hash.data[ 9] << 8 | pkzip->hash.data[ 8]; - salt->salt_buf[3] = pkzip->hash.data[15] << 24 | pkzip->hash.data[14] << 16 | pkzip->hash.data[13] << 8 | pkzip->hash.data[ 12]; + u32 *ptr = (u32 *) pkzip->hash.data; + + salt->salt_buf[0] = ptr[0]; + salt->salt_buf[1] = ptr[1]; + salt->salt_buf[2] = ptr[2]; + salt->salt_buf[3] = ptr[3]; salt->salt_len = 16; - // fake hash - digest[0] = pkzip->hash.data[ 0] << 24 | pkzip->hash.data[ 1] << 16 | pkzip->hash.data[ 2] << 8 | pkzip->hash.data[ 3]; - digest[1] = pkzip->hash.data[ 4] << 24 | pkzip->hash.data[ 5] << 16 | pkzip->hash.data[ 6] << 8 | pkzip->hash.data[ 7]; - digest[2] = pkzip->hash.data[ 8] << 24 | pkzip->hash.data[ 9] << 16 | pkzip->hash.data[10] << 8 | pkzip->hash.data[11]; - digest[3] = pkzip->hash.data[12] << 24 | pkzip->hash.data[13] << 16 | pkzip->hash.data[14] << 8 | pkzip->hash.data[15]; + digest[0] = pkzip->hash.crc32; + digest[1] = 0; + digest[2] = 0; + digest[3] = 0; return (PARSER_OK); } int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) { - const u32 *digest = (const u32 *) digest_buf; - const pkzip_t *pkzip = (const pkzip_t *) esalt_buf; int out_len = 0; @@ -352,10 +363,11 @@ void module_init (module_ctx_t *module_ctx) module_ctx->module_hash_binary_count = MODULE_DEFAULT; module_ctx->module_hash_binary_parse = MODULE_DEFAULT; module_ctx->module_hash_binary_save = MODULE_DEFAULT; - module_ctx->module_hash_decode_outfile = MODULE_DEFAULT; + module_ctx->module_hash_decode_potfile = MODULE_DEFAULT; module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT; module_ctx->module_hash_decode = module_hash_decode; module_ctx->module_hash_encode_status = MODULE_DEFAULT; + module_ctx->module_hash_encode_potfile = MODULE_DEFAULT; module_ctx->module_hash_encode = module_hash_encode; module_ctx->module_hash_init_selftest = MODULE_DEFAULT; module_ctx->module_hash_mode = MODULE_DEFAULT; @@ -380,6 +392,7 @@ void module_init (module_ctx_t *module_ctx) module_ctx->module_opts_type = module_opts_type; module_ctx->module_outfile_check_disable = MODULE_DEFAULT; module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_custom_check = MODULE_DEFAULT; module_ctx->module_potfile_disable = MODULE_DEFAULT; module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; module_ctx->module_pwdump_column = MODULE_DEFAULT; diff --git a/src/modules/module_17210.c b/src/modules/module_17210.c index 8c235fe67..eae85153f 100644 --- a/src/modules/module_17210.c +++ b/src/modules/module_17210.c @@ -80,7 +80,8 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ @@ -92,41 +93,26 @@ Author: Sein Coray #include "shared.h" static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; -static const u32 DGST_POS0 = 1; -static const u32 DGST_POS1 = 2; -static const u32 DGST_POS2 = 3; -static const u32 DGST_POS3 = 4; +static const u32 DGST_POS0 = 0; +static const u32 DGST_POS1 = 1; +static const u32 DGST_POS2 = 2; +static const u32 DGST_POS3 = 3; static const u32 DGST_SIZE = DGST_SIZE_4_4; static const u32 HASH_CATEGORY = HASH_CATEGORY_ARCHIVE; static const char *HASH_NAME = "PKZIP (Uncompressed)"; static const u64 KERN_TYPE = 17210; static const u32 OPTI_TYPE = 0; -static const u64 OPTS_TYPE = OPTS_TYPE_PT_NEVERCRACK; +static const u64 OPTS_TYPE = OPTS_TYPE_PT_NEVERCRACK; // nevercrack is required because it's quite likely that a collision is found which will not necessarily work as password for the archive static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat"; static const char *ST_HASH = "$pkzip2$1*1*2*0*1d1*1c5*eda7a8de*0*28*0*1d1*eda7*5096*1dea673da43d9fc7e2be1a1f4f664269fceb6cb88723a97408ae1fe07f774d31d1442ea8485081e63f919851ca0b7588d5e3442317fff19fe547a4ef97492ed75417c427eea3c4e146e16c100a2f8b6abd7e5988dc967e5a0e51f641401605d673630ea52ebb04da4b388489901656532c9aa474ca090dbac7cf8a21428d57b42a71da5f3d83fed927361e5d385ca8e480a6d42dea5b4bf497d3a24e79fc7be37c8d1721238cbe9e1ea3ae1eb91fc02aabdf33070d718d5105b70b3d7f3d2c28b3edd822e89a5abc0c8fee117c7fbfbfd4b4c8e130977b75cb0b1da080bfe1c0859e6483c42f459c8069d45a76220e046e6c2a2417392fd87e4aa4a2559eaab3baf78a77a1b94d8c8af16a977b4bb45e3da211838ad044f209428dba82666bf3d54d4eed82c64a9b3444a44746b9e398d0516a2596d84243b4a1d7e87d9843f38e45b6be67fd980107f3ad7b8453d87300e6c51ac9f5e3f6c3b702654440c543b1d808b62f7a313a83b31a6faaeedc2620de7057cd0df80f70346fe2d4dccc318f0b5ed128bcf0643e63d754bb05f53afb2b0fa90b34b538b2ad3648209dff587df4fa18698e4fa6d858ad44aa55d2bba3b08dfdedd3e28b8b7caf394d5d9d95e452c2ab1c836b9d74538c2f0d24b9b577*$/pkzip2$"; -static const char *SIGNATURE_PKZIP_V1 = "$pkzip$"; -static const char *SIGNATURE_PKZIP_V2 = "$pkzip2$"; +#define MAX_DATA (16 * 1024 * 1024) -#define MAX_UNCOMPRESSED_LENGTH 4096 +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) -u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } -u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } -u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } -u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } -u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } -u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } -u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } -const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } -u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } -u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } -u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } -u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } -const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } -const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } - -typedef struct pkzip_hash +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -139,16 +125,43 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_UNCOMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; + +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; -typedef struct pkzip +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hash; -} pkzip_t; + +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +static const char *SIGNATURE_PKZIP_V1 = "$pkzip$"; +static const char *SIGNATURE_PKZIP_V2 = "$pkzip2$"; + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { @@ -214,7 +227,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE p = strtok(NULL, "*"); if (p == NULL) return PARSER_HASH_LENGTH; pkzip->hash.uncompressed_length = strtoul(p, NULL, 16); - if (pkzip->hash.uncompressed_length > MAX_UNCOMPRESSED_LENGTH) + if (pkzip->hash.uncompressed_length > MAX_DATA) { return PARSER_TOKEN_LENGTH; } @@ -261,18 +274,19 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE hex_to_binary(p, strlen(p), (char *) &(pkzip->hash.data)); // fake salt - salt->salt_buf[0] = pkzip->hash.data[ 3] << 24 | pkzip->hash.data[ 2] << 16 | pkzip->hash.data[ 1] << 8 | pkzip->hash.data[ 0]; - salt->salt_buf[1] = pkzip->hash.data[ 7] << 24 | pkzip->hash.data[ 6] << 16 | pkzip->hash.data[ 5] << 8 | pkzip->hash.data[ 4]; - salt->salt_buf[2] = pkzip->hash.data[11] << 24 | pkzip->hash.data[10] << 16 | pkzip->hash.data[ 9] << 8 | pkzip->hash.data[ 8]; - salt->salt_buf[3] = pkzip->hash.data[15] << 24 | pkzip->hash.data[14] << 16 | pkzip->hash.data[13] << 8 | pkzip->hash.data[ 12]; + u32 *ptr = (u32 *) pkzip->hash.data; + + salt->salt_buf[0] = ptr[0]; + salt->salt_buf[1] = ptr[1]; + salt->salt_buf[2] = ptr[2]; + salt->salt_buf[3] = ptr[3]; salt->salt_len = 16; - // fake hash - digest[0] = pkzip->hash.data[ 0] << 24 | pkzip->hash.data[ 1] << 16 | pkzip->hash.data[ 2] << 8 | pkzip->hash.data[ 3]; - digest[1] = pkzip->hash.data[ 4] << 24 | pkzip->hash.data[ 5] << 16 | pkzip->hash.data[ 6] << 8 | pkzip->hash.data[ 7]; - digest[2] = pkzip->hash.data[ 8] << 24 | pkzip->hash.data[ 9] << 16 | pkzip->hash.data[10] << 8 | pkzip->hash.data[11]; - digest[3] = pkzip->hash.data[12] << 24 | pkzip->hash.data[13] << 16 | pkzip->hash.data[14] << 8 | pkzip->hash.data[15]; + digest[0] = pkzip->hash.crc32; + digest[1] = 0; + digest[2] = 0; + digest[3] = 0; return (PARSER_OK); } @@ -354,10 +368,11 @@ void module_init (module_ctx_t *module_ctx) module_ctx->module_hash_binary_count = MODULE_DEFAULT; module_ctx->module_hash_binary_parse = MODULE_DEFAULT; module_ctx->module_hash_binary_save = MODULE_DEFAULT; - module_ctx->module_hash_decode_outfile = MODULE_DEFAULT; + module_ctx->module_hash_decode_potfile = MODULE_DEFAULT; module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT; module_ctx->module_hash_decode = module_hash_decode; module_ctx->module_hash_encode_status = MODULE_DEFAULT; + module_ctx->module_hash_encode_potfile = MODULE_DEFAULT; module_ctx->module_hash_encode = module_hash_encode; module_ctx->module_hash_init_selftest = MODULE_DEFAULT; module_ctx->module_hash_mode = MODULE_DEFAULT; @@ -382,6 +397,7 @@ void module_init (module_ctx_t *module_ctx) module_ctx->module_opts_type = module_opts_type; module_ctx->module_outfile_check_disable = MODULE_DEFAULT; module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_custom_check = MODULE_DEFAULT; module_ctx->module_potfile_disable = MODULE_DEFAULT; module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; module_ctx->module_pwdump_column = MODULE_DEFAULT; diff --git a/src/modules/module_17220.c b/src/modules/module_17220.c index 2ce885473..4253a73ce 100644 --- a/src/modules/module_17220.c +++ b/src/modules/module_17220.c @@ -80,7 +80,8 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ @@ -92,11 +93,11 @@ Author: Sein Coray #include "shared.h" static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; -static const u32 DGST_POS0 = 1; -static const u32 DGST_POS1 = 2; -static const u32 DGST_POS2 = 3; -static const u32 DGST_POS3 = 4; -static const u32 DGST_SIZE = DGST_SIZE_4_4; +static const u32 DGST_POS0 = 0; +static const u32 DGST_POS1 = 1; +static const u32 DGST_POS2 = 2; +static const u32 DGST_POS3 = 3; +static const u32 DGST_SIZE = DGST_SIZE_4_8; static const u32 HASH_CATEGORY = HASH_CATEGORY_ARCHIVE; static const char *HASH_NAME = "PKZIP (Compressed Multi-File)"; static const u64 KERN_TYPE = 17220; @@ -106,28 +107,12 @@ static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat"; static const char *ST_HASH = "$pkzip2$3*1*1*0*8*24*a425*8827*d1730095cd829e245df04ebba6c52c0573d49d3bbeab6cb385b7fa8a28dcccd3098bfdd7*1*0*8*24*2a74*882a*51281ac874a60baedc375ca645888d29780e20d4076edd1e7154a99bde982152a736311f*2*0*e3*1c5*eda7a8de*0*29*8*e3*eda7*5096*1455781b59707f5151139e018bdcfeebfc89bc37e372883a7ec0670a5eafc622feb338f9b021b6601a674094898a91beac70e41e675f77702834ca6156111a1bf7361bc9f3715d77dfcdd626634c68354c6f2e5e0a7b1e1ce84a44e632d0f6e36019feeab92fb7eac9dda8df436e287aafece95d042059a1b27d533c5eab62c1c559af220dc432f2eb1a38a70f29e8f3cb5a207704274d1e305d7402180fd47e026522792f5113c52a116d5bb25b67074ffd6f4926b221555234aabddc69775335d592d5c7d22462b75de1259e8342a9ba71cb06223d13c7f51f13be2ad76352c3b8ed*$/pkzip2$"; -static const char *SIGNATURE_PKZIP_V1 = "$pkzip$"; -static const char *SIGNATURE_PKZIP_V2 = "$pkzip2$"; - -#define MAX_COMPRESSED_LENGTH 2048 -#define MAX_UNCOMPRESSED_LENGTH 4096 +#define MAX_DATA (16 * 1024 * 1024) -u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } -u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } -u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } -u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } -u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } -u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } -u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } -const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } -u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } -u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } -u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } -u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } -const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } -const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) -typedef struct pkzip_hash +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -140,16 +125,43 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_COMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; -typedef struct pkzip +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; + +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hashes[8]; -} pkzip_t; + +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +static const char *SIGNATURE_PKZIP_V1 = "$pkzip$"; +static const char *SIGNATURE_PKZIP_V2 = "$pkzip2$"; + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { @@ -217,7 +229,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE p = strtok(NULL, "*"); if (p == NULL) return PARSER_HASH_LENGTH; pkzip->hashes[i].uncompressed_length = strtoul(p, NULL, 16); - if (pkzip->hashes[i].compressed_length > MAX_COMPRESSED_LENGTH || pkzip->hashes[i].uncompressed_length > MAX_UNCOMPRESSED_LENGTH) + if (pkzip->hashes[i].compressed_length > MAX_DATA) { return PARSER_TOKEN_LENGTH; } @@ -264,20 +276,15 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE hex_to_binary(p, strlen(p), (char *) &(pkzip->hashes[i].data)); // fake salt - salt->salt_buf[0] ^= pkzip->hashes[i].data[ 3] << 24 | pkzip->hashes[i].data[ 2] << 16 | pkzip->hashes[i].data[ 1] << 8 | pkzip->hashes[i].data[ 0]; - salt->salt_buf[1] ^= pkzip->hashes[i].data[ 7] << 24 | pkzip->hashes[i].data[ 6] << 16 | pkzip->hashes[i].data[ 5] << 8 | pkzip->hashes[i].data[ 4]; - salt->salt_buf[2] ^= pkzip->hashes[i].data[11] << 24 | pkzip->hashes[i].data[10] << 16 | pkzip->hashes[i].data[ 9] << 8 | pkzip->hashes[i].data[ 8]; - salt->salt_buf[3] ^= pkzip->hashes[i].data[15] << 24 | pkzip->hashes[i].data[14] << 16 | pkzip->hashes[i].data[13] << 8 | pkzip->hashes[i].data[ 12]; - - salt->salt_len = 16; - - // fake hash - digest[0] ^= pkzip->hashes[i].data[ 0] << 24 | pkzip->hashes[i].data[ 1] << 16 | pkzip->hashes[i].data[ 2] << 8 | pkzip->hashes[i].data[ 3]; - digest[1] ^= pkzip->hashes[i].data[ 4] << 24 | pkzip->hashes[i].data[ 5] << 16 | pkzip->hashes[i].data[ 6] << 8 | pkzip->hashes[i].data[ 7]; - digest[2] ^= pkzip->hashes[i].data[ 8] << 24 | pkzip->hashes[i].data[ 9] << 16 | pkzip->hashes[i].data[10] << 8 | pkzip->hashes[i].data[11]; - digest[3] ^= pkzip->hashes[i].data[12] << 24 | pkzip->hashes[i].data[13] << 16 | pkzip->hashes[i].data[14] << 8 | pkzip->hashes[i].data[15]; + u32 *ptr = (u32 *) pkzip->hashes[i].data; + + salt->salt_buf[i] = ptr[0]; + + if (i == 0) digest[i] = pkzip->hashes[i].checksum_from_crc; } + salt->salt_len = pkzip->hash_count << 2; + return (PARSER_OK); } @@ -358,10 +365,11 @@ void module_init (module_ctx_t *module_ctx) module_ctx->module_hash_binary_count = MODULE_DEFAULT; module_ctx->module_hash_binary_parse = MODULE_DEFAULT; module_ctx->module_hash_binary_save = MODULE_DEFAULT; - module_ctx->module_hash_decode_outfile = MODULE_DEFAULT; + module_ctx->module_hash_decode_potfile = MODULE_DEFAULT; module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT; module_ctx->module_hash_decode = module_hash_decode; module_ctx->module_hash_encode_status = MODULE_DEFAULT; + module_ctx->module_hash_encode_potfile = MODULE_DEFAULT; module_ctx->module_hash_encode = module_hash_encode; module_ctx->module_hash_init_selftest = MODULE_DEFAULT; module_ctx->module_hash_mode = MODULE_DEFAULT; @@ -386,6 +394,7 @@ void module_init (module_ctx_t *module_ctx) module_ctx->module_opts_type = module_opts_type; module_ctx->module_outfile_check_disable = MODULE_DEFAULT; module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_custom_check = MODULE_DEFAULT; module_ctx->module_potfile_disable = MODULE_DEFAULT; module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; module_ctx->module_pwdump_column = MODULE_DEFAULT; diff --git a/src/modules/module_17230.c b/src/modules/module_17230.c index 9e82c3c6d..1861cae65 100644 --- a/src/modules/module_17230.c +++ b/src/modules/module_17230.c @@ -80,7 +80,8 @@ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Author: Sein Coray +Author: Sein Coray +Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp5g= */ @@ -92,11 +93,11 @@ Author: Sein Coray #include "shared.h" static const u32 ATTACK_EXEC = ATTACK_EXEC_INSIDE_KERNEL; -static const u32 DGST_POS0 = 1; -static const u32 DGST_POS1 = 2; -static const u32 DGST_POS2 = 3; -static const u32 DGST_POS3 = 4; -static const u32 DGST_SIZE = DGST_SIZE_4_4; +static const u32 DGST_POS0 = 0; +static const u32 DGST_POS1 = 1; +static const u32 DGST_POS2 = 2; +static const u32 DGST_POS3 = 3; +static const u32 DGST_SIZE = DGST_SIZE_4_8; static const u32 HASH_CATEGORY = HASH_CATEGORY_ARCHIVE; static const char *HASH_NAME = "PKZIP (Compressed Multi-File Checksum-Only)"; static const u64 KERN_TYPE = 17230; @@ -106,27 +107,12 @@ static const u32 SALT_TYPE = SALT_TYPE_EMBEDDED; static const char *ST_PASS = "hashcat"; static const char *ST_HASH = "$pkzip2$8*1*1*0*8*24*a425*8827*3bd479d541019c2f32395046b8fbca7e1dca218b9b5414975be49942c3536298e9cc939e*1*0*8*24*2a74*882a*537af57c30fd9fd4b3eefa9ce55b6bff3bbfada237a7c1dace8ebf3bb0de107426211da3*1*0*8*24*2a74*882a*5f406b4858d3489fd4a6a6788798ac9b924b5d0ca8b8e5a6371739c9edcfd28c82f75316*1*0*8*24*2a74*882a*1843aca546b2ea68bd844d1e99d4f74d86417248eb48dd5e956270e42a331c18ea13f5ed*1*0*8*24*2a74*882a*aca3d16543bbfb2e5d2659f63802e0fa5b33e0a1f8ae47334019b4f0b6045d3d8eda3af1*1*0*8*24*2a74*882a*fbe0efc9e10ae1fc9b169bd060470bf3e39f09f8d83bebecd5216de02b81e35fe7e7b2f2*1*0*8*24*2a74*882a*537886dbabffbb7cac77deb01dc84760894524e6966183b4478a4ef56f0c657375a235a1*1*0*8*24*eda7*5096*40eb30ef1ddd9b77b894ed46abf199b480f1e5614fde510855f92ae7b8026a11f80e4d5f*$/pkzip2$"; -static const char *SIGNATURE_PKZIP_V1 = "$pkzip$"; -static const char *SIGNATURE_PKZIP_V2 = "$pkzip2$"; - -#define MAX_COMPRESSED_LENGTH 2048 +#define MAX_DATA (16 * 1024 * 1024) -u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } -u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } -u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } -u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } -u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } -u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } -u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } -const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } -u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } -u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } -u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } -u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } -const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } -const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } +// this is required to force mingw to accept the packed attribute +#pragma pack(push,1) -typedef struct pkzip_hash +struct pkzip_hash { u8 data_type_enum; u8 magic_type_enum; @@ -139,16 +125,43 @@ typedef struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_COMPRESSED_LENGTH]; -} pkzip_hash_t; + u8 data[MAX_DATA]; -typedef struct pkzip +} __attribute__((packed)); + +typedef struct pkzip_hash pkzip_hash_t; + +struct pkzip { u8 hash_count; u8 checksum_size; u8 version; + pkzip_hash_t hashes[8]; -} pkzip_t; + +} __attribute__((packed)); + +typedef struct pkzip pkzip_t; + +#pragma pack(pop) + +static const char *SIGNATURE_PKZIP_V1 = "$pkzip$"; +static const char *SIGNATURE_PKZIP_V2 = "$pkzip2$"; + +u32 module_attack_exec (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ATTACK_EXEC; } +u32 module_dgst_pos0 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS0; } +u32 module_dgst_pos1 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS1; } +u32 module_dgst_pos2 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS2; } +u32 module_dgst_pos3 (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_POS3; } +u32 module_dgst_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return DGST_SIZE; } +u32 module_hash_category (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_CATEGORY; } +const char *module_hash_name (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return HASH_NAME; } +u64 module_kern_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return KERN_TYPE; } +u32 module_opti_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTI_TYPE; } +u64 module_opts_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return OPTS_TYPE; } +u32 module_salt_type (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return SALT_TYPE; } +const char *module_st_hash (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_HASH; } +const char *module_st_pass (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { return ST_PASS; } u64 module_esalt_size (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { @@ -217,7 +230,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE p = strtok(NULL, "*"); if (p == NULL) return PARSER_HASH_LENGTH; pkzip->hashes[i].uncompressed_length = strtoul(p, NULL, 16); - if (pkzip->hashes[i].compressed_length > MAX_COMPRESSED_LENGTH) + if (pkzip->hashes[i].compressed_length > MAX_DATA) { return PARSER_TOKEN_LENGTH; } @@ -264,20 +277,15 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE hex_to_binary(p, strlen(p), (char *) &(pkzip->hashes[i].data)); // fake salt - salt->salt_buf[0] ^= pkzip->hashes[i].data[ 3] << 24 | pkzip->hashes[i].data[ 2] << 16 | pkzip->hashes[i].data[ 1] << 8 | pkzip->hashes[i].data[ 0]; - salt->salt_buf[1] ^= pkzip->hashes[i].data[ 7] << 24 | pkzip->hashes[i].data[ 6] << 16 | pkzip->hashes[i].data[ 5] << 8 | pkzip->hashes[i].data[ 4]; - salt->salt_buf[2] ^= pkzip->hashes[i].data[11] << 24 | pkzip->hashes[i].data[10] << 16 | pkzip->hashes[i].data[ 9] << 8 | pkzip->hashes[i].data[ 8]; - salt->salt_buf[3] ^= pkzip->hashes[i].data[15] << 24 | pkzip->hashes[i].data[14] << 16 | pkzip->hashes[i].data[13] << 8 | pkzip->hashes[i].data[ 12]; - - salt->salt_len = 16; - - // fake hash - digest[0] ^= pkzip->hashes[i].data[ 0] << 24 | pkzip->hashes[i].data[ 1] << 16 | pkzip->hashes[i].data[ 2] << 8 | pkzip->hashes[i].data[ 3]; - digest[1] ^= pkzip->hashes[i].data[ 4] << 24 | pkzip->hashes[i].data[ 5] << 16 | pkzip->hashes[i].data[ 6] << 8 | pkzip->hashes[i].data[ 7]; - digest[2] ^= pkzip->hashes[i].data[ 8] << 24 | pkzip->hashes[i].data[ 9] << 16 | pkzip->hashes[i].data[10] << 8 | pkzip->hashes[i].data[11]; - digest[3] ^= pkzip->hashes[i].data[12] << 24 | pkzip->hashes[i].data[13] << 16 | pkzip->hashes[i].data[14] << 8 | pkzip->hashes[i].data[15]; + u32 *ptr = (u32 *) pkzip->hashes[i].data; + + salt->salt_buf[i] = ptr[0]; + + if (i == 0) digest[i] = pkzip->hashes[i].checksum_from_crc; } + salt->salt_len = pkzip->hash_count << 2; + return (PARSER_OK); } @@ -358,10 +366,11 @@ void module_init (module_ctx_t *module_ctx) module_ctx->module_hash_binary_count = MODULE_DEFAULT; module_ctx->module_hash_binary_parse = MODULE_DEFAULT; module_ctx->module_hash_binary_save = MODULE_DEFAULT; - module_ctx->module_hash_decode_outfile = MODULE_DEFAULT; + module_ctx->module_hash_decode_potfile = MODULE_DEFAULT; module_ctx->module_hash_decode_zero_hash = MODULE_DEFAULT; module_ctx->module_hash_decode = module_hash_decode; module_ctx->module_hash_encode_status = MODULE_DEFAULT; + module_ctx->module_hash_encode_potfile = MODULE_DEFAULT; module_ctx->module_hash_encode = module_hash_encode; module_ctx->module_hash_init_selftest = MODULE_DEFAULT; module_ctx->module_hash_mode = MODULE_DEFAULT; @@ -386,6 +395,7 @@ void module_init (module_ctx_t *module_ctx) module_ctx->module_opts_type = module_opts_type; module_ctx->module_outfile_check_disable = MODULE_DEFAULT; module_ctx->module_outfile_check_nocomp = MODULE_DEFAULT; + module_ctx->module_potfile_custom_check = MODULE_DEFAULT; module_ctx->module_potfile_disable = MODULE_DEFAULT; module_ctx->module_potfile_keep_all_hashes = MODULE_DEFAULT; module_ctx->module_pwdump_column = MODULE_DEFAULT; From fe61813af46fe7c867536488dcddd84d26ca3893 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Tue, 14 May 2019 10:34:22 +0200 Subject: [PATCH 08/19] remove unused digest variable --- src/modules/module_17210.c | 2 -- src/modules/module_17230.c | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/modules/module_17210.c b/src/modules/module_17210.c index eae85153f..64f235991 100644 --- a/src/modules/module_17210.c +++ b/src/modules/module_17210.c @@ -293,8 +293,6 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) { - const u32 *digest = (const u32 *) digest_buf; - const pkzip_t *pkzip = (const pkzip_t *) esalt_buf; int out_len = 0; diff --git a/src/modules/module_17230.c b/src/modules/module_17230.c index 1861cae65..d9f3ebbfd 100644 --- a/src/modules/module_17230.c +++ b/src/modules/module_17230.c @@ -291,8 +291,6 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) { - const u32 *digest = (const u32 *) digest_buf; - const pkzip_t *pkzip = (const pkzip_t *) esalt_buf; int out_len = 0; From d5418c25c5fc329b10a890c4a534f52db109e6af Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Tue, 14 May 2019 10:34:40 +0200 Subject: [PATCH 09/19] remove unused digest variable --- src/modules/module_17220.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/module_17220.c b/src/modules/module_17220.c index 4253a73ce..80f2a1bcb 100644 --- a/src/modules/module_17220.c +++ b/src/modules/module_17220.c @@ -290,8 +290,6 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const void *digest_buf, MAYBE_UNUSED const salt_t *salt, MAYBE_UNUSED const void *esalt_buf, MAYBE_UNUSED const void *hook_salt_buf, MAYBE_UNUSED const hashinfo_t *hash_info, char *line_buf, MAYBE_UNUSED const int line_size) { - const u32 *digest = (const u32 *) digest_buf; - const pkzip_t *pkzip = (const pkzip_t *) esalt_buf; int out_len = 0; From e300fe0d637f8812781500cec2a407bfe9b976ac Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Tue, 14 May 2019 13:41:40 +0200 Subject: [PATCH 10/19] fixes to avoid crashing on gpu on multiple inner loops --- OpenCL/inc_zip_inflate.cl | 22 +++++++++--------- OpenCL/m17220_a3-pure.cl | 46 ++++++++++++++++++-------------------- src/modules/module_17220.c | 2 +- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/OpenCL/inc_zip_inflate.cl b/OpenCL/inc_zip_inflate.cl index 9f0b86d0e..cd10fe077 100644 --- a/OpenCL/inc_zip_inflate.cl +++ b/OpenCL/inc_zip_inflate.cl @@ -180,7 +180,7 @@ typedef int mz_bool; typedef mz_uint64 tinfl_bit_buf_t; -void memcpy(void *dest, const void *src, size_t n){ +void memcpy(void *dest, const void *src, u32 n){ char *csrc = (char *)src; char *cdest = (char *)dest; for (int i=0; i 0) { *dst = (u8) c; @@ -206,7 +206,7 @@ void *memset(void *s, int c, u32 len){ #define TINFL_LZ_DICT_SIZE 32768 #define TINFL_MEMCPY(d, s, l) memcpy(d, s, l) #define TINFL_MEMCPY_G(d, s, l, p) memcpy_g(d, s, l, p) -#define TINFL_MEMSET(p, c, l) memset(p, c, l) +#define TINFL_MEMSET(p, c, l) memset(p, c, (u32)l) #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj)) #define TINFL_CR_FINISH } @@ -418,7 +418,7 @@ typedef struct typedef struct mz_stream_s { - __global const unsigned char *next_in; /* pointer to next byte to read */ + GLOBAL_AS const unsigned char *next_in; /* pointer to next byte to read */ unsigned int avail_in; /* number of bytes available at next_in */ mz_ulong total_in; /* total number of bytes consumed so far */ @@ -427,7 +427,7 @@ typedef struct mz_stream_s mz_ulong total_out; /* total number of bytes produced so far */ char *msg; /* error msg (unused) */ - struct inflate_state *state; /* internal state, allocated by zalloc/zfree */ + inflate_state *state; /* internal state, allocated by zalloc/zfree */ void *opaque; /* heap alloc function user pointer */ @@ -472,15 +472,15 @@ const mz_uint8 pIn_xor_byte (const mz_uint8 c, mz_streamp pStream) } -void memcpy_g(void *dest, __global const void *src, size_t n, mz_streamp pStream){ - __global char *csrc = (__global char *)src; +void memcpy_g(void *dest, GLOBAL_AS const void *src, size_t n, mz_streamp pStream){ + GLOBAL_AS char *csrc = (GLOBAL_AS char *)src; char *cdest = (char *)dest; for (int i=0; ireserved = 0; //pStream->state = (struct mz_internal_state *)pDecomp; - pStream->state = (struct inflate_state *) pDecomp; + pStream->state = (inflate_state *) pDecomp; tinfl_init(&pDecomp->m_decomp); pDecomp->m_dict_ofs = 0; diff --git a/OpenCL/m17220_a3-pure.cl b/OpenCL/m17220_a3-pure.cl index 682d5562b..f92675d47 100644 --- a/OpenCL/m17220_a3-pure.cl +++ b/OpenCL/m17220_a3-pure.cl @@ -87,6 +87,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #include "inc_vendor.h" #include "inc_types.h" +#include "inc_platform.cl" #include "inc_common.cl" #include "inc_simd.cl" @@ -129,7 +130,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -227,7 +228,7 @@ typedef struct { u16 val; /* offset in table or code value */ } code; -CONSTANT_AS code lenfix[512] = { +CONSTANT_VK code lenfix[512] = { {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, @@ -304,7 +305,7 @@ CONSTANT_AS code lenfix[512] = { {0,9,255} }; -CONSTANT_AS code distfix[32] = { +CONSTANT_VK code distfix[32] = { {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, @@ -538,14 +539,14 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -604,13 +605,11 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) for (u32 idx = 0; idx < hash_count; idx++) { - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - u32x key0 = key0init; u32x key1 = key1init; u32x key2 = key2init; - next = data_ptr[0]; + next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -628,7 +627,7 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[1]; + next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -646,7 +645,7 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[2]; + next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -672,7 +671,7 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) u8 tmp[TMPSIZ]; - next = data_ptr[3]; + next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -697,7 +696,7 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) for (int i = 16; i < 36; i += 4) { - next = data_ptr[i / 4]; + next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -734,7 +733,7 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array @@ -805,14 +804,14 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -871,13 +870,11 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) for (u32 idx = 0; idx < hash_count; idx++) { - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - u32x key0 = key0init; u32x key1 = key1init; u32x key2 = key2init; - next = data_ptr[0]; + next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -895,7 +892,7 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[1]; + next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -913,7 +910,7 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[2]; + next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -939,7 +936,7 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) u8 tmp[TMPSIZ]; - next = data_ptr[3]; + next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -964,7 +961,7 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) for (int i = 16; i < 36; i += 4) { - next = data_ptr[i / 4]; + next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -990,7 +987,8 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; - if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1){ + if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) + { continue; // so far everything matches for this hash, but it's only a partial one, so we need to continue with the next one } @@ -1000,7 +998,7 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) infstream.opaque = Z_NULL; infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array diff --git a/src/modules/module_17220.c b/src/modules/module_17220.c index 80f2a1bcb..f6fe0d12c 100644 --- a/src/modules/module_17220.c +++ b/src/modules/module_17220.c @@ -125,7 +125,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); From 2434380da2c7b1af1233f6b22034e44abeb5390e Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Tue, 14 May 2019 14:00:18 +0200 Subject: [PATCH 11/19] fixed printing of hash for module 17220 and 17230 using the u32 data array --- src/modules/module_17220.c | 12 ++++++++++-- src/modules/module_17230.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/modules/module_17220.c b/src/modules/module_17220.c index f6fe0d12c..989c509ee 100644 --- a/src/modules/module_17220.c +++ b/src/modules/module_17220.c @@ -308,6 +308,10 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE for (int cnt = 0; cnt < pkzip->hash_count; cnt++) { + if (cnt > 0) + { + out_len += sprintf (line_buf + out_len, "*"); + } out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hashes[cnt].data_type_enum, pkzip->hashes[cnt].magic_type_enum); if (pkzip->hashes[cnt].data_type_enum > 1) { @@ -320,9 +324,13 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE out_len += sprintf (line_buf + out_len, "%x*", pkzip->hashes[cnt].checksum_from_timestamp); } - for (u32 i = 0; i < pkzip->hashes[cnt].data_length; i++) + for (u32 i = 0; i < pkzip->hashes[cnt].data_length / 4; i++) + { + out_len += sprintf (line_buf + out_len, "%08x", byte_swap_32 (pkzip->hashes[cnt].data[i])); + } + for (u32 i = 0; i < pkzip->hashes[cnt].data_length % 4; i++) { - out_len += sprintf (line_buf + out_len, "%02x", pkzip->hashes[cnt].data[i]); + out_len += sprintf (line_buf + out_len, "%02x", (pkzip->hashes[cnt].data[pkzip->hashes[cnt].data_length / 4] >> i*8) & 0xff); } } diff --git a/src/modules/module_17230.c b/src/modules/module_17230.c index d9f3ebbfd..41d9270a0 100644 --- a/src/modules/module_17230.c +++ b/src/modules/module_17230.c @@ -309,6 +309,10 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE for (int cnt = 0; cnt < pkzip->hash_count; cnt++) { + if (cnt > 0) + { + out_len += sprintf (line_buf + out_len, "*"); + } out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hashes[cnt].data_type_enum, pkzip->hashes[cnt].magic_type_enum); if (pkzip->hashes[cnt].data_type_enum > 1) { @@ -321,9 +325,13 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE out_len += sprintf (line_buf + out_len, "%x*", pkzip->hashes[cnt].checksum_from_timestamp); } - for (u32 i = 0; i < pkzip->hashes[cnt].data_length; i++) + for (u32 i = 0; i < pkzip->hashes[cnt].data_length / 4; i++) + { + out_len += sprintf (line_buf + out_len, "%08x", byte_swap_32 (pkzip->hashes[cnt].data[i])); + } + for (u32 i = 0; i < pkzip->hashes[cnt].data_length % 4; i++) { - out_len += sprintf (line_buf + out_len, "%02x", pkzip->hashes[cnt].data[i]); + out_len += sprintf (line_buf + out_len, "%02x", (pkzip->hashes[cnt].data[pkzip->hashes[cnt].data_length / 4] >> i*8) & 0xff); } } From ff718cf53f585d870010a79f42cc523b5c409198 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Tue, 14 May 2019 14:08:11 +0200 Subject: [PATCH 12/19] all pkzip modules use u32 to store the hash data and use appropriate printing --- src/modules/module_17200.c | 12 ++++++++---- src/modules/module_17210.c | 35 ++++++++++++++++++----------------- src/modules/module_17230.c | 4 ++-- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/modules/module_17200.c b/src/modules/module_17200.c index 516a7c9e5..fff5e9c82 100644 --- a/src/modules/module_17200.c +++ b/src/modules/module_17200.c @@ -125,7 +125,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -227,7 +227,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE p = strtok(NULL, "*"); if (p == NULL) return PARSER_HASH_LENGTH; pkzip->hash.uncompressed_length = strtoul(p, NULL, 16); - if (pkzip->hash.compressed_length > MAX_DATA) + if (pkzip->hash.compressed_length > MAX_DATA * 4) { return PARSER_TOKEN_LENGTH; } @@ -321,9 +321,13 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE out_len += sprintf (line_buf + out_len, "%x*", pkzip->hash.checksum_from_timestamp); } - for (u32 i = 0; i < pkzip->hash.data_length; i++) + for (u32 i = 0; i < pkzip->hash.data_length / 4; i++) { - out_len += sprintf (line_buf + out_len, "%02x", pkzip->hash.data[i]); + out_len += sprintf (line_buf + out_len, "%08x", byte_swap_32 (pkzip->hash.data[i])); + } + for (u32 i = 0; i < pkzip->hash.data_length % 4; i++) + { + out_len += sprintf (line_buf + out_len, "%02x", (pkzip->hash.data[pkzip->hash.data_length / 4] >> i*8) & 0xff); } if (pkzip->version == 1) diff --git a/src/modules/module_17210.c b/src/modules/module_17210.c index 64f235991..3ef59834e 100644 --- a/src/modules/module_17210.c +++ b/src/modules/module_17210.c @@ -125,7 +125,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -227,7 +227,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE p = strtok(NULL, "*"); if (p == NULL) return PARSER_HASH_LENGTH; pkzip->hash.uncompressed_length = strtoul(p, NULL, 16); - if (pkzip->hash.uncompressed_length > MAX_DATA) + if (pkzip->hash.uncompressed_length > MAX_DATA * 4) { return PARSER_TOKEN_LENGTH; } @@ -309,24 +309,25 @@ int module_hash_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE } out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hash_count, pkzip->checksum_size); - for (int cnt = 0; cnt < pkzip->hash_count; cnt++) + out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hash.data_type_enum, pkzip->hash.magic_type_enum); + if (pkzip->hash.data_type_enum > 1) { - out_len += sprintf (line_buf + out_len, "%i*%i*", pkzip->hash.data_type_enum, pkzip->hash.magic_type_enum); - if (pkzip->hash.data_type_enum > 1) - { - out_len += sprintf (line_buf + out_len, "%x*%x*%x*%x*%x*", pkzip->hash.compressed_length, pkzip->hash.uncompressed_length, pkzip->hash.crc32, pkzip->hash.offset, pkzip->hash.additional_offset); - } + out_len += sprintf (line_buf + out_len, "%x*%x*%x*%x*%x*", pkzip->hash.compressed_length, pkzip->hash.uncompressed_length, pkzip->hash.crc32, pkzip->hash.offset, pkzip->hash.additional_offset); + } - out_len += sprintf (line_buf + out_len, "%i*%x*%x*", pkzip->hash.compression_type, pkzip->hash.data_length, pkzip->hash.checksum_from_crc); - if (pkzip->version == 2) - { - out_len += sprintf (line_buf + out_len, "%x*", pkzip->hash.checksum_from_timestamp); - } + out_len += sprintf (line_buf + out_len, "%i*%x*%x*", pkzip->hash.compression_type, pkzip->hash.data_length, pkzip->hash.checksum_from_crc); + if (pkzip->version == 2) + { + out_len += sprintf (line_buf + out_len, "%x*", pkzip->hash.checksum_from_timestamp); + } - for (u32 i = 0; i < pkzip->hash.data_length; i++) - { - out_len += sprintf (line_buf + out_len, "%02x", pkzip->hash.data[i]); - } + for (u32 i = 0; i < pkzip->hash.data_length / 4; i++) + { + out_len += sprintf (line_buf + out_len, "%08x", byte_swap_32 (pkzip->hash.data[i])); + } + for (u32 i = 0; i < pkzip->hash.data_length % 4; i++) + { + out_len += sprintf (line_buf + out_len, "%02x", (pkzip->hash.data[pkzip->hash.data_length / 4] >> i*8) & 0xff); } if (pkzip->version == 1) diff --git a/src/modules/module_17230.c b/src/modules/module_17230.c index 41d9270a0..ed01166e5 100644 --- a/src/modules/module_17230.c +++ b/src/modules/module_17230.c @@ -125,7 +125,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -230,7 +230,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE p = strtok(NULL, "*"); if (p == NULL) return PARSER_HASH_LENGTH; pkzip->hashes[i].uncompressed_length = strtoul(p, NULL, 16); - if (pkzip->hashes[i].compressed_length > MAX_DATA) + if (pkzip->hashes[i].compressed_length > MAX_DATA * 4) { return PARSER_TOKEN_LENGTH; } From b29019ae75c977df3b129663b071f21108323583 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Tue, 14 May 2019 14:21:41 +0200 Subject: [PATCH 13/19] updated m17200 to be cuda compatible --- OpenCL/m17200_a0-pure.cl | 43 +++++++++++++++++++--------------------- OpenCL/m17200_a1-pure.cl | 43 +++++++++++++++++++--------------------- OpenCL/m17200_a3-pure.cl | 43 +++++++++++++++++++--------------------- 3 files changed, 60 insertions(+), 69 deletions(-) diff --git a/OpenCL/m17200_a0-pure.cl b/OpenCL/m17200_a0-pure.cl index 84b1c85d7..bf212a813 100644 --- a/OpenCL/m17200_a0-pure.cl +++ b/OpenCL/m17200_a0-pure.cl @@ -87,6 +87,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #include "inc_vendor.h" #include "inc_types.h" +#include "inc_platform.cl" #include "inc_common.cl" #include "inc_simd.cl" #include "inc_rp.h" @@ -131,7 +132,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -231,7 +232,7 @@ typedef struct } code; -CONSTANT_AS code lenfix[512] = { +CONSTANT_VK code lenfix[512] = { {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, @@ -308,7 +309,7 @@ CONSTANT_AS code lenfix[512] = { {0,9,255} }; -CONSTANT_AS code distfix[32] = { +CONSTANT_VK code distfix[32] = { {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, @@ -528,7 +529,7 @@ DECLSPEC int check_inflate_code1 (u8 *next, int left) } } -__kernel void m17200_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +KERNEL_FQ void m17200_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) { /** * modifier @@ -542,25 +543,23 @@ __kernel void m17200_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - - LOCAL_AS u32 l_data[MAX_LOCAL]; + LOCAL_VK u32 l_data[MAX_LOCAL]; for (u64 i = lid; i < MAX_LOCAL; i += lsz) { - l_data[i] = data_ptr[i]; + l_data[i] = esalt_bufs[digests_offset].hash.data[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -734,8 +733,8 @@ __kernel void m17200_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) inflate_state pStream; infstream.opaque = Z_NULL; - infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input - infstream.next_in = esalt_bufs[digests_offset].hash.data + 12; // input char array + infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hash.data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array @@ -768,7 +767,7 @@ __kernel void m17200_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) } } -__kernel void m17200_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +KERNEL_FQ void m17200_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) { /** * modifier @@ -782,25 +781,23 @@ __kernel void m17200_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); - - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; + SYNC_THREADS(); - LOCAL_AS u32 l_data[MAX_LOCAL]; + LOCAL_VK u32 l_data[MAX_LOCAL]; for (u64 i = lid; i < MAX_LOCAL; i += lsz) { - l_data[i] = data_ptr[i]; + l_data[i] = esalt_bufs[digests_offset].hash.data[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -962,8 +959,8 @@ __kernel void m17200_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) inflate_state pStream; infstream.opaque = Z_NULL; - infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input - infstream.next_in = esalt_bufs[digests_offset].hash.data + 12; // input char array + infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hash.data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array diff --git a/OpenCL/m17200_a1-pure.cl b/OpenCL/m17200_a1-pure.cl index 3d8aaf662..08c4beeb1 100644 --- a/OpenCL/m17200_a1-pure.cl +++ b/OpenCL/m17200_a1-pure.cl @@ -87,6 +87,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #include "inc_vendor.h" #include "inc_types.h" +#include "inc_platform.cl" #include "inc_common.cl" #include "inc_simd.cl" @@ -129,7 +130,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -229,7 +230,7 @@ typedef struct } code; -CONSTANT_AS code lenfix[512] = { +CONSTANT_VK code lenfix[512] = { {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, @@ -306,7 +307,7 @@ CONSTANT_AS code lenfix[512] = { {0,9,255} }; -CONSTANT_AS code distfix[32] = { +CONSTANT_VK code distfix[32] = { {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, @@ -526,7 +527,7 @@ DECLSPEC int check_inflate_code1 (u8 *next, int left) } } -__kernel void m17200_sxx (KERN_ATTR_ESALT (pkzip_t)) +KERNEL_FQ void m17200_sxx (KERN_ATTR_ESALT (pkzip_t)) { /** * modifier @@ -540,25 +541,23 @@ __kernel void m17200_sxx (KERN_ATTR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - - LOCAL_AS u32 l_data[MAX_LOCAL]; + LOCAL_VK u32 l_data[MAX_LOCAL]; for (u64 i = lid; i < MAX_LOCAL; i += lsz) { - l_data[i] = data_ptr[i]; + l_data[i] = esalt_bufs[digests_offset].hash.data[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -736,8 +735,8 @@ __kernel void m17200_sxx (KERN_ATTR_ESALT (pkzip_t)) inflate_state pStream; infstream.opaque = Z_NULL; - infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input - infstream.next_in = esalt_bufs[digests_offset].hash.data + 12; // input char array + infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hash.data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array @@ -770,7 +769,7 @@ __kernel void m17200_sxx (KERN_ATTR_ESALT (pkzip_t)) } } -__kernel void m17200_mxx (KERN_ATTR_ESALT (pkzip_t)) +KERNEL_FQ void m17200_mxx (KERN_ATTR_ESALT (pkzip_t)) { /** * modifier @@ -784,25 +783,23 @@ __kernel void m17200_mxx (KERN_ATTR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); - - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; + SYNC_THREADS(); - LOCAL_AS u32 l_data[MAX_LOCAL]; + LOCAL_VK u32 l_data[MAX_LOCAL]; for (u64 i = lid; i < MAX_LOCAL; i += lsz) { - l_data[i] = data_ptr[i]; + l_data[i] = esalt_bufs[digests_offset].hash.data[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -968,8 +965,8 @@ __kernel void m17200_mxx (KERN_ATTR_ESALT (pkzip_t)) inflate_state pStream; infstream.opaque = Z_NULL; - infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input - infstream.next_in = esalt_bufs[digests_offset].hash.data + 12; // input char array + infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hash.data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array diff --git a/OpenCL/m17200_a3-pure.cl b/OpenCL/m17200_a3-pure.cl index 4f0c278a3..60e01bfbc 100644 --- a/OpenCL/m17200_a3-pure.cl +++ b/OpenCL/m17200_a3-pure.cl @@ -87,6 +87,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #include "inc_vendor.h" #include "inc_types.h" +#include "inc_platform.cl" #include "inc_common.cl" #include "inc_simd.cl" @@ -129,7 +130,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -229,7 +230,7 @@ typedef struct } code; -CONSTANT_AS code lenfix[512] = +CONSTANT_VK code lenfix[512] = { {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, @@ -307,7 +308,7 @@ CONSTANT_AS code lenfix[512] = {0,9,255} }; -CONSTANT_AS code distfix[32] = +CONSTANT_VK code distfix[32] = { {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, @@ -527,7 +528,7 @@ DECLSPEC int check_inflate_code1 (u8 *next, int left) } } -__kernel void m17200_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +KERNEL_FQ void m17200_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) { /** * modifier @@ -541,25 +542,23 @@ __kernel void m17200_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - - LOCAL_AS u32 l_data[MAX_LOCAL]; + LOCAL_VK u32 l_data[MAX_LOCAL]; for (u64 i = lid; i < MAX_LOCAL; i += lsz) { - l_data[i] = data_ptr[i]; + l_data[i] = esalt_bufs[digests_offset].hash.data[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -749,8 +748,8 @@ __kernel void m17200_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) inflate_state pStream; infstream.opaque = Z_NULL; - infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input - infstream.next_in = esalt_bufs[digests_offset].hash.data + 12; // input char array + infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hash.data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array @@ -783,7 +782,7 @@ __kernel void m17200_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) } } -__kernel void m17200_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +KERNEL_FQ void m17200_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) { /** * modifier @@ -797,25 +796,23 @@ __kernel void m17200_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); - - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; + SYNC_THREADS(); - LOCAL_AS u32 l_data[MAX_LOCAL]; + LOCAL_VK u32 l_data[MAX_LOCAL]; for (u64 i = lid; i < MAX_LOCAL; i += lsz) { - l_data[i] = data_ptr[i]; + l_data[i] = esalt_bufs[digests_offset].hash.data[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -993,8 +990,8 @@ __kernel void m17200_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) inflate_state pStream; infstream.opaque = Z_NULL; - infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input - infstream.next_in = esalt_bufs[digests_offset].hash.data + 12; // input char array + infstream.avail_in = esalt_bufs[digests_offset].hash.data_length - 12; // size of input + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hash.data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array From c9c7261a050fb7711c7c0d3e46073b9505342c57 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Tue, 14 May 2019 14:38:55 +0200 Subject: [PATCH 14/19] updated m17210 to be cuda compatible --- OpenCL/m17210_a0-pure.cl | 31 ++++++++++++++----------------- OpenCL/m17210_a1-pure.cl | 31 ++++++++++++++----------------- OpenCL/m17210_a3-pure.cl | 31 ++++++++++++++----------------- 3 files changed, 42 insertions(+), 51 deletions(-) diff --git a/OpenCL/m17210_a0-pure.cl b/OpenCL/m17210_a0-pure.cl index 8308d10ef..e6f4515ad 100644 --- a/OpenCL/m17210_a0-pure.cl +++ b/OpenCL/m17210_a0-pure.cl @@ -87,6 +87,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #include "inc_vendor.h" #include "inc_types.h" +#include "inc_platform.cl" #include "inc_common.cl" #include "inc_simd.cl" #include "inc_rp.h" @@ -131,7 +132,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -219,7 +220,7 @@ CONSTANT_AS u32a crc32tab[256] = 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -__kernel void m17210_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +KERNEL_FQ void m17210_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) { /** * modifier @@ -233,25 +234,23 @@ __kernel void m17210_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - - LOCAL_AS u32 l_data[MAX_LOCAL]; + LOCAL_VK u32 l_data[MAX_LOCAL]; for (u64 i = lid; i < MAX_LOCAL; i += lsz) { - l_data[i] = data_ptr[i]; + l_data[i] = esalt_bufs[digests_offset].hash.data[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -428,7 +427,7 @@ __kernel void m17210_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) } } -__kernel void m17210_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +KERNEL_FQ void m17210_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) { /** * modifier @@ -442,25 +441,23 @@ __kernel void m17210_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); - - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; + SYNC_THREADS(); - LOCAL_AS u32 l_data[MAX_LOCAL]; + LOCAL_VK u32 l_data[MAX_LOCAL]; for (u64 i = lid; i < MAX_LOCAL; i += lsz) { - l_data[i] = data_ptr[i]; + l_data[i] = esalt_bufs[digests_offset].hash.data[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; diff --git a/OpenCL/m17210_a1-pure.cl b/OpenCL/m17210_a1-pure.cl index 4e726f759..4540b20b2 100644 --- a/OpenCL/m17210_a1-pure.cl +++ b/OpenCL/m17210_a1-pure.cl @@ -87,6 +87,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #include "inc_vendor.h" #include "inc_types.h" +#include "inc_platform.cl" #include "inc_common.cl" #include "inc_simd.cl" @@ -129,7 +130,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -217,7 +218,7 @@ CONSTANT_AS u32a crc32tab[256] = 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -__kernel void m17210_sxx (KERN_ATTR_ESALT (pkzip_t)) +KERNEL_FQ void m17210_sxx (KERN_ATTR_ESALT (pkzip_t)) { /** * modifier @@ -231,25 +232,23 @@ __kernel void m17210_sxx (KERN_ATTR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - - LOCAL_AS u32 l_data[MAX_LOCAL]; + LOCAL_VK u32 l_data[MAX_LOCAL]; for (u64 i = lid; i < MAX_LOCAL; i += lsz) { - l_data[i] = data_ptr[i]; + l_data[i] = esalt_bufs[digests_offset].hash.data[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -428,7 +427,7 @@ __kernel void m17210_sxx (KERN_ATTR_ESALT (pkzip_t)) } } -__kernel void m17210_mxx (KERN_ATTR_ESALT (pkzip_t)) +KERNEL_FQ void m17210_mxx (KERN_ATTR_ESALT (pkzip_t)) { /** * modifier @@ -442,25 +441,23 @@ __kernel void m17210_mxx (KERN_ATTR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); - - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; + SYNC_THREADS(); - LOCAL_AS u32 l_data[MAX_LOCAL]; + LOCAL_VK u32 l_data[MAX_LOCAL]; for (u64 i = lid; i < MAX_LOCAL; i += lsz) { - l_data[i] = data_ptr[i]; + l_data[i] = esalt_bufs[digests_offset].hash.data[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; diff --git a/OpenCL/m17210_a3-pure.cl b/OpenCL/m17210_a3-pure.cl index c15fb57db..e5796ecab 100644 --- a/OpenCL/m17210_a3-pure.cl +++ b/OpenCL/m17210_a3-pure.cl @@ -87,6 +87,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #include "inc_vendor.h" #include "inc_types.h" +#include "inc_platform.cl" #include "inc_common.cl" #include "inc_simd.cl" @@ -129,7 +130,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -217,7 +218,7 @@ CONSTANT_AS u32a crc32tab[256] = 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -__kernel void m17210_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +KERNEL_FQ void m17210_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) { /** * modifier @@ -231,25 +232,23 @@ __kernel void m17210_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; - - LOCAL_AS u32 l_data[MAX_LOCAL]; + LOCAL_VK u32 l_data[MAX_LOCAL]; for (u64 i = lid; i < MAX_LOCAL; i += lsz) { - l_data[i] = data_ptr[i]; + l_data[i] = esalt_bufs[digests_offset].hash.data[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -440,7 +439,7 @@ __kernel void m17210_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) } } -__kernel void m17210_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +KERNEL_FQ void m17210_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) { /** * modifier @@ -454,25 +453,23 @@ __kernel void m17210_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); - - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hash.data; + SYNC_THREADS(); - LOCAL_AS u32 l_data[MAX_LOCAL]; + LOCAL_VK u32 l_data[MAX_LOCAL]; for (u64 i = lid; i < MAX_LOCAL; i += lsz) { - l_data[i] = data_ptr[i]; + l_data[i] = esalt_bufs[digests_offset].hash.data[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; From 8d1e737d60414b5262ff19aa64c6a452a035d90e Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Tue, 14 May 2019 14:47:48 +0200 Subject: [PATCH 15/19] updated m17220 to be cuda compatible --- OpenCL/m17220_a0-pure.cl | 51 +++++++++++++++++++--------------------- OpenCL/m17220_a1-pure.cl | 51 +++++++++++++++++++--------------------- OpenCL/m17220_a3-pure.cl | 12 +++++----- 3 files changed, 54 insertions(+), 60 deletions(-) diff --git a/OpenCL/m17220_a0-pure.cl b/OpenCL/m17220_a0-pure.cl index 13bfbe70e..430060525 100644 --- a/OpenCL/m17220_a0-pure.cl +++ b/OpenCL/m17220_a0-pure.cl @@ -87,6 +87,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #include "inc_vendor.h" #include "inc_types.h" +#include "inc_platform.cl" #include "inc_common.cl" #include "inc_simd.cl" #include "inc_rp.h" @@ -131,7 +132,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -229,7 +230,7 @@ typedef struct { u16 val; /* offset in table or code value */ } code; -CONSTANT_AS code lenfix[512] = { +CONSTANT_VK code lenfix[512] = { {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, @@ -306,7 +307,7 @@ CONSTANT_AS code lenfix[512] = { {0,9,255} }; -CONSTANT_AS code distfix[32] = { +CONSTANT_VK code distfix[32] = { {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, @@ -526,7 +527,7 @@ DECLSPEC int check_inflate_code1 (u8 *next, int left) } } -__kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +KERNEL_FQ void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) { /** * modifier @@ -540,14 +541,14 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -592,13 +593,11 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) for (u32 idx = 0; idx < hash_count; idx++) { - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - u32x key0 = key0init; u32x key1 = key1init; u32x key2 = key2init; - next = data_ptr[0]; + next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -616,7 +615,7 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[1]; + next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -634,7 +633,7 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[2]; + next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -660,7 +659,7 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) u8 tmp[TMPSIZ]; - next = data_ptr[3]; + next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -685,7 +684,7 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) for (int i = 16; i < 36; i += 4) { - next = data_ptr[i / 4]; + next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -721,8 +720,8 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) inflate_state pStream; infstream.opaque = Z_NULL; - infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array @@ -779,7 +778,7 @@ __kernel void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) } } -__kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +KERNEL_FQ void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) { /** * modifier @@ -793,14 +792,14 @@ __kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -845,13 +844,11 @@ __kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) for (u32 idx = 0; idx < hash_count; idx++) { - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - u32x key0 = key0init; u32x key1 = key1init; u32x key2 = key2init; - next = data_ptr[0]; + next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -869,7 +866,7 @@ __kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[1]; + next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -887,7 +884,7 @@ __kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[2]; + next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -913,7 +910,7 @@ __kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) u8 tmp[TMPSIZ]; - next = data_ptr[3]; + next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -938,7 +935,7 @@ __kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) for (int i = 16; i < 36; i += 4) { - next = data_ptr[i / 4]; + next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -974,8 +971,8 @@ __kernel void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) inflate_state pStream; infstream.opaque = Z_NULL; - infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array diff --git a/OpenCL/m17220_a1-pure.cl b/OpenCL/m17220_a1-pure.cl index 68c3c2f7c..0c0cec887 100644 --- a/OpenCL/m17220_a1-pure.cl +++ b/OpenCL/m17220_a1-pure.cl @@ -87,6 +87,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #include "inc_vendor.h" #include "inc_types.h" +#include "inc_platform.cl" #include "inc_common.cl" #include "inc_simd.cl" @@ -129,7 +130,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -227,7 +228,7 @@ typedef struct { u16 val; /* offset in table or code value */ } code; -CONSTANT_AS code lenfix[512] = { +CONSTANT_VK code lenfix[512] = { {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, @@ -304,7 +305,7 @@ CONSTANT_AS code lenfix[512] = { {0,9,255} }; -CONSTANT_AS code distfix[32] = { +CONSTANT_VK code distfix[32] = { {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, @@ -524,7 +525,7 @@ DECLSPEC int check_inflate_code1 (u8 *next, int left) } } -__kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) +KERNEL_FQ void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) { /** * modifier @@ -538,14 +539,14 @@ __kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -592,13 +593,11 @@ __kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) for (u32 idx = 0; idx < hash_count; idx++) { - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - u32x key0 = key0init2; u32x key1 = key1init2; u32x key2 = key2init2; - next = data_ptr[0]; + next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -616,7 +615,7 @@ __kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[1]; + next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -634,7 +633,7 @@ __kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[2]; + next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -660,7 +659,7 @@ __kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) u8 tmp[TMPSIZ]; - next = data_ptr[3]; + next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -685,7 +684,7 @@ __kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) for (int i = 16; i < 36; i += 4) { - next = data_ptr[i / 4]; + next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -721,8 +720,8 @@ __kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) inflate_state pStream; infstream.opaque = Z_NULL; - infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array @@ -779,7 +778,7 @@ __kernel void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) } } -__kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) +KERNEL_FQ void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) { /** * modifier @@ -793,14 +792,14 @@ __kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -847,13 +846,11 @@ __kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) for (u32 idx = 0; idx < hash_count; idx++) { - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - u32x key0 = key0init2; u32x key1 = key1init2; u32x key2 = key2init2; - next = data_ptr[0]; + next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -871,7 +868,7 @@ __kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[1]; + next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -889,7 +886,7 @@ __kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[2]; + next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -915,7 +912,7 @@ __kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) u8 tmp[TMPSIZ]; - next = data_ptr[3]; + next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -940,7 +937,7 @@ __kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) for (int i = 16; i < 36; i += 4) { - next = data_ptr[i / 4]; + next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -976,8 +973,8 @@ __kernel void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) inflate_state pStream; infstream.opaque = Z_NULL; - infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array diff --git a/OpenCL/m17220_a3-pure.cl b/OpenCL/m17220_a3-pure.cl index f92675d47..73a9b4f84 100644 --- a/OpenCL/m17220_a3-pure.cl +++ b/OpenCL/m17220_a3-pure.cl @@ -525,7 +525,7 @@ DECLSPEC int check_inflate_code1 (u8 *next, int left) } } -__kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +KERNEL_FQ void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) { /** * modifier @@ -732,8 +732,8 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) inflate_state pStream; infstream.opaque = Z_NULL; - infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array @@ -790,7 +790,7 @@ __kernel void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) } } -__kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +KERNEL_FQ void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) { /** * modifier @@ -997,8 +997,8 @@ __kernel void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) inflate_state pStream; infstream.opaque = Z_NULL; - infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input - infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array + infstream.avail_in = esalt_bufs[digests_offset].hashes[idx].data_length - 12; // size of input + infstream.next_in = (GLOBAL_AS u8 *) esalt_bufs[digests_offset].hashes[idx].data + 12; // input char array infstream.avail_out = TMPSIZ; // size of output infstream.next_out = tmp; // output char array From d9e5a86765e67a61682cc0f9e70ae279188462b2 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Tue, 14 May 2019 14:56:37 +0200 Subject: [PATCH 16/19] updated m17230 to be cuda compatible --- OpenCL/m17230_a0-pure.cl | 35 ++++++++++++++++------------------- OpenCL/m17230_a1-pure.cl | 35 ++++++++++++++++------------------- OpenCL/m17230_a3-pure.cl | 35 ++++++++++++++++------------------- 3 files changed, 48 insertions(+), 57 deletions(-) diff --git a/OpenCL/m17230_a0-pure.cl b/OpenCL/m17230_a0-pure.cl index 0d8428b5c..d3b1121ff 100644 --- a/OpenCL/m17230_a0-pure.cl +++ b/OpenCL/m17230_a0-pure.cl @@ -87,6 +87,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #include "inc_vendor.h" #include "inc_types.h" +#include "inc_platform.cl" #include "inc_common.cl" #include "inc_simd.cl" #include "inc_rp.h" @@ -131,7 +132,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -219,7 +220,7 @@ CONSTANT_AS u32a crc32tab[256] = 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -__kernel void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +KERNEL_FQ void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) { /** * modifier @@ -233,14 +234,14 @@ __kernel void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -285,13 +286,11 @@ __kernel void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) for (u32 idx = 0; idx < hash_count; idx++) { - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - u32x key0 = key0init; u32x key1 = key1init; u32x key2 = key2init; - next = data_ptr[0]; + next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -309,7 +308,7 @@ __kernel void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[1]; + next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -327,7 +326,7 @@ __kernel void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[2]; + next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -347,7 +346,7 @@ __kernel void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[3]; + next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -378,7 +377,7 @@ __kernel void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) } } -__kernel void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) +KERNEL_FQ void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) { /** * modifier @@ -392,14 +391,14 @@ __kernel void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -444,13 +443,11 @@ __kernel void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) for (u32 idx = 0; idx < hash_count; idx++) { - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - u32x key0 = key0init; u32x key1 = key1init; u32x key2 = key2init; - next = data_ptr[0]; + next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -468,7 +465,7 @@ __kernel void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[1]; + next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -486,7 +483,7 @@ __kernel void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[2]; + next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -506,7 +503,7 @@ __kernel void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[3]; + next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; diff --git a/OpenCL/m17230_a1-pure.cl b/OpenCL/m17230_a1-pure.cl index 327773f74..2f79da216 100644 --- a/OpenCL/m17230_a1-pure.cl +++ b/OpenCL/m17230_a1-pure.cl @@ -87,6 +87,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #include "inc_vendor.h" #include "inc_types.h" +#include "inc_platform.cl" #include "inc_common.cl" #include "inc_simd.cl" @@ -129,7 +130,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -217,7 +218,7 @@ CONSTANT_AS u32a crc32tab[256] = 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -__kernel void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) +KERNEL_FQ void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) { /** * modifier @@ -231,14 +232,14 @@ __kernel void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -285,13 +286,11 @@ __kernel void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) for (u32 idx = 0; idx < hash_count; idx++) { - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - u32x key0 = key0init2; u32x key1 = key1init2; u32x key2 = key2init2; - next = data_ptr[0]; + next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -309,7 +308,7 @@ __kernel void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[1]; + next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -327,7 +326,7 @@ __kernel void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[2]; + next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -347,7 +346,7 @@ __kernel void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[3]; + next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -378,7 +377,7 @@ __kernel void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) } } -__kernel void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) +KERNEL_FQ void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) { /** * modifier @@ -392,14 +391,14 @@ __kernel void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -446,13 +445,11 @@ __kernel void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) for (u32 idx = 0; idx < hash_count; idx++) { - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - u32x key0 = key0init2; u32x key1 = key1init2; u32x key2 = key2init2; - next = data_ptr[0]; + next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -470,7 +467,7 @@ __kernel void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[1]; + next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -488,7 +485,7 @@ __kernel void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[2]; + next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -508,7 +505,7 @@ __kernel void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[3]; + next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; diff --git a/OpenCL/m17230_a3-pure.cl b/OpenCL/m17230_a3-pure.cl index 2ae2e3d3a..5da181f34 100644 --- a/OpenCL/m17230_a3-pure.cl +++ b/OpenCL/m17230_a3-pure.cl @@ -87,6 +87,7 @@ Related publication: https://scitepress.org/PublicationsDetail.aspx?ID=KLPzPqStp #include "inc_vendor.h" #include "inc_types.h" +#include "inc_platform.cl" #include "inc_common.cl" #include "inc_simd.cl" @@ -129,7 +130,7 @@ struct pkzip_hash u32 data_length; u16 checksum_from_crc; u16 checksum_from_timestamp; - u8 data[MAX_DATA]; + u32 data[MAX_DATA]; } __attribute__((packed)); @@ -217,7 +218,7 @@ CONSTANT_AS u32a crc32tab[256] = 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -__kernel void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +KERNEL_FQ void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) { /** * modifier @@ -231,14 +232,14 @@ __kernel void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -299,13 +300,11 @@ __kernel void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) for (u32 idx = 0; idx < hash_count; idx++) { - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - u32x key0 = key0init; u32x key1 = key1init; u32x key2 = key2init; - next = data_ptr[0]; + next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -323,7 +322,7 @@ __kernel void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[1]; + next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -341,7 +340,7 @@ __kernel void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[2]; + next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -361,7 +360,7 @@ __kernel void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[3]; + next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -392,7 +391,7 @@ __kernel void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) } } -__kernel void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) +KERNEL_FQ void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) { /** * modifier @@ -406,14 +405,14 @@ __kernel void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) * sbox, kbox */ - LOCAL_AS u32 l_crc32tab[256]; + LOCAL_VK u32 l_crc32tab[256]; for (u64 i = lid; i < 256; i += lsz) { l_crc32tab[i] = crc32tab[i]; } - barrier (CLK_LOCAL_MEM_FENCE); + SYNC_THREADS(); if (gid >= gid_max) return; @@ -474,13 +473,11 @@ __kernel void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) for (u32 idx = 0; idx < hash_count; idx++) { - __global u32 *data_ptr = (__global u32 *) esalt_bufs[digests_offset].hashes[idx].data; - u32x key0 = key0init; u32x key1 = key1init; u32x key2 = key2init; - next = data_ptr[0]; + next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -498,7 +495,7 @@ __kernel void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[1]; + next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -516,7 +513,7 @@ __kernel void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[2]; + next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -536,7 +533,7 @@ __kernel void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = data_ptr[3]; + next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; From 06554f5071bfb97ebba3d4ff846aac0c8696f3e0 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Tue, 14 May 2019 15:39:31 +0200 Subject: [PATCH 17/19] applied speed improvements to modes 17220 and 17230 --- OpenCL/m17220_a0-pure.cl | 48 +++++++++++++++++++++++++++++++--------- OpenCL/m17220_a1-pure.cl | 48 +++++++++++++++++++++++++++++++--------- OpenCL/m17220_a3-pure.cl | 39 +++++++++++++++++++++++--------- OpenCL/m17230_a0-pure.cl | 42 ++++++++++++++++++++++++++++------- OpenCL/m17230_a1-pure.cl | 42 ++++++++++++++++++++++++++++------- OpenCL/m17230_a3-pure.cl | 44 ++++++++++++++++++++++++++++-------- 6 files changed, 208 insertions(+), 55 deletions(-) diff --git a/OpenCL/m17220_a0-pure.cl b/OpenCL/m17220_a0-pure.cl index 430060525..4fd6631ee 100644 --- a/OpenCL/m17220_a0-pure.cl +++ b/OpenCL/m17220_a0-pure.cl @@ -550,6 +550,15 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) SYNC_THREADS(); + LOCAL_VK u32 l_data[MAX_LOCAL]; + + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = esalt_bufs[digests_offset].hashes[0].data[i]; + } + + SYNC_THREADS(); + if (gid >= gid_max) return; /** @@ -597,7 +606,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) u32x key1 = key1init; u32x key2 = key2init; - next = esalt_bufs[digests_offset].hashes[idx].data[0]; + if (idx == 0) next = l_data[0]; + else next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -615,7 +625,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[1]; + if (idx == 0) next = l_data[1]; + else next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -633,7 +644,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[2]; + if (idx == 0) next = l_data[2]; + else next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -659,7 +671,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) u8 tmp[TMPSIZ]; - next = esalt_bufs[digests_offset].hashes[idx].data[3]; + if (idx == 0) next = l_data[3]; + else next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -684,7 +697,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) for (int i = 16; i < 36; i += 4) { - next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; + if (idx == 0) next = l_data[i / 4]; + else next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -801,6 +815,15 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) SYNC_THREADS(); + LOCAL_VK u32 l_data[MAX_LOCAL]; + + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = esalt_bufs[digests_offset].hashes[0].data[i]; + } + + SYNC_THREADS(); + if (gid >= gid_max) return; /** @@ -848,7 +871,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) u32x key1 = key1init; u32x key2 = key2init; - next = esalt_bufs[digests_offset].hashes[idx].data[0]; + if (idx == 0) next = l_data[0]; + else next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -866,7 +890,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[1]; + if (idx == 0) next = l_data[1]; + else next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -884,7 +909,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[2]; + if (idx == 0) next = l_data[2]; + else next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -910,7 +936,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) u8 tmp[TMPSIZ]; - next = esalt_bufs[digests_offset].hashes[idx].data[3]; + if (idx == 0) next = l_data[3]; + else next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -935,7 +962,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) for (int i = 16; i < 36; i += 4) { - next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; + if (idx == 0) next = l_data[i / 4]; + else next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; diff --git a/OpenCL/m17220_a1-pure.cl b/OpenCL/m17220_a1-pure.cl index 0c0cec887..177fa394d 100644 --- a/OpenCL/m17220_a1-pure.cl +++ b/OpenCL/m17220_a1-pure.cl @@ -548,6 +548,15 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) SYNC_THREADS(); + LOCAL_VK u32 l_data[MAX_LOCAL]; + + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = esalt_bufs[digests_offset].hashes[0].data[i]; + } + + SYNC_THREADS(); + if (gid >= gid_max) return; /** @@ -597,7 +606,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) u32x key1 = key1init2; u32x key2 = key2init2; - next = esalt_bufs[digests_offset].hashes[idx].data[0]; + if (idx == 0) next = l_data[0]; + else next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -615,7 +625,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[1]; + if (idx == 0) next = l_data[1]; + else next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -633,7 +644,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[2]; + if (idx == 0) next = l_data[2]; + else next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -659,7 +671,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) u8 tmp[TMPSIZ]; - next = esalt_bufs[digests_offset].hashes[idx].data[3]; + if (idx == 0) next = l_data[3]; + else next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -684,7 +697,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) for (int i = 16; i < 36; i += 4) { - next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; + if (idx == 0) next = l_data[i / 4]; + else next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -801,6 +815,15 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) SYNC_THREADS(); + LOCAL_VK u32 l_data[MAX_LOCAL]; + + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = esalt_bufs[digests_offset].hashes[0].data[i]; + } + + SYNC_THREADS(); + if (gid >= gid_max) return; /** @@ -850,7 +873,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) u32x key1 = key1init2; u32x key2 = key2init2; - next = esalt_bufs[digests_offset].hashes[idx].data[0]; + if (idx == 0) next = l_data[0]; + else next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -868,7 +892,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[1]; + if (idx == 0) next = l_data[1]; + else next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -886,7 +911,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[2]; + if (idx == 0) next = l_data[2]; + else next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -912,7 +938,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) u8 tmp[TMPSIZ]; - next = esalt_bufs[digests_offset].hashes[idx].data[3]; + if (idx == 0) next = l_data[3]; + else next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -937,7 +964,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) for (int i = 16; i < 36; i += 4) { - next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; + if (idx == 0) next = l_data[i / 4]; + else next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; diff --git a/OpenCL/m17220_a3-pure.cl b/OpenCL/m17220_a3-pure.cl index 73a9b4f84..e21a7a672 100644 --- a/OpenCL/m17220_a3-pure.cl +++ b/OpenCL/m17220_a3-pure.cl @@ -548,6 +548,15 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) SYNC_THREADS(); + LOCAL_VK u32 l_data[MAX_LOCAL]; + + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = esalt_bufs[digests_offset].hashes[0].data[i]; + } + + SYNC_THREADS(); + if (gid >= gid_max) return; /** @@ -609,7 +618,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) u32x key1 = key1init; u32x key2 = key2init; - next = esalt_bufs[digests_offset].hashes[idx].data[0]; + if (idx == 0) next = l_data[0]; + else next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -627,7 +637,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[1]; + if (idx == 0) next = l_data[1]; + else next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -645,7 +656,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[2]; + if (idx == 0) next = l_data[2]; + else next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -671,7 +683,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) u8 tmp[TMPSIZ]; - next = esalt_bufs[digests_offset].hashes[idx].data[3]; + if (idx == 0) next = l_data[3]; + else next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -696,7 +709,8 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) for (int i = 16; i < 36; i += 4) { - next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; + if (idx == 0) next = l_data[i / 4]; + else next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -874,7 +888,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) u32x key1 = key1init; u32x key2 = key2init; - next = esalt_bufs[digests_offset].hashes[idx].data[0]; + if (idx == 0) next = l_data[0]; + else next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -892,7 +907,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[1]; + if (idx == 0) next = l_data[1]; + else next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -910,7 +926,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[2]; + if (idx == 0) next = l_data[2]; + else next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -936,7 +953,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) u8 tmp[TMPSIZ]; - next = esalt_bufs[digests_offset].hashes[idx].data[3]; + if (idx == 0) next = l_data[3]; + else next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -961,7 +979,8 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) for (int i = 16; i < 36; i += 4) { - next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; + if (idx == 0) next = l_data[i / 4]; + else next = esalt_bufs[digests_offset].hashes[idx].data[i / 4]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; diff --git a/OpenCL/m17230_a0-pure.cl b/OpenCL/m17230_a0-pure.cl index d3b1121ff..02afbcb3f 100644 --- a/OpenCL/m17230_a0-pure.cl +++ b/OpenCL/m17230_a0-pure.cl @@ -243,6 +243,15 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) SYNC_THREADS(); + LOCAL_VK u32 l_data[MAX_LOCAL]; + + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = esalt_bufs[digests_offset].hashes[0].data[i]; + } + + SYNC_THREADS(); + if (gid >= gid_max) return; /** @@ -290,7 +299,8 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) u32x key1 = key1init; u32x key2 = key2init; - next = esalt_bufs[digests_offset].hashes[idx].data[0]; + if (idx == 0) next = l_data[0]; + else next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -308,7 +318,8 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[1]; + if (idx == 0) next = l_data[1]; + else next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -326,7 +337,8 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[2]; + if (idx == 0) next = l_data[2]; + else next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -346,7 +358,8 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[3]; + if (idx == 0) next = l_data[3]; + else next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -400,6 +413,15 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) SYNC_THREADS(); + LOCAL_VK u32 l_data[MAX_LOCAL]; + + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = esalt_bufs[digests_offset].hashes[0].data[i]; + } + + SYNC_THREADS(); + if (gid >= gid_max) return; /** @@ -447,7 +469,8 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) u32x key1 = key1init; u32x key2 = key2init; - next = esalt_bufs[digests_offset].hashes[idx].data[0]; + if (idx == 0) next = l_data[0]; + else next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -465,7 +488,8 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[1]; + if (idx == 0) next = l_data[1]; + else next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -483,7 +507,8 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[2]; + if (idx == 0) next = l_data[2]; + else next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -503,7 +528,8 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[3]; + if (idx == 0) next = l_data[3]; + else next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; diff --git a/OpenCL/m17230_a1-pure.cl b/OpenCL/m17230_a1-pure.cl index 2f79da216..8294a5c49 100644 --- a/OpenCL/m17230_a1-pure.cl +++ b/OpenCL/m17230_a1-pure.cl @@ -241,6 +241,15 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) SYNC_THREADS(); + LOCAL_VK u32 l_data[MAX_LOCAL]; + + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = esalt_bufs[digests_offset].hashes[0].data[i]; + } + + SYNC_THREADS(); + if (gid >= gid_max) return; /** @@ -290,7 +299,8 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) u32x key1 = key1init2; u32x key2 = key2init2; - next = esalt_bufs[digests_offset].hashes[idx].data[0]; + if (idx == 0) next = l_data[0]; + else next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -308,7 +318,8 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[1]; + if (idx == 0) next = l_data[1]; + else next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -326,7 +337,8 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[2]; + if (idx == 0) next = l_data[2]; + else next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -346,7 +358,8 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_ESALT (pkzip_t)) if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[3]; + if (idx == 0) next = l_data[3]; + else next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -400,6 +413,15 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) SYNC_THREADS(); + LOCAL_VK u32 l_data[MAX_LOCAL]; + + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = esalt_bufs[digests_offset].hashes[0].data[i]; + } + + SYNC_THREADS(); + if (gid >= gid_max) return; /** @@ -449,7 +471,8 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) u32x key1 = key1init2; u32x key2 = key2init2; - next = esalt_bufs[digests_offset].hashes[idx].data[0]; + if (idx == 0) next = l_data[0]; + else next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -467,7 +490,8 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[1]; + if (idx == 0) next = l_data[1]; + else next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -485,7 +509,8 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[2]; + if (idx == 0) next = l_data[2]; + else next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -505,7 +530,8 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_ESALT (pkzip_t)) if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[3]; + if (idx == 0) next = l_data[3]; + else next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; diff --git a/OpenCL/m17230_a3-pure.cl b/OpenCL/m17230_a3-pure.cl index 5da181f34..e13289442 100644 --- a/OpenCL/m17230_a3-pure.cl +++ b/OpenCL/m17230_a3-pure.cl @@ -241,6 +241,15 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) SYNC_THREADS(); + LOCAL_VK u32 l_data[MAX_LOCAL]; + + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = esalt_bufs[digests_offset].hashes[0].data[i]; + } + + SYNC_THREADS(); + if (gid >= gid_max) return; /** @@ -304,7 +313,8 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) u32x key1 = key1init; u32x key2 = key2init; - next = esalt_bufs[digests_offset].hashes[idx].data[0]; + if (idx == 0) next = l_data[0]; + else next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -322,7 +332,8 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[1]; + if (idx == 0) next = l_data[1]; + else next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -340,7 +351,8 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[2]; + if (idx == 0) next = l_data[2]; + else next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -360,13 +372,14 @@ KERNEL_FQ void m17230_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[3]; + if (idx == 0) next = l_data[3]; + else next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; if ((plain & 6) == 0 || (plain & 6) == 6) break; - if (idx + 1 == esalt_bufs[digests_offset].hash_count) + if (idx + 1 == hash_count) { /** * digest @@ -414,6 +427,15 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) SYNC_THREADS(); + LOCAL_VK u32 l_data[MAX_LOCAL]; + + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = esalt_bufs[digests_offset].hashes[0].data[i]; + } + + SYNC_THREADS(); + if (gid >= gid_max) return; /** @@ -477,7 +499,8 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) u32x key1 = key1init; u32x key2 = key2init; - next = esalt_bufs[digests_offset].hashes[idx].data[0]; + if (idx == 0) next = l_data[0]; + else next = esalt_bufs[digests_offset].hashes[idx].data[0]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -495,7 +518,8 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[1]; + if (idx == 0) next = l_data[1]; + else next = esalt_bufs[digests_offset].hashes[idx].data[1]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -513,7 +537,8 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) plain = unpack_v8d_from_v32_S (next) ^ key3; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[2]; + if (idx == 0) next = l_data[2]; + else next = esalt_bufs[digests_offset].hashes[idx].data[2]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; @@ -533,7 +558,8 @@ KERNEL_FQ void m17230_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) if ((plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_crc >> 8)) && (plain != (esalt_bufs[digests_offset].hashes[idx].checksum_from_timestamp >> 8))) break; update_key012 (key0, key1, key2, plain, l_crc32tab); - next = esalt_bufs[digests_offset].hashes[idx].data[3]; + if (idx == 0) next = l_data[3]; + else next = esalt_bufs[digests_offset].hashes[idx].data[3]; update_key3 (key2, key3); plain = unpack_v8a_from_v32_S (next) ^ key3; From 845878f607b19891ced346b31cad447f1082db89 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Tue, 14 May 2019 15:43:01 +0200 Subject: [PATCH 18/19] added missing pre-load --- OpenCL/m17220_a3-pure.cl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/OpenCL/m17220_a3-pure.cl b/OpenCL/m17220_a3-pure.cl index e21a7a672..3e581367a 100644 --- a/OpenCL/m17220_a3-pure.cl +++ b/OpenCL/m17220_a3-pure.cl @@ -827,6 +827,15 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) SYNC_THREADS(); + LOCAL_VK u32 l_data[MAX_LOCAL]; + + for (u64 i = lid; i < MAX_LOCAL; i += lsz) + { + l_data[i] = esalt_bufs[digests_offset].hashes[0].data[i]; + } + + SYNC_THREADS(); + if (gid >= gid_max) return; /** From cd7b3ed67263a3d2304cfee9d731b016a190c2e5 Mon Sep 17 00:00:00 2001 From: Sein Coray Date: Wed, 15 May 2019 16:49:52 +0200 Subject: [PATCH 19/19] fixed size of tmp to be checked on static huffman inflate --- OpenCL/m17200_a0-pure.cl | 10 +++++----- OpenCL/m17200_a1-pure.cl | 10 +++++----- OpenCL/m17200_a3-pure.cl | 10 +++++----- OpenCL/m17210_a0-pure.cl | 6 +++--- OpenCL/m17210_a1-pure.cl | 6 +++--- OpenCL/m17210_a3-pure.cl | 6 +++--- OpenCL/m17220_a0-pure.cl | 4 ++-- OpenCL/m17220_a1-pure.cl | 4 ++-- OpenCL/m17220_a3-pure.cl | 4 ++-- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/OpenCL/m17200_a0-pure.cl b/OpenCL/m17200_a0-pure.cl index bf212a813..e56ddc34b 100644 --- a/OpenCL/m17200_a0-pure.cl +++ b/OpenCL/m17200_a0-pure.cl @@ -570,9 +570,9 @@ KERNEL_FQ void m17200_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) const u32 search[4] = { digests_buf[digests_offset].digest_buf[DGST_R0], - digests_buf[digests_offset].digest_buf[DGST_R1], - digests_buf[digests_offset].digest_buf[DGST_R2], - digests_buf[digests_offset].digest_buf[DGST_R3] + 0, + 0, + 0 }; /** @@ -725,7 +725,7 @@ KERNEL_FQ void m17200_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) update_key012 (key0, key1, key2, plain, l_crc32tab); } - if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) continue; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 24)) continue; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) continue; mz_stream infstream; @@ -951,7 +951,7 @@ KERNEL_FQ void m17200_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) update_key012 (key0, key1, key2, plain, l_crc32tab); } - if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) continue; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 24)) continue; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) continue; mz_stream infstream; diff --git a/OpenCL/m17200_a1-pure.cl b/OpenCL/m17200_a1-pure.cl index 08c4beeb1..fc506431e 100644 --- a/OpenCL/m17200_a1-pure.cl +++ b/OpenCL/m17200_a1-pure.cl @@ -568,9 +568,9 @@ KERNEL_FQ void m17200_sxx (KERN_ATTR_ESALT (pkzip_t)) const u32 search[4] = { digests_buf[digests_offset].digest_buf[DGST_R0], - digests_buf[digests_offset].digest_buf[DGST_R1], - digests_buf[digests_offset].digest_buf[DGST_R2], - digests_buf[digests_offset].digest_buf[DGST_R3] + 0, + 0, + 0 }; /** @@ -727,7 +727,7 @@ KERNEL_FQ void m17200_sxx (KERN_ATTR_ESALT (pkzip_t)) update_key012 (key0, key1, key2, plain, l_crc32tab); } - if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) continue; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 24)) continue; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) continue; mz_stream infstream; @@ -957,7 +957,7 @@ KERNEL_FQ void m17200_mxx (KERN_ATTR_ESALT (pkzip_t)) update_key012 (key0, key1, key2, plain, l_crc32tab); } - if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) continue; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 24)) continue; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) continue; mz_stream infstream; diff --git a/OpenCL/m17200_a3-pure.cl b/OpenCL/m17200_a3-pure.cl index 60e01bfbc..000ec4c35 100644 --- a/OpenCL/m17200_a3-pure.cl +++ b/OpenCL/m17200_a3-pure.cl @@ -569,9 +569,9 @@ KERNEL_FQ void m17200_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) const u32 search[4] = { digests_buf[digests_offset].digest_buf[DGST_R0], - digests_buf[digests_offset].digest_buf[DGST_R1], - digests_buf[digests_offset].digest_buf[DGST_R2], - digests_buf[digests_offset].digest_buf[DGST_R3] + 0, + 0, + 0 }; /** @@ -740,7 +740,7 @@ KERNEL_FQ void m17200_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) update_key012 (key0, key1, key2, plain, l_crc32tab); } - if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) continue; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 24)) continue; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) continue; mz_stream infstream; @@ -982,7 +982,7 @@ KERNEL_FQ void m17200_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) update_key012 (key0, key1, key2, plain, l_crc32tab); } - if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) continue; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 24)) continue; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) continue; mz_stream infstream; diff --git a/OpenCL/m17210_a0-pure.cl b/OpenCL/m17210_a0-pure.cl index e6f4515ad..086333702 100644 --- a/OpenCL/m17210_a0-pure.cl +++ b/OpenCL/m17210_a0-pure.cl @@ -261,9 +261,9 @@ KERNEL_FQ void m17210_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) const u32 search[4] = { digests_buf[digests_offset].digest_buf[DGST_R0], - digests_buf[digests_offset].digest_buf[DGST_R1], - digests_buf[digests_offset].digest_buf[DGST_R2], - digests_buf[digests_offset].digest_buf[DGST_R3] + 0, + 0, + 0 }; /** diff --git a/OpenCL/m17210_a1-pure.cl b/OpenCL/m17210_a1-pure.cl index 4540b20b2..1573fd3a4 100644 --- a/OpenCL/m17210_a1-pure.cl +++ b/OpenCL/m17210_a1-pure.cl @@ -259,9 +259,9 @@ KERNEL_FQ void m17210_sxx (KERN_ATTR_ESALT (pkzip_t)) const u32 search[4] = { digests_buf[digests_offset].digest_buf[DGST_R0], - digests_buf[digests_offset].digest_buf[DGST_R1], - digests_buf[digests_offset].digest_buf[DGST_R2], - digests_buf[digests_offset].digest_buf[DGST_R3] + 0, + 0, + 0 }; /** diff --git a/OpenCL/m17210_a3-pure.cl b/OpenCL/m17210_a3-pure.cl index e5796ecab..5a2939533 100644 --- a/OpenCL/m17210_a3-pure.cl +++ b/OpenCL/m17210_a3-pure.cl @@ -259,9 +259,9 @@ KERNEL_FQ void m17210_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) const u32 search[4] = { digests_buf[digests_offset].digest_buf[DGST_R0], - digests_buf[digests_offset].digest_buf[DGST_R1], - digests_buf[digests_offset].digest_buf[DGST_R2], - digests_buf[digests_offset].digest_buf[DGST_R3] + 0, + 0, + 0 }; /** diff --git a/OpenCL/m17220_a0-pure.cl b/OpenCL/m17220_a0-pure.cl index 4fd6631ee..4c7773186 100644 --- a/OpenCL/m17220_a0-pure.cl +++ b/OpenCL/m17220_a0-pure.cl @@ -721,7 +721,7 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_RULES_ESALT (pkzip_t)) update_key012 (key0, key1, key2, plain, l_crc32tab); } - if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 24)) break; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) @@ -986,7 +986,7 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_RULES_ESALT (pkzip_t)) update_key012 (key0, key1, key2, plain, l_crc32tab); } - if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 24)) break; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) diff --git a/OpenCL/m17220_a1-pure.cl b/OpenCL/m17220_a1-pure.cl index 177fa394d..a7b2d8508 100644 --- a/OpenCL/m17220_a1-pure.cl +++ b/OpenCL/m17220_a1-pure.cl @@ -721,7 +721,7 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_ESALT (pkzip_t)) update_key012 (key0, key1, key2, plain, l_crc32tab); } - if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 24)) break; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) @@ -988,7 +988,7 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_ESALT (pkzip_t)) update_key012 (key0, key1, key2, plain, l_crc32tab); } - if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 24)) break; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) diff --git a/OpenCL/m17220_a3-pure.cl b/OpenCL/m17220_a3-pure.cl index 3e581367a..e92712dbf 100644 --- a/OpenCL/m17220_a3-pure.cl +++ b/OpenCL/m17220_a3-pure.cl @@ -733,7 +733,7 @@ KERNEL_FQ void m17220_sxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) update_key012 (key0, key1, key2, plain, l_crc32tab); } - if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 24)) break; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1) @@ -1012,7 +1012,7 @@ KERNEL_FQ void m17220_mxx (KERN_ATTR_VECTOR_ESALT (pkzip_t)) update_key012 (key0, key1, key2, plain, l_crc32tab); } - if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 36)) break; + if (((tmp[0]) & 6) == 2 && !check_inflate_code1 (tmp, 24)) break; if (((tmp[0]) & 6) == 4 && !check_inflate_code2 (tmp)) break; if (esalt_bufs[digests_offset].hashes[idx].data_type_enum == 1)