Skip to content

Support argon2 on GPUs through OpenCL#5382

Merged
solardiz merged 3 commits into
openwall:bleeding-jumbofrom
alainesp:bleeding-jumbo
Dec 4, 2023
Merged

Support argon2 on GPUs through OpenCL#5382
solardiz merged 3 commits into
openwall:bleeding-jumbofrom
alainesp:bleeding-jumbo

Conversation

@alainesp

@alainesp alainesp commented Dec 4, 2023

Copy link
Copy Markdown
Contributor

No description provided.

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Thank you @alainesp!

Since the OpenCL code (not just ideas, right?) is based on https://gitlab.com/omos/argon2-gpu I think we need to add their copyright statement + license to the kernel file. And also your copyright statement for your edits of their code.

In fact, maybe add a preceding commit of their original code as-is, and then your commit with your changes to the OpenCL code + addition of your host code? So that we have revision history of their code vs. first our revision of it in here. I'm sorry this idea didn't occur to me in our e-mail discussion.

@ghost

ghost commented Dec 4, 2023

Copy link
Copy Markdown

CI failure is due to Intel driver update to 2024.0.

Please let me know if you guys want to roll back and use a VM with Ubuntu 16 and Intel 18 driver or if we should disable the problematic formats for this test.

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

The failure of ci/circleci: encoding-opencl seen here is weird - it doesn't yet get to testing this new format, yet some other OpenCL formats start failing now? Why would they be?

Anyway, this is also our reminder that we either need to get argon2-opencl to work on CPU right away (per our e-mails, it only works on GPUs now, with CPU support postponed for a further PR) or exclude it from CI (@claudioandre-br can advise how we should do that, right?)

Version: 1.9.0-jumbo-1+bleeding-ed8009f4b0 2023-12-04 16:54:14 +0100
Build: linux-gnu 64-bit x86_64 AVX512BW AC OMP OPENCL
SIMD: AVX512BW, interleaving: MD4:3 MD5:3 SHA1:1 SHA256:1 SHA512:1
CPU tests: AVX512BW
$JOHN is ../run/
Format interface version: 14
Max. number of reported tunable costs: 4
Rec file version: REC4
Charset file version: CHR3
CHARSET_MIN: 1 (0x01)
CHARSET_MAX: 255 (0xff)
CHARSET_LENGTH: 24
SALT_HASH_SIZE: 1048576
SINGLE_IDX_MAX: 2147483648
SINGLE_BUF_MAX: 4294967295
Effective limit: Number of salts vs. SingleMaxBufferSize
Max. Markov mode level: 400
Max. Markov mode password length: 30
gcc version: 11.4.0
GNU libc version: 2.35 (loaded: 2.35)
OpenCL headers version: 1.2
Crypto library: OpenSSL
OpenSSL library version: 030000020
OpenSSL 3.0.2 15 Mar 2022
GMP library version: 6.2.1
File locking: fcntl()
fseek(): fseek
ftell(): ftell
fopen(): fopen
memmem(): System's
times(2) sysconf(_SC_CLK_TCK) is 100
Using times(2) for timers, resolution 10 ms
HR timer: clock_gettime(), latency 37 ns
Total physical host memory: 70717 MiB
Available physical host memory: 59630 MiB
Terminal locale string: C
Parsed terminal locale: UNDEF
--------------------------------------------------------------------------------
-- Running $JTR --test-full=0 --format=opencl '--encoding=utf8' --
Device 1: Intel(R) FPGA Emulation Device
Testing: diskcryptor-opencl, DiskCryptor [PBKDF2-SHA512 OpenCL, UTF-8]... (2xOMP) Build log: Compilation started
Compilation done
Linking started
Linking done
Device build started
Options used by backend compiler: -I opencl -cl-mad-enable -DDEVICE_INFO=36 -D__SIZEOF_HOST_SIZE_T__=8 -DDEV_VER_MAJOR=2023 -DDEV_VER_MINOR=16 -D_OPENCL_COMPILER -DHASH_LOOPS=250 -DPLAINTEXT_LENGTH=110 -DPBKDF2_64_MAX_SALT_SIZE=107
Device build done
Kernel "pbkdf2_sha512_loop" was successfully vectorized (16)
Kernel "pbkdf2_sha512_kernel" was successfully vectorized (16)
Done.
PASS
Testing: diskcryptor-aes-opencl, DiskCryptor AES XTS (only) [PBKDF2-SHA512 AES OpenCL, UTF-8]... Build log: Compilation started
Compilation done
Linking started
Linking done
Device build started
Options used by backend compiler: -I opencl -cl-mad-enable -DDEVICE_INFO=36 -D__SIZEOF_HOST_SIZE_T__=8 -DDEV_VER_MAJOR=2023 -DDEV_VER_MINOR=16 -D_OPENCL_COMPILER -DHASH_LOOPS=250 -DPLAINTEXT_LENGTH=110 -DPBKDF2_64_MAX_SALT_SIZE=107
Device build done
Kernel "pbkdf2_sha512_loop" was successfully vectorized (16)
Kernel "pbkdf2_sha512_kernel" was successfully vectorized (16)
Kernel "diskcryptor_final" was successfully vectorized (16)
Done.
PASS
Testing: krb5pa-md5-opencl, Kerberos 5 AS-REQ Pre-Auth etype 23 [MD4 HMAC-MD5 RC4 OpenCL, UTF-8]... Build log: Compilation started
Compilation done
Linking started
Linking done
Device build started
Options used by backend compiler: -I opencl -cl-mad-enable -DDEVICE_INFO=36 -D__SIZEOF_HOST_SIZE_T__=8 -DDEV_VER_MAJOR=2023 -DDEV_VER_MINOR=16 -D_OPENCL_COMPILER -DNUM_INT_KEYS=1 -DIS_STATIC_GPU_MASK=0 -DSALT_PARAM_BASE=13 -DUCS_2 -D CONST_CACHE_SIZE=131072 -DUTF_8 -DENC_RAW -DPLAINTEXT_LENGTH=27 -D LOC_0=-1 -D LOC_1=-1 -D LOC_2=-1 -D LOC_3=-1
Device build done
Kernel "krb5pa_md5" was successfully vectorized (16)
Done.
FAILED (crypt_all(48) zero return)
Testing: krb5tgs-opencl, Kerberos 5 TGS-REP etype 23 [MD4 HMAC-MD5 RC4 OpenCL, UTF-8]... Build log: Compilation started
Compilation done
Linking started
Linking done
Device build started
Options used by backend compiler: -I opencl -cl-mad-enable -DDEVICE_INFO=36 -D__SIZEOF_HOST_SIZE_T__=8 -DDEV_VER_MAJOR=2023 -DDEV_VER_MINOR=16 -D_OPENCL_COMPILER -DPLAINTEXT_LENGTH=27 -DDATA_LEN=1145 -DUCS_2 -DCONST_CACHE_SIZE=131072 -DUTF_8 -DENC_RAW -DLOC_0=-1 -DLOC_1=-1 -DLOC_2=-1 -DLOC_3=-1 -DNUM_INT_KEYS=1 -DIS_STATIC_GPU_MASK=0
Device build done
Kernel "krb5tgs_init" was successfully vectorized (16)
Kernel "krb5tgs_crypt" was successfully vectorized (16)
Done.
FAILED (crypt_all(49) zero return)
Testing: mscash-opencl, M$ Cache Hash [MD4 OpenCL, UTF-8]... Build log: Compilation started
Compilation done
Linking started
Linking done
Device build started
Options used by backend compiler: -I opencl -cl-mad-enable -DDEVICE_INFO=36 -D__SIZEOF_HOST_SIZE_T__=8 -DDEV_VER_MAJOR=2023 -DDEV_VER_MINOR=16 -D_OPENCL_COMPILER -D NUM_INT_KEYS=1 -D IS_STATIC_GPU_MASK=0 -DUCS_2 -D CONST_CACHE_SIZE=131072 -DUTF_8 -DENC_RAW -DPLAINTEXT_LENGTH=27 -D LOC_0=-1 -D LOC_1=-1 -D LOC_2=-1 -D LOC_3=-1
Device build done
Kernel "mscash" was successfully vectorized (16)
Done.
FAILED (crypt_all(48) zero return)
Testing: mscash2-opencl, MS Cache Hash 2 (DCC2) [PBKDF2-SHA1 OpenCL, UTF-8]... Build log: Compilation started
Compilation done
Linking started
Linking done
Device build started
Options used by backend compiler: -I opencl -cl-mad-enable -DDEVICE_INFO=36 -D__SIZEOF_HOST_SIZE_T__=8 -DDEV_VER_MAJOR=2023 -DDEV_VER_MINOR=16 -D_OPENCL_COMPILER -D SALT_BUFFER_SIZE=260
Device build done
Kernel "pbkdf2_preprocess_short" was successfully vectorized (16)
Kernel "pbkdf2_preprocess_long" was successfully vectorized (16)
Kernel "pbkdf2_iter" was successfully vectorized (16)
Kernel "pbkdf2_postprocess" was successfully vectorized (16)
Done.
.circleci/circle-ci.sh: line 102:  6213 Segmentation fault      (core dumped) $JTR --test-full=0 --format="$ENCODING_TEST" --encoding=utf8

@alainesp

alainesp commented Dec 4, 2023

Copy link
Copy Markdown
Contributor Author

In fact, maybe add a preceding commit of their original code as-is, and then your commit with your changes to the OpenCL code + addition of your host code? So that we have revision history of their code vs. first our revision of it in here. I'm sorry this idea didn't occur to me in our e-mail discussion.

How to do that? I think we can't add commits on the past. Do I close this PR and Create a new one with a new fork of JtR code?

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

CI failure is due to Intel driver update to 2024.0.

Please let me know if you guys want to roll back

I think let's roll back. Will you be sending a separate PR for that, which we'll need to rebase on? Thank you!

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

I think we can't add commits on the past.

We can, e.g. with git rebase -i. Then you'd force-push.

Do I close this PR and Create a new one with a new fork of JtR code?

We normally just rebase/amend commits and force-push, without closing/reopening PRs. However, if your use of git isn't from the command-line and you're uncomfortable switching to the command-line (although I highly recommend it), you may do the new PR thing.

@ghost

ghost commented Dec 4, 2023

Copy link
Copy Markdown

In fact, maybe add a preceding commit of their original code as-is, and then your commit with your changes to the OpenCL code + addition of your host code? So that we have revision history of their code vs. first our revision of it in here. I'm sorry this idea didn't occur to me in our e-mail discussion.

How to do that? I think we can't add commits on the past. Do I close this PR and Create a new one with a new fork of JtR code?

An easy way to do this:

  • copy all 8 files you changed to another folder (keep them saved).
  • git reset --hard HEAD~1 # this will revert the last commit (you will lose everything).
  • do your change (the original code as-is)
  • commit and save your work;
  • copy back all 8 files.
  • create the second commit (you can edit things before the second commit, if you want to).
  • git push origin bleeding-jumbo -f

You can also use git rebase -i, but the above list of tasks is quite easy to understand and follow.

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Just for the record, here are the speeds at $argon2d$v=19$m=16384,t=3,p=1$c2hvcnRfc2FsdA$TLSTPihIo+5F67Y1vJdfWdB9:

GTX 1080:

[solar@super run]$ ./john -form=argon2-opencl -w=w pw -dev=4
Device 4: GeForce GTX 1080
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl [Blake2 OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes

Trying to use 4096 MB / 8119 MB GPU memory. Max Allocation: 2029 MB
Autotune [type: 1, lanes: 1, segments: 4096 => (1, 1) => 12 ms]
Autotune [type: 0, lanes: 1, segments: 4096 => (1, 1) => 10 ms]
Autotune [type: 1, lanes: 1, segments: 1024 => (1, 1) => 02 ms]
Autotune [type: 0, lanes: 1, segments: 1024 => (1, 1) => 02 ms]
Autotune [type: 2, lanes: 3, segments: 1365 => (1, 1) => 11 ms]
Autotune [type: 2, lanes: 1, segments: 1024 => (1, 1) => 02 ms]
Autotune [type: 1, lanes: 3, segments: 1365 => (1, 1) => 12 ms]
Autotune [type: 0, lanes: 3, segments: 1365 => (1, 1) => 09 ms]
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
blessed_dead     (?)     
1g 0:00:00:06 DONE (2023-12-04 18:00) 0g/s 1428p/s 1428c/s 1428C/s Dev#4:44C slipknot6..fighter1

(was 1416 c/s with turbo off on host CPUs, like I normally keep them lately to save power)

Even the speed on Titan Kepler isn't bad:

[solar@super run]$ ./john -form=argon2-opencl -w=w pw -dev=6
Device 6: GeForce GTX TITAN
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl [Blake2 OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes

Trying to use 4096 MB / 6083 MB GPU memory. Max Allocation: 1520 MB
Autotune [type: 1, lanes: 1, segments: 4096 => (1, 4) => 22 ms]
Autotune [type: 0, lanes: 1, segments: 4096 => (1, 2) => 18 ms]
Autotune [type: 1, lanes: 1, segments: 1024 => (1, 2) => 05 ms]
Autotune [type: 0, lanes: 1, segments: 1024 => (1, 2) => 04 ms]
Autotune [type: 2, lanes: 3, segments: 1365 => (1, 1) => 25 ms]
Autotune [type: 2, lanes: 1, segments: 1024 => (1, 2) => 05 ms]
Autotune [type: 1, lanes: 3, segments: 1365 => (1, 1) => 25 ms]
Autotune [type: 0, lanes: 3, segments: 1365 => (1, 1) => 23 ms]
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
blessed_dead     (?)     
1g 0:00:00:10 DONE (2023-12-04 18:05) 0g/s 934.8p/s 934.8c/s 934.8C/s Dev#6:56C slipknot6..fighter1

CPU format, 2x E5-2670, turbo on, slight unrelated load on ~1 core:

[solar@super run]$ GOMP_CPU_AFFINITY=0-31 OMP_NUM_THREADS=31 ./john -form=argon2 -w=w pw 
Using default input encoding: UTF-8
Loaded 1 password hash (argon2 [Blake2 AVX])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i]) is 0 for all loaded hashes
Will run 31 OpenMP threads
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
blessed_dead     (?)     
1g 0:00:00:36 DONE (2023-12-04 17:57) 0g/s 283.4p/s 283.4c/s 283.4C/s leonard1..rainbow123

So there's a 5x speedup at these Argon2 settings (which are more reasonable than the 4 MiB ones we historically use in --test) when going from CPUs to GTX 1080. Not bad for the first PR.

@alainesp

alainesp commented Dec 4, 2023

Copy link
Copy Markdown
Contributor Author

An easy way to do this:

  • copy all 8 files you changed to another folder (keep them saved).
  • git reset --hard HEAD~1 # this will revert the last commit (you will lose everything).
  • do your change (the original code as-is)
  • commit and save your work;
  • copy back all 8 files.
  • create the second commit (you can edit things before the second commit, if you want to).
  • git push origin bleeding-jumbo -f

I did that. I think now the PR is in order?

//-------------------------------------------------------------------------------------
//
// Based on OpenCL code from https://gitlab.com/omos/argon2-gpu.
// Copyright (c) 2016 Ondrej Mosnáček

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If what we have here is a derived work to an extent that @WOnder93 is a copyright holder, then we have to use his MIT license for this source file. That license says: "this permission notice shall be included in all copies or substantial portions of the Software." It says "this permission notice" (emphasis mine), so we should not replace MIT's permission notice with ours.

Alternatively, we need @WOnder93's permission to use our 0-clause BSD for the derived work.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to see my 7 years old code being useful :)

I'd prefer to keep the licensing as is. Does having an MIT-licensed code in john pose a problem for you? If yes, I can consider dual-licensing it also under 0BSD.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WOnder93 This isn't really a problem, but if you simply reply here saying we can relicense the code under 0BSD, that would make things more consistent for us. There's no need for you to make changes in your repo. Thank you!

I think we'll be switching this code to use our shared header files e.g. providing device type detection and bit rotate macros, which are under 0BSD.

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

I did that. I think now the PR is in order?

What you did is as desired, thank you! However, now we (1) expect CI failure when it starts testing this new format (and we'll need to deal with that, e.g. by excluding this format from CI for now), and (2) need to address the kernel license issue (maybe Ondrej will be quick to comment, so please don't hurry to make changes yet).

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

expect CI failure when it starts testing this new format

Oh, I was too quick to state that. First we need to merge @claudioandre-br's PR reverting us to older Intel OpenCL, then you need to rebase on top of that.

@ghost

ghost commented Dec 4, 2023

Copy link
Copy Markdown

Just run (after the merge of #5383 ).

git pull --rebase git@github.com:openwall/john.git
git push origin bleeding-jumbo -f

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Merge branch 'openwall:bleeding-jumbo' into bleeding-jumbo

No, we don't do things like that! Please remove this merge commit and rebase instead.

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Looks good now, thanks @alainesp! Now waiting to see what CI says about the new format (expecting failure since it's known to fail on CPU in our manual tests).

@alainesp

alainesp commented Dec 4, 2023

Copy link
Copy Markdown
Contributor Author

Just for the record, here are the speeds at $argon2d$v=19$m=16384,t=3,p=1$c2hvcnRfc2FsdA$TLSTPihIo+5F67Y1vJdfWdB9:

GTX 1080:

[solar@super run]$ ./john -form=argon2-opencl -w=w pw -dev=4
Device 4: GeForce GTX 1080
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl [Blake2 OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes

Trying to use 4096 MB / 8119 MB GPU memory. Max Allocation: 2029 MB
Autotune [type: 1, lanes: 1, segments: 4096 => (1, 1) => 12 ms]
Autotune [type: 0, lanes: 1, segments: 4096 => (1, 1) => 10 ms]
Autotune [type: 1, lanes: 1, segments: 1024 => (1, 1) => 02 ms]
Autotune [type: 0, lanes: 1, segments: 1024 => (1, 1) => 02 ms]
Autotune [type: 2, lanes: 3, segments: 1365 => (1, 1) => 11 ms]
Autotune [type: 2, lanes: 1, segments: 1024 => (1, 1) => 02 ms]
Autotune [type: 1, lanes: 3, segments: 1365 => (1, 1) => 12 ms]
Autotune [type: 0, lanes: 3, segments: 1365 => (1, 1) => 09 ms]
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
blessed_dead     (?)     
1g 0:00:00:06 DONE (2023-12-04 18:00) 0g/s 1428p/s 1428c/s 1428C/s Dev#4:44C slipknot6..fighter1

(was 1416 c/s with turbo off on host CPUs, like I normally keep them lately to save power)

Using more GPU memory may result in better performance. You can change it using an appropriate GWS.

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Using more GPU memory may result in better performance. You can change it using an appropriate GWS.

Yes, got slight speedup below - but it's hard to tune GWS for this format manually given that it does not report what value of GWS it had auto-selected (our typical formats report LWS and GWS, and this one eventually should too). Also, trying some GWS values gave me Invalid lanes_per_block! - by the way, without a trailing linefeed.

[solar@super run]$ ./john -form=argon2-opencl -w=w pw -dev=4 -gws=46080
Device 4: GeForce GTX 1080
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl [Blake2 OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes

Custom GWS result on MAX_KEYS_PER_CRYPT = 480
Trying to use 7680 MB / 8119 MB GPU memory. Max Allocation: 2029 MB
Autotune [type: 1, lanes: 1, segments: 4096 => (1, 1) => 18 ms]
Autotune [type: 0, lanes: 1, segments: 4096 => (1, 1) => 16 ms]
Autotune [type: 1, lanes: 1, segments: 1024 => (1, 1) => 04 ms]
Autotune [type: 0, lanes: 1, segments: 1024 => (1, 1) => 03 ms]
Autotune [type: 2, lanes: 3, segments: 1365 => (1, 1) => 19 ms]
Autotune [type: 2, lanes: 1, segments: 1024 => (1, 1) => 04 ms]
Autotune [type: 1, lanes: 3, segments: 1365 => (1, 1) => 19 ms]
Autotune [type: 0, lanes: 3, segments: 1365 => (1, 1) => 14 ms]
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
blessed_dead     (?)     
1g 0:00:00:06 DONE (2023-12-04 18:48) 0g/s 1557p/s 1557c/s 1557C/s Dev#4:60C doodoo..coralie

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Now waiting to see what CI says about the new format (expecting failure since it's known to fail on CPU in our manual tests).

CI passed test - turns out we're only testing 16 OpenCL formats, @claudioandre-br?

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

@alainesp Please also add a NEWS entry when convenient. Thank you!

@ghost

ghost commented Dec 4, 2023

Copy link
Copy Markdown

Now waiting to see what CI says about the new format (expecting failure since it's known to fail on CPU in our manual tests).

CI passed test - turns out we're only testing 16 OpenCL formats, @claudioandre-br?

This is an encoding test (not OpenCL one).

Only formats with some tag (FMT_UNICODE or FMT_ENC or ...) are being tested.

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Titan X Maxwell defaults:

[solar@super run]$ ./john -form=argon2-opencl -w=w pw -dev=5
Device 5: GeForce GTX TITAN X
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl [Blake2 OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes

Trying to use 4096 MB / 12212 MB GPU memory. Max Allocation: 3053 MB
Autotune [type: 1, lanes: 1, segments: 4096 => (1, 1) => 17 ms]
Autotune [type: 0, lanes: 1, segments: 4096 => (1, 1) => 15 ms]
Autotune [type: 1, lanes: 1, segments: 1024 => (1, 1) => 04 ms]
Autotune [type: 0, lanes: 1, segments: 1024 => (1, 1) => 03 ms]
Autotune [type: 2, lanes: 3, segments: 1365 => (1, 1) => 09 ms]
Autotune [type: 2, lanes: 1, segments: 1024 => (1, 1) => 04 ms]
Autotune [type: 1, lanes: 3, segments: 1365 => (1, 1) => 09 ms]
Autotune [type: 0, lanes: 3, segments: 1365 => (1, 1) => 08 ms]
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
blessed_dead     (?)
1g 0:00:00:09 DONE (2023-12-04 19:01) 0g/s 1026p/s 1026c/s 1026C/s Dev#5:66C slipknot6..fighter1

Doubled(?) GWS is slightly faster:

[solar@super run]$ ./john -form=argon2-opencl -w=w pw -dev=5 -gws=49152
Device 5: GeForce GTX TITAN X
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl [Blake2 OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes

Custom GWS result on MAX_KEYS_PER_CRYPT = 512
Trying to use 8192 MB / 12212 MB GPU memory. Max Allocation: 3053 MB
Autotune [type: 1, lanes: 1, segments: 4096 => (1, 2) => 21 ms]
Autotune [type: 0, lanes: 1, segments: 4096 => (1, 4) => 19 ms]
Autotune [type: 1, lanes: 1, segments: 1024 => (1, 2) => 05 ms]
Autotune [type: 0, lanes: 1, segments: 1024 => (1, 4) => 04 ms]
Autotune [type: 2, lanes: 3, segments: 1365 => (1, 1) => 17 ms]
Autotune [type: 2, lanes: 1, segments: 1024 => (1, 2) => 05 ms]
Autotune [type: 1, lanes: 3, segments: 1365 => (1, 1) => 17 ms]
Autotune [type: 0, lanes: 3, segments: 1365 => (1, 1) => 16 ms]
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
blessed_dead     (?)
1g 0:00:00:09 DONE (2023-12-04 19:04) 0g/s 1055p/s 1055c/s 1055C/s Dev#5:64C slipknot6..jordan5

Nearly max GWS is slower:

[solar@super run]$ ./john -form=argon2-opencl -w=w pw -dev=5 -gws=72000
Device 5: GeForce GTX TITAN X
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl [Blake2 OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes

Custom GWS result on MAX_KEYS_PER_CRYPT = 750
Trying to use 12000 MB / 12212 MB GPU memory. Max Allocation: 3053 MB
Autotune [type: 1, lanes: 1, segments: 4096 => (1, 1) => 45 ms]
Autotune [type: 0, lanes: 1, segments: 4096 => (1, 1) => 30 ms]
Autotune [type: 1, lanes: 1, segments: 1024 => (1, 1) => 07 ms]
Autotune [type: 0, lanes: 1, segments: 1024 => (1, 1) => 07 ms]
Autotune [type: 2, lanes: 3, segments: 1365 => (1, 1) => 26 ms]
Autotune [type: 2, lanes: 1, segments: 1024 => (1, 1) => 07 ms]
Autotune [type: 1, lanes: 3, segments: 1365 => (1, 1) => 27 ms]
Autotune [type: 0, lanes: 3, segments: 1365 => (1, 1) => 24 ms]
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
blessed_dead     (?)     
1g 0:00:00:16 DONE (2023-12-04 19:07) 0g/s 621.3p/s 621.3c/s 621.3C/s Dev#5:54C 258741..italian

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Vega 64 defaults:

[solar@super run]$ ./john -form=argon2-opencl -w=w pw -dev=1 
Device 1: gfx900 [Radeon RX Vega]
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl [Blake2 OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes

Trying to use 4096 MB / 8176 MB GPU memory. Max Allocation: 4048 MB

Trying to use 2048 MB / 8176 MB GPU memory. Max Allocation: 4048 MB
Autotune [type: 1, lanes: 1, segments: 4096 => (1, 1) => 15 ms]
Autotune [type: 0, lanes: 1, segments: 4096 => (1, 1) => 15 ms]
Autotune [type: 1, lanes: 1, segments: 1024 => (1, 1) => 03 ms]
Autotune [type: 0, lanes: 1, segments: 1024 => (1, 1) => 03 ms]
Autotune [type: 2, lanes: 3, segments: 1365 => (1, 1) => 07 ms]
Autotune [type: 2, lanes: 1, segments: 1024 => (1, 1) => 04 ms]
Autotune [type: 1, lanes: 3, segments: 1365 => (1, 1) => 07 ms]
Autotune [type: 0, lanes: 3, segments: 1365 => (1, 1) => 07 ms]
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
blessed_dead     (?)     
1g 0:00:00:15 DONE (2023-12-04 19:12) 0g/s 637.5p/s 637.5c/s 637.5C/s fuzzy1..fighter1

Tuned:

[solar@super run]$ ./john -form=argon2-opencl -w=w pw -dev=1 -gws=45056
Device 1: gfx900 [Radeon RX Vega]
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl [Blake2 OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes

Custom GWS result on MAX_KEYS_PER_CRYPT = 469
Trying to use 7504 MB / 8176 MB GPU memory. Max Allocation: 4048 MB

Trying to use 3752 MB / 8176 MB GPU memory. Max Allocation: 4048 MB
Autotune [type: 1, lanes: 1, segments: 4096 => (1, 1) => 16 ms]
Autotune [type: 0, lanes: 1, segments: 4096 => (1, 1) => 16 ms]
Autotune [type: 1, lanes: 1, segments: 1024 => (1, 1) => 04 ms]
Autotune [type: 0, lanes: 1, segments: 1024 => (1, 1) => 04 ms]
Autotune [type: 2, lanes: 3, segments: 1365 => (1, 1) => 10 ms]
Autotune [type: 2, lanes: 1, segments: 1024 => (1, 1) => 04 ms]
Autotune [type: 1, lanes: 3, segments: 1365 => (1, 1) => 09 ms]
Autotune [type: 0, lanes: 3, segments: 1365 => (1, 1) => 09 ms]
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
blessed_dead     (?)     
1g 0:00:00:09 DONE (2023-12-04 19:13) 0g/s 1073p/s 1073c/s 1073C/s angelbaby..good123

Looks like we'll eventually (beyond this PR) need some trick to bypass the max allocation on AMD, as the above is using at most half the memory.

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

This is an encoding test (not OpenCL one).

Only formats with some tag (FMT_UNICODE or FMT_ENC or ...) are being tested.

Hmm, this makes some sense. Can we afford to test all OpenCL formats (or excluding only those where failure is somehow expected)?

@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Anyway, I think this PR is good enough to merge now! So I will. Further improvements are to be in their own PRs then.

@solardiz solardiz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's of course a lot to clean up here, but this is a good start.

@solardiz
solardiz merged commit 4222aa4 into openwall:bleeding-jumbo Dec 4, 2023
@solardiz

solardiz commented Dec 4, 2023

Copy link
Copy Markdown
Member

Added MIT license to OpenCL code

@alainesp For further occasions, please prefix your commit titles with subsystem name (where applicable), e.g. this one could have been argon2-opencl: Add MIT license to OpenCL code.

@ghost

ghost commented Dec 4, 2023

Copy link
Copy Markdown

Can we afford to test all OpenCL formats?

The problem is that this would take a long time (the encoding test alone takes more than 10 minutes).

  • we expect CI to give us something back in 5 to 10 minutes.

The Intel driver/runtime is slow.

HANDLE_CLERROR(clEnqueueWriteBufferRect(queue[gpu_id], memory_buffer, CL_FALSE,
zero3, zero3,
region3_in,
jobSize, 0, copySize, 0, blocks_in, 0, NULL, NULL), "Copy data to gpu");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only usage of clEnqueueWriteBufferRect currently in our tree. Is there any special reason why we need this specific OpenCL function here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we need to copy the memory to the GPU by pieces and not continuously, and that's what clEnqueueWriteBufferRect provides.

@solardiz

Copy link
Copy Markdown
Member

CPU format, 2x E5-2670, turbo on, slight unrelated load on ~1 core:

Looks like I underestimated the effect of that slight unrelated load back then. Testing now, I get only 4x speedup for GTX 1080 vs. 2x E5-2670 on idle system (CPU turbo on, GPU not yet fully heated up so also at max turbo). That's for our latest code, beyond what was in this PR.

[solar@super run]$ GOMP_CPU_AFFINITY=0-31 ./john pw-argon2 -w=w -form=opencl -dev=4
Device 4: GeForce GTX 1080
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl [Blake2 OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes
Trying to compute 480 hashes at a time using 7680 of 8119 MiB device memory
LWS=[32-256] GWS=[15360-15360] ([60-480] blocks) => Mode: WARP_SHUFFLE
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
0g 0:00:00:02 0.22% (ETA: 21:39:36) 0g/s 1634p/s 1634c/s 1634C/s Dev#4:47C lauren1..stonecold
0g 0:00:00:04 0.40% (ETA: 21:40:55) 0g/s 1690p/s 1690c/s 1690C/s Dev#4:49C password14..piccolo
0g 0:00:00:18 1.74% (ETA: 21:41:30) 0g/s 1741p/s 1741c/s 1741C/s Dev#4:53C 310591..hairball
0g 0:00:00:20 1.92% (ETA: 21:41:36) 0g/s 1743p/s 1743c/s 1743C/s Dev#4:54C cannavaro..manpreet
0g 0:00:00:24 2.31% (ETA: 21:41:32) 0g/s 1745p/s 1745c/s 1745C/s Dev#4:55C 03011986..calvin123
blessed_dead     (?)     
1g 0:00:00:28 DONE (2024-03-27 21:24) 0.03457g/s 1742p/s 1742c/s 1742C/s Dev#4:53C thriller1..d1amond
[solar@super run]$ GOMP_CPU_AFFINITY=0-31 ./john pw-argon2 -w=w 
Warning: detected hash type "argon2", but the string is also recognized as "argon2-opencl"
Use the "--format=argon2-opencl" option to force loading these as that type instead
Using default input encoding: UTF-8
Loaded 1 password hash (argon2 [Blake2 AVX])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i]) is 0 for all loaded hashes
Will run 32 OpenMP threads
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
0g 0:00:00:03 0.11% (ETA: 22:12:42) 0g/s 422.0p/s 422.0c/s 422.0C/s keller..222222
0g 0:00:00:07 0.18% (ETA: 22:31:15) 0g/s 430.3p/s 430.3c/s 430.3C/s modem..123654789
blessed_dead     (?)     
1g 0:00:01:54 DONE (2024-03-27 21:27) 0.008726g/s 437.8p/s 437.8c/s 437.8C/s 050489..010591

(The wordlist is different from what I used before. I now put the correct password around line 50k. I think previous one was with it at around like 10k.)

@solardiz

Copy link
Copy Markdown
Member

Curiously, the above test (with our latest code, not from this PR's) works even on the ancient GTX 570 with 1280 MB:

$ ./john -form=argon2-opencl -w=w pw-argon2
Device 1: GeForce GTX 570
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl [Blake2 OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes
Note: Passwords longer than 33 [worst case UTF-8] to 100 [ASCII] rejected
Trying to compute 74 hashes at a time using 1184 of 1279 MiB device memory
LWS=32 GWS=2368 (74 blocks) => Mode: LOCAL_MEMORY
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
0g 0:00:00:07 0.13% (ETA: 18:45:01) 0g/s 333.5p/s 333.5c/s 333.5C/s Dev#1:53C cheerleader..yourmom
0g 0:00:00:10 0.17% (ETA: 18:49:42) 0g/s 335.0p/s 335.0c/s 335.0C/s Dev#1:55C lima..1332
0g 0:00:00:23 0.41% (ETA: 18:45:18) 0g/s 337.2p/s 337.2c/s 337.2C/s Dev#1:59C lifesucks..marcello
0g 0:00:00:49 0.90% (ETA: 18:43:24) 0g/s 338.1p/s 338.1c/s 338.1C/s Dev#1:66C sassie..weed12
0g 0:00:01:27 1.60% (ETA: 18:43:21) 0g/s 338.2p/s 338.2c/s 338.2C/s Dev#1:69C 21021989..17111986
0g 0:00:01:46 1.95% (ETA: 18:43:18) 0g/s 338.3p/s 338.3c/s 338.3C/s Dev#1:70C 27111989..228228228
0g 0:00:02:12 2.43% (ETA: 18:43:11) 0g/s 338.3p/s 338.3c/s 338.3C/s Dev#1:71C gr33nday..Undertaker
blessed_dead     (?)
1g 0:00:02:27 DONE (2024-08-13 17:14) 0.006762g/s 338.3p/s 338.3c/s 338.3C/s Dev#1:71C alfaomega..199514

and our default tuning gets really close to the full memory size:

| NVIDIA-SMI 5.319.23   Driver Version: 319.23         |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 570     Off  | 0000:01:00.0     N/A |                  N/A |
| 61%   71C  N/A     N/A /  N/A |     1257MB /  1279MB |     N/A      Default |

This speed isn't bad for this ancient machine, too. Running the same on its FX-8120 CPU gives ~110 c/s. So even with such low GPU memory size, the GPU provides a 3x speedup over CPU on this 12 year old machine.

@solardiz

Copy link
Copy Markdown
Member

Same test on RTX 5090:

$ cat pw-argon2
$argon2d$v=19$m=16384,t=3,p=1$c2hvcnRfc2FsdA$TLSTPihIo+5F67Y1vJdfWdB9
$ ./john -form=argon2-opencl -w=w pw-argon2
Device 1: NVIDIA GeForce RTX 5090
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl, Argon2 [BlaMka OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes
Trying to compute 1700 hashes at a time using 27200 of 32109 MiB device memory
LWS=32 GWS=54400 (1700 blocks) => Mode: WARP_SHUFFLE
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
blessed_dead     (?)     
1g 0:00:00:04 DONE (2025-07-31 04:47) 0.2242g/s 11434p/s 11434c/s 11434C/s Dev#1:38°C 28071982..rangers9

That's with correct password around line 50k, as in previous tests. Now trying with it around like 500k (since 4 seconds feels too quick for a proper test):

$ ./john -form=argon2-opencl -w=w pw-argon2
Device 1: NVIDIA GeForce RTX 5090
Using default input encoding: UTF-8
Loaded 1 password hash (argon2-opencl, Argon2 [BlaMka OpenCL])
Cost 1 (t) is 3 for all loaded hashes
Cost 2 (m) is 16384 for all loaded hashes
Cost 3 (p) is 1 for all loaded hashes
Cost 4 (type [0:Argon2d 1:Argon2i 2:Argon2id]) is 0 for all loaded hashes
Trying to compute 1700 hashes at a time using 27200 of 32109 MiB device memory
LWS=32 GWS=54400 (1700 blocks) => Mode: WARP_SHUFFLE
Press 'q' or Ctrl-C to abort, 'h' for help, almost any other key for status
blessed_dead     (?)     
1g 0:00:00:43 DONE (2025-07-31 04:49) 0.02286g/s 11465p/s 11465c/s 11465C/s Dev#1:47°C 74427442..sexgirl1

@solardiz solardiz mentioned this pull request Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants