Browse Source

Replace md5 usage with xxh128.

The latter is much faster than md5. xxh128 is not cryptographically secure but
that's not required in the context it is used.
ADmad 1 year ago
parent
commit
b43f245ddc

+ 1 - 1
src/Cache/CacheEngine.php

@@ -341,7 +341,7 @@ abstract class CacheEngine implements CacheInterface, CacheEngineInterface
 
         $prefix = '';
         if ($this->_groupPrefix) {
-            $prefix = md5(implode('_', $this->groups()));
+            $prefix = hash('xxh128', implode('_', $this->groups()));
         }
         $key = preg_replace('/[\s]+/', '_', $key);
 

+ 1 - 1
src/Core/functions.php

@@ -372,7 +372,7 @@ if (!function_exists('Cake\Core\deprecationWarning')) {
         }
 
         static $errors = [];
-        $checksum = md5($message);
+        $checksum = hash('xxh128', $message);
         $duplicate = (bool)Configure::read('Error.allowDuplicateDeprecations', false);
         if (isset($errors[$checksum]) && !$duplicate) {
             return;

+ 1 - 1
src/Http/Client/FormData.php

@@ -67,7 +67,7 @@ class FormData implements Countable, Stringable
         if ($this->_boundary) {
             return $this->_boundary;
         }
-        $this->_boundary = md5(uniqid((string)time()));
+        $this->_boundary = hash('xxh128', uniqid((string)time()));
 
         return $this->_boundary;
     }

+ 1 - 1
src/Mailer/Message.php

@@ -1292,7 +1292,7 @@ class Message implements JsonSerializable
                 $this->emailFormat === static::MESSAGE_BOTH
             )
         ) {
-            $this->boundary = md5(Security::randomBytes(16));
+            $this->boundary = hash('xxh128', Security::randomBytes(16));
         }
     }
 

+ 4 - 1
src/Utility/Text.php

@@ -212,7 +212,10 @@ class Text
         );
 
         $dataKeys = array_keys($data);
-        $hashKeys = array_map('md5', $dataKeys);
+        $hashKeys = array_map(
+            fn ($str) => hash('xxh128', $str),
+            $dataKeys
+        );
         /** @var array<string, string> $tempData */
         $tempData = array_combine($dataKeys, $hashKeys);
         krsort($tempData);