[GH-ISSUE #863] linux 32 bit SSE code for SHA512 busted in bitcoin format #467

Closed
opened 2026-10-14 03:09:35 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @jfoug on GitHub (Nov 29, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/863

If I make this change, it works (OMP build only). Non OMP build runs fine. This is a SSE4.1 build, that gets SSE4.1 code for SHA512. Most 32 bit builds do not get SIMD code.

ghost32@ghost32-VirtualBox:/JtR/bleed/src$ git diff bitcoin_fmt_plug.c
diff --git a/src/bitcoin_fmt_plug.c b/src/bitcoin_fmt_plug.c
index 9e8584e..000da24 100644
--- a/src/bitcoin_fmt_plug.c
+++ b/src/bitcoin_fmt_plug.c
@@ -274,7 +274,8 @@ static int crypt_all(int *pcount, struct db_salt *salt)
                int i;

 #ifdef MMX_COEF_SHA512
-               JTR_ALIGN(16) ARCH_WORD_64 key_iv[MMX_COEF_SHA512*SHA512_BUF_SIZ];  // 2 * 16 bytes == 2048 bits, i.e. two SHA blocks
+               //JTR_ALIGN(16) ARCH_WORD_64 key_iv[MMX_COEF_SHA512*SHA512_BUF_SIZ];  // 2 * 16 bytes == 2048 bits, i.e. two SHA blocks
+               ARCH_WORD_64 *key_iv = mem_alloc_tiny(sizeof(ARCH_WORD_64)*MMX_COEF_SHA512*SHA512_BUF_SIZ, 16);
                JTR_ALIGN(8)  unsigned char hash1[SHA512_DIGEST_LENGTH];            // 512 bits
                int index2;

@magnumripper it is pretty obvious that the JTR_ALIGN(16) is not working right for this, do you have any ideas? Could we do a union, and put an __m128i as one of the unused elements, and get proper alignment??? I KNOW the mem_alloc_tiny is NOT how this will be done, I was just doing that to test. I put that code in there, and crash just went away.

Originally created by @jfoug on GitHub (Nov 29, 2014). Original GitHub issue: https://github.com/openwall/john/issues/863 If I make this change, it works (OMP build only). Non OMP build runs fine. This is a SSE4.1 build, that gets SSE4.1 code for SHA512. Most 32 bit builds do not get SIMD code. ``` ghost32@ghost32-VirtualBox:/JtR/bleed/src$ git diff bitcoin_fmt_plug.c diff --git a/src/bitcoin_fmt_plug.c b/src/bitcoin_fmt_plug.c index 9e8584e..000da24 100644 --- a/src/bitcoin_fmt_plug.c +++ b/src/bitcoin_fmt_plug.c @@ -274,7 +274,8 @@ static int crypt_all(int *pcount, struct db_salt *salt) int i; #ifdef MMX_COEF_SHA512 - JTR_ALIGN(16) ARCH_WORD_64 key_iv[MMX_COEF_SHA512*SHA512_BUF_SIZ]; // 2 * 16 bytes == 2048 bits, i.e. two SHA blocks + //JTR_ALIGN(16) ARCH_WORD_64 key_iv[MMX_COEF_SHA512*SHA512_BUF_SIZ]; // 2 * 16 bytes == 2048 bits, i.e. two SHA blocks + ARCH_WORD_64 *key_iv = mem_alloc_tiny(sizeof(ARCH_WORD_64)*MMX_COEF_SHA512*SHA512_BUF_SIZ, 16); JTR_ALIGN(8) unsigned char hash1[SHA512_DIGEST_LENGTH]; // 512 bits int index2; ``` @magnumripper it is pretty obvious that the JTR_ALIGN(16) is not working right for this, do you have any ideas? Could we do a union, and put an __m128i as one of the unused elements, and get proper alignment??? I KNOW the mem_alloc_tiny is NOT how this will be done, I was just doing that to test. I put that code in there, and crash just went away.
Author
Owner

@magnumripper commented on GitHub (Nov 29, 2014):

Yeah a union should do the trick. This must be a compiler bug, right? I have seen similar problems with auto variables long ago (perhaps gcc 4.6, possibly older).

<!-- gh-comment-id:64961359 --> @magnumripper commented on GitHub (Nov 29, 2014): Yeah a union should do the trick. This must be a compiler bug, right? I have seen similar problems with auto variables long ago (perhaps gcc 4.6, possibly older).
Author
Owner

@jfoug commented on GitHub (Nov 29, 2014):

I could not get __m128i (or __m128d) into a union (or struct for that matter). They are defined as a union on 32 bit systems, so I think there is some issues.

Yes, I am pretty sure this is a compiler bug. If I built without OMP, it worked fine. as soon as I added OMP, I had to come up with some other memory layout technique othr than JTR_ALIGN(16). The align(8) is fine on teh hash1 array, but who knows if it is aligned.

What I have ended up doing, is making a new method in memory.h that aligns stack memory. You have to provide a large enough stack buffer (X-1 bytes larger at least than needed), pass the pointer and the alignment value, and get back a pointer inside the array that is aligned. It would not have to be a stack var, anything, even allocate memory could be used, AS LONG is the buffer has enough extra padding. I will be checking in soon.

This affected ONLY the bitcoin format.

<!-- gh-comment-id:64968380 --> @jfoug commented on GitHub (Nov 29, 2014): I could not get __m128i (or __m128d) into a union (or struct for that matter). They are defined as a union on 32 bit systems, so I think there is some issues. Yes, I am pretty sure this is a compiler bug. If I built without OMP, it worked fine. as soon as I added OMP, I had to come up with some other memory layout technique othr than JTR_ALIGN(16). The align(8) is fine on teh hash1 array, but who knows if it is aligned. What I have ended up doing, is making a new method in memory.h that aligns stack memory. You have to provide a large enough stack buffer (X-1 bytes larger at least than needed), pass the pointer and the alignment value, and get back a pointer inside the array that is aligned. It would not have to be a stack var, anything, even allocate memory could be used, AS LONG is the buffer has enough extra padding. I will be checking in soon. This affected ONLY the bitcoin format.
Author
Owner

@jfoug commented on GitHub (Nov 29, 2014):

82c5c16 fixed.

<!-- gh-comment-id:64968499 --> @jfoug commented on GitHub (Nov 29, 2014): 82c5c16 fixed.
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#467
No description provided.