mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #1379] Combine CRC32 code #871
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#871
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 @jfoug on GitHub (Jun 4, 2015).
Original GitHub issue: https://github.com/openwall/john/issues/1379
We have at least 3 instances of CRC32 at this time. They all compute same crc values. We should unify this code.
@magnumripper commented on GitHub (Jun 4, 2015):
An undocumented (at least vaguely documented) caveat with Solar's crc32.c is you need to call CRC32_Init() from a single-thread region the first time (eg. in format's init()). After that, it's thread-safe. Just putting it out here, we had an intermittent bug in RAR for months that I just could not nail (Solar eventually did) because of it.
@magnumripper commented on GitHub (Jun 4, 2015):
@jfoug are you familiar with CRC-32? I tried implementing SSE4.2 crc32 intrinsics in our crc32 format, and it was totally trivial but unfortunately it turned out it was some other flavor of CRC-32 (namely CRC-32C as in Castagnoli) - but it was damn fast when ran with --skip-self-test! I still wonder if it can be used anyway, using some other initialization or workaround of some sort. Maybe it's totally different and can't be used.
We could of course implement a crc32c format too. Not that I see any use for it, but it would be cool for benchmarking. According to wikipedia it's used in eg. iSCSI, SCTP, G.hn payload, Btrfs, ext4 and Ceph.
@magnumripper commented on GitHub (Jun 5, 2015):
The pkzip version seems to be 5% faster than Solar's. Not sure why though, they do exactly the same thing as far as I can tell (I inlined Solar's version in crc32 format for comparison).
@jfoug commented on GitHub (Jun 5, 2015):
#defines are almost always faster, due to allowing the compiler to better optimize things. Even an inlined function has certain rules that must be handled, i.e. all ops must be done within certain sequence points within loops, etc, even if the compiler can figure out how to delay things for better optimization. The #defined types are simply inlined code. There the compiler may be able to better intermix instructions. One other thing is that I use an array, while solars code uses a pointer to an allocated array. There should be a deference there, while on mine, just using a static array, it is just an indexed offset. I bet if you put the static array into solar's code, it would be same speed (or close).
@magnumripper commented on GitHub (Jun 5, 2015):
I added a CRC-32C format just for fun. 99% based on the normal crc32 format. It reads a byte at a time, using _mm_crc32_u8(). It would probably be a lot faster reading 32 bits at a time with _mm_crc32_u32() if it wasn't for the fact a strlen() would totally ruin performance :)
@magnumripper commented on GitHub (Jun 5, 2015):
Come to think of it, I should have added the new format in the same source file.
@magnumripper commented on GitHub (Jun 5, 2015):
Here's an idea. We could not only use a single source file, but actually a single format. In set_salt() we could set the function pointer to crypt_all(). For
$crc32$it would be the normal function, and for$crc32c$it would be the CRC-32C function. No overhead at all!@jfoug commented on GitHub (Jun 5, 2015):
No strlen() would be needed at all. Just compute length in set_key() after the key is copied (of course we would need an array of ints (or unsigned chars to keep working set smaller).
@jfoug commented on GitHub (Jun 5, 2015):
I tried using _mm_crc32_u32() and it did not make that much difference:
Here is the code changes (not including setup of the saved_len array)
@magnumripper commented on GitHub (Jun 6, 2015):
LOL, that is damn near EXACTLY the code I tried. And I did use a ptr diff to get length in set_key. But even that has too much overhead in OMP (we're really hitting bottlenecks at these speeds). Just using u8 was a tad faster on this machine.
@jfoug commented on GitHub (Jun 10, 2015):
Ok, I have fully integrated all crc (crc32 and crc-32C) into crc32.[ch], and changed all usages to properly use only this data (pkzip, dynamic, truecrypt, etc). However, this adds code to a pair of core files. I am waiting on @magnumripper to list how he wishes to proceed here.
This is a diff of the changes:
@jfoug commented on GitHub (Jun 10, 2015):
NOTE, that line had to be retained in the table_init() function.
@jfoug commented on GitHub (Jun 10, 2015):
We should just call CRC32_Init_tab() within john_init code. It runs in milliseconds, so no one will ever know. Then the tables will simply be 'ready'.
I have updated the patch, with changes (the bInit) return, and adding init call to John, and removing the init call from the crc_init function.
@magnumripper commented on GitHub (Jun 11, 2015):
So perhaps
__SSE4_2__logic should be added to crc32.[hc] too, so a format don't need to care about it.__mm_crc32_u8(no overhead).__mm_crc32_u32or even__mm_crc32_u64for significant boost.CRC32C_ALGO_NAMEmacro.