Skip to content

Commit 95c8509

Browse files
bug #60908 [Uid] Improve entropy of the increment for UUIDv7 (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- [Uid] Improve entropy of the increment for UUIDv7 | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT Looks like we're missing the sign bit when computing the random increments on x64. Commits ------- 125f4ad [Uid] Improve entropy of the increment for UUIDv7
2 parents ff6d684 + 125f4ad commit 95c8509

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Symfony/Component/Uid/UuidV7.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static function generate(?\DateTimeInterface $time = null): string
6060

6161
if ($time > self::$time || (null !== $mtime && $time !== self::$time)) {
6262
randomize:
63-
self::$rand = unpack('n*', isset(self::$seed) ? random_bytes(10) : self::$seed = random_bytes(16));
63+
self::$rand = unpack('S*', isset(self::$seed) ? random_bytes(10) : self::$seed = random_bytes(16));
6464
self::$rand[1] &= 0x03FF;
6565
self::$time = $time;
6666
} else {
@@ -76,7 +76,7 @@ public static function generate(?\DateTimeInterface $time = null): string
7676
// 24-bit number in the self::$seedParts list and decrement self::$seedIndex.
7777

7878
if (!self::$seedIndex) {
79-
$s = unpack('l*', self::$seed = hash('sha512', self::$seed, true));
79+
$s = unpack(\PHP_INT_SIZE >= 8 ? 'L*' : 'l*', self::$seed = hash('sha512', self::$seed, true));
8080
$s[] = ($s[1] >> 8 & 0xFF0000) | ($s[2] >> 16 & 0xFF00) | ($s[3] >> 24 & 0xFF);
8181
$s[] = ($s[4] >> 8 & 0xFF0000) | ($s[5] >> 16 & 0xFF00) | ($s[6] >> 24 & 0xFF);
8282
$s[] = ($s[7] >> 8 & 0xFF0000) | ($s[8] >> 16 & 0xFF00) | ($s[9] >> 24 & 0xFF);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy