mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #978] OpenCL formats: share more code with CPU formats #577
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#577
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 (Dec 30, 2014).
Original GitHub issue: https://github.com/openwall/john/issues/978
We (myself definitely included) keep forgetting to port CPU format fixes (most notably in valid) to the OpenCL/CUDA alternative or vice versa. We should put all such code in shared files so this can't even happen.
Sometimes the OpenCL formats differ (eg. less algos supported like in GPG) but that should still be fixed with one shared valid() that behaves a bit differently depending on some macro definition. But this means we need to put C code in headers - we can't use a shared function. I personally don't mind putting C code in headers and with latest improvements to Makefile targets we don't miss dependecies.
partly done: move things like get_salt if possible, and46c55eaad2191fad2191fad2191fad2191ff3a81f577866c177866c177866c15c463ed5c463ed8c0a72fca62969partly done: improved with a6f842cpartly done: improved with a6f842c[To Claudio Ok] partly done: out of the base format files.687dfd4687dfd4687dfd4e3abe0d21e8c12eff5a92a8560adc8be465ad2e472ad2e472END OF FIRST TODO PRIORITY HASHES
cuda_pwsafe_fmt_plug.c(not sure when)9493a85d66ad2e472ad2e4727858951b8bopencl_sxc_fmt_plug.c@jfoug commented on GitHub (Dec 30, 2014):
I do agree that it is less ugly putting C code in headers now with proper dependencies. It still makes sense to use non-static functions for many of these items. Even valid can be a common non-static function. Instead of #define, simply use runtime if() logic, then have a valid in each format, that calls the common valid, telling that common valid which hashes to look for.
I am really surprised about the layout of john. Solar got pretty anal about 'bloat' in the autoconfig stuff, BUT we have TONSSSS of bloat, in static functions, especially statics in headers that get included by multiple files. Ugly, ugly practice.
@jfoug commented on GitHub (Dec 30, 2014):
I will start with the latest 2 that you noted.
NOTE, should we also address the cuda also ?? I would assume so.
Here are the functions that are good ones to put in common code. I will add to these as others are found.
@jfoug commented on GitHub (Dec 30, 2014):
What about this one: phpass
phpass-cpu is a thin format. prepare is mostly done in dyna
phpass-cuda and opencl, we could use a common valid.
Almost all the 'common' stuff in phpass-cpu is in dyna. I find no way to really do that in a common code way. But the cuda/opencl certainly could use common functions.
@magnumripper commented on GitHub (Dec 30, 2014):
Is there any statics in headers in core john? I thought only Jumbo had that.
@magnumripper commented on GitHub (Dec 30, 2014):
Yes of course. Although CUDA is pretty much dead in Jumbo, no-one actively develops any CUDA stuff. And why would they, now that OpenCL is as good and non-proprietary.
Right, the CUDA and OpenCL ones should share.
@jfoug commented on GitHub (Dec 30, 2014):
yes (only in jumbo, I think), but autoconf is also ONLY jumbo, and Solar has beat his chest listing that core will not get autoconf. Yet:
@jfoug commented on GitHub (Dec 30, 2014):
Of the 2 CPU-opencl common code cleanups I have done, do you think either of these was any harder to do using a common non-static file, than a header with static functions? I personally find it much cleaner to put declaration stuff in the header (the salt struct, the function declarations, etc), and code into a *_common_plug.c file.
One of the biggest reasons for all the statics, is due to having such a COMMON interface, that many people will want to name their functions and data objects the same across formats. That is a no-no on C, since the linker will complain. C++ could easily work around that with namespaces, BUT the end result is 100% the same, duplicated functions both in code, AND in the stored and running binary image.
Now, in core, since it is SO tiny, this is really not that big of an issue. But with 200+ 'real' formats now in jumbo, it is a problem, and only getting worse as time goes on. I guess I will simply stop whining about the issue, and simply start to work on this myself, hopefully to get some 'prototypes' on how to easily do it, so that others can continue in that method. Simply 'always' assuming that all functions have to be static, is really pretty short sighted. Yes, many of them DO have to be static. People love the name crypt_all() as a function. That is just fine, since each format will have to write a specific special purpose function to do this, so having it be static and IN the .c file make 100% sense. But other ones that really 'should' be the same function in multiple formats, 'could' be static and in a .h file, and that does unify the code. However, it does bloat up the binary and memory image, and gains almost nothing. Yes, I do understand the need for inline, BUT not every function should be inlined. In fact, often very few functions get benefit from inlining. Inlining something with a call to some oSSL hash is really just silly.
I will just continue forward. This cleanup is not going to be done overnight. There are a LOT of formats to do, and these take a while. It is pretty easy work, but time consuming. When done (or the closer to done we get), things will be better, when someone lists something wrong in a prepare, split or valid, and we fix it, it (should) be fixed for all the formats, and that can ONLY be a good thing.
@magnumripper commented on GitHub (Dec 30, 2014):
I never said we shouldn't make non-static functions like office_valid() - do it any way you like! What I wrote was in the context of actual differences in the functions (as in GPG) and like you said, even that can be worked around.
@jfoug commented on GitHub (Dec 31, 2014):
@magnumripper do you have any idea where this hash came from? {"$1$saltstring$YmP55hH3qcHg2cCffyxrq/", "ala"},
It is in opencl-cryptmd5 The salt is 10 bytes long, but valid for MD5_fmt.c (and even my pass_gen.pl) list valid salt length as 8. I changed valid to accept 10 byte salts, put this hash into MD5_fmt.c and it works fine. BUT is this hash even valid? If so, what is the max salt length?
@magnumripper commented on GitHub (Dec 31, 2014):
Git tells me @ukasz added it in
6dd9322, that's all I know.@jfoug commented on GitHub (Dec 31, 2014):
Both md5crypt and opencl only USE 8 bytes of salt. But opencl has this 10 byte salt in ST and it's valid did not Len check. I think I'm keeping 8 byte salt check in valid, and will fix that ST hash
@magnumripper commented on GitHub (Dec 31, 2014):
If that limit is decreased to 8 the optimizers might end up with significantly faster code. GPUs are unpredictable - some changes make a lot of impact. And 8 is a whole lot more even than 10...
@jfoug commented on GitHub (Dec 31, 2014):
It is only valid that's promiscuous in opencl. Setsalt only uses at most first 8 chars.
@magnumripper commented on GitHub (Dec 31, 2014):
LOL, so that hash is a valid one for a salt of "saltstri"? I did wonder what the heck was going on.
@jfoug commented on GitHub (Dec 31, 2014):
Yup, I cut off the 2 bytes, it now passes that 'proper' valid check, and the hash is fine.. IF we do have ITW hashes like this, we could fix them up in prepare/split
@jfoug commented on GitHub (Dec 31, 2014):
I am at a roadblock. I have what I 'think' to be all the code needed, to get the {smd5} working within opencl, but it is not working :( Can you have a look.
I think the only diff is that {smd5} does not prefix itself to the salt like
1orapr1do. I made changes to the salt() (actually no change needed), and to the cryptmd5_kernel.cl, thinking I knew what I was doing. The only 'real' change, was in the kernel, I had to do an else if() to check for a 'a' character in ctx_update_prefix(), so that a 'null' prefix character (which the {smd5} would get, would not add any data to the buffer.But if I put {smd5} hashes into the test string, they fail, and I do not know what I did wrong. If you do not have time for this, then I will have to make adjustments to valid, so that the GPU version will not validate {smd5} hashes, since they are not working.
@magnumripper commented on GitHub (Dec 31, 2014):
Cool, just hand it to me. Maybe you can just commit it, but with those test vectors commented out?
@jfoug commented on GitHub (Dec 31, 2014):
My bad, I was editing the .cl in my other work folder (my VC folder). I had *.cl excluded from my win-merge so was not copying the fix. I thought I was editing the one in my normal compile test dir for cygwin.
Now with the right *.cl file there, I think it is working just fine. I will also have these changes into the cuda format.
NOTE, the salt() function is ripe for common code, but the salt structure is just a bit different. I will let that one slide. Even between cuda/opencl there are differences.
NOTE, I can not test cuda, so will be committing blind.
@jfoug commented on GitHub (Dec 31, 2014):
Scratch that, I was wrong again. The {smd5} is not working (and likely would not be working for cuda). I have all the code there, but will have the ST vars commented out.
I will be committing soon. NOTE, valid() will say {smd5} is valid, so unless you can figure out why these are failing, I will have to change that, so that {smd5} is only valid for CPU.
@magnumripper commented on GitHub (Dec 31, 2014):
I am pretty sure you know that in order for an OpenCL format to run-time compile your changed kernel, you still have to run "make" since that's what copies it to the ../run/kernels folder. Just putting it out so you don't fall for a silly mistake.
@magnumripper commented on GitHub (Dec 31, 2014):
I'll probably be offline for 48+ hours from now. Happy new year :-P
@jfoug commented on GitHub (Dec 31, 2014):
HNY to you also! Yes, I know, AND the file has to be touched. Some copying of lines only (using winmerge) does not touch the file, so I have to be careful with that also. But I touched ( by hand) the .cl and did a make.
@jfoug commented on GitHub (Dec 31, 2014):
I ordered the todo list in what I 'think' is highest usage order. The bottom set of hashes is unordered. I have no idea about those hashes. But I think the top set is most used. Well, raw-md5 is probably most used, but since JtR's gpu code for these lags behind tools like hashcat, I really think few people use the JTR code for them, so they are on the 'do later' list.
@magnumripper commented on GitHub (Feb 7, 2015):
I ticked off wpapsk, afaik they were properly done to start with.
@magnumripper commented on GitHub (Mar 22, 2015):
http://www.openwall.com/lists/john-dev/2015/03/22/1
@ghost commented on GitHub (Mar 23, 2015):
Using the old way, we can discuss a path like this one for [RAW / X]-SHA512. BTW: -ng is slower than the regular version.
@magnumripper commented on GitHub (Mar 23, 2015):
The reason raw-sha256/512-ng formats are kept despite currently being slower, is they are more suitable for reversing steps and tricks like that, than the ones that use shared code from sse-intrinsics.c.
@magnumripper commented on GitHub (Mar 23, 2015):
Looks fine to me. What's to discuss?
@jfoug commented on GitHub (Feb 25, 2016):
Well part of the problem with doing this, is we now have a header which MUST be placed after memdbg.h However, we have a rule memdbg.h should be the last header.
The reason it must be after memdbg.h, is because it is NOT a header, it is code, AND there is allocations within that code. Having a code style sheet, that I get thumped with often, and NOT having a 'do NOT put code into headers' rule in this coding style seems strange.
These should be done with proper change. A header file that declares the data/functions, and a c module that defines them.
@magnumripper commented on GitHub (Feb 25, 2016):
If we call it rawSHA512_common.c instead of rawSHA512_common.h (which also hints reader that it contains code as opposed to just macros and definitions), we can simply say that memdbg.h must be the last of header (as in .h) files included.
Then again, we'd have to state that such .c files must not in turn include any .h headers - they'll need to be included by the mother file(s).
I'm not saying this is perfect, but it may be a way ahead.
@magnumripper commented on GitHub (Feb 25, 2016):
Oh, and for functions that are actually identical - yes of course they should be an actual C module that is not included but linked. Ie. foo_common.h with extern definitons and foo_common_plug.c with code.
@jfoug commented on GitHub (Feb 25, 2016):
That was my point exactly. The ONLY thing lost, is the ability to 'hide' the namespace with a static moniker. That is why in the past when I coded these 'global' functions, that i used something like:
RawSHA1_common_valid() as the name, vs valid()
Other than external name space, (and an extra .o module), I really see no downsides to putting the definition code into a .c file, with the declaration code into a .h file. That is what 'normal' convention is anyway.
@jfoug commented on GitHub (Feb 25, 2016):
And actually, this would (should) be part of the coding guidelines IMHO. It is not just here, there are other cases. I have searched a couple times for where/what some code is, then to later fine out it was in some 'header looking' object.
The one 'gotcha' we may not be able to work around, is the sph library. That one I think we really would have to use as it is, since it is not jtr native code.
@solardiz commented on GitHub (May 25, 2019):
magnum, do we need to keep this issue open? The list of formats looks out of date.
@magnumripper commented on GitHub (May 25, 2019):
Nah let's close it. It's sort of an ever-present issue.