[GH-ISSUE #1686] Try to get rid of as much OpenSSL EVP and BIO crap as possible, as well as Gladman stuff. #1110

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

Originally created by @magnumripper on GitHub (Aug 19, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1686

High-level interfaces and abstraction layers are not the best things you can put in high-performance code.

Unfortunately our own AES (aes.h) can only do CBC (right now anyway).


Here is a start, at least ID possible files/formats to work on (edited by jfoug):

EVP_ stuff

  • dmg_fmt_plug.c (des_ede3:cbc, aes:cbc, hmac:sha1)
  • opencl_dmg_fmt_plug (des_ede3:cbc, aes:cbc, hmac:sha1)
  • encfs_common_plug.c (aes:cbc aes:cfb)
  • openbsdsoftraid_fmt_plug.c (hmac:sha1)
  • openssl_enc_fmt_plug.c (only EVP_BytesToKey remains)
  • rar_common.c (aes:cbc)
  • ssh2john.c/ssh_fmt_plug.c (numerous crypts, PEM_ stuff, etc)
  • wpapsk.h
  • autoconf (provided we manage to remove all of the above)

BIO_ stuff

  • ssh2john.c/ssh_fmt_plug.c
  • ssh_ng_fmt_plug.c
  • john.c (wrapper keeping pfx2john and ssh2john from building)
  • luks2john.c used for base-64 ??? wtf?
  • pfx_fmt_plug.c/pfx2john.c (PKCS12_bio ?)
  • autoconf (provided we manage to remove all of the above)

Gladman stuff

  • dmg2john.c
  • efs_fmt_plug.c
  • krb5pa-sha1_fmt_plug.c
  • opencl_krb5pa-sha1_fmt_plug.c
  • opencl_zip_fmt_plug.c
  • putty_fmt_plug.c
  • twofish_plug.c
  • zip2john.c
  • zip_fmt_plug.c
  • Makefile.in & Makefile.legacy
  • delete all gladman files after the above
Originally created by @magnumripper on GitHub (Aug 19, 2015). Original GitHub issue: https://github.com/openwall/john/issues/1686 High-level interfaces and abstraction layers are not the best things you can put in high-performance code. Unfortunately our own AES (aes.h) can only do CBC (right now anyway). --- Here is a start, at least ID possible files/formats to work on (edited by jfoug): #### EVP_ stuff - [x] dmg_fmt_plug.c (des_ede3:cbc, aes:cbc, hmac:sha1) - [x] opencl_dmg_fmt_plug (des_ede3:cbc, aes:cbc, hmac:sha1) - [ ] encfs_common_plug.c (aes:cbc aes:cfb) - [x] openbsdsoftraid_fmt_plug.c (hmac:sha1) - [ ] openssl_enc_fmt_plug.c (only EVP_BytesToKey remains) - [x] rar_common.c (aes:cbc) - [x] ssh2john.c/ssh_fmt_plug.c (numerous crypts, PEM_ stuff, etc) - [x] wpapsk.h - [ ] autoconf (provided we manage to remove all of the above) #### BIO_ stuff - [x] ssh2john.c/ssh_fmt_plug.c - [x] ssh_ng_fmt_plug.c - [x] john.c (wrapper keeping pfx2john and ssh2john from building) - [x] luks2john.c used for base-64 ??? wtf? - [x] pfx_fmt_plug.c/pfx2john.c (PKCS12_bio ?) - [ ] autoconf (provided we manage to remove all of the above) #### Gladman stuff - [x] dmg2john.c - [x] efs_fmt_plug.c - [x] krb5pa-sha1_fmt_plug.c - [x] opencl_krb5pa-sha1_fmt_plug.c - [x] opencl_zip_fmt_plug.c - [x] putty_fmt_plug.c - [x] twofish_plug.c - [x] zip2john.c - [x] zip_fmt_plug.c - [x] Makefile.in & Makefile.legacy - [x] **delete** all gladman files after the above
Author
Owner

@magnumripper commented on GitHub (Aug 20, 2015):

The RAR patch shows all benefits: Less code, cleaner code, no OpenMP problems and workarounds, better performance.

<!-- gh-comment-id:132836476 --> @magnumripper commented on GitHub (Aug 20, 2015): The RAR patch shows all benefits: Less code, cleaner code, no OpenMP problems and workarounds, better performance.
Author
Owner

@jfoug commented on GitHub (Aug 20, 2015):

Yes,, dumping the very high level oSSL crap whenever we can, sometimes makes things MUCH better. I have seen 2x or 4x improvements (10x if we have SIMD stuff). An yes, things like openmp issues go away along with all sorts of other shit.

This should almost be in the coding style, to use our own fast and internally maintained code, over 3rd party stuff whenever we can.

<!-- gh-comment-id:132837359 --> @jfoug commented on GitHub (Aug 20, 2015): Yes,, dumping the very high level oSSL crap whenever we can, sometimes makes things MUCH better. I have seen 2x or 4x improvements (10x if we have SIMD stuff). An yes, things like openmp issues go away along with all sorts of other shit. This should almost be in the coding style, to use our own fast and internally maintained code, over 3rd party stuff whenever we can.
Author
Owner

@magnumripper commented on GitHub (Aug 20, 2015):

This should almost be in the coding style

Agreed. I hate high-level stuff, frameworks and abstractions - well at least in JtR I do.

I was the one adding EVP crap to RAR long ago though. That was the way to get AES-NI at the time.

Anyway, I wonder if we could do EDE3 using Solar's/Deepika's bitslice DES. Maybe tricky. Those HMAC-SHA1 should be piece of cake. If we don't have a shared function already we should add one (we might even be able to use SIMD while at it).

Base64, wow lol.

<!-- gh-comment-id:132839006 --> @magnumripper commented on GitHub (Aug 20, 2015): > This should almost be in the coding style Agreed. I hate high-level stuff, frameworks and abstractions - well at least in JtR I do. I was the one adding EVP crap to RAR long ago though. That was the way to get AES-NI at the time. Anyway, I wonder if we could do EDE3 using Solar's/Deepika's bitslice DES. Maybe tricky. Those HMAC-SHA1 should be piece of cake. If we don't have a shared function already we should add one (we might even be able to use SIMD while at it). Base64, wow lol.
Author
Owner

@jfoug commented on GitHub (Aug 20, 2015):

Another set of stuff that was hard to wean ppl off of was that gladman hmac crap. It was harder than using the damn pbkdf2*.h files (by far), but some simply would not use anything but that gladman code. I am glad (pun intended) it is gone man.

<!-- gh-comment-id:132840171 --> @jfoug commented on GitHub (Aug 20, 2015): Another set of stuff that was hard to wean ppl off of was that gladman hmac crap. It was harder than using the damn pbkdf2*.h files (by far), but some simply would not use anything but that gladman code. I am glad (pun intended) it is gone man.
Author
Owner

@magnumripper commented on GitHub (Aug 20, 2015):

Yeah BTW I thought all gladman files were gone but I see they are still there:

$ ls *glad*
gladman_fileenc.h   gladman_hmac.h      gladman_pwd2key.c   gladman_pwd2key.o
gladman_hmac.c      gladman_hmac.o      gladman_pwd2key.h   gladman_sha1.h

$ git grep -l "gladman.*h"
Makefile.in
Makefile.legacy
dmg2john.c
efs_fmt_plug.c
gladman_fileenc.h
gladman_hmac.c
gladman_hmac.h
gladman_pwd2key.c
krb5pa-sha1_fmt_plug.c
opencl_krb5pa-sha1_fmt_plug.c
opencl_zip_fmt_plug.c
putty_fmt_plug.c
twofish_plug.c
zip2john.c
zip_fmt_plug.c

We should probably fix that too. Or is there anything good in them?

<!-- gh-comment-id:132842491 --> @magnumripper commented on GitHub (Aug 20, 2015): Yeah BTW I thought all gladman files were gone but I see they are still there: ``` $ ls *glad* gladman_fileenc.h gladman_hmac.h gladman_pwd2key.c gladman_pwd2key.o gladman_hmac.c gladman_hmac.o gladman_pwd2key.h gladman_sha1.h $ git grep -l "gladman.*h" Makefile.in Makefile.legacy dmg2john.c efs_fmt_plug.c gladman_fileenc.h gladman_hmac.c gladman_hmac.h gladman_pwd2key.c krb5pa-sha1_fmt_plug.c opencl_krb5pa-sha1_fmt_plug.c opencl_zip_fmt_plug.c putty_fmt_plug.c twofish_plug.c zip2john.c zip_fmt_plug.c ``` We should probably fix that too. Or is there anything good in them?
Author
Owner

@jfoug commented on GitHub (Aug 20, 2015):

I thought we smoked them?? Someone put them back 👎 👎 👎

<!-- gh-comment-id:132848875 --> @jfoug commented on GitHub (Aug 20, 2015): I thought we smoked them?? Someone put them back :-1: :-1: :-1:
Author
Owner

@magnumripper commented on GitHub (Aug 20, 2015):

We probably just stopped using them for PBKDF2. But dropping them should be easy. I'm adding it to the list for this issue.

<!-- gh-comment-id:132851354 --> @magnumripper commented on GitHub (Aug 20, 2015): We probably just stopped using them for PBKDF2. But dropping them should be easy. I'm adding it to the list for this issue.
Author
Owner

@jfoug commented on GitHub (Aug 21, 2015):

babb42f These header includes were not needed.

<!-- gh-comment-id:133459775 --> @jfoug commented on GitHub (Aug 21, 2015): babb42f These header includes were not needed.
Author
Owner

@jfoug commented on GitHub (Aug 21, 2015):

Gladman code totally gone. Actually VERY trivial (other than a couple defines needed moved into pkzip.h).

The only thing used was hmac_sha1() function, so I wrote 'our own' for JtR. It is faster than gladmans code. It is only about 15% faster, but still faster 👍

Ok, after a couple of false starts (thank you CI's and I hope I have it all this time) the gladman code has now been eliminated.

Grrrrrrr, there may still be a non-SIMD 32 bit problems. ..... New code is great (simplifies a lot), but there simply is a lot of work to get things 'right'.

<!-- gh-comment-id:133512641 --> @jfoug commented on GitHub (Aug 21, 2015): Gladman code totally gone. Actually VERY trivial (other than a couple defines needed moved into pkzip.h). The only thing used was hmac_sha1() function, so I wrote 'our own' for JtR. It is faster than gladmans code. It is only about 15% faster, but still faster :+1: Ok, after a couple of false starts (thank you CI's and I hope I have it all this time) the gladman code has now been eliminated. Grrrrrrr, there may still be a non-SIMD 32 bit problems. ..... New code is great (simplifies a lot), but there simply is a lot of work to get things 'right'.
Author
Owner

@jfoug commented on GitHub (Aug 21, 2015):

992af99 openbsd-softraid. This crap is easy to remove, now that i have added hmac_sha1.h There should be NO excuse now, for @kholia or others using other type code for these simple things. IF we need to add other hmac algos, then by all means speak up, and we can EASILY add them.

<!-- gh-comment-id:133582871 --> @jfoug commented on GitHub (Aug 21, 2015): 992af99 openbsd-softraid. This crap is easy to remove, now that i have added hmac_sha1.h There should be NO excuse now, for @kholia or others using other type code for these simple things. IF we need to add other hmac algos, then by all means speak up, and we can EASILY add them.
Author
Owner

@jfoug commented on GitHub (Aug 23, 2015):

f837171 dmg hmac:sha1 only (still the DES stuff to do)

<!-- gh-comment-id:133868578 --> @jfoug commented on GitHub (Aug 23, 2015): f837171 dmg hmac:sha1 only (still the DES stuff to do)
Author
Owner

@jfoug commented on GitHub (Aug 23, 2015):

My opinion about removing the EVP_* and BIO_* checks from the configure, even if we do remove all current code that uses them, is that we should not remove them.

Some of these changes are HARD, and not trivial. Having these options available to developers to quickly add a format is really needed. Later we can clean them up and 'own' the code. Some things like the PKCS12_bio 'can' be done with our owned code (and when I did it, I got a couple orders of magnitude improvement, and could do SIMD), BUT it takes a lot of code reversing to get to an understanding of the actual algorithm used. However, using already created samples moving to a john format quickly pretty much means that we need to know and use these high level interfaces at times.

<!-- gh-comment-id:133869052 --> @jfoug commented on GitHub (Aug 23, 2015): My opinion about removing the EVP_\* and BIO_\* checks from the configure, even if we do remove all current code that uses them, is that we should not remove them. Some of these changes are HARD, and not trivial. Having these options available to developers to quickly add a format is really needed. Later we can clean them up and 'own' the code. Some things like the PKCS12_bio 'can' be done with our owned code (and when I did it, I got a couple orders of magnitude improvement, and could do SIMD), BUT it takes a lot of code reversing to get to an understanding of the actual algorithm used. However, using already created samples moving to a john format quickly pretty much means that we need to know and use these high level interfaces at times.
Author
Owner

@magnumripper commented on GitHub (Aug 23, 2015):

Yeah that sounds like a good idea

<!-- gh-comment-id:133897985 --> @magnumripper commented on GitHub (Aug 23, 2015): Yeah that sounds like a good idea
Author
Owner

@jfoug commented on GitHub (Aug 24, 2015):

Building full oSSL with VC with debug symbols in it (no asm also). This should make stepping into a lot of the code to really see the simplicity of the 'real' algorithm SOOOO much easier. Things seem to be building well. I used perl inside cygwin, so the canned .bat files from the oSSL sources had to be interpreted and turned into commands properly handled in cygwin (mostly changing \ to / ) But with the ability to step into oSSL functions will help in figuring out if we can remove them.

<!-- gh-comment-id:134004259 --> @jfoug commented on GitHub (Aug 24, 2015): Building full oSSL with VC with debug symbols in it (no asm also). This should make stepping into a lot of the code to really see the simplicity of the 'real' algorithm SOOOO much easier. Things seem to be building well. I used perl inside cygwin, so the canned .bat files from the oSSL sources had to be interpreted and turned into commands properly handled in cygwin (mostly changing \ to / ) But with the ability to step into oSSL functions will help in figuring out if we can remove them.
Author
Owner

@magnumripper commented on GitHub (Aug 27, 2015):

I suspect the DMG format (especially OpenCL) has huge problems with OpenMP. We should try to switch to some lower-level interface even if still using OpenSSL.

<!-- gh-comment-id:135482254 --> @magnumripper commented on GitHub (Aug 27, 2015): I suspect the DMG format (especially OpenCL) has huge problems with OpenMP. We should try to switch to some lower-level interface even if still using OpenSSL.
Author
Owner

@jfoug commented on GitHub (Aug 27, 2015):

I bet there are more than just that format. I have been digging into oSSL, and yes, they have thread support, but it sucks, AND you actually LOSE performance going to OMP, because all of the oSSL code handles multi threading by letting only 1 thread at a time run, IF it even works properly. So removing the oSSL, then managing threading by making sure that each thread gets it's OWN data to work on, so that all threads can run, IS the right way to go.

Again, when cygwin was having those horrible issues on certain formats with OMP, once I ported code out of oSSL, all of those problems went away, and huge performance improvements were seen.

<!-- gh-comment-id:135487287 --> @jfoug commented on GitHub (Aug 27, 2015): I bet there are more than just that format. I have been digging into oSSL, and yes, they have thread support, but it sucks, AND you actually LOSE performance going to OMP, because all of the oSSL code handles multi threading by letting only 1 thread at a time run, IF it even works properly. So removing the oSSL, then managing threading by making sure that each thread gets it's OWN data to work on, so that all threads can run, IS the right way to go. Again, when cygwin was having those horrible issues on certain formats with OMP, once I ported code out of oSSL, all of those problems went away, and huge performance improvements were seen.
Author
Owner

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

I really need to fix the DMG format. Had to disable OpenMP completely for it due to segfaults from threading, and it was a major performance hit. I will look into it.

<!-- gh-comment-id:137294716 --> @magnumripper commented on GitHub (Sep 3, 2015): I really need to fix the DMG format. Had to disable OpenMP completely for it due to segfaults from threading, and it was a major performance hit. I will look into it.
Author
Owner

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

DMG fixed. Note, I added this to jumbo.[hc]

/*
 * Standard PKCS padding check. On success, returns net length.
 * On failure, returns -1.
 */
extern int check_pkcs_pad(const unsigned char* data, size_t len, int blocksize);

blocksize is obviously 16 for AES, 8 for DES and so on.

The EVP functions check padding but now we need to do it ourselves. Goes like this:

    DES_ede3_cbc_encrypt(in, out, len, &ks1, &ks2, &ks3, iv, DES_DECRYPT);

    if (check_pkcs_pad(out, len, 8) < 0)
        goto early_reject;
<!-- gh-comment-id:137604955 --> @magnumripper commented on GitHub (Sep 4, 2015): DMG fixed. Note, I added this to jumbo.[hc] ``` c /* * Standard PKCS padding check. On success, returns net length. * On failure, returns -1. */ extern int check_pkcs_pad(const unsigned char* data, size_t len, int blocksize); ``` `blocksize` is obviously 16 for AES, 8 for DES and so on. The EVP functions check padding but now we need to do it ourselves. Goes like this: ``` c DES_ede3_cbc_encrypt(in, out, len, &ks1, &ks2, &ks3, iv, DES_DECRYPT); if (check_pkcs_pad(out, len, 8) < 0) goto early_reject; ```
Author
Owner

@kholia commented on GitHub (Jun 19, 2016):

Commit 063b838e02 fixes the problem for ssh-ng format.

<!-- gh-comment-id:226990247 --> @kholia commented on GitHub (Jun 19, 2016): Commit 063b838e021007a746dc9698a4135779ce22b337 fixes the problem for ssh-ng format.
Author
Owner

@kholia commented on GitHub (Mar 8, 2017):

BIO_ stuff is all gone now. Let's keep the support for it in our autoconf scripts for now.

https://www.cryptopp.com/wiki/OPENSSL_EVP_BytesToKey documents the algorithm behind EVP_BytesToKey function.

<!-- gh-comment-id:285007416 --> @kholia commented on GitHub (Mar 8, 2017): BIO_ stuff is all gone now. Let's keep the support for it in our autoconf scripts for now. https://www.cryptopp.com/wiki/OPENSSL_EVP_BytesToKey documents the algorithm behind `EVP_BytesToKey` function.
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#1110
No description provided.