1
0
mirror of https://github.com/hashcat/hashcat.git synced 2025-07-08 15:48:15 +00:00
Commit Graph

157 Commits

Author SHA1 Message Date
Jens Steube
d9918d7e44 Add Argon2 support for OpenCL and HIP
=====================================

This patch modifies the existing Argon2 plugin, which was initially
designed to work only with CUDA. Supporting OpenCL and HIP required
broader architectural changes.

1. The tmps[] structure no longer holds the "large buffer". This
buffer stored the scratch areas for all password candidates in one
chunk. But we do not need to hold scratch areas for all candidates
simultaneously. All we need to do is hold chunks large enough
per password.

To simplify logic, the buffer is not divided by password count, but
divided by four, which fits within the "1/4 global memory" limit on
some OpenCL runtimes.

Hashcat already had logic to support this, but the buffer needed to be
moved to a different buffer type. It has now been relocated from the
"tmp buffer" to the "extra tmp buffer", following the same strategy
used in newer SCRYPT plugins.

This improves handling across several subcomponents:

  - Hashcat backend divides into four asymmetric buffers, hence the
    name "4-buffer strategy"
  - If the candidate count isn't divisible by 4, leftover candidates are
    assigned to the first (and possibly second and third) buffer
  - No code in the plugin is required, as this was designed for exactly
    such cases where future algorithms require a lot of memory
  - Plugin was rewritten to report the size needed in
    module_extra_tmp_size(), which triggers the "4-buffer" strategy
  - The split is not even, but each part is large enough to hold
    a multiple of a full scratch buffer for a password
  - The kernel code in m34000_init/loop/comp now uses a code block
    that finds its buffer by doing "group_id % 4"
  - Prevents the need to over-allocate memory to avoid OOB access
  - The original "tmps buffer" now holds a small dummy state buffer

2. Replaced warp shuffle instruction

The instruction __shfl_sync() is not available in runtimes
other than CUDA. Some have alternatives, some do not.

To prevent branching per backend runtime, the new general macro
hc__shfl_sync() replaces all calls to __shfl_sync().
This allows us to implement runtime-specific solutions and
take effect at compile time to prevent regressions.

- CUDA:
  We simply map to the original __shfl_sync()

- HIP:
  We map to shfl(), a built-in intrinsic. This instruction doesn't
  support masks like __shfl_sync() does, but masks are not needed
  in Argon2 anyway. It requires an additional parameter, the wavefront
  size. This is natively 64, but we hardcode this to 32 so it aligns
  with NVIDIA's warp size.

- OpenCL:
  - AMD: We have access to the instruction __builtin_amdgcn_ds_bpermute().
    This instruction only supports 32-bit integers, requiring us to
    pack and unpack the 64-bit values manually
  - NVIDIA: We use inline assembly with "shfl.sync.idx.b32". Same as
    with AMD, we need to pack and unpack 32-bit integers. The 64-bit
    support in CUDA is just overloaded and internally does the same thing.
  - Others: We use a shared memory pool and combine it with a barrier.
    This LOCAL_VK pool must be sized at compile time and transported to
    the Argon2 code in "inc_hash_argon2.cl". This required changing all
    function declarations that use shuffles slightly.

Unlock full threading for init and comp kernels
===============================================

This is implemented using a new flag:
  OPTS_TYPE_THREAD_MULTI_DISABLE

Behavior is similar to:
  OPTS_TYPE_MP_MULTI_DISABLE

It simply disables the multiplier normally applied to password batch size.

But attention, this change completely unbinds this effect from the
real threads spawned on the compute device. If the thread count is not
set to 1 in the plugin, it will start autotuning it.

In the case of Argon2, we hard-code it to 32 instead, which also changes
how "warp size" was used in the original implementation, and which is not
compatible with HIP and/or OpenCL. However, we need to maintain this thread
size to utilize warp shuffle and its alternatives in other runtimes.

Benefits:

  - Enables full threading for init and comp kernels (1667 H/s to 1722 H/s)
  - Allows future algorithms to enable parallel processing of single
    password candidates, if supported

Plugin changes:

  - Removed the "hack" where thread count = 1 disabled the multiplier
  - Removed per-device warp count detection code and struct changes
  - Removed warp handling and "num_elements / thread_count" division in
    the run_kernel() function

Simplified autotune logic for Argon2
====================================

The goal is to calculate the maximum number of password candidates that
can run in parallel, constrained only by device memory.

  - Removed all code related to Argon2 from autotune
  - Implemented in "module_extra_tuningdb_block()" (like SCRYPT)
  - We create a tuningdb entry at runtime!
  - Still allows override via tuningdb or CLI
  - Considers register spilling (read at startup)
  - Prevents global-to-host memory swap performance issues

Add Argon2I and ArgonD support
==============================

The kernel prepared from NFI already had support for the different Argon
types. No change was needed.

To support the other Argon2 types, the tokenizer had to be improved to
support a variety of different signatures in the same hash-mode.

Bugfixes
========

- Fixed missing entries in "switch_buffer_by_offset_8x4_le_S()"
- Fixed benchmark hash misdetection for scrypt. This was due to
  outdated logic used in scrypt to detect whether the plugin was
  called from a benchmark session or a regular one
- Fixed a bug in "module_hash_encode()" where Base64 padding '=' was
  retained
- Fixed missing "GLOBAL_AS" / "PRIVATE_AS" casts for OpenCL
- Fixed compiler warnings (e.g., "index_u32x4()", "get_group_id()")
  by adding return values
- Fixed a bug in token.len_max[6], which was allowing decoding
  of a 256-byte data into a 16-byte buffer (digest)

Other improvements
==================

- Added unit test module for automated testing
- Added support to the tokenizer to allow multiple signatures.
  Leave out TOKEN_ATTR_FIXED_LENGTH to enable this in your plugins
- Updated "hc_umulhi()", also exists for HIP
- Renamed "gid" to "bid" when using "get_group_id()" for clarity
- Removed "#ifdef IS_CUDA" as all backends are now supported
- Removed deprecated "OPTS_TYPE_MAXIMUM_ACCEL" attribute

Performance note
================

For testing, I used the self-test hash configured according to the
RFC 9106 recommendation: m=65536, t=3, p=1.

In my benchmarks, the AMD RX 7900 XTX achieved 1401 H/s using the same
hash that was used to test NVIDIA's RTX 4090. The RTX 4090 reached
1722 H/s, making it faster in absolute terms. However, at the time of
writing, it is more than three times as expensive as the 7900 XTX.

It's also worth noting that an older NVIDIA GTX 1080 Ti still reached
565 H/s with the same test vector, and may be found at significantly
lower cost.

Across all tested Argon2 configurations, the performance gap between
the RX 7900 XTX and the RTX 4090 remained proportionally consistent,
indicating a clear linear scaling relationship between the two GPUs.
2025-07-02 11:02:57 +02:00
Pelle Kuiters
3c1649ccc8 GPU support for Argon2id for NVIDIA CUDA 2025-07-02 10:47:00 +02:00
Jens Steube
40365a32d0
Merge pull request #4195 from matrix/issue_4175
Improve ASN.1 check for RSA/DSA/EC/OpenSSH Private Keys modules (22911, 22921, 22931, 22941, 22951)
2025-05-24 16:29:26 +02:00
Gabriele Gristina
6a6dd103f6 fix asn1_check_int_tag build failure with Apple Metal 2025-04-25 19:28:14 +02:00
Gabriele Gristina
cc9ae09b94 Improve ASN.1 check for RSA/DSA/EC/OpenSSH Private Keys modules (22911, 22921, 22931, 22941, 22951) 2025-04-25 19:13:33 +02:00
Gabriele Gristina
db814b5837 Update PR #3735 2024-10-31 18:29:23 +01:00
jsteube
f8bd133373 Add new function count_bits_32() in inc_common.cl 2023-11-22 03:36:28 +00:00
PenguinKeeper7
4ea43742b9 Update inc_common.cl 2023-09-18 13:13:17 +01:00
Gabriele Gristina
7ab1110907 Fixed build failure for almost all hash modes that make use of hc_swap64 and/or hc_swap64_S with Apple Metal 2023-05-20 03:54:06 +02:00
jsteube
d5a74b2536 Add new function is_valid_printable_32() to check if 32 bit integer consist only of printable characters and update -m 26610 as example use case 2023-03-07 21:43:44 +00:00
jsteube
9ec6392c92 Fix untested byte range coverage in UTF8 to UTF16 converter 2023-02-14 09:46:28 +00:00
Jens Steube
730b1cd5cc Update UTF8 to UTF16 conversion to match RFC 3629 2023-02-10 23:28:23 +01:00
jsteube
6ee2658104 Prefix more macros to avoid collisions in other existing libraries 2023-01-30 14:41:12 +00:00
jsteube
98d721cf69 Prepare rename macros in kernel files from _MACRO to MACRO 2023-01-18 15:34:49 +00:00
philsmd
4ec7b83ddb
add make_utf16beN_S () and sha1_update_utf16beN () 2022-06-04 11:11:40 +02:00
piwvvo
1ecfb8899f Added sha1($salt.sha1($username.':'.$pass, true)) 2022-05-07 02:09:27 +02:00
Jens Steube
753994bfe0 Fixed password reassembling function reporting an incorrect candidate in some cases when the correct candidate has zero length 2022-03-30 20:52:47 +02:00
Gabriele Gristina
9d36245d51 Kernels: Set the default Address Space Qualifier for any pointer, refactored / updated KERN_ATTR macros and rc4 cipher functions, in order to support Apple Metal runtime 2022-02-04 19:54:00 +01:00
Jens Steube
af40ec0640
Merge pull request #2907 from fse-a/GPG
Added GPG module and kernel
2021-09-04 18:27:54 +02:00
hops
ab164ddba2 Fix HAS_VPERM check in make-/undo_utf16* functions 2021-09-02 11:37:09 +02:00
Jens Steube
1f22984313 The hc_bytealign_be_S() was merged too early, but is not yet used anywhere for this platform so we can remove it again. 2021-08-12 15:15:32 +02:00
Jens Steube
f72f2b0f09 Encoding: Truncate password candidates in UTF8 -> UTF16 conversion if it contains an invalid UTF8 byte sequence 2021-08-11 16:44:04 +02:00
therealartifex
0738820a89
Merge branch 'hashcat:master' into master 2021-08-05 09:29:41 -04:00
Jens Steube
cb69e2d413 Added some HIP version checks, fall back to OpenCL automatically
Switched HIP version check from driverVersion to runtimeVersion
Fixed syntax check of HAS_VPERM macro in several kernel includes causing invalid error message for AMD GPUs on Windows
Updated AMD driver requirements
Updated docs/changes.txt with missing changes from previous commits
Fixed invalid vector data type in Murmur Hash in -a 3 mode
Fixed uninitialized variable warning in src/hashes.c
Fixed broken support for --generate-rules-func-min
2021-08-04 20:49:22 +02:00
therealartifex
ff55f31081 Update module, add a0 and a1 optimized kernels 2021-08-04 01:39:47 -04:00
Jens Steube
3d4e2aec43 Work around segmentation fault in Intel JiT 2021.12.6.0.19_160000 compiling hc_enc_next()/hc_enc_next_global() 2021-08-03 08:34:37 +02:00
Jens Steube
0810126145 Fix Blake2b in generic mode 2021-08-02 14:12:36 +02:00
pelle
00c9c2ed1b Added GPG module and kernel. 2021-07-27 20:46:33 +02:00
Jens Steube
cf512faa53 Update large switch() cases in inc_common.cl and some inline assembly common functions for devices managed with HIP backend 2021-07-14 17:06:20 +02:00
Jens Steube
1b84a9e53b Add missing backports from code base v6.2.2
Fix context to thread management
Fix missing code in selftest.c, autotune.c, hashes.c, dispatch.c and backend.c
Use IS_HIP depending code makes it easier for future optimization related to inline assembly calls - instead of using IS_CUDA || IS_HIP
See TODO markers for more optimizations / next steps
2021-07-11 12:38:59 +02:00
Jens Steube
a22f8149fc
Merge branch 'HIP' into hip 2021-07-10 21:34:09 +02:00
reger-men
ea7b74389f First draft HIP Version 2021-07-09 03:50:40 +00:00
Jens Steube
62397283c1 VeraCrypt: Increase password length support for non-boot volumes from 64 to 128.
See https://github.com/hashcat/hashcat/issues/2616 for details.
2021-06-17 09:45:30 +02:00
Jens Steube
e4dab0f1bf OpenCL Runtime: Workaround JiT compiler segfault on legacy AMDGPU driver compiling RAR3 OpenCL kernel 2021-05-09 07:38:22 +00:00
Jens Steube
9813811493 Remove truncation of buffer in hc_enc_next() to workaround AMD JiT compiler (legacy) issue 2021-05-08 16:38:48 +02:00
Jens Steube
0439f0c4a1 Refactor UTF8 to UTF16 conversion from fixed size to a dynamic size using a context struct. This allows handle buffer sizes of arbitrary length for conversion 2021-05-01 12:49:43 +02:00
Jens Steube
f8ea1d5e78 Improve performance of test_any_8th_bit() by manually unrolling a few first steps 2021-04-30 17:22:31 +02:00
Jens Steube
b7dffd9259 Improve performance for UTF8->UTF16 conversion
Reverted d343e2c4a0 and ee26805138
Adds a test to decide whatever conversion technique to use. If all UTF8 characters are 7 bit, there's no need for regular conversion and we can stick to naive conversion.
2021-04-30 16:55:30 +02:00
Jens Steube
62fc3601bb Wrap atomic functions with hc_ prefix to have better platform control 2021-04-20 17:47:44 +02:00
Jens Steube
d343e2c4a0 Added support for true UTF8 to UTF16 conversion in kernel crypto library 2021-04-11 11:53:47 +02:00
Jens Steube
04d5e5a119 New Attack-Mode: Association Attack. Like JtR's single mode. Very early
stage. See hashcat Forum for detailed writeup.
2020-09-29 15:56:32 +02:00
Jens Steube
ade00c412b Add code to inc_common.cl to do PKCS padding checks as well as (naive) ASN.1 detection 2020-07-30 14:51:04 +02:00
Jens Steube
4658e470a2 OpenCL Kernels: Added datatypes to literals of some 64 bit kernel constants 2020-07-22 14:06:58 +02:00
Jens Steube
70ba719169 OpenCL Kernels: Added datatypes to literals of enum costants 2020-07-22 12:34:00 +02:00
philsmd
bd9304724c
fixes #1298: add pure kernels for -m 600 = BLAKE2b-512 2020-06-24 23:41:58 +02:00
Jens Steube
fa4b521d48 Add unpack_v8x_from_v32 for vector datatypes, update -m 200 2020-03-06 13:31:32 +01:00
Jens Steube
c9fdb34698 Do not use V_BFE_U32 with latest rocm version 2020-02-13 13:24:20 +01:00
Jens Steube
525f8af200 Add v8x_from_v64_x to inc_common.cl 2020-02-03 15:51:08 +01:00
Jens Steube
1fc37c25f9 OpenCL Kernels: Moved "gpu_decompress", "gpu_memset" and "gpu_atinit" into new OpenCL/shared.cl in order to reduce compile time 2020-02-01 09:00:48 +01:00
Jens Steube
3a5544a554 Help some compiler with 64 bit constants 2020-01-21 22:09:56 +01:00