Skip to content

Commit 125f4ad

Browse files
[Uid] Improve entropy of the increment for UUIDv7
1 parent c6f3da1 commit 125f4ad

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