Needs work
Project:
Drupal core
Version:
main
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
3 Sep 2022 at 06:25 UTC
Updated:
18 Nov 2025 at 20:15 UTC
Jump to comment: Most recent
PHP 8.1 adds support for xxHash - a very fast, collision-resistant, non-crytographic hash.
We use a lot of hashes for non-crypto purposes, and our approach flip-flops between using weak non-crypto hashes like crc32, or mis-using cryptographic hashes to be 'correct'. xxHash means we don't need to flip-flop any more.
Open sub-issues for each hash usage we want to change, including the recently added one in #2531564: Fix leaky and brittle container serialization solution.
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
neclimdulUsed some downtime to do the busywork to get a first pass at some of the obvious crc/md5/sha1 changes out of the way. The only remaining uses should be legacy stuff like d6/d7 password migration and composer compatibility. They all seem pretty straight forward not touching anything that would really be visible or a BC break.
The places where we use sha256 will be a bit trickier but I expect almost everything outside of hmac usage is probably not actually cryptographic and fair game if its not a BC break.
Speaking of sha256 uses, look at this odd ball method. \Drupal\Core\Cache\Cache::keyFromQuery. No usage in core and one usage in contrib on a project with no releases. Seems like something to just deprecate and remove. :-D.
Comment #4
catchThat was added in 2010 factored out of forum module, it's been rendered (see what I did there) irrelevant by render caching. Should definitely deprecate and remove.
Comment #5
neclimdulsplit that off here #3308507: Remove Cache::keyFromQuery
Comment #6
catch#3032078: Multiple webheads can cause infinite growth of Twig cache introduces another crc32.
Comment #7
cilefen commentedComment #13
catchThe fork was too far behind (early 10.x branch) to be able to rebase on, so cherry-picked the one commit that still applied to 11.x, recreated one more of @neclimdul's and pushed a new branch.
Also adding PermissionsHashGenerator here after discovering it makes debugging test cache changes unhelpfully difficult. We probably need to split that to its own issue though because it'll likely need constructor deprecations and a double check that it's definitely not security sensitive (I don't think it is though, it's a hash of permissions, not account information otherwise).
Comment #15
nicxvan commentedApplied some suggestions for cs and stan.
Comment #16
nicxvan commentedAh core services needs to be updated too.
Comment #17
nicxvan commentedIs there a reason not to use xxh3?
https://xxhash.com/
It seems to be supported and faster, but I'll admit I'm not super familiar with this so I may be missing something.
Comment #18
catchCan't see any reason not to use xxh3, probably got thrown off by it being 'new' but it was included in PHP 8.1
Comment #19
catchThe MR is back to green, but we need to figure out scope here. There are other sha256 and other hash usages in core we can probably convert.
Also not sure whether we want to spin-off PermissionsHashGenerator and any other logic changes to their own issues. Also noticed in the twig change that we're using Crypt::base64Encode() purely to base64 encode a hash but I think that's already the case with xxh3 so we could probably use xxh3 for that case too.
Comment #20
smustgrave commentedAny suggestion on how to review this?
Comment #21
smustgrave commentedAppears to need a rebase