Skip to content

Commit 095940f

Browse files
Upgrade/Install: Update sodium_compat to v1.18.0.
The latest version of sodium_compat includes some improvements, as well as a new feature which will also be included in PHP 8.2. * Fixed issues with the PHP autoloader: * [paragonie/sodium_compat#145 #145]: For WordPress, this ensures when Ed25519 is included, so too is the class it inherits from. * [paragonie/sodium_compat#148 #148], [paragonie/sodium_compat#149 #149]: For PHP 7.4+ with opcache preloading, this ensures the include guards don't fail. * [paragonie/sodium_compat#144 #144]: Added `sodium_crypto_stream_xchacha20_xor_ic()` * See [php/php-src#8276 pull request for php-src] (merged in PHP 8.2) * For motivation: [paragonie/halite#178 paragonie/halite#178] Release notes: https://github.com/paragonie/sodium_compat/releases/tag/v1.18.0 A full list of changes in this update can be found on GitHub: paragonie/sodium_compat@v1.17.1...v1.18.0 Follow-up to [49741], [51002], [51591], [52988]. Props jrf, paragoninitiativeenterprises. Fixes #56564. Built from https://develop.svn.wordpress.org/trunk@54150 git-svn-id: https://core.svn.wordpress.org/trunk@53709 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 03f5949 commit 095940f

File tree

6 files changed

+76
-2
lines changed

6 files changed

+76
-2
lines changed

wp-includes/sodium_compat/autoload.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ function sodiumCompatAutoloader($class)
4242
}
4343

4444
/* Explicitly, always load the Compat class: */
45-
require_once dirname(__FILE__) . '/src/Compat.php';
45+
if (!class_exists('ParagonIE_Sodium_Compat', false)) {
46+
require_once dirname(__FILE__) . '/src/Compat.php';
47+
}
4648

4749
if (!class_exists('SodiumException', false)) {
4850
require_once dirname(__FILE__) . '/src/SodiumException.php';
@@ -69,4 +71,5 @@ function sodiumCompatAutoloader($class)
6971
// Older versions of {PHP, ext/sodium} will not define these
7072
require_once(dirname(__FILE__) . '/lib/php72compat.php');
7173
}
74+
require_once(dirname(__FILE__) . '/lib/stream-xchacha20.php');
7275
require_once(dirname(__FILE__) . '/lib/ristretto255.php');

wp-includes/sodium_compat/lib/stream-xchacha20.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,19 @@ function sodium_crypto_stream_xchacha20_xor($message, $nonce, $key)
4141
return ParagonIE_Sodium_Compat::crypto_stream_xchacha20_xor($message, $nonce, $key, true);
4242
}
4343
}
44+
if (!is_callable('sodium_crypto_stream_xchacha20_xor_ic')) {
45+
/**
46+
* @see ParagonIE_Sodium_Compat::crypto_stream_xchacha20_xor_ic()
47+
* @param string $message
48+
* @param string $nonce
49+
* @param int $counter
50+
* @param string $key
51+
* @return string
52+
* @throws SodiumException
53+
* @throws TypeError
54+
*/
55+
function sodium_crypto_stream_xchacha20_xor_ic($message, $nonce, $counter, $key)
56+
{
57+
return ParagonIE_Sodium_Compat::crypto_stream_xchacha20_xor_ic($message, $nonce, $counter, $key, true);
58+
}
59+
}

wp-includes/sodium_compat/src/Compat.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,6 +3154,55 @@ public static function crypto_stream_xchacha20_xor($message, $nonce, $key, $dont
31543154
return ParagonIE_Sodium_Core_XChaCha20::streamXorIc($message, $nonce, $key);
31553155
}
31563156

3157+
/**
3158+
* DANGER! UNAUTHENTICATED ENCRYPTION!
3159+
*
3160+
* Unless you are following expert advice, do not use this feature.
3161+
*
3162+
* Algorithm: XChaCha20
3163+
*
3164+
* This DOES NOT provide ciphertext integrity.
3165+
*
3166+
* @param string $message Plaintext message
3167+
* @param string $nonce Number to be used Once; must be 24 bytes
3168+
* @param int $counter
3169+
* @param string $key Encryption key
3170+
* @return string Encrypted text which is vulnerable to chosen-
3171+
* ciphertext attacks unless you implement some
3172+
* other mitigation to the ciphertext (i.e.
3173+
* Encrypt then MAC)
3174+
* @param bool $dontFallback
3175+
* @throws SodiumException
3176+
* @throws TypeError
3177+
* @psalm-suppress MixedArgument
3178+
*/
3179+
public static function crypto_stream_xchacha20_xor_ic($message, $nonce, $counter, $key, $dontFallback = false)
3180+
{
3181+
/* Type checks: */
3182+
ParagonIE_Sodium_Core_Util::declareScalarType($message, 'string', 1);
3183+
ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
3184+
ParagonIE_Sodium_Core_Util::declareScalarType($counter, 'int', 3);
3185+
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 4);
3186+
3187+
/* Input validation: */
3188+
if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_STREAM_XCHACHA20_NONCEBYTES) {
3189+
throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_XCHACHA20_NONCEBYTES long.');
3190+
}
3191+
if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_STREAM_XCHACHA20_KEYBYTES) {
3192+
throw new SodiumException('Argument 3 must be CRYPTO_SECRETBOX_XCHACHA20_KEYBYTES long.');
3193+
}
3194+
3195+
if (is_callable('sodium_crypto_stream_xchacha20_xor_ic') && !$dontFallback) {
3196+
return sodium_crypto_stream_xchacha20_xor_ic($message, $nonce, $counter, $key);
3197+
}
3198+
3199+
$ic = ParagonIE_Sodium_Core_Util::store64_le($counter);
3200+
if (PHP_INT_SIZE === 4) {
3201+
return ParagonIE_Sodium_Core32_XChaCha20::streamXorIc($message, $nonce, $key, $ic);
3202+
}
3203+
return ParagonIE_Sodium_Core_XChaCha20::streamXorIc($message, $nonce, $key, $ic);
3204+
}
3205+
31573206
/**
31583207
* Return a secure random key for use with crypto_stream_xchacha20
31593208
*

wp-includes/sodium_compat/src/Core/Ed25519.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
if (class_exists('ParagonIE_Sodium_Core_Ed25519', false)) {
44
return;
55
}
6+
if (!class_exists('ParagonIE_Sodium_Core_Curve25519', false)) {
7+
require_once dirname(__FILE__) . '/Curve25519.php';
8+
}
69

710
/**
811
* Class ParagonIE_Sodium_Core_Ed25519

wp-includes/sodium_compat/src/Core32/Ed25519.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
if (class_exists('ParagonIE_Sodium_Core32_Ed25519', false)) {
44
return;
55
}
6+
if (!class_exists('ParagonIE_Sodium_Core32_Curve25519')) {
7+
require_once dirname(__FILE__) . '/Curve25519.php';
8+
}
69

710
/**
811
* Class ParagonIE_Sodium_Core32_Ed25519

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.1-alpha-54149';
19+
$wp_version = '6.1-alpha-54150';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)