Skip to content

Commit f7d457d

Browse files
Upgrade/Install: Update sodium_compat to v1.24.0.
The latest version includes a security fix to ensure that the public key is on the prime order subgroup. References: * [https://github.com/paragonie/sodium_compat/releases/tag/v1.24.0 sodium_compat 1.24.0 release notes] * [paragonie/sodium_compat@v1.23.0...v1.24.0 Full list of changes in sodium_compat 1.24.0] Follow-up to [55699], [58752], [58753], [60787], [60905]. Props paragoninitiativeenterprises, johnbillion, SergeyBiryukov. Fixes #64462. git-svn-id: https://develop.svn.wordpress.org/trunk@61419 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e77c857 commit f7d457d

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ public static function publickey_from_secretkey($sk)
106106
return self::sk_to_pk($sk);
107107
}
108108

109+
/**
110+
* Returns TRUE if $A represents a point on the order of the Edwards25519 prime order subgroup.
111+
* Returns FALSE if $A is on a different subgroup.
112+
*
113+
* @param ParagonIE_Sodium_Core_Curve25519_Ge_P3 $A
114+
* @return bool
115+
*
116+
* @throws SodiumException
117+
*/
118+
public static function is_on_main_subgroup(ParagonIE_Sodium_Core_Curve25519_Ge_P3 $A)
119+
{
120+
$p1 = self::ge_mul_l($A);
121+
$t = self::fe_sub($p1->Y, $p1->Z);
122+
return self::fe_isnonzero($p1->X) && self::fe_isnonzero($t);
123+
}
124+
109125
/**
110126
* @param string $pk
111127
* @return string
@@ -118,9 +134,8 @@ public static function pk_to_curve25519($pk)
118134
throw new SodiumException('Public key is on a small order');
119135
}
120136
$A = self::ge_frombytes_negate_vartime(self::substr($pk, 0, 32));
121-
$p1 = self::ge_mul_l($A);
122-
if (!self::fe_isnonzero($p1->X)) {
123-
throw new SodiumException('Unexpected zero result');
137+
if (!self::is_on_main_subgroup($A)) {
138+
throw new SodiumException('Public key is not on a member of the main subgroup');
124139
}
125140

126141
# fe_1(one_minus_y);
@@ -287,7 +302,7 @@ public static function verify_detached($sig, $message, $pk)
287302
throw new SodiumException('Argument 3 must be CRYPTO_SIGN_PUBLICKEYBYTES long');
288303
}
289304
if ((self::chrToInt($sig[63]) & 240) && self::check_S_lt_L(self::substr($sig, 32, 32))) {
290-
throw new SodiumException('S < L - Invalid signature');
305+
throw new SodiumException('S >= L - Invalid signature');
291306
}
292307
if (self::small_order($sig)) {
293308
throw new SodiumException('Signature is on too small of an order');
@@ -311,6 +326,9 @@ public static function verify_detached($sig, $message, $pk)
311326

312327
/** @var ParagonIE_Sodium_Core_Curve25519_Ge_P3 $A */
313328
$A = self::ge_frombytes_negate_vartime($pk);
329+
if (!self::is_on_main_subgroup($A)) {
330+
throw new SodiumException('Public key is not on a member of the main subgroup');
331+
}
314332

315333
/** @var string $hDigest */
316334
$hDigest = hash(

src/wp-includes/sodium_compat/src/File.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,14 @@ public static function verify(
786786
// Set ParagonIE_Sodium_Compat::$fastMult to true to speed up verification.
787787
ParagonIE_Sodium_Compat::$fastMult = true;
788788

789+
if (ParagonIE_Sodium_Core_Ed25519::small_order($publicKey)) {
790+
throw new SodiumException('Public key has small order');
791+
}
789792
/** @var ParagonIE_Sodium_Core_Curve25519_Ge_P3 $A */
790793
$A = ParagonIE_Sodium_Core_Ed25519::ge_frombytes_negate_vartime($publicKey);
794+
if (!ParagonIE_Sodium_Core_Ed25519::is_on_main_subgroup($A)) {
795+
throw new SodiumException('Public key is not on a member of the main subgroup');
796+
}
791797

792798
$hs = hash_init('sha512');
793799
self::hash_update($hs, self::substr($sig, 0, 32));

0 commit comments

Comments
 (0)