[GH-ISSUE #716] Implement RAR 5 (PBKDF2-SHA256) OpenCL format #360

Closed
opened 2026-10-14 03:02:54 +07:00 by bsakaguchi · 27 comments
Owner

Originally created by @kholia on GitHub (Aug 15, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/716

Originally assigned to: @magnumripper on GitHub.

@magnumripper hi, are you up for it?

Originally created by @kholia on GitHub (Aug 15, 2014). Original GitHub issue: https://github.com/openwall/john/issues/716 Originally assigned to: @magnumripper on GitHub. @magnumripper hi, are you up for it?
bsakaguchi 2026-10-14 03:02:54 +07:00
Author
Owner

@kholia commented on GitHub (Aug 15, 2014):

$ ../run/john --format=rar5 --test
Will run 8 OpenMP threads
Benchmarking: RAR5 [(experimental) PBKDF2-SHA256 32/64]... (8xOMP) DONE
Raw:    88.0 c/s real, 11.2 c/s virtual

This format sucks too much on CPU ;(

<!-- gh-comment-id:52289094 --> @kholia commented on GitHub (Aug 15, 2014): ``` $ ../run/john --format=rar5 --test Will run 8 OpenMP threads Benchmarking: RAR5 [(experimental) PBKDF2-SHA256 32/64]... (8xOMP) DONE Raw: 88.0 c/s real, 11.2 c/s virtual ``` This format sucks too much on CPU ;(
Author
Owner

@magnumripper commented on GitHub (Aug 15, 2014):

Should be easy. And possibly faster than RAR3!

How's this format in terms of post-processing or verification?

<!-- gh-comment-id:52308709 --> @magnumripper commented on GitHub (Aug 15, 2014): Should be easy. And possibly faster than RAR3! How's this format in terms of post-processing or verification?
Author
Owner

@magnumripper commented on GitHub (Aug 15, 2014):

Seems fine.

        // special wtf processing
        memset(PswCheck, 0, SIZE_PSWCHECK);
        for (i = 0; i <SHA256_DIGEST_SIZE; i++)
            PswCheck[i % SIZE_PSWCHECK] ^= PswCheckValue[i];

Then we have a "real" binary (with sufficient size) and normal cmp_* functions!

<!-- gh-comment-id:52308992 --> @magnumripper commented on GitHub (Aug 15, 2014): Seems fine. ``` // special wtf processing memset(PswCheck, 0, SIZE_PSWCHECK); for (i = 0; i <SHA256_DIGEST_SIZE; i++) PswCheck[i % SIZE_PSWCHECK] ^= PswCheckValue[i]; ``` Then we have a "real" binary (with sufficient size) and normal cmp_\* functions!
Author
Owner

@kholia commented on GitHub (Aug 15, 2014):

Cool 👍

So far, I could only crack two RAR 5 hashes from CMIYC 2014 using the CPU format.

Also, I suspect that our format might be somewhat buggy currently (I forgot what I missed implementing in it though).

<!-- gh-comment-id:52309425 --> @kholia commented on GitHub (Aug 15, 2014): Cool :+1: So far, I could only crack two RAR 5 hashes from CMIYC 2014 using the CPU format. Also, I suspect that our format might be somewhat buggy currently (I forgot what I missed implementing in it though).
Author
Owner

@magnumripper commented on GitHub (Aug 15, 2014):

Also, I suspect that our format might be somewhat buggy currently (I forgot what I missed implementing in it though).

rar5tojohn has this:

# TODO: Only files using "PSWCHECK" are supported

As far as I can see, files not using "PSWCHECK" will be rejected by rar5tojohn, which makes it Good Enough™ (for now) in my book. I presume supporting other files will be a lot more complicated, probably requiring implementing unrar5() and probably a new story of finding early rejections. Hopefully such files will be rare?

<!-- gh-comment-id:52361339 --> @magnumripper commented on GitHub (Aug 15, 2014): > Also, I suspect that our format might be somewhat buggy currently (I forgot what I missed implementing in it though). rar5tojohn has this: ``` # TODO: Only files using "PSWCHECK" are supported ``` As far as I can see, files not using "PSWCHECK" will be rejected by rar5tojohn, which makes it Good Enough™ (for now) in my book. I presume supporting other files will be a lot more complicated, probably requiring implementing unrar5() and probably a new story of finding early rejections. Hopefully such files will be rare?
Author
Owner

@magnumripper commented on GitHub (Aug 20, 2014):

Hmm this is not PBKDF2, is it? I believe it's just iterated HMAC-SHA256, with crap added to confuse the spectator. We should change the algorithm names.

<!-- gh-comment-id:52754117 --> @magnumripper commented on GitHub (Aug 20, 2014): Hmm this is not PBKDF2, is it? I believe it's just iterated HMAC-SHA256, with crap added to confuse the spectator. We should change the algorithm names.
Author
Owner

@kholia commented on GitHub (Aug 20, 2014):

Yes, you are right. PBKDF2 work is just used for marketing it seems ;(

http://www.rarlab.com/technote.htm

<!-- gh-comment-id:52758754 --> @kholia commented on GitHub (Aug 20, 2014): Yes, you are right. PBKDF2 work is just used for marketing it seems ;( http://www.rarlab.com/technote.htm
Author
Owner

@magnumripper commented on GitHub (Aug 20, 2014):

We could say "alleged PBKDF2" to avoid confusing people too much 😕

<!-- gh-comment-id:52814407 --> @magnumripper commented on GitHub (Aug 20, 2014): We could say "alleged PBKDF2" to avoid confusing people too much :confused:
Author
Owner

@magnumripper commented on GitHub (Aug 20, 2014):

Still, I think the usual tricks to double the speed of PBKDF2 applies here as well. I just need to wrap my head around it.

<!-- gh-comment-id:52814736 --> @magnumripper commented on GitHub (Aug 20, 2014): Still, I think the usual tricks to double the speed of PBKDF2 applies here as well. I just need to wrap my head around it.
Author
Owner

@kholia commented on GitHub (Aug 20, 2014):

I actually committed your "alleged PBKDF2" idea just now 👍

<!-- gh-comment-id:52815272 --> @kholia commented on GitHub (Aug 20, 2014): I actually committed your "alleged PBKDF2" idea just now :+1:
Author
Owner

@magnumripper commented on GitHub (Aug 20, 2014):

It might actually be normal PBKDF2 for Key, I'm not really sure yet. Unrolling the outer loop makes it look a lot less strange. Anyway I have a 33% boost for the CPU format already, just by not re-hashing things that doesn't change within the loops.

<!-- gh-comment-id:52849964 --> @magnumripper commented on GitHub (Aug 20, 2014): It might actually be normal PBKDF2 for `Key`, I'm not really sure yet. Unrolling the outer loop makes it look a lot less strange. Anyway I have a 33% boost for the CPU format already, just by not re-hashing things that doesn't change within the loops.
Author
Owner

@magnumripper commented on GitHub (Aug 20, 2014):

Ouch.

static void *get_salt(char *ciphertext)
{
...
    cs.iterations = 1 << 15;

We need to fix this before doing anything else. rar5tojohn must store the actual iterations count and we must honor it. Some comments indicate it's stored in the "hash" but I believe it isn't. Only (redundant) hash lengths are. Right? I'm adding a separate issue (#720) for this.

<!-- gh-comment-id:52850424 --> @magnumripper commented on GitHub (Aug 20, 2014): Ouch. ``` static void *get_salt(char *ciphertext) { ... cs.iterations = 1 << 15; ``` We need to fix this before doing anything else. rar5tojohn must store the actual iterations count and we must honor it. Some comments indicate it's stored in the "hash" but I believe it isn't. Only (redundant) hash lengths are. Right? I'm adding a separate issue (#720) for this.
Author
Owner

@magnumripper commented on GitHub (Aug 20, 2014):

Anyway I have a 33% boost for the CPU format already

Make that 90% 😄 ... see 1e6acb9

<!-- gh-comment-id:52850935 --> @magnumripper commented on GitHub (Aug 20, 2014): > Anyway I have a 33% boost for the CPU format already Make that 90% :smile: ... see 1e6acb9
Author
Owner

@magnumripper commented on GitHub (Aug 26, 2014):

First try in 3774f329. Not yet faster than RAR3 :-(

$ ../run/john -test -form:rar5-opencl -dev=1
Benchmarking: RAR5-opencl [PBKDF2-SHA256 OpenCL]... Device 1: Tahiti
Local worksize (LWS) 64, Global worksize (GWS) 32768
DONE
Raw:    15906 c/s real, 3276K c/s virtual

According to its web site, cRARk is also slower with RAR5 than RAR3. But at lengths over 8 or so, RAR5 should be faster and it doesn't get any performance hit from varying password length in a batch.

<!-- gh-comment-id:53464563 --> @magnumripper commented on GitHub (Aug 26, 2014): First try in 3774f329. Not yet faster than RAR3 :-( ``` $ ../run/john -test -form:rar5-opencl -dev=1 Benchmarking: RAR5-opencl [PBKDF2-SHA256 OpenCL]... Device 1: Tahiti Local worksize (LWS) 64, Global worksize (GWS) 32768 DONE Raw: 15906 c/s real, 3276K c/s virtual ``` According to its web site, cRARk is also slower with RAR5 than RAR3. But at lengths over 8 or so, RAR5 should be faster and it doesn't get any performance hit from varying password length in a batch.
Author
Owner

@kholia commented on GitHub (Aug 26, 2014):

Good stuff 👍

<!-- gh-comment-id:53465512 --> @kholia commented on GitHub (Aug 26, 2014): Good stuff :+1:
Author
Owner

@magnumripper commented on GitHub (Aug 26, 2014):

Well it's better than 88 c/s 😆

<!-- gh-comment-id:53467414 --> @magnumripper commented on GitHub (Aug 26, 2014): Well it's better than 88 c/s :laughing:
Author
Owner

@magnumripper commented on GitHub (Aug 26, 2014):

I believe we are doing 65,602 (or so) SHA2 operations per candidate so that would mean we're doing about a billion SHA256 per second on Tahiti. That seems to be on par with oclHashcat's raw speed so maybe we're closer to the theoretical limit than I thought.

That's your kernel @ukasz - I did not modifiy a bit of it! Good stuff.

<!-- gh-comment-id:53467805 --> @magnumripper commented on GitHub (Aug 26, 2014): I believe we are doing 65,602 (or so) SHA2 operations per candidate so that would mean we're doing about a billion SHA256 per second on Tahiti. That seems to be on par with oclHashcat's raw speed so maybe we're closer to the theoretical limit than I thought. That's your kernel @ukasz - I did not modifiy a bit of it! Good stuff.
Author
Owner

@ghost commented on GitHub (Aug 27, 2014):

I tried to use shared code for auto-tune in this new file. I will publish it here for future reference.

<!-- gh-comment-id:53592860 --> @ghost commented on GitHub (Aug 27, 2014): I tried to use shared code for auto-tune in this new file. I will publish it here for future reference. - https://gist.github.com/claudioandre/52936b0bddbee00eb5c2
Author
Owner

@ghost commented on GitHub (Aug 27, 2014):

BTW:

$ ../run/john -te   -form=RAR5-opencl -dev=0 -verb=5
[...]
Benchmarking: RAR5-opencl [PBKDF2-SHA256 OpenCL]... Device 0: Juniper (AMD Radeon HD 6700 Series)
Calculating best global worksize (GWS); max. 10.0 s duration.
Raw speed figures including buffer transfers:
data xfer: 0.37 ms, salt xfer: 0.58 ms, prepare: 0.59 ms, result xfer: 0.30 ms, crypt: 57.54 ms
gws:      1024        1110 c/s    36409997 rounds/s   0.922 sec per crypt_all()+
data xfer: 0.21 ms, salt xfer: 0.19 ms, prepare: 0.13 ms, result xfer: 0.31 ms, crypt: 37.25 ms
gws:      2048        3430 c/s   112532356 rounds/s   0.597 sec per crypt_all()+
data xfer: 5.67 ms, salt xfer: 5.33 ms, prepare: 0.25 ms, result xfer: 5.20 ms, crypt: 74.41 ms
gws:      4096        3393 c/s   111302942 rounds/s   1.207 sec per crypt_all()
data xfer: 1.31 ms, salt xfer: 5.12 ms, prepare: 0.50 ms, result xfer: 0.24 ms, crypt: 148.66 ms
gws:      8192        3433 c/s   112625491 rounds/s   2.386 sec per crypt_all()
data xfer: 0.31 ms, salt xfer: 0.14 ms, prepare: 0.91 ms, result xfer: 0.35 ms, crypt: 260.11 ms
gws:     16384        3935 c/s   129070052 rounds/s   4.163 sec per crypt_all()+
data xfer: 0.57 ms, salt xfer: 0.01 ms, prepare: 1.73 ms, result xfer: 5.19 ms, crypt: 482.87 ms
gws:     32768        4237 c/s   138977036 rounds/s   7.733 sec per crypt_all()+
data xfer: 1.12 ms, salt xfer: 0.01 ms, prepare: 3.39 ms, result xfer: 0.63 ms, crypt: 965.54 ms
gws:     65536        4240 c/s   139093555 rounds/s  15.454 sec per crypt_all() - too slow
Optimal global worksize 32768
(to avoid this test on next run, put "rar5_GWS = 32768" in john.conf, section [Options:OpenCL])
Max local worksize 256, Optimal local worksize 256
(to avoid this test on next run, put "rar5_LWS = 256" in john.conf, section [Options:OpenCL])
Local worksize (LWS) 256, global worksize (GWS) 32768
DONE
Raw:    4228 c/s real, 5820 c/s virtual

<!-- gh-comment-id:53593114 --> @ghost commented on GitHub (Aug 27, 2014): BTW: ``` $ ../run/john -te -form=RAR5-opencl -dev=0 -verb=5 [...] Benchmarking: RAR5-opencl [PBKDF2-SHA256 OpenCL]... Device 0: Juniper (AMD Radeon HD 6700 Series) Calculating best global worksize (GWS); max. 10.0 s duration. Raw speed figures including buffer transfers: data xfer: 0.37 ms, salt xfer: 0.58 ms, prepare: 0.59 ms, result xfer: 0.30 ms, crypt: 57.54 ms gws: 1024 1110 c/s 36409997 rounds/s 0.922 sec per crypt_all()+ data xfer: 0.21 ms, salt xfer: 0.19 ms, prepare: 0.13 ms, result xfer: 0.31 ms, crypt: 37.25 ms gws: 2048 3430 c/s 112532356 rounds/s 0.597 sec per crypt_all()+ data xfer: 5.67 ms, salt xfer: 5.33 ms, prepare: 0.25 ms, result xfer: 5.20 ms, crypt: 74.41 ms gws: 4096 3393 c/s 111302942 rounds/s 1.207 sec per crypt_all() data xfer: 1.31 ms, salt xfer: 5.12 ms, prepare: 0.50 ms, result xfer: 0.24 ms, crypt: 148.66 ms gws: 8192 3433 c/s 112625491 rounds/s 2.386 sec per crypt_all() data xfer: 0.31 ms, salt xfer: 0.14 ms, prepare: 0.91 ms, result xfer: 0.35 ms, crypt: 260.11 ms gws: 16384 3935 c/s 129070052 rounds/s 4.163 sec per crypt_all()+ data xfer: 0.57 ms, salt xfer: 0.01 ms, prepare: 1.73 ms, result xfer: 5.19 ms, crypt: 482.87 ms gws: 32768 4237 c/s 138977036 rounds/s 7.733 sec per crypt_all()+ data xfer: 1.12 ms, salt xfer: 0.01 ms, prepare: 3.39 ms, result xfer: 0.63 ms, crypt: 965.54 ms gws: 65536 4240 c/s 139093555 rounds/s 15.454 sec per crypt_all() - too slow Optimal global worksize 32768 (to avoid this test on next run, put "rar5_GWS = 32768" in john.conf, section [Options:OpenCL]) Max local worksize 256, Optimal local worksize 256 (to avoid this test on next run, put "rar5_LWS = 256" in john.conf, section [Options:OpenCL]) Local worksize (LWS) 256, global worksize (GWS) 32768 DONE Raw: 4228 c/s real, 5820 c/s virtual ```
Author
Owner

@magnumripper commented on GitHub (Aug 27, 2014):

@claudioandre cool, I will commit that soon. I forgot how mature that shared code is now.

Almost the same patch should apply to opencl_pbkdf2_hmac_sha256_fmt_plug.c as well, it's almost identical.

<!-- gh-comment-id:53611379 --> @magnumripper commented on GitHub (Aug 27, 2014): @claudioandre cool, I will commit that soon. I forgot how mature that shared code is now. Almost the same patch should apply to opencl_pbkdf2_hmac_sha256_fmt_plug.c as well, it's almost identical.
Author
Owner

@magnumripper commented on GitHub (Aug 27, 2014):

The LWS enumeration is far too slow though, considering it almost never adds significant speed. I'll see how to tweak that.

<!-- gh-comment-id:53614299 --> @magnumripper commented on GitHub (Aug 27, 2014): The LWS enumeration is far too slow though, considering it almost never adds significant speed. I'll see how to tweak that.
Author
Owner

@ghost commented on GitHub (Aug 27, 2014):

I noticed that on CPU, but I guess there is a GPU on bull where max LWS is 1024 (a problem anyway).

To me, the best approach seems to be the usage of a default LWS (for example, 128). Something like this:

Inside the fmt_ file (already there - helper functions - just change from 0 to 128)

static size_t get_default_workgroup()
{
    return 128;
}
<!-- gh-comment-id:53634254 --> @ghost commented on GitHub (Aug 27, 2014): I noticed that on CPU, but I guess there is a GPU on bull where max LWS is 1024 (a problem anyway). To me, the best approach seems to be the usage of a default LWS (for example, 128). Something like this: Inside the fmt_ file (already there - helper functions - just change from 0 to 128) ``` static size_t get_default_workgroup() { return 128; } ```
Author
Owner

@magnumripper commented on GitHub (Aug 27, 2014):

Ah, yes I remember now we've been through this before :)

In this case the LWS enumeration does some good though: With enumeration, a self-test take just over a minute, LWS becomes 1024 and speed is 1631 c/s on my laptop GPU. Using a fixed value of 128, test takes 25 seconds and speed is 1481 c/s.

BTW using my old, non-shared enumeration (also with fixed LWS) it took 28 seconds and ended up with same GWS so it was no better in any way.

So I'll set the default to 128. You can still force an enumeration passing LWS=0. I like this, I should do this to all "my" formats. I had forgot about it :-)

<!-- gh-comment-id:53641615 --> @magnumripper commented on GitHub (Aug 27, 2014): Ah, yes I remember now we've been through this before :) In this case the LWS enumeration does some good though: With enumeration, a self-test take just over a minute, LWS becomes 1024 and speed is 1631 c/s on my laptop GPU. Using a fixed value of 128, test takes 25 seconds and speed is 1481 c/s. BTW using my old, non-shared enumeration (also with fixed LWS) it took 28 seconds and ended up with same GWS so it was no better in any way. So I'll set the default to 128. You can still force an enumeration passing LWS=0. I like this, I should do this to all "my" formats. I had forgot about it :-)
Author
Owner

@ghost commented on GitHub (Aug 27, 2014):

Also, you can experiment with HASH_LOOPS (if you haven't).

<!-- gh-comment-id:53656953 --> @ghost commented on GitHub (Aug 27, 2014): Also, you can experiment with HASH_LOOPS (if you haven't).
Author
Owner

@ghost commented on GitHub (Aug 29, 2014):

And, while doing some new test/development, try the below change (one and/or both)

diff --git a/src/common-opencl.c b/src/common-opencl.c

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- HEAD
+++ Modificado na Árvore de Trabalho
@@ -1289,14 +1289,14 @@
                           sizeof(cl_ulong), &endTime,
                           NULL),
               "Failed to get profiling info");
-   numloops = (int)(size_t)(500000000ULL / (endTime-startTime));
+   numloops = (int)(size_t)(200000000ULL / (endTime-startTime));

    release_profiling_events();

    if (numloops < 1)
        numloops = 1;
-   else if (numloops > 10)
-       numloops = 10;
+   else if (numloops > 5)
+       numloops = 5;

    // Find minimum time
    for (optimal_work_group = my_work_group = wg_multiple;
<!-- gh-comment-id:53900565 --> @ghost commented on GitHub (Aug 29, 2014): And, while doing some new test/development, try the below change (one and/or both) ``` diff --git a/src/common-opencl.c b/src/common-opencl.c # This patch file was generated by NetBeans IDE # It uses platform neutral UTF-8 encoding and \n newlines. --- HEAD +++ Modificado na Árvore de Trabalho @@ -1289,14 +1289,14 @@ sizeof(cl_ulong), &endTime, NULL), "Failed to get profiling info"); - numloops = (int)(size_t)(500000000ULL / (endTime-startTime)); + numloops = (int)(size_t)(200000000ULL / (endTime-startTime)); release_profiling_events(); if (numloops < 1) numloops = 1; - else if (numloops > 10) - numloops = 10; + else if (numloops > 5) + numloops = 5; // Find minimum time for (optimal_work_group = my_work_group = wg_multiple; ```
Author
Owner

@magnumripper commented on GitHub (Sep 1, 2014):

OK, so what's happening there? The first thing is trying to aim at 200ms, right? And the second one tries to pick a decent number of loops but not too many?

<!-- gh-comment-id:54093425 --> @magnumripper commented on GitHub (Sep 1, 2014): OK, so what's happening there? The first thing is trying to aim at 200ms, right? And the second one tries to pick a decent number of loops but not too many?
Author
Owner

@ghost commented on GitHub (Sep 2, 2014):

Yes. But the proper 200ms check is not here.

<!-- gh-comment-id:54153164 --> @ghost commented on GitHub (Sep 2, 2014): Yes. But the proper 200ms check is not here.
bsakaguchi changed title from [GH-ISSUE #716] Implement RAR 5 (PBKDF2-SHA256) OpenCL format to [GH-ISSUE #716] Implement RAR 5 (PBKDF2-SHA256) OpenCL format 2026-10-14 04:19:19 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
openwall/john#360
No description provided.