Skip to content

Commit 16e5820

Browse files
committed
feature #52948 Use faster hashing algorithms when possible (javiereguiluz)
This PR was squashed before being merged into the 7.1 branch. Discussion ---------- Use faster hashing algorithms when possible | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT `xxh128` is 60 times faster than `sha256` (source: https://php.watch/versions/8.1/xxHash) but it's not cryptographically secure. In previous versions we already used `xxh128` in some places. In this PR I propose to use it in all places where we don't need a cryptographically secure hash. Comments: * ~I also remove some `base64` encoding of binary hashes, etc. It looks convoluted and to me it looks unnecessary. But I can revert these changes if needed.~ **REVERTED** * There are some places where we can probably use `xxh128` but I'm not sure, so I didn't. These: * https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/HttpKernel/EventListener/CacheAttributeListener.php#L71 * https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/HttpKernel/HttpCache/Store.php#L421-L434 * https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/HttpKernel/HttpCache/Store.php#L421-L434 * And there's this use case, where a function explicitly tells that we're generating a sha256 hash, so I'm not sure if changing it is a BC break: https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php#L42-L65 #SymfonyHackday Commits ------- 3d4d3557f7 Use faster hashing algorithms when possible
2 parents 080c679 + d73a168 commit 16e5820

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

EventListener/ConsoleProfilerListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function initialize(ConsoleCommandEvent $event): void
7777
return;
7878
}
7979

80-
$request->attributes->set('_stopwatch_token', substr(hash('sha256', uniqid(mt_rand(), true)), 0, 6));
80+
$request->attributes->set('_stopwatch_token', substr(hash('xxh128', uniqid(mt_rand(), true)), 0, 6));
8181
$this->stopwatch->openSection();
8282
}
8383

Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ public function testCachePoolServices()
16931693
->replaceArgument(0, $expectedSeed)
16941694
->replaceArgument(1, 12),
16951695
(new ChildDefinition('cache.adapter.redis'))
1696-
->replaceArgument(0, new Reference('.cache_connection.kYdiLgf'))
1696+
->replaceArgument(0, new Reference('.cache_connection.U5HliuY'))
16971697
->replaceArgument(1, $expectedSeed)
16981698
->replaceArgument(2, 12),
16991699
],

0 commit comments

Comments
 (0)