-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Replace slow generic sha3 implementation by KeccakCodePackage #2453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This appears to cause failures in the hash extension tests ... |
I looked at the AppVeyor build failure but I couldn't figure out how Windows builds handle include paths. Who should I get in touch with for this? |
You'll have to edit ext/hash/config.w32. I guess best to take look at the ext/gd/config.w32, most likely it'll changes to use CHECK_HEADER_ADD_INCLUDE(), ADD_SOURCES() and anything else necessary. Thanks. |
Hmm, I don't have Windows around to test it so it's kind of a shot in the dark. |
@chschneider if no one beats me to it, i'll be able to support you with the matter later this week. While on it, could you please link to your benchmarks? Thanks. |
@weltling Thanks! I tried setting up a Windows dev environment but no luck so far :-( I used a simple loop like |
@chschneider please check to cherry-pick chschneider/php-src@sha3...weltling:sha3 The benchmark on Windows x64 shows 7x improvement best, still significant. Yet some points
Thanks. |
|
Keccak*.h is included in the ext header, which gets installed. Any depending ext will have to set the include path, yep. Thinking a bit more about it - probably indeed it would be better to hide this dependency by including Keccak*.h in the .c file only, thus introducing no new include path dependency. I'd suggest to do so. Regarding the test procedure - nope, there is none. For 32-bit I could test as well, for big endian it were great to have it tested. Maybe @remicollet could play a part ;) Thanks. |
KeccakHash.h only included in php_hash_sha3.h which in turn is only included in hash_sha3.c. |
Those headers being installed is correct, as they provide publicly available symbols. With that, algorithms are usable directly without the hash factory. I didn't mean to modify the bundled files. Instead, the bundled header should be included only in the actual .c file hash_sha3.c where they're needed. In php_hash_sha3.h it could be abstracted the way Keccak*.h inclusion to be not required. Thanks. |
…t to install php_hash_sha3.h
I moved the dependency on Keccak*.h to hash_sha3.c which meant I use void * in php_hash_sha3.h. |
Yeah, that's a normal intermittent failure. /cc @sgolemon as you added this functionality originally |
Excuse my ignorance, I haven't really worked with Github before: Do you mean I should send a message (Mail? Github?) to sgolemon or was that already done with your comment? |
she got a ping because of the comment. |
@chschneider with Thanks. |
I don't get the struct PHP_SHA_CTX { void ctx; }; part: As long as the proper structure (or at least its size plus alignment) is not provided it cannot be used externally anyway. How would you allocate the amount of memory needed for the struct? Side-note: On my 64bit system the actual struct size is 224 bytes right now... Is that what you mean? |
Nope, i was talking about the usage, not about the exact declaration of the PHP_MD5_CTX. Of course, every hashing algo will have some difference. The example like here https://github.com/php/php-src/blob/master/ext/standard/md5.c#L47 is how it would be used by some dependent code. Having to pass Thanks. |
…not need to know about implementation details while keeping API backward compatible to original sha3 implementation
I think I finally got it. Thank for being patient with me. |
Yeah, thanks for being patient yourself ;) Seems the PR is close to finish. Please check the travis fails yet, seems that clone causes some mem leaks. Thanks. |
…allocates the hashinstance
I fixed the memory leak but eh travis-check has some weird failures again. Is there a way to re-run it? |
open and close the PR |
I've restarted the build. |
Usually you close and reopen, yep. Seems Travis was still not reliable, lets retry once. Otherwise, I plan to check manually anyway, hopefully next days, will ping back yet. Thanks. |
I finally was able to do additional tests. The current patch shows no regressions so far. The given bench snippet in #2453 (comment) shows improvements, here's by platform and factor
Though I could not compare absolute numbers, as all those were test VMs in different locations, so it only witnesses there's improvement on the same given VM. I couldn't see 30x speedup on any available machine with the given snippet, still the bench results look good, given also the current tests pass. I think, the chances are good for the PR to be merged. Probably would be still nice to hear from @remicollet, if he could find time for some big endian platform test :) Anyway, in worst case, the old code might have to be kept, and the old code used where the new code is not supported. Time to let the state ripen and see whether some more comments and tests are to come. Thanks. |
If there are no further comments or objections, I'm going to give this patch a try in master anytime soon. Thanks. |
Squashed and merged as 91663a9. Thanks |
Only for memory, this only work on LittleEndian.
Should be fixed by #2789 |
By using https://github.com/gvanas/KeccakCodePackage for the sha3 implementation we get a ~30 times speedup in a simple benchmark.
Currently it compiles either the generic64lc or the generic32lc version of KeccakCodePackage depending on the machine architecture, not sure if this is necessary or whether the 64 bit version could be used all the time.
It should also be easier to update the code one KeccakCodePackage releases a new version because it is stored in a separate directory without any source code modifications.