[GH-ISSUE #2342] Make raw-SHA0 self-contained (was: build fails against libressl 2.4.2) #1569

Closed
opened 2026-10-15 04:20:19 +07:00 by bsakaguchi · 22 comments
Owner

Originally created by @rofl0r on GitHub (Nov 25, 2016).
Original GitHub issue: https://github.com/openwall/john/issues/2342

hmac_sha_plug.c:(.text.JTR_hmac_sha1+0x2d): undefined reference to `SHA_Init'
hmac_sha_plug.c:(.text.JTR_hmac_sha1+0xb8): undefined reference to `SHA_Init'
hmac_sha_plug.c:(.text.JTR_hmac_sha1+0x113): undefined reference to `SHA_Init'

Originally created by @rofl0r on GitHub (Nov 25, 2016). Original GitHub issue: https://github.com/openwall/john/issues/2342 ``` hmac_sha_plug.c:(.text.JTR_hmac_sha1+0x2d): undefined reference to `SHA_Init' hmac_sha_plug.c:(.text.JTR_hmac_sha1+0xb8): undefined reference to `SHA_Init' hmac_sha_plug.c:(.text.JTR_hmac_sha1+0x113): undefined reference to `SHA_Init' ```
bsakaguchi 2026-10-15 04:20:19 +07:00
Author
Owner

@solardiz commented on GitHub (Nov 25, 2016):

Do they have SHA1_Init()? (With the "1".)

<!-- gh-comment-id:262999895 --> @solardiz commented on GitHub (Nov 25, 2016): Do they have SHA1_Init()? (With the "1".)
Author
Owner

@jfoug commented on GitHub (Nov 25, 2016):

This should be handled with #define block either in the sha.h header (best spot), or at the top of the C file(s)

Then if it is SHA1_init (or sha_init) We can just define SHA_Init to be the 'correct' value for the lib. Also, if order of params are different, etc, then #defines can hide all the ugly shit, and we just have 1 simple 'oSSL' CTX interface in the code, and the defines will convert to proper values.

@rofl0r, can you please document just what the CTX interface is for this lib please (in this post), and it should be trivial to add code. We will also add a new check for this lib in the configure script, so that when you configure it will setup the autoconfig.h/Makefile properly, so that the oSSL 'looking' code will build, link and run properly.

<!-- gh-comment-id:263001103 --> @jfoug commented on GitHub (Nov 25, 2016): This should be handled with #define block either in the sha.h header (best spot), or at the top of the C file(s) Then if it is SHA1_init (or sha_init) We can just define SHA_Init to be the 'correct' value for the lib. Also, if order of params are different, etc, then #defines can hide all the ugly shit, and we just have 1 simple 'oSSL' CTX interface in the code, and the defines will convert to proper values. @rofl0r, can you please document just what the CTX interface is for this lib please (in this post), and it should be trivial to add code. We will also add a new check for this lib in the configure script, so that when you configure it will setup the autoconfig.h/Makefile properly, so that the oSSL 'looking' code will build, link and run properly.
Author
Owner

@rofl0r commented on GitHub (Nov 25, 2016):

yes, they have SHA1_Init (i'm using that already in my older patch here https://github.com/sabotage-linux/sabotage/blob/master/KEEP/john-sha0.patch which i'm unsure if its right)

<!-- gh-comment-id:263001308 --> @rofl0r commented on GitHub (Nov 25, 2016): yes, they have SHA1_Init (i'm using that already in my older patch here https://github.com/sabotage-linux/sabotage/blob/master/KEEP/john-sha0.patch which i'm unsure if its right)
Author
Owner

@rofl0r commented on GitHub (Nov 25, 2016):

if the purpose of SHA_Init is to actually use SHA1 (not sha ZERO, if that exists), i suppose we could just use SHA1_* everywhere and be done with it.

<!-- gh-comment-id:263001675 --> @rofl0r commented on GitHub (Nov 25, 2016): if the purpose of SHA_Init is to actually use SHA1 (not sha ZERO, if that exists), i suppose we could just use SHA1_* everywhere and be done with it.
Author
Owner

@jfoug commented on GitHub (Nov 25, 2016):

No, in 'code' (the .c files), we will always use the oSSL interface types and functions. Then we will do this in the header (with proper setup handled by configure so that the #defines are setup)

#ifdef (HAVE_LIBRESSL)
#define SHA_Init SHA1_Init
// any other defines needed
#endif

Then when you configure and compile, the compiler will replace the SHA_Init calls with SHA1_Init everywhere it is used. Thus, when we properly include JOHN's sha.h file (which is what we always do), your code will properly build.

This adds a portability layer of abstraction, keeping all the #ifdef out of the source, and only a single block in the header. That way when libfoobar_ssl comes along, we only have 1 place to edit, vs having dozens of source files to change, and then having to change EVERY source file using SHA1 from that point on.

<!-- gh-comment-id:263011668 --> @jfoug commented on GitHub (Nov 25, 2016): No, in 'code' (the .c files), we will always use the oSSL interface types and functions. Then we will do this in the header (with proper setup handled by configure so that the #defines are setup) #ifdef (HAVE_LIBRESSL) #define SHA_Init SHA1_Init // any other defines needed #endif Then when you configure and compile, the compiler will replace the SHA_Init calls with SHA1_Init everywhere it is used. Thus, when we properly include JOHN's sha.h file (which is what we always do), your code will properly build. This adds a portability layer of abstraction, keeping all the #ifdef out of the source, and only a single block in the header. That way when libfoobar_ssl comes along, we only have 1 place to edit, vs having dozens of source files to change, and then having to change EVERY source file using SHA1 from that point on.
Author
Owner

@jfoug commented on GitHub (Nov 25, 2016):

Note, we 'may' have to make the same type adjustments in the header file to get our existing raw-sha0 code to work right for this lib. Also, are there any other CTX interfaces that vary from the OpenSSL interface?

<!-- gh-comment-id:263011893 --> @jfoug commented on GitHub (Nov 25, 2016): Note, we 'may' have to make the same type adjustments in the header file to get our existing raw-sha0 code to work right for this lib. Also, are there any other CTX interfaces that vary from the OpenSSL interface?
Author
Owner

@solardiz commented on GitHub (Nov 25, 2016):

I didn't check, but I would be surprised if LibreSSL haven't dropped SHA-0 from the tree yet.

<!-- gh-comment-id:263012584 --> @solardiz commented on GitHub (Nov 25, 2016): I didn't check, but I would be surprised if LibreSSL haven't dropped SHA-0 from the tree yet.
Author
Owner

@rofl0r commented on GitHub (Nov 25, 2016):

oops, just opened a PR since i didnt see your new comments yet.
as for the specific compile error i got, the code in question used SHA_Init(), followed by SHA1_Update(), which is either just inconsistent, or if the former is for SHA0, actually a bug.

<!-- gh-comment-id:263012840 --> @rofl0r commented on GitHub (Nov 25, 2016): oops, just opened a PR since i didnt see your new comments yet. as for the specific compile error i got, the code in question used SHA_Init(), followed by SHA1_Update(), which is either just inconsistent, or if the former is for SHA0, actually a bug.
Author
Owner

@rofl0r commented on GitHub (Nov 25, 2016):

Also, are there any other CTX interfaces that vary from the OpenSSL interface?

no, everything else compiles flawlessly.

<!-- gh-comment-id:263012987 --> @rofl0r commented on GitHub (Nov 25, 2016): > Also, are there any other CTX interfaces that vary from the OpenSSL interface? no, everything else compiles flawlessly.
Author
Owner

@rofl0r commented on GitHub (Nov 25, 2016):

the pr is #2343

<!-- gh-comment-id:263013086 --> @rofl0r commented on GitHub (Nov 25, 2016): the pr is #2343
Author
Owner

@jfoug commented on GitHub (Nov 25, 2016):

The only place I have found sha0 was in oSSL (it may be in the SPH lib which we have code integrated into jtr, but I am not sure)

<!-- gh-comment-id:263018882 --> @jfoug commented on GitHub (Nov 25, 2016): The only place I have found sha0 was in oSSL (it may be in the SPH lib which we have code integrated into jtr, but I am not sure)
Author
Owner

@rofl0r commented on GitHub (Nov 25, 2016):

@jfoug whats your opinion on the mixed use of SHA_Init and SHA1_Update in hmac_sha_plug.c ? doesn't that smell like a bug ?

<!-- gh-comment-id:263020653 --> @rofl0r commented on GitHub (Nov 25, 2016): @jfoug whats your opinion on the mixed use of SHA_Init and SHA1_Update in hmac_sha_plug.c ? doesn't that smell like a bug ?
Author
Owner

@jfoug commented on GitHub (Nov 25, 2016):

I do not care for it, but it was how oSSL did it, so that is what is in dozens of source (.c) files. We could change it to SHA1_Init() in all of these source files, and then have #defines when building that tells the compiler that SHA1_Init() really should be built when building with oSSL.

The problem with that, is many people write their code AGAINST oSSL, and then move it to john. That would mean they would need to port their 'working' code to have SHA1_Init(). I am not overly concerned about that (changing SHA_Init to SHA1_Init) You have to also consider the data structure is SHA_CTX. Is that also inconsistant? (I say yes, but it is what it is).

I still say the best fix is to KEEP the SHA_Init() in all source files, and simply build a 3 line #define for when building against this library. Then within the configure.ac we will have to build testing probes to see if this library is being used, and set the macro (HAVE_LIBRESSL sounds like a good macro name).

I am away from any system where I can do this. Can you work with your hacked code until early next week (unless @magnumripper or @kholia or @rofl0r can make the proper changes). The only hardish change would be in the configure.ac script (and possibly Makefile.in and Makefile.legacy files).

<!-- gh-comment-id:263022122 --> @jfoug commented on GitHub (Nov 25, 2016): I do not care for it, but it was how oSSL did it, so that is what is in dozens of source (.c) files. We could change it to SHA1_Init() in all of these source files, and then have #defines when building that tells the compiler that SHA1_Init() really should be built when building with oSSL. The problem with that, is many people write their code AGAINST oSSL, and then move it to john. That would mean they would need to port their 'working' code to have SHA1_Init(). I am not overly concerned about that (changing SHA_Init to SHA1_Init) You have to also consider the data structure is SHA_CTX. Is that also inconsistant? (I say yes, but it is what it is). I still say the best fix is to KEEP the SHA_Init() in all source files, and simply build a 3 line #define for when building against this library. Then within the configure.ac we will have to build testing probes to see if this library is being used, and set the macro (HAVE_LIBRESSL sounds like a good macro name). I am away from any system where I can do this. Can you work with your hacked code until early next week (unless @magnumripper or @kholia or @rofl0r can make the proper changes). The only hardish change would be in the configure.ac script (and possibly Makefile.in and Makefile.legacy files).
Author
Owner

@solardiz commented on GitHub (Nov 25, 2016):

I don't understand what you're saying, @jfoug. My guess is that SHA1_Init and SHA_Init were/are the same for OpenSSL, but we should be using SHA1_Init only (when we mean SHA-1), as @rofl0r suggests. Why would we need any #define's or any porting effort then? I think we wouldn't.

<!-- gh-comment-id:263022859 --> @solardiz commented on GitHub (Nov 25, 2016): I don't understand what you're saying, @jfoug. My guess is that SHA1_Init and SHA_Init were/are the same for OpenSSL, but we should be using SHA1_Init only (when we mean SHA-1), as @rofl0r suggests. Why would we need any #define's or any porting effort then? I think we wouldn't.
Author
Owner

@jfoug commented on GitHub (Nov 25, 2016):

There is no SHA1_Init in openssl. There is SHA_Init. There is also SHA0_Init for the older SHA0 variant. The same goes for the context naming. It is not SHA1_CTX, but SHA_CTX.

If we make source changes, then that means everyone's code and or prototypes will not run without modification. That is why we do this in the header, and ONLY do it for code being built on non-oSSL systems.

<!-- gh-comment-id:263025606 --> @jfoug commented on GitHub (Nov 25, 2016): There is no SHA1_Init in openssl. There is SHA_Init. There is also SHA0_Init for the older SHA0 variant. The same goes for the context naming. It is not SHA1_CTX, but SHA_CTX. If we make source changes, then that means everyone's code and or prototypes will not run without modification. That is why we do this in the header, and ONLY do it for code being built on non-oSSL systems.
Author
Owner

@rofl0r commented on GitHub (Nov 25, 2016):

if there's a SHA1_Update, then there's also a SHA1_Init.
voila http://osxr.org:8080/openssl/source/include/openssl/sh.h#0122

<!-- gh-comment-id:263025830 --> @rofl0r commented on GitHub (Nov 25, 2016): if there's a SHA1_Update, then there's also a SHA1_Init. voila http://osxr.org:8080/openssl/source/include/openssl/sh.h#0122
Author
Owner

@magnumripper commented on GitHub (Nov 25, 2016):

@jfoug all our SHA-1 files except hmac_sha_plug.c already use SHA1_Init

<!-- gh-comment-id:263026421 --> @magnumripper commented on GitHub (Nov 25, 2016): @jfoug all our SHA-1 files except hmac_sha_plug.c already use SHA1_Init
Author
Owner

@magnumripper commented on GitHub (Nov 25, 2016):

For raw-SHA0 (which we have just because no-one else has) we should add our own code before it disappears from OpenSSL too.

<!-- gh-comment-id:263026522 --> @magnumripper commented on GitHub (Nov 25, 2016): For raw-SHA0 (which we have just because no-one else has) we should add our own code before it disappears from OpenSSL too.
Author
Owner

@jfoug commented on GitHub (Nov 25, 2016):

Then it is my bad. IF we should be using SHA1_Init, then the PR is right. I knew that SHA_CTX was the structure name (and an 'oddball'). I thought the init was the same odd ball.

So yes, we should modify that single source file to be the proper SHA1_Init.

Like I said, I am away from a computer with any source on it (I could have tried looking at source on github, but from my phone, that would be painful.

I agree about internal support on sha0. Yes, it 'is' in oSSL, but we have to assume it is deprecated. We can either do it ourselves, or simply drop it. I doubt there are RL implementations using SHA0-raw for passwords. Having a tool that can give you the result is not a bad thing, but is it really deserving a real format (or a format that is not stored in unused

<!-- gh-comment-id:263029127 --> @jfoug commented on GitHub (Nov 25, 2016): Then it is my bad. IF we should be using SHA1_Init, then the PR is right. I knew that SHA_CTX was the structure name (and an 'oddball'). I thought the init was the same odd ball. So yes, we should modify that single source file to be the proper SHA1_Init. Like I said, I am away from a computer with any source on it (I could have tried looking at source on github, but from my phone, that would be painful. I agree about internal support on sha0. Yes, it 'is' in oSSL, but we have to assume it is deprecated. We can either do it ourselves, or simply drop it. I doubt there are RL implementations using SHA0-raw for passwords. Having a tool that can give you the result is not a bad thing, but is it really deserving a real format (or a format that is not stored in unused
Author
Owner

@magnumripper commented on GitHub (Nov 25, 2016):

I wouldn't want to drop it. We can insert reference code functions right into the format file, it's likely in some old RFC.

<!-- gh-comment-id:263029905 --> @magnumripper commented on GitHub (Nov 25, 2016): I wouldn't want to drop it. We can insert reference code functions right into the format file, it's likely in some old RFC.
Author
Owner

@magnumripper commented on GitHub (Nov 25, 2016):

I changed my mind. Apparently SHA-0 was withdrawn shortly after publication due to an undisclosed "significant flaw" and replaced by the slightly revised version SHA-1. And this was in 1993. I'll just move the format to unused.

<!-- gh-comment-id:263030815 --> @magnumripper commented on GitHub (Nov 25, 2016): I changed my mind. Apparently SHA-0 was withdrawn shortly after publication due to an undisclosed "significant flaw" and replaced by the slightly revised version SHA-1. And this was in 1993. I'll just move the format to unused.
Author
Owner

@jfoug commented on GitHub (Nov 25, 2016):

It is in openssl, and the openssl process 'can' do a sha0sum (I do not think there is an sha0sum process though). I think you use things like -algo and -dgst but when I made the jtr-ts input file, I used spawning the openssl process 1500 times to do it.

<!-- gh-comment-id:263031425 --> @jfoug commented on GitHub (Nov 25, 2016): It is in openssl, and the openssl process 'can' do a sha0sum (I do not think there is an sha0sum process though). I think you use things like -algo and -dgst but when I made the jtr-ts input file, I used spawning the openssl process 1500 times to do it.
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#1569
No description provided.