mirror of
https://github.com/openwall/john.git
synced 2026-12-03 20:43:49 +07:00
[GH-ISSUE #1217] Add interleaving to primary SHA-2 intrinsics functions. #764
Labels
No labels
bug
core branch
documentation
enhancement
enhancement
fixed - pending verify
fuzz bug
good first issue
invalid
invalid
maintenance/cleanup
new cracking mode
new format
new tool
non-trivial
notes/external issues
portability
question
RFC / discussion
testing
WONTFIX
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openwall/john#764
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @magnumripper on GitHub (Apr 23, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1217
Originally assigned to: @lei-april on GitHub.
This is a GSoC task.
Some is already done: There are SIMD_PARA_SHA256 and SIMD_PARA_SHA512 defined in some header files. And some formats does use them in index calculations (although they are currently hard-coded to 1). I think some formats does not yet. The SHA-2 functions in sse-intrinsics.c needs to have a little code added.
@lei-april commented on GitHub (May 14, 2015):
Now I added interleaving to SHA512, mostly mimicking SHA1, and it works when
SIMD_PARA_SHA512 = 1. I noticed some formats are already usingSIMD_PARA_SHA512, e.g. sapH and Office, so I gave them a try. But they failed to work whenSIMD_PARA_SHA512is set other than 1.I'm not sure whether I've done something wrong when adding interleaving to SHA512, or those formats are not using
SIMD_PARA_SHA512the proper way. Do you have any thoughts?@magnumripper commented on GitHub (May 14, 2015):
I would guess the formats lack some little detail. If you watch for every mention of SHA1_SSE_PARA and ensure the SHA512 version has a corresponding SIMD_PARA_SHA512, you should be almost set.
But there's also index calculations. They are harder to find because they do not really use the para macro. You need to verify any mention of SIMD_COEF_64 and verify that it does not calculate an index without honoring interleaving. Sunmd5 has both variants - here's the one that does NOT honor interleaving:
Almost the same macro but honoring interleaving:
So, in Office we have a good GETPOS macro (similar to the latter above) but it's only used for byte access. What about the index calculations for 32-bit or 64-bit access?
Line 456
The telltale part is
j/SIMD_COEF_64*xxxso this one seems to be complete. Same for lines 464-465. Actually I can't spot a single place in Office where it's missing. But I'm really not sure. You might need to add debug prints. If self test says cmp_all(5) failed, dump data for index 4 in some places and verify everything looks like it should.@lei-april commented on GitHub (May 22, 2015):
I added interleaving to SHA256 and managed to make it work with a few formats. Here're some statistics obtained from experimenting with the interleaving factor (pwsafe, sybasease & aix-ssha256, tested on well):
SIMD_PARA_SHA256 = 1
Benchmarking: pwsafe, Password Safe [SHA256 256/256 AVX2 8x]... (8xOMP) DONE
Speed for cost 1 (iteration count) of 2048
Raw: 44224 c/s real, 5528 c/s virtual
Benchmarking: sybasease, Sybase ASE [SHA256 256/256 AVX2 8x]... (8xOMP) DONE
Many salts: 8421K c/s real, 1052K c/s virtual
Only one salt: 7503K c/s real, 935644 c/s virtual
Benchmarking: aix-ssha256, AIX LPA {ssha256} [PBKDF2-SHA256 256/256 AVX2 8x]... (8xOMP) DONE
Speed for cost 1 (iteration count) of 64
Raw: 567296 c/s real, 70823 c/s virtual
SIMD_PARA_SHA256 = 2
Benchmarking: pwsafe, Password Safe [SHA256 256/256 AVX2 8x]... (8xOMP) DONE
Speed for cost 1 (iteration count) of 2048
Raw: 34978 c/s real, 4404 c/s virtual
Benchmarking: sybasease, Sybase ASE [SHA256 256/256 AVX2 8x]... (8xOMP) DONE
Many salts: 6815K c/s real, 853034 c/s virtual
Only one salt: 6291K c/s real, 791378 c/s virtual
Benchmarking: aix-ssha256, AIX LPA {ssha256} [PBKDF2-SHA256 256/256 AVX2 8x]... (8xOMP) DONE
Speed for cost 1 (iteration count) of 64
Raw: 461306 c/s real, 58240 c/s virtual
SIMD_PARA_SHA256 = 4
Benchmarking: pwsafe, Password Safe [SHA256 256/256 AVX2 8x]... (8xOMP) DONE
Speed for cost 1 (iteration count) of 2048
Raw: 35738 c/s real, 4483 c/s virtual
Benchmarking: sybasease, Sybase ASE [SHA256 256/256 AVX2 8x]... (8xOMP) DONE
Many salts: 6810K c/s real, 862958 c/s virtual
Only one salt: 6553K c/s real, 857801 c/s virtual
Benchmarking: aix-ssha256, AIX LPA {ssha256} [PBKDF2-SHA256 256/256 AVX2 8x]... (8xOMP) DONE
Speed for cost 1 (iteration count) of 64
Raw: 473088 c/s real, 59062 c/s virtual
SIMD_PARA_SHA256 = 8
Benchmarking: pwsafe, Password Safe [SHA256 256/256 AVX2 8x]... (8xOMP) DONE
Speed for cost 1 (iteration count) of 2048
Raw: 40554 c/s real, 5075 c/s virtual
Benchmarking: sybasease, Sybase ASE [SHA256 256/256 AVX2 8x]... (8xOMP) DONE
Many salts: 7453K c/s real, 986015 c/s virtual
Only one salt: 7340K c/s real, 983918 c/s virtual
Benchmarking: aix-ssha256, AIX LPA {ssha256} [PBKDF2-SHA256 256/256 AVX2 8x]... (8xOMP) DONE
Speed for cost 1 (iteration count) of 64
Raw: 523152 c/s real, 65637 c/s virtual
It seems interleaving doesn't give much help here.
BTW, when adding interleaving to SHA256, I realized that I might have done something wrong with SHA512, which renders it only functional with
SIMD_PARA_SHA512 = 1@magnumripper commented on GitHub (May 22, 2015):
It's a pity it didn't bring any gain. What exact CPU was this, a desktop Haswell? Some older or future CPU (including the MIC, you should definitely try it!) may show better results. Also, SHA512 still might show a gain.
We should implement it fully and commit it anyway (but using para 1 for now) even if we can't find any current CPU which benefits from it. It might eventually get used for non-intel, the pseudo-intrinsics isn't necessarily bound to intel intrinsics.
Maybe here's a plan:
@lei-april commented on GitHub (May 22, 2015):
The previous experimentation was done on well, so it's Haswell.
Some formats don't work with the new SHA256 & SHA512 at the moment, so I don't thinks it's a good idea to commit to
bleeding-jumbo. I'm currently working on another temporary branchinterleavingin my repo. Is there some branch in the public repo to commit unstable code?unstable-jumbolooks like one.@magnumripper commented on GitHub (May 22, 2015):
No, unstable-jumbo is an old branch based on core 1.7.9
But there should be no problem at all committing it as long as SIMD_PARA_SHAXX is defined to 1, right?
@lei-april commented on GitHub (May 23, 2015):
Yes, that's right. I got it.
@magnumripper commented on GitHub (May 26, 2015):
After
1629e65no formats segfault for me even with ASan, but several still fails (using para 2). Now only a bunch of details left to fix 😆@magnumripper commented on GitHub (May 26, 2015):
@jfoug @zzlei I fail to see what is wrong with some SHA512 formats when trying with PARA 2 or 3. A very good example is Drupal7. Look at
git diff b96ed88fc5009^ drupal7_fmt_plug.c. Very simple fixes, I really can't see anything missing. It should work. So I've been looking into SHA512 in sse-intrinsics.c but can't see anything wrong there either.Also, all formats using pbkdf2_hmac_sha512.h fails. But there's nothing wrong with it!?
I give them up for now and concentrate on trivial fixes for SHA224/256 for a while.
@magnumripper commented on GitHub (May 27, 2015):
The only SHA256 format that fails is raw-sha256. All the rest are SHA512.
Cloudkeychain is PBKDF2-SHA512 but it doesn't use the shared function, it has a copy of its own. And that one, for some reason, works (or rather, it passes self-test. The tests doesn't catch all bugs).
@magnumripper commented on GitHub (May 27, 2015):
After
e229de81, all SHA256 formats pass the Test Suite. Most or all SHA512 formats fail (they might pass self-test but not the Test Suite).I'm pretty sure that raw-sha512 (among others) are 100% right now (after
885c3cba5) but they still fail. I have been staring at sse-intrinsics.c a lot but can't see any problem there either.@magnumripper commented on GitHub (May 27, 2015):
On a side note I'm seeing good results for interleaving SHA256 on Haswell core i7 AVX2 (4790, gcc 4.8.2, 8xOMP w/ HT)
Raw-SHA256
Raw-SHA384 (buggy code though - result may change)
With older core i7 mobile, AVX gcc 4.9.2 8xOMP w/ HT, I see no gain from interleaving (but loss).
@magnumripper commented on GitHub (May 27, 2015):
Gotcha.
@zzlei you did right writing it like this
I was confused by the fact SHA512 has a different way of "expanding" the buffer from 16 to 80 so I erroneously changed it (somewhat mislead by your comment "something's not right here" which turns out to be incorrect - it was 100% right).
@magnumripper commented on GitHub (May 27, 2015):
After
ce1f6e4, all formats pass self-test. Now on to Test Suite.@magnumripper commented on GitHub (May 27, 2015):
@lei-april commented on GitHub (May 28, 2015):
SHA512_PARA_DO(i) memcpy(w[i], &data[i * 16], 16 * sizeof(vtype));Well, when I first tested the interleaved SHA512, every format which takes the above code path failed self-test. I guess that statement is somehow incorrect, but
memcpy(w, &data, 16 * sizeof(vtype) *SIMD_PARA_SHA512)doesn't seem right to me, either. So I just left that comment. Sorry for misleading you :)@magnumripper commented on GitHub (May 28, 2015):
It does make sense since we have w[80] and something like data[16]. The reasons they failed self-test were other things, now fixed.
@magnumripper commented on GitHub (May 28, 2015):
On a different note, we might want to try interleaving differently. Here's part of SHA1 (MD4 and MD5 are made similarly):
And here's how it goes in SHA256 and SHA512
One difference is that the former is almost guaranteed to be fully unrolled why the latter might not.
@magnumripper commented on GitHub (May 28, 2015):
Another thing I realized is SHA512 has a larger footprint. It uses w[80] throughout the function while SHA256 uses w[16] and handles the expansion in STEP_R. We should try changing that and see what happens. I think we should discuss both these things with Solar, he usually can tell by heart what it would mean to caches and pipelines :)
@lei-april commented on GitHub (May 28, 2015):
I did notice the difference when I wrote it. But honestly I didn't get the point of wrapping each statement with a
forclause. How does that help unrolling?@magnumripper commented on GitHub (May 28, 2015):
Maybe it gets unrolled anyway... but unrolled or not, the order of instructions ends up different (or rather, we leave more to the optimizer - which may be good or bad).
Current SHA1:
Current SHA2:
Assuming 'foo' is actually a load and 'bar' is an operation, the difference might be significant. OTOH assuming a good optimizer, this will be shuffled around to the best anyway.
@lei-april commented on GitHub (May 29, 2015):
Awesome. Guess I can start benchmarking for MIC now?
@magnumripper commented on GitHub (May 29, 2015):
Please do. I think you should now use pbkdf2-hmac-sha256 and pbkdf2-hmac-sha512 for benching.
For each "para" between 1 and 5 (or more), try using 240 threads as well as 60 forks x 4 threads. And perhaps even using no threads. I have a feeling you should also try decreasing OMP_SCALE to 1 for pbkdf2-hmac-sha256 (it is 1 already for pbkdf2-hmac-sha512).
Please state exact compiler version when documenting, and post results to john-dev.
@magnumripper commented on GitHub (May 29, 2015):
BTW the positive results I saw for Haswell seem to be gone now.
i7-4790 (HT) AVX2 gcc 4.8.2
E5-2670 (HT) AVX gcc 4.8.2
AMD 8435 (six-core) SSE2 gcc 4.8.2
@lei-april commented on GitHub (May 29, 2015):
240 threads on MIC:
pbkdf2-hmac-sha256
x1
Raw: 9142 c/s real, 38.0 c/s virtual
x2
Raw: 6592 c/s real, 27.9 c/s virtual
x3
Raw: 7078 c/s real, 29.6 c/s virtual
x4
Raw: 7253 c/s real, 30.4 c/s virtual
x5
Raw: 7305 c/s real, 30.5 c/s virtual
pbkdf2-hmac-sha512
x1
Raw: 426 c/s real, 1.8 c/s virtual
x2
Raw: 474 c/s real, 1.9 c/s virtual
x3
Raw: 482 c/s real, 2.0 c/s virtual
x4
Raw: 506 c/s real, 2.1 c/s virtual
x5
Raw: 509 c/s real, 2.1 c/s virtual
BTW,
OMP_SCALE = 1andOMP_SCALE = 4has nearly the same performance on MIC.@lei-april commented on GitHub (May 29, 2015):
Somehow I couldn't get useful info from a forked run of pbkdf2-hmac-sha256/512. I used the same settings as I benchmarked raw-md4(5), but only got output like:
I tried increasing
--max-run, but to no avail. Something wrong here?@magnumripper commented on GitHub (May 29, 2015):
I guess the total time for one crypt_all() is longer than the timer abort grace time. I think it's equivalent to pressing 'q' and then press it again after 30 seconds unless session has ended. Could it be that one call is longer than that? Maybe you used many salts? Try only loading one.
@magnumripper commented on GitHub (May 29, 2015):
Posted to john-dev: http://www.openwall.com/lists/john-dev/2015/05/29/13
@lei-april commented on GitHub (May 30, 2015):
I'm cracking only one hash here. And even when I increase
--max-runto 5 mins, the results are still all zeroes.But self-test doesn't take long for pbkdf2-hmac-sha256.
@magnumripper commented on GitHub (May 30, 2015):
That's very strange. You should debug it and sort out what happens. Maybe your test hash has a lot higher iteration count? Or maybe some bug make it spin for ever.
@magnumripper commented on GitHub (May 31, 2015):
@zzlei be sure to read http://www.openwall.com/lists/john-dev/2015/05/30/6 and follow-ups
@magnumripper commented on GitHub (Jun 1, 2015):
core i7 (AVX) laptop, 8xOMP/HT, OMP_SCALE=1, gcc 4.9.2
testpara.sh run in bleeding-jumbo
testpara.sh run in topic branch "intrinsics-loops"
@magnumripper commented on GitHub (Jun 2, 2015):
SHA1 variants. @jfoug's SHA-1 expansion is ingenious, can't beat that. But lots of redundant temporary space can be dropped!
@magnumripper commented on GitHub (Jun 2, 2015):
testpara.sh in bleeding-jumbo after
c81f637a7, now with assorted things from that topic branch merged.core i7 (AVX) laptop, 8xOMP/HT, OMP_SCALE=1, gcc 4.9.2
I believe the slight regressions seen in SHA-2 are random variations.
@magnumripper commented on GitHub (Jun 2, 2015):
testpara.sh in bleeding-jumbo after
d85f8fd, now with tmp[SIMD_PARA] back (only that change).core i7 (AVX) laptop, 8xOMP/HT, OMP_SCALE=1, gcc 4.9.2
@magnumripper commented on GitHub (Jun 2, 2015):
Decreased w[80] pad of SHA512 to w[16] using same sliding-window technique as SHA1 & SHA256. Just a little gain... if any. Interestingly enough it had a bad effect on interleaving. Perhaps I should try the opposite with SHA1 and see what happens.
core i7 (AVX) laptop, 8xOMP/HT, OMP_SCALE=1, gcc 4.9.2
@magnumripper commented on GitHub (Jun 3, 2015):
Tried a few other things
"narrow for loops"
"drop tmp2"
I'm just throwing things at it and see what sticks. This is probably pointless, nothing is conclusive except reading asm output...
@magnumripper commented on GitHub (Jun 3, 2015):
icc 14.0.0 (super) AVX 32x (NT is non-OMP)
NOTE figures fluctuate a lot between runs despite no load on the system.
current bleeding-jumbo (
518b8c4e)FAILED (cmp_all(1))I can't reproduce that SHA512 failure elsewhere.
Older code (pre
cde0fb47):FAILED (cmp_all(1))Current bleeding, but with per-line loops:
FAILED (cmp_all(1))@magnumripper commented on GitHub (Jun 4, 2015):
Well, AVX2, current code (
a277eb6)gcc version 4.9.2 (GCC)
With per-line interleaving loops:
super, AVX, 16xOMP
gcc version 4.8.1 20130715 (Red Hat 4.8.1-4) (GCC)
With per-line interleaving loops:
All OpenMP figures are OMP_SCALE 1, except NT.
@lei-april commented on GitHub (Jun 5, 2015):
How did SHA512 fail self-test? Is it specific with icc?
@magnumripper commented on GitHub (Jun 5, 2015):
Not sure if it's a compiler bug or something nasty in the code. I haven't seen it anywhere else. This is icc 14.0.0 on "super", maybe you have some other version to try?
@lei-april commented on GitHub (Jun 5, 2015):
icc 15.0.2 works fine on my Linux VM. I'd guess that's an icc issue, but I'm not sure.
@magnumripper commented on GitHub (Jun 20, 2015):
Added PBKDF2-HMAC formats for MD4 and MD5 just to make testparas.pl better. And changed number of iterations to 1000 for all of them:
gcc version 5.1.0 (Homebrew gcc5 5.1.0)
John the Ripper password cracker, version 1.8.0.6-jumbo-1-bleeding_omp [darwin14.3.0 64-bit AVX-autoconf]
@lei-april commented on GitHub (Jun 21, 2015):
This seems a similar issue as https://github.com/magnumripper/JohnTheRipper/issues/1452#issuecomment-113814032 on MIC. I turned off auto-vectorization, and the problem is gone.
@lei-april commented on GitHub (Jun 21, 2015):
Here's the right result on MIC (I'll delete the previous one):
icc version 14.0.0 (gcc version 4.4.7 compatibility)
John the Ripper password cracker, version 1.8.0.6-jumbo-1-bleeding_omp [linux-gnu 64-bit mic-autoconf]
@lei-april commented on GitHub (Jun 22, 2015):
BTW, we've been stalling at this issue for a while. Which direction should we push in next?
@magnumripper commented on GitHub (Jun 22, 2015):
Please report those latest figures on john-dev, including a notice we are now benching "PBKDF2-HMAC" even for MD4 and MD5.
Also, let's bring that question to john-dev for discussion. What would you prefer doing now? Actually it might be a good time reviewing the project definition and make a timeline on remaining tasks (also listing what is already done). Please do so, and we'll discuss it on john-dev.
@magnumripper commented on GitHub (Jul 21, 2015):
@zzlei our mic.h still defaults to para 1 for all hashes. Perhaps we should set it to 2 for MD4/MD5? Then I think we can close this issue for now.
@lei-april commented on GitHub (Jul 22, 2015):
@magnumripper I agree. I'll change it.