[GH-ISSUE #363] Add SIMD support to the sha512 formats that are missing it. #103

Closed
opened 2026-10-14 02:52:47 +07:00 by bsakaguchi · 42 comments
Owner

Originally created by @magnumripper on GitHub (Aug 15, 2013).
Original GitHub issue: https://github.com/openwall/john/issues/363

Originally created by @magnumripper on GitHub (Aug 15, 2013). Original GitHub issue: https://github.com/openwall/john/issues/363
bsakaguchi 2026-10-14 02:52:47 +07:00
Author
Owner

@jfoug commented on GitHub (Oct 2, 2014):

I am working on this. Not as trivial as some others. I am getting the right results, but things are not working. I have some endianity and flat vs interleaved issues to work out and it should be working. I do not expect a 'huge' gain. Possibly 2x, but probably not much more than that. That's on a 64 bit. There will be a much larger gain on 32 bit, since oSSL sucks big wind for 64 bit SHA2 functions on 32 bit. It does use a 'little' SIMD logic for some things (64 bit ROR), and that help, but it is still using 32 bit u64 code, that takes 3 ops to do 1 64 bit op. I expect 3-4x improvement on 32 bit builds.

But FIRST I have to get it working. lol.

<!-- gh-comment-id:57569151 --> @jfoug commented on GitHub (Oct 2, 2014): I am working on this. Not as trivial as some others. I am getting the right results, but things are not working. I have some endianity and flat vs interleaved issues to work out and it should be working. I do not expect a 'huge' gain. Possibly 2x, but probably not much more than that. That's on a 64 bit. There will be a much larger gain on 32 bit, since oSSL sucks big wind for 64 bit SHA2 functions on 32 bit. It does use a 'little' SIMD logic for some things (64 bit ROR), and that help, but it is still using 32 bit u64 code, that takes 3 ops to do 1 64 bit op. I expect 3-4x improvement on 32 bit builds. But FIRST I have to get it working. lol.
Author
Owner

@magnumripper commented on GitHub (Feb 12, 2015):

We do have SIMD support in PBKDF2-SHA512 and Truecrypt. We lack it in sha512crypt, HMAC-SHA512, SSHA512 and xsha512.

<!-- gh-comment-id:74063720 --> @magnumripper commented on GitHub (Feb 12, 2015): We do have SIMD support in PBKDF2-SHA512 and Truecrypt. We lack it in sha512crypt, HMAC-SHA512, SSHA512 and xsha512.
Author
Owner

@jfoug commented on GitHub (Feb 12, 2015):

This list is likely larger than what will be done for jumbo-2. We can leave it there for now, but some of these are NOT trivial.

The JTR_ALIGN(16) is failing within cygwin32 builds :( I guess I can switch to allocation, or do this off the stack, and then use an 'index' into a preallocated block. This has been fixed, but I am leaving this comment as a memory jogger for when doing other of these more complex formats.

<!-- gh-comment-id:74108367 --> @jfoug commented on GitHub (Feb 12, 2015): - [x] cryptsha256 81bfe4e - [x] cryptsha512 7b0d8a7 - [x] ssha512 4744bf1 - [x] hmac-sha224 e3e0163 - [x] hmac-sha256 e3e0163 - [x] hmac-sha384 e1795f9 - [x] hmac-sha512 295982b - [x] xsha512 0429f68 and a fix: 0177995 - [x] drupal7 335e609 - [x] office 2007 71b3cff - [x] office 2010 c814cff (still has dbg code commented out) 54ef466 - [x] office 2013 c814cff 54ef466 (this is a cleaned version). - [x] ecryptfs ecdd488 (with debugging). 8465a3d cleaned up - [x] mssql12 2da93fc, 5184d81 - [x] pwsafe 236b1f1 - [x] keyring 1f5ed37 - [x] SAPH 853afe0 - [x] SybaseASE da92ad8 - [x] blackberry_ES10 c0d6a02 - [x] dynamic 60fb066 - [ ] dragonfly3-32 - [ ] dragonfly3-64 - [ ] dragonfly4-32 - [ ] dragonfly4-64 - [ ] episerver - [ ] pdf ? This list is likely larger than what will be done for jumbo-2. We can leave it there for now, but some of these are NOT trivial. The JTR_ALIGN(16) is failing within cygwin32 builds :( I guess I can switch to allocation, or do this off the stack, and then use an 'index' into a preallocated block. This has been fixed, but I am leaving this comment as a memory jogger for when doing other of these more complex formats.
Author
Owner

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

32 bit cygwin got a pretty good gain (with SIMD of the crypt-sha2 stuff)

Benchmarking: sha512crypt, crypt(3) $6$ (rounds=5000) [SHA512 128/128 SSE4.1 2x]... (8xOMP) DONE
Raw:    2477 c/s real, 384 c/s virtual
Benchmarking: sha256crypt, crypt(3) $5$ (rounds=5000) [SHA256 128/128 SSE4.1 4x]... (8xOMP) DONE
Raw:    3921 c/s real, 626 c/s virtual


Benchmarking: sha512crypt, crypt(3) $6$ (rounds=5000) [SHA512 32/32 OpenSSL]... (8xOMP) DONE
Raw:    1022 c/s real, 160 c/s virtual
Benchmarking: sha256crypt, crypt(3) $5$ (rounds=5000) [SHA256 32/32 OpenSSL]... (8xOMP) DONE
Raw:    1384 c/s real, 190 c/s virtual
<!-- gh-comment-id:74331445 --> @jfoug commented on GitHub (Feb 13, 2015): 32 bit cygwin got a pretty good gain (with SIMD of the crypt-sha2 stuff) ``` Benchmarking: sha512crypt, crypt(3) $6$ (rounds=5000) [SHA512 128/128 SSE4.1 2x]... (8xOMP) DONE Raw: 2477 c/s real, 384 c/s virtual Benchmarking: sha256crypt, crypt(3) $5$ (rounds=5000) [SHA256 128/128 SSE4.1 4x]... (8xOMP) DONE Raw: 3921 c/s real, 626 c/s virtual Benchmarking: sha512crypt, crypt(3) $6$ (rounds=5000) [SHA512 32/32 OpenSSL]... (8xOMP) DONE Raw: 1022 c/s real, 160 c/s virtual Benchmarking: sha256crypt, crypt(3) $5$ (rounds=5000) [SHA256 32/32 OpenSSL]... (8xOMP) DONE Raw: 1384 c/s real, 190 c/s virtual ```
Author
Owner

@magnumripper commented on GitHub (Feb 28, 2015):

At some point in time someone has to explain to me how the heck you can do crypt-md5 and/or crypt-sha2 formats with SIMD. I have really tried to wrap my head around it but I can't. It's likely much simpler than I imagine. How can you not have problems with different length input?

<!-- gh-comment-id:76496645 --> @magnumripper commented on GitHub (Feb 28, 2015): At some point in time someone has to explain to me how the heck you can do crypt-md5 and/or crypt-sha2 formats with SIMD. I have really tried to wrap my head around it but I can't. It's likely much simpler than I imagine. How can you not have problems with different length input?
Author
Owner

@jfoug commented on GitHub (Mar 3, 2015):

@magnumripper

Could you rank the above non-completed SIMD formats by order of most popular (if you know?)

The dragonfly might not be bad ones to start on. It should only take doing one of them, then all is cut/paste. SAPH I started on, but could not get correct results. Probably should not take too much to get it fixed (dump_stuff functions until I find the problem).

Dynamic is pretty involved. It would probably take 12-36 hours to get everything right in that format. Also, the BIG formats like sha12(sha512(p).sha512($s)) and things like that I might have a VERY hard time getting done. Those take 3 buffers, and we have only 2. For flat it is fine, we need 256 bytes, but for SIMD flat we would need 384 byte buffers. Every time I have gone over 256, dyna has fallen apart.

<!-- gh-comment-id:77058801 --> @jfoug commented on GitHub (Mar 3, 2015): @magnumripper Could you rank the above non-completed SIMD formats by order of most popular (if you know?) The dragonfly might not be bad ones to start on. It should only take doing one of them, then all is cut/paste. SAPH I started on, but could not get correct results. Probably should not take too much to get it fixed (dump_stuff functions until I find the problem). Dynamic is pretty involved. It would probably take 12-36 hours to get everything right in that format. Also, the BIG formats like sha12(sha512(p).sha512($s)) and things like that I might have a VERY hard time getting done. Those take 3 buffers, and we have only 2. For flat it is fine, we need 256 bytes, but for SIMD flat we would need 384 byte buffers. Every time I have gone over 256, dyna has fallen apart.
Author
Owner

@magnumripper commented on GitHub (Mar 3, 2015):

I'd put Office, MSSQL12 and PDF highest. I haven't ever heard of Dragonfly except for when Solar mentioned it and I wrote those formats to force them to fix their code (which they did indeed, so boosting these are probably 100% academic). I've seen others ask for SAP formats many times so they are probably fairly high prio.

<!-- gh-comment-id:77061246 --> @magnumripper commented on GitHub (Mar 3, 2015): I'd put Office, MSSQL12 and PDF highest. I haven't ever heard of Dragonfly except for when Solar mentioned it and I wrote those formats to force them to fix their code (which they did indeed, so boosting these are probably 100% academic). I've seen others ask for SAP formats many times so they are probably fairly high prio.
Author
Owner

@magnumripper commented on GitHub (Mar 3, 2015):

We have no OpenCL support for MSSQL12 or PDF so maybe Office is lower prio than them because of that.

<!-- gh-comment-id:77061539 --> @magnumripper commented on GitHub (Mar 3, 2015): We have no OpenCL support for MSSQL12 or PDF so maybe Office is lower prio than them because of that.
Author
Owner

@magnumripper commented on GitHub (Mar 3, 2015):

The Office formats should be as easy as Drupal7 - due to high iteration counts you only ever need to worry about crypt_all(). I believe MSSQL12 is single salted SHA512 but you might get away with the same there. At speeds around 6-7M c/s for OpenSSL, the overhead is still pretty small.

<!-- gh-comment-id:77062394 --> @magnumripper commented on GitHub (Mar 3, 2015): The Office formats should be as easy as Drupal7 - due to high iteration counts you only ever need to worry about crypt_all(). I believe MSSQL12 is single salted SHA512 but you might get away with the same there. At speeds around 6-7M c/s for OpenSSL, the overhead is still pretty small.
Author
Owner

@jfoug commented on GitHub (Mar 4, 2015):

I am not sure PDF is a really good candidate for SIMD. Yes, we could do it, but it is so fuked up, trying to put 50 different version variations into the same format, that it makes doing this with SIMD ugly as hell.

<!-- gh-comment-id:77204410 --> @jfoug commented on GitHub (Mar 4, 2015): I am not sure PDF is a really good candidate for SIMD. Yes, we could do it, but it is so fuked up, trying to put 50 different version variations into the same format, that it makes doing this with SIMD ugly as hell.
Author
Owner

@magnumripper commented on GitHub (Mar 4, 2015):

I believe MSSQL12 is single salted SHA512 but you might get away with the same there. At speeds around 6-7M c/s for OpenSSL, the overhead is still pretty small.

OTOH that format will benefit from dupe salts, which make it worthwhile to do it "properly". And you could probably nick large portions from XSHA512.

<!-- gh-comment-id:77218976 --> @magnumripper commented on GitHub (Mar 4, 2015): > I believe MSSQL12 is single salted SHA512 but you might get away with the same there. At speeds around 6-7M c/s for OpenSSL, the overhead is still pretty small. OTOH that format will benefit from dupe salts, which make it worthwhile to do it "properly". And you could probably nick large portions from XSHA512.
Author
Owner

@jfoug commented on GitHub (Mar 4, 2015):

I have an early version of office-2007 (sha1). It passes ST, but is failing on the TS. But here will be exected speed gains:

$ ../run/john -test=4 -form=office
Will run 8 OpenMP threads
Benchmarking: Office, 2007/2010 (SHA-1) / 2013 (SHA-512), with AES [32/64 OpenSSL]... (8xOMP) DONE
Speed for cost 1 (MS Office version) of 2007, cost 2 (iteration count) of 50000
Raw: 464 c/s real, 66.0 c/s virtual

$ ../run/john -test=4 -form=office
Will run 8 OpenMP threads
Benchmarking: Office, 2007/2010 (SHA-1) / 2013 (SHA-512), with AES [32/64 OpenSSL]... (8xOMP) DONE
Speed for cost 1 (MS Office version) of 2007, cost 2 (iteration count) of 50000
Raw: 1870 c/s real, 248 c/s virtual

Not bad. SHA256 should also get pretty good gain (4x) and SHA512 should get 2x.

I could not crypt directly into the input buffer for this format. I had to setup input buffer properly, then crypt to a normal crypt buffer. This is because we have a 4 byte number that is appened to the prior hash value ....... Thinking about this, I 'might' be able to do this without the crypt buffer by using &inputBuf[4*MMX_COEF] and then set the flag to write output using input buffer format. I think that would work fine (I have to test just in case). It would save some memmove calls. That are not overly significant, BUT writing data into the next input location certainly saves us the double buffering.

<!-- gh-comment-id:77242654 --> @jfoug commented on GitHub (Mar 4, 2015): I have an early version of office-2007 (sha1). It passes ST, but is failing on the TS. But here will be exected speed gains: $ ../run/john -test=4 -form=office Will run 8 OpenMP threads Benchmarking: Office, 2007/2010 (SHA-1) / 2013 (SHA-512), with AES [32/64 OpenSSL]... (8xOMP) DONE Speed for cost 1 (MS Office version) of 2007, cost 2 (iteration count) of 50000 Raw: 464 c/s real, 66.0 c/s virtual $ ../run/john -test=4 -form=office Will run 8 OpenMP threads Benchmarking: Office, 2007/2010 (SHA-1) / 2013 (SHA-512), with AES [32/64 OpenSSL]... (8xOMP) DONE Speed for cost 1 (MS Office version) of 2007, cost 2 (iteration count) of 50000 Raw: 1870 c/s real, 248 c/s virtual Not bad. SHA256 should also get pretty good gain (4x) and SHA512 should get 2x. I could not crypt directly into the input buffer for this format. I had to setup input buffer properly, then crypt to a normal crypt buffer. This is because we have a 4 byte number that is appened to the prior hash value ....... Thinking about this, I 'might' be able to do this without the crypt buffer by using &inputBuf[4*MMX_COEF] and then set the flag to write output using input buffer format. I think that would work fine (I have to test just in case). It would save some memmove calls. That are not overly significant, BUT writing data into the next input location certainly saves us the double buffering.
Author
Owner

@magnumripper commented on GitHub (Mar 4, 2015):

Cool. Once you have 2007 working, 2010 is not that far from a copy+paste. And 2013 is exactly like 2010 except it uses SHA512 instead of SHA1 IIRC from the OpenCL formats.

<!-- gh-comment-id:77244155 --> @magnumripper commented on GitHub (Mar 4, 2015): Cool. Once you have 2007 working, 2010 is not that far from a copy+paste. And 2013 is _exactly_ like 2010 except it uses SHA512 instead of SHA1 IIRC from the OpenCL formats.
Author
Owner

@magnumripper commented on GitHub (Mar 4, 2015):

SHA256 should also get pretty good gain (4x) and SHA512 should get 2x.

SHA256 is not used. 2007/2010 both use SHA1 and 2013 uses SHA512.

<!-- gh-comment-id:77244523 --> @magnumripper commented on GitHub (Mar 4, 2015): > SHA256 should also get pretty good gain (4x) and SHA512 should get 2x. SHA256 is not used. 2007/2010 both use SHA1 and 2013 uses SHA512.
Author
Owner

@jfoug commented on GitHub (Mar 4, 2015):

I was able to get working without the double buffering. It is no faster (possibly just a 'touch' slower).

<!-- gh-comment-id:77254604 --> @jfoug commented on GitHub (Mar 4, 2015): I was able to get working without the double buffering. It is no faster (possibly just a 'touch' slower).
Author
Owner

@jfoug commented on GitHub (Mar 4, 2015):

It might be just a hair slower, since we are now dumping output to align(4) and not align(16) for most of the iterations. Before it was writing output to a 5*4*MMX_COEF*SHA_PARA buffer that was aligned(16). Now it is dumping data sparsely into 64*4*MMX_COEF*SHA_PARA buffer at offset 4*MMX_COEF, i.e. at offset 20, which is align(4). That may actually be slower, than dumping into align(16), and then performing a memcpy to copy MMX_COEF*20 bytes SHA_PARA times. I am actually wondering how this is working. I thought we had to have output aligned at 16 ???

<!-- gh-comment-id:77255535 --> @jfoug commented on GitHub (Mar 4, 2015): It might be just a hair slower, since we are now dumping output to align(4) and not align(16) for most of the iterations. Before it was writing output to a `5*4*MMX_COEF*SHA_PARA` buffer that was aligned(16). Now it is dumping data sparsely into `64*4*MMX_COEF*SHA_PARA` buffer at offset `4*MMX_COEF`, i.e. at offset 20, which is align(4). That may actually be slower, than dumping into align(16), and then performing a memcpy to copy `MMX_COEF*20` bytes SHA_PARA times. I am actually wondering how this is working. I thought we had to have output aligned at 16 ???
Author
Owner

@jfoug commented on GitHub (Mar 4, 2015):

My bad, the offset is 4*MMX_COEF or 16 bytes past start of input buffer. All is good. This might have problems for an MMX build (MMX_COEF==2), but I actually think alignment only needs to be 8 bytes anyway in that case.

<!-- gh-comment-id:77256232 --> @jfoug commented on GitHub (Mar 4, 2015): My bad, the offset is 4*MMX_COEF or 16 bytes past start of input buffer. All is good. This might have problems for an MMX build (MMX_COEF==2), but I actually think alignment only needs to be 8 bytes anyway in that case.
Author
Owner

@jfoug commented on GitHub (Mar 4, 2015):

And 2013 is exactly like 2010 except it uses SHA512

The nuances between the 32 bit and 64 bit SIMD can at times be more difficult to get right, than having to modify the logic going from one format of same data size. It 'seems' easy, but sometimes things just do not work out right. Now that I have gotten more of the 64 bit ones done, I think I have most of the nuanced issues figured out however. I think I might get these other 2 office formats done this evening, now that I have 2007 figure out.

<!-- gh-comment-id:77266770 --> @jfoug commented on GitHub (Mar 4, 2015): > And 2013 is _exactly_ like 2010 except it uses SHA512 The nuances between the 32 bit and 64 bit SIMD can at times be more difficult to get right, than having to modify the logic going from one format of same data size. It 'seems' easy, but sometimes things just do not work out right. Now that I have gotten more of the 64 bit ones done, I think I have most of the nuanced issues figured out however. I think I might get these other 2 office formats done this evening, now that I have 2007 figure out.
Author
Owner

@jfoug commented on GitHub (Mar 5, 2015):

Speed on crappy slow Dual-HT XOP laptop Non SIMD vs SIMD. I do not think I will check in, until I get 2013 done.

Speed for cost 1 (MS Office version) of 2010, cost 2 (iteration count) of 100000
Raw: 99.5 c/s real, 26.6 c/s virtual
Speed for cost 1 (MS Office version) of 2010, cost 2 (iteration count) of 100000
Raw: 410 c/s real, 108 c/s virtual

Speed for cost 1 (MS Office version) of 2013, cost 2 (iteration count) of 100000
Raw: 36.8 c/s real, 9.7 c/s virtual
Speed for cost 1 (MS Office version) of 2013, cost 2 (iteration count) of 100000
Raw: 77.0 c/s real, 20.2 c/s virtual

<!-- gh-comment-id:77348953 --> @jfoug commented on GitHub (Mar 5, 2015): Speed on crappy slow Dual-HT XOP laptop Non SIMD vs SIMD. I do not think I will check in, until I get 2013 done. Speed for cost 1 (MS Office version) of 2010, cost 2 (iteration count) of 100000 Raw: 99.5 c/s real, 26.6 c/s virtual Speed for cost 1 (MS Office version) of 2010, cost 2 (iteration count) of 100000 Raw: 410 c/s real, 108 c/s virtual Speed for cost 1 (MS Office version) of 2013, cost 2 (iteration count) of 100000 Raw: 36.8 c/s real, 9.7 c/s virtual Speed for cost 1 (MS Office version) of 2013, cost 2 (iteration count) of 100000 Raw: 77.0 c/s real, 20.2 c/s virtual
Author
Owner

@kholia commented on GitHub (Mar 5, 2015):

Awesome speedup 👍

<!-- gh-comment-id:77352170 --> @kholia commented on GitHub (Mar 5, 2015): Awesome speedup :+1:
Author
Owner

@jfoug commented on GitHub (Mar 5, 2015):

And 2013 is exactly like 2010 except it uses SHA512

The 2013 required an ugly shuffling within the inner loop. There is a 4 byte counter appended to prior crypt. Thus, the crypt starts 1/2 way into first 64 bit value. I got code to do it, but there might be a little more elegant solution. I still got over 2x speed improvement, so I did not look any further.

The 2010 allowed me to sha1 from input back into input (offsetting it just a bit). 2013, could not be done like that at all.

Other than that, 2013/2010 were pretty similar, and 2007 was also very similar. Once the 2007 was done, the others were pretty much cut/paste with a few changes here and there. 2010 and 2007 were by far the closest to each other (almost cut/paste until after inner loop.)

<!-- gh-comment-id:77366506 --> @jfoug commented on GitHub (Mar 5, 2015): > And 2013 is exactly like 2010 except it uses SHA512 The 2013 required an ugly shuffling within the inner loop. There is a 4 byte counter appended to prior crypt. Thus, the crypt starts 1/2 way into first 64 bit value. I got code to do it, but there might be a little more elegant solution. I still got over 2x speed improvement, so I did not look any further. The 2010 allowed me to sha1 from input back into input (offsetting it just a bit). 2013, could not be done like that at all. Other than that, 2013/2010 were pretty similar, and 2007 was also very similar. Once the 2007 was done, the others were pretty much cut/paste with a few changes here and there. 2010 and 2007 were by far the closest to each other (almost cut/paste until after inner loop.)
Author
Owner

@magnumripper commented on GitHub (Mar 5, 2015):

Excellent speedup, I have no idea why we waited this long?! These were much simpler than the raw formats, let alone the crypt ones.

Unless you started with MSSQL12 I'll have a look at that one.

<!-- gh-comment-id:77397482 --> @magnumripper commented on GitHub (Mar 5, 2015): Excellent speedup, I have no idea why we waited this long?! These were much simpler than the raw formats, let alone the crypt ones. Unless you started with MSSQL12 I'll have a look at that one.
Author
Owner

@jfoug commented on GitHub (Mar 5, 2015):

I have not started MSSQL12. If it is simply a salted hash, then you will have to duplicate the set key stuff to get the needed gain, OR possibly we should look at using a flat buffer (but I still think you need aligned(16) and full 128 byte buffers)

<!-- gh-comment-id:77400085 --> @jfoug commented on GitHub (Mar 5, 2015): I have not started MSSQL12. If it is simply a salted hash, then you will have to duplicate the set key stuff to get the needed gain, OR possibly we should look at using a flat buffer (but I still think you need aligned(16) and full 128 byte buffers)
Author
Owner

@magnumripper commented on GitHub (Mar 5, 2015):

Yeah it looks like I need to put some work into set_key(). Getting 2x gain with many salts is easy but with single salt it's harder.

<!-- gh-comment-id:77401797 --> @magnumripper commented on GitHub (Mar 5, 2015): Yeah it looks like I need to put some work into set_key(). Getting 2x gain with many salts is easy but with single salt it's harder.
Author
Owner

@jfoug commented on GitHub (Mar 5, 2015):

At some point in time someone has to explain to me how the heck you can do crypt-md5 and/or crypt-sha2 formats with SIMD. I have really tried to wrap my head around it but I can't. It's likely much simpler than I imagine. How can you not have problems with different length input?

There are serious problems with different input lengths. What I do is to load 'enough' of them, then process them in groups of 'similar' length passwords, and when done, reshuffle them back into original order. md5crypt was easy. We simply set pw len at max 15 bytes. That was ALL passwords fit into 1 limb. For sha256, 1 limb was not an option. Only password length 0-3 fits in 1 limb. But I got 5 groupings for all passwords that fit into 1 or 2 limbs with 35 byte password being the max you can do under 3 limbs of crypt. For most of them, some of the crypts are done as 1 limb, some as 2, BUT the algorithm will do 1 limb or 2 limbs for ALL passwords in the group at the same step of the inner loop. That is the key.

If you look at the top comment in cryptsha256_fmt_plug.c, you will see the length of pw vs number of limbs needed for the 8 different 'types' of encryption done.

Then within crypt_all, I use a simple array (MixOrder), to loop through the passwords (5 types), looking for lengths that fit into each grouping (i.e. passwords that jump between 1 and 2 limb crypts at the same time for every step). Once they are 'grouped', the MixOrder array is used to pluck out and hash passwords in a non-linear order, and at the end of the hashing, MixOrder is again used to determine just what slot to put the results in (so that JtR core gets them back in same order).

How is this handled in opencl ? Do we simply do them 1 at a time in parallel ? Could this type processing be of a benefit to speed by allowing vectored access ? That is really all we have in SIMD is a vectored walk through the data. It is just that we have to have magic logic to get the vectors loaded properly with compatible data.

These 2 were not easy, BUT they have been done. This is what I was asking for months ago, when I was asking you about a format that did some of these out of order (dcc2 I think). I simply needed to remember 'how' I had done that to be able to make it work here.

NOTE, we could do the same thing within the md5-crypt format(s), and make crypt(3) processing for md5crypt totally irrelevant. I think we could do up to 15+32 byte password in 1 or 2 limbs for md5 (that would give us 47 bytes as max length). NOTE, I am not volunteering for this, lol.

<!-- gh-comment-id:77407313 --> @jfoug commented on GitHub (Mar 5, 2015): > At some point in time someone has to explain to me how the heck you can do crypt-md5 and/or crypt-sha2 formats with SIMD. I have really tried to wrap my head around it but I can't. It's likely much simpler than I imagine. How can you not have problems with different length input? There are serious problems with different input lengths. What I do is to load 'enough' of them, then process them in groups of 'similar' length passwords, and when done, reshuffle them back into original order. md5crypt was easy. We simply set pw len at max 15 bytes. That was ALL passwords fit into 1 limb. For sha256, 1 limb was not an option. Only password length 0-3 fits in 1 limb. But I got 5 groupings for all passwords that fit into 1 or 2 limbs with 35 byte password being the max you can do under 3 limbs of crypt. For most of them, some of the crypts are done as 1 limb, some as 2, BUT the algorithm will do 1 limb or 2 limbs for ALL passwords in the group at the same step of the inner loop. That is the key. If you look at the top comment in cryptsha256_fmt_plug.c, you will see the length of pw vs number of limbs needed for the 8 different 'types' of encryption done. Then within crypt_all, I use a simple array (MixOrder), to loop through the passwords (5 types), looking for lengths that fit into each grouping (i.e. passwords that jump between 1 and 2 limb crypts at the same time for every step). Once they are 'grouped', the MixOrder array is used to pluck out and hash passwords in a non-linear order, and at the end of the hashing, MixOrder is again used to determine just what slot to put the results in (so that JtR core gets them back in same order). How is this handled in opencl ? Do we simply do them 1 at a time in parallel ? Could this type processing be of a benefit to speed by allowing vectored access ? That is really all we have in SIMD is a vectored walk through the data. It is just that we have to have magic logic to get the vectors loaded properly with compatible data. These 2 were not easy, BUT they have been done. This is what I was asking for months ago, when I was asking you about a format that did some of these out of order (dcc2 I think). I simply needed to remember 'how' I had done that to be able to make it work here. NOTE, we could do the same thing within the md5-crypt format(s), and make crypt(3) processing for md5crypt totally irrelevant. I think we could do up to 15+32 byte password in 1 or 2 limbs for md5 (that would give us 47 bytes as max length). NOTE, I am not volunteering for this, lol.
Author
Owner

@magnumripper commented on GitHub (Mar 5, 2015):

MSSQL12 done in 2da93fc. I'm not quite happy with the overhead in set_key(). We'd need something like the MSSQL05 set_key() but for 64-bit. Not sure it's worthwhile.

<!-- gh-comment-id:77416976 --> @magnumripper commented on GitHub (Mar 5, 2015): MSSQL12 done in 2da93fc. I'm not quite happy with the overhead in set_key(). We'd need something like the MSSQL05 set_key() but for 64-bit. Not sure it's worthwhile.
Author
Owner

@magnumripper commented on GitHub (Mar 5, 2015):

How is this handled in opencl ? Do we simply do them 1 at a time in parallel ? Could this type processing be of a benefit to speed by allowing vectored access ? That is really all we have in SIMD is a vectored walk through the data. It is just that we have to have magic logic to get the vectors loaded properly with compatible data.

The current OpenCL code is scalar so the kernels are very straightforward. But as soon as a single thread get a larger number of limbs, all other threads will wait for that one. We should probably try sorting by length on CPU side. Actually IIRC even our MD5crypt has that problem. I'm not sure why.

<!-- gh-comment-id:77417882 --> @magnumripper commented on GitHub (Mar 5, 2015): > How is this handled in opencl ? Do we simply do them 1 at a time in parallel ? Could this type processing be of a benefit to speed by allowing vectored access ? That is really all we have in SIMD is a vectored walk through the data. It is just that we have to have magic logic to get the vectors loaded properly with compatible data. The current OpenCL code is scalar so the kernels are very straightforward. But as soon as a single thread get a larger number of limbs, all other threads will wait for that one. We should probably try sorting by length on CPU side. Actually IIRC even our MD5crypt has that problem. I'm not sure why.
Author
Owner

@jfoug commented on GitHub (Mar 5, 2015):

The sorting is pretty trivial and fast. It ONLY needs to look at length of the password, to know which bucket it should be put in. I simply loop of the lengths 5 times (I think). Each password will only get put into 1 bucket. If this is something that could improve opencl (or even allow it to become vector run), then that design logic probably should be looked at.

If nothing else, it might help keep the stalling from happening, if that happens with variable length passwords being intermixed.

<!-- gh-comment-id:77424432 --> @jfoug commented on GitHub (Mar 5, 2015): The sorting is pretty trivial and fast. It ONLY needs to look at length of the password, to know which bucket it should be put in. I simply loop of the lengths 5 times (I think). Each password will only get put into 1 bucket. If this is something that could improve opencl (or even allow it to become vector run), then that design logic probably should be looked at. If nothing else, it might help keep the stalling from happening, if that happens with variable length passwords being intermixed.
Author
Owner

@magnumripper commented on GitHub (Mar 5, 2015):

I will have a look at your formats and see where it takes me. I haven't been quite sure how/what to sort. I'm thinking if I just sort a pointer array, I can't see it really helping in OpenCL: I think I need to have the actual buffers sorted, and I picture this will be very slow. Maybe I totally overlook something.

So what I have contemplated for a good while is trying to put stuff "in the right bucket" right away, in set_key(). But it gets non-trivial when it comes to the details.

<!-- gh-comment-id:77445579 --> @magnumripper commented on GitHub (Mar 5, 2015): I will have a look at your formats and see where it takes me. I haven't been quite sure how/what to sort. I'm thinking if I just sort a pointer array, I can't see it really helping in OpenCL: I think I need to have the actual buffers sorted, and I picture this will be very slow. Maybe I totally overlook something. So what I have contemplated for a good while is trying to put stuff "in the right bucket" right away, in set_key(). But it gets non-trivial when it comes to the details.
Author
Owner

@jfoug commented on GitHub (Mar 5, 2015):

Sorting the buffers would likely be very slow. I simply have an array (double dimension array) of ints. Those ints are just indexes into the input passwords (and anything else needed).

Take for instance, I know that 1,2,6,7,8,11,16,19 are all one 'group'. Then I simply run those. The next group is 3,4,5,9,10,12,13,14,15,17,18 and i run them The first fits in 2 SHA256 buffers (para=1). The 2nd group takes 3 runs (since there are 11 of them). That is simply how it is done. I think I fill out the last buffer to use a crypt output 1 past the 'real' buffers (I allocate an extra, and simply use that). So if there were 2 'extra' slots, both of those would point to the same chunk of memory, that is past the 'real' working memory.

Yes, the crypt-* is VERY non trivial, since the sub crypts can vary in amount of required work. But I do like how I did it on the sha256 and 512. I 'may' do that at some time on md5, to relieve the 15 byte password crippling rule we have.

<!-- gh-comment-id:77462649 --> @jfoug commented on GitHub (Mar 5, 2015): Sorting the buffers would likely be very slow. I simply have an array (double dimension array) of ints. Those ints are just indexes into the input passwords (and anything else needed). Take for instance, I know that 1,2,6,7,8,11,16,19 are all one 'group'. Then I simply run those. The next group is 3,4,5,9,10,12,13,14,15,17,18 and i run them The first fits in 2 SHA256 buffers (para=1). The 2nd group takes 3 runs (since there are 11 of them). That is simply how it is done. I think I fill out the last buffer to use a crypt output 1 past the 'real' buffers (I allocate an extra, and simply use that). So if there were 2 'extra' slots, both of those would point to the same chunk of memory, that is past the 'real' working memory. Yes, the crypt-\* is VERY non trivial, since the sub crypts can vary in amount of required work. But I do like how I did it on the sha256 and 512. I 'may' do that at some time on md5, to relieve the 15 byte password crippling rule we have.
Author
Owner

@jfoug commented on GitHub (Mar 6, 2015):

Getting closer to finish line. I wonder if there are other formats where we should put SIMD instructions in there? I image there are more than we have listed here. Even getting back to SHA1/MD5 I bet there are some.

I would much rather do these 'simple' key stretched formats. They are easy to figure out, and the code can be inserted very easily without a huge change (except for some that may NOT be well laid out for vectorization). Often for these key 'simple' stretched formats, it is just changing crypt_all.

<!-- gh-comment-id:77560431 --> @jfoug commented on GitHub (Mar 6, 2015): Getting closer to finish line. I wonder if there are other formats where we should put SIMD instructions in there? I image there are more than we have listed here. Even getting back to SHA1/MD5 I bet there are some. I would much rather do these 'simple' key stretched formats. They are easy to figure out, and the code can be inserted very easily without a huge change (except for some that may NOT be well laid out for vectorization). Often for these key 'simple' stretched formats, it is just changing crypt_all.
Author
Owner

@magnumripper commented on GitHub (Mar 6, 2015):

Even getting back to SHA1/MD5 I bet there are some.

Several. I guess oldoffice format is among the highest prio ones.

<!-- gh-comment-id:77561939 --> @magnumripper commented on GitHub (Mar 6, 2015): > Even getting back to SHA1/MD5 I bet there are some. Several. I guess oldoffice format is among the highest prio ones.
Author
Owner

@jfoug commented on GitHub (Mar 6, 2015):

Looking at oldoffice, we would get some gain by going to SIMD, but not as much as normal. I bet 2x probably could be obtained, possibly 3x. It will not get 3.8x-4x like most MD5/SHA1 'should' be able to do.

Now it 'may' be possible to optimize this to work a little better. The BIG problem I see, is that you load keys, and if using interleaved MMX, you would have to reload them twice (at least), if you have salts that are SHA1 and also MD5. This could be optimized by sorting salts, then load keys into one layout, the first salts all would be of that layout, and then when you hit the first salt of the other type, you load the passwords into the other layout.

<!-- gh-comment-id:77580429 --> @jfoug commented on GitHub (Mar 6, 2015): Looking at oldoffice, we would get some gain by going to SIMD, but not as much as normal. I bet 2x probably could be obtained, possibly 3x. It will not get 3.8x-4x like most MD5/SHA1 'should' be able to do. Now it 'may' be possible to optimize this to work a little better. The BIG problem I see, is that you load keys, and if using interleaved MMX, you would have to reload them twice (at least), if you have salts that are SHA1 and also MD5. This could be optimized by sorting salts, then load keys into one layout, the first salts all would be of that layout, and then when you hit the first salt of the other type, you load the passwords into the other layout.
Author
Owner

@jfoug commented on GitHub (Mar 6, 2015):

Looking into sap-h.

It appears that SIMD may be limited to PLAINTEXT_LENGTH of (55-32) which is only 23. Is that acceptable?

This is due to sha256. The format has this inner loop: sha256( $p . prior_hash ) This will limit us to 23 bytes. Is that too short?? @frank-dittrich this is kinda pointed at you, since you were pushing for this format.

Now, a non-SIMD build will not have this limit, so this would allow running shorter length wordlists in SIMD code, and then reverting over non-SIMD to do longer words.

NOTE, since this is a 'unified' format, we are being limited by this type hash. The SHA1 has a 35 byte limit, while 384/512 have limit of 63 and 47 max lengths respectively. So if this was multiple formats, we 'could' get away with better stuff. But as a unified format, we have to use the sha256 limit of 23 bytes.

<!-- gh-comment-id:77604409 --> @jfoug commented on GitHub (Mar 6, 2015): Looking into sap-h. It appears that SIMD may be limited to PLAINTEXT_LENGTH of (55-32) which is only 23. Is that acceptable? This is due to sha256. The format has this inner loop: `sha256( $p . prior_hash )` This will limit us to 23 bytes. Is that too short?? @frank-dittrich this is kinda pointed at you, since you were pushing for this format. Now, a non-SIMD build will not have this limit, so this would allow running shorter length wordlists in SIMD code, and then reverting over non-SIMD to do longer words. NOTE, since this is a 'unified' format, we are being limited by this type hash. The SHA1 has a 35 byte limit, while 384/512 have limit of 63 and 47 max lengths respectively. So if this was multiple formats, we 'could' get away with better stuff. But as a unified format, we have to use the sha256 limit of 23 bytes.
Author
Owner

@magnumripper commented on GitHub (Mar 6, 2015):

It appears that SIMD may be limited to PLAINTEXT_LENGTH of (55-32) which is only 23. Is that acceptable?

Anything over 16 is plenty, I think it's fine.

<!-- gh-comment-id:77652124 --> @magnumripper commented on GitHub (Mar 6, 2015): > It appears that SIMD may be limited to PLAINTEXT_LENGTH of (55-32) which is only 23. Is that acceptable? Anything over 16 is plenty, I think it's fine.
Author
Owner

@magnumripper commented on GitHub (Mar 6, 2015):

NOTE, since this is a 'unified' format, we are being limited by this type hash. The SHA1 has a 35 byte limit, while 384/512 have limit of 63 and 47 max lengths respectively. So if this was multiple formats, we 'could' get away with better stuff. But as a unified format, we have to use the sha256 limit of 23 bytes.

Theoretically we might be able to detect that all salts are 64-bit SHA-2 and adjust. But we also want the code simple, so this depends on what the details would look like.

<!-- gh-comment-id:77652611 --> @magnumripper commented on GitHub (Mar 6, 2015): > NOTE, since this is a 'unified' format, we are being limited by this type hash. The SHA1 has a 35 byte limit, while 384/512 have limit of 63 and 47 max lengths respectively. So if this was multiple formats, we 'could' get away with better stuff. But as a unified format, we have to use the sha256 limit of 23 bytes. Theoretically we might be able to detect that all salts are 64-bit SHA-2 and adjust. But we also want the code simple, so this depends on what the details would look like.
Author
Owner

@magnumripper commented on GitHub (Mar 6, 2015):

Looking at oldoffice, we would get some gain by going to SIMD, but not as much as normal. I bet 2x probably could be obtained, possibly 3x. It will not get 3.8x-4x like most MD5/SHA1 'should' be able to do.

The good news: These formats are crippled inside to 40-bit RC4, so we'll find a working candidate (even though not always the "intended" one) typically within 2^39 candidates. It's already doable and 2x-3x is good stuff.

<!-- gh-comment-id:77652979 --> @magnumripper commented on GitHub (Mar 6, 2015): > Looking at oldoffice, we would get some gain by going to SIMD, but not as much as normal. I bet 2x probably could be obtained, possibly 3x. It will not get 3.8x-4x like most MD5/SHA1 'should' be able to do. The good news: These formats are crippled inside to 40-bit RC4, so we'll find a working candidate (even though not always the "intended" one) typically within 2^39 candidates. It's already doable and 2x-3x is good stuff.
Author
Owner

@jfoug commented on GitHub (Mar 8, 2015):

Other than dynamic, I think I am done with sha2 stuff (the ones I found). There may be a few extra ones I missed. But for ones like episerver, I will leave for someone else. That one is a fast format. I have been working on the slower formats first. I would do the dragonfly, but @magnumripper kinda said they were not important, so I will go on to something else.

It may be a good thing to spend a little R/D time looking at all the CPU side formats in totality, to find the ones we do not handle yet in SIMD (along with which ones we do not handle with OMP). Many of these just take a couple hours to do with SIMD (and probably about the same or even less to get them OMP compliant). Doing this really bumps up the overall relbench for a jumbo release.

<!-- gh-comment-id:77763950 --> @jfoug commented on GitHub (Mar 8, 2015): Other than dynamic, I think I am done with sha2 stuff (the ones I found). There may be a few extra ones I missed. But for ones like episerver, I will leave for someone else. That one is a fast format. I have been working on the slower formats first. I would do the dragonfly, but @magnumripper kinda said they were not important, so I will go on to something else. It may be a good thing to spend a little R/D time looking at all the CPU side formats in totality, to find the ones we do not handle yet in SIMD (along with which ones we do not handle with OMP). Many of these just take a couple hours to do with SIMD (and probably about the same or even less to get them OMP compliant). Doing this really bumps up the overall relbench for a jumbo release.
Author
Owner

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

Good job. A good number of formats were improved and many of them got quite a bit faster. So should we close this issue and open another for MD4/MD4/SHA1?

<!-- gh-comment-id:77775994 --> @magnumripper commented on GitHub (Mar 8, 2015): Good job. A good number of formats were improved and many of them got quite a bit faster. So should we close this issue and open another for MD4/MD4/SHA1?
Author
Owner

@jfoug commented on GitHub (Mar 8, 2015):

We could just leave this open and add formats needing work

<!-- gh-comment-id:77776616 --> @jfoug commented on GitHub (Mar 8, 2015): We could just leave this open and add formats needing work
Author
Owner

@magnumripper commented on GitHub (Mar 9, 2015):

Nah, this is long enough as it is

<!-- gh-comment-id:77815358 --> @magnumripper commented on GitHub (Mar 9, 2015): Nah, this is long enough as it is
Author
Owner

@jfoug commented on GitHub (Mar 9, 2015):

Got dyna done for sha384/512. Testing a bit more, but will get checked in (unless there is serious problems). Getting 1.6x or so speed gain. About what I expected.

Dyna 87 and 88 had to be commented out, for doing SIMD. We can only do up to 128+111 length, and both of those require 256

<!-- gh-comment-id:77933602 --> @jfoug commented on GitHub (Mar 9, 2015): Got dyna done for sha384/512. Testing a bit more, but will get checked in (unless there is serious problems). Getting 1.6x or so speed gain. About what I expected. Dyna 87 and 88 had to be commented out, for doing SIMD. We can only do up to 128+111 length, and both of those require 256
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#103
No description provided.