[GH-ISSUE #1758] Intrinsics: Improve reversing of steps for SHA-2 #1166

Closed
opened 2026-10-14 03:37:38 +07:00 by bsakaguchi · 9 comments
Owner

Originally created by @magnumripper on GitHub (Sep 13, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1758

Originally assigned to: @magnumripper on GitHub.

I think last three steps can be reversed with no pain at all for all SHA-2 formats.

Originally created by @magnumripper on GitHub (Sep 13, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1758 Originally assigned to: @magnumripper on GitHub. I think last three steps can be reversed with no pain at all for all SHA-2 formats.
bsakaguchi 2026-10-14 03:37:38 +07:00
Author
Owner

@jfoug commented on GitHub (Sep 13, 2015):

But the only reason to do this, is on raw (or single iteration) formats. Making this change on something with 1000 (or 100000) iterations is pointless, and the side effects due to a .00001% improvement are not worth it. Side effects are things such as my code to find casing failures. This was not even dreamed about until just a couple days ago. But the extra code, and changes in debuggability certainly are other concerns. Yes, WHEN it makes a difference, then the side effects are certainly justified. BUT where there is absolutely no noticeable improvements in performance, we should not be doing the reversing IMHO. I would think anything past about 2 or 3 crypt iterations is pointless.

But for single limb hashes (raw, simple salted, etc), bring it on. I was pretty impressed with speed gains on the MD[45] you did. If sha-2 formats can also gain, then great!

<!-- gh-comment-id:139929405 --> @jfoug commented on GitHub (Sep 13, 2015): But the only reason to do this, is on raw (or single iteration) formats. Making this change on something with 1000 (or 100000) iterations is pointless, and the side effects due to a .00001% improvement are not worth it. Side effects are things such as my code to find casing failures. This was not even dreamed about until just a couple days ago. But the extra code, and changes in debuggability certainly are other concerns. Yes, WHEN it makes a difference, then the side effects are certainly justified. BUT where there is absolutely no noticeable improvements in performance, we should not be doing the reversing IMHO. I would think anything past about 2 or 3 crypt iterations is pointless. But for single limb hashes (raw, simple salted, etc), bring it on. I was pretty impressed with speed gains on the MD[45] you did. If sha-2 formats can also gain, then great!
Author
Owner

@ghost commented on GitHub (Sep 14, 2015):

  • I wasn't happy with the results in SHA2 OpenCL.
<!-- gh-comment-id:139938126 --> @ghost commented on GitHub (Sep 14, 2015): - I wasn't happy with the results in SHA2 OpenCL.
Author
Owner

@magnumripper commented on GitHub (Sep 14, 2015):

But the only reason to do this, is on raw (or single iteration) formats.

Yes, obviously. Single-iteration formats, salted or not.

I wasn't happy with the results in SHA2 OpenCL

For SHA-2, just skipping last three steps should be a 4% gain. If you don't see it, that's probably a hint something else can be improved.

<!-- gh-comment-id:139986172 --> @magnumripper commented on GitHub (Sep 14, 2015): > But the only reason to do this, is on raw (or single iteration) formats. Yes, obviously. Single-iteration formats, salted or not. > I wasn't happy with the results in SHA2 OpenCL For SHA-2, just skipping last three steps should be a 4% gain. If you don't see it, that's probably a hint something else can be improved.
Author
Owner

@ghost commented on GitHub (Sep 16, 2015):

just skipping last three steps should be a 4% gain

I (kind of) disagree. Disclaimer: I need a computer to get the real numbers, but I hope the main point is clear:

  • transfer data from host to device: 1 ms
  • transfer data from __global to __private (registers): 1ms
  • call block(): 20ms
  • transfer results back to host: 1 ms

Even is this situation, 4% gain is not possible any more. Ok, using a CPU it is.

<!-- gh-comment-id:140768309 --> @ghost commented on GitHub (Sep 16, 2015): > just skipping last three steps should be a 4% gain I (kind of) disagree. Disclaimer: I need a computer to get the real numbers, but I hope the main point is clear: - transfer data from host to device: 1 ms - transfer data from __global to __private (registers): 1ms - call block(): 20ms - transfer results back to host: 1 ms Even is this situation, 4% gain is not possible any more. Ok, using a CPU it is.
Author
Owner

@magnumripper commented on GitHub (Sep 16, 2015):

Sure but that is a strange point of view. Any boost is good. Solar's recent work with loading 29M hashes looked silly at times (hey guys I saved 300 ms out of 49 seconds) but in the end he saved a whole lot of seconds.

<!-- gh-comment-id:140799819 --> @magnumripper commented on GitHub (Sep 16, 2015): Sure but that is a strange point of view. Any boost is good. Solar's recent work with loading 29M hashes looked silly at times (hey guys I saved 300 ms out of 49 seconds) but in the end he saved a whole lot of seconds.
Author
Owner

@ghost commented on GitHub (Sep 16, 2015):

I'm not saying it is a bad thing. I'm saying: on a GPU the gain was disappointing.

BTW: the reversing will be back (but not for mask mode where a full comparison is done inside GPU).

<!-- gh-comment-id:140812052 --> @ghost commented on GitHub (Sep 16, 2015): I'm not saying it is a bad thing. I'm saying: on a GPU the gain was disappointing. BTW: the reversing will be back (but not for mask mode where a full comparison is done inside GPU).
Author
Owner

@magnumripper commented on GitHub (Sep 26, 2015):

As of 72af172 we reverse seven steps for SHA-256 for another 3-4% boost, and we'll soon do the same for SHA-512. As far as I understand we can't do it for SHA-224/384, they'll be stuck at three because of unknown data when reversing.

The raw boost in the SHA function alone should be about 10.5% for SHA-256 and 8.5% for SHA-512 (compared to no reversing at all).

<!-- gh-comment-id:143380971 --> @magnumripper commented on GitHub (Sep 26, 2015): As of 72af172 we reverse seven steps for SHA-256 for another 3-4% boost, and we'll soon do the same for SHA-512. As far as I understand we can't do it for SHA-224/384, they'll be stuck at three because of unknown data when reversing. The raw boost in the SHA function alone should be about 10.5% for SHA-256 and 8.5% for SHA-512 (compared to no reversing at all).
Author
Owner

@magnumripper commented on GitHub (Sep 26, 2015):

Reopening for seven steps of SHA-512

<!-- gh-comment-id:143381778 --> @magnumripper commented on GitHub (Sep 26, 2015): Reopening for seven steps of SHA-512
Author
Owner

@magnumripper commented on GitHub (Oct 8, 2015):

Implemented in a73a7742 and for MSSQL12 in 409fa047

<!-- gh-comment-id:146689664 --> @magnumripper commented on GitHub (Oct 8, 2015): Implemented in a73a7742 and for MSSQL12 in 409fa047
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#1166
No description provided.