From e14e9e92caeebee85012fc3cb676ad7549e9dbf5 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Thu, 7 Jan 2021 19:35:34 -0600 Subject: [PATCH] EC: use the correct case up front --- phpseclib/Crypt/EC.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/phpseclib/Crypt/EC.php b/phpseclib/Crypt/EC.php index 38592445..2c0ab197 100644 --- a/phpseclib/Crypt/EC.php +++ b/phpseclib/Crypt/EC.php @@ -161,13 +161,15 @@ abstract class EC extends AsymmetricKey $privatekey = new PrivateKey; $curveName = $curve; - $curve = '\phpseclib3\Crypt\EC\Curves\\' . $curveName; - if (!class_exists($curve)) { + if (preg_match('#(?:^curve|^ed)\d+$#', $curveName)) { $curveName = ucfirst($curveName); - $curve = '\phpseclib3\Crypt\EC\Curves\\' . $curveName; - if (!class_exists($curve)) { - throw new UnsupportedCurveException('Named Curve of ' . $curveName . ' is not supported'); - } + } elseif (substr($curveName, 0, 10) == 'brainpoolp') { + $curveName = 'brainpoolP' . substr($curveName, 10); + } + $curve = '\phpseclib3\Crypt\EC\Curves\\' . $curveName; + + if (!class_exists($curve)) { + throw new UnsupportedCurveException('Named Curve of ' . $curveName . ' is not supported'); } $reflect = new \ReflectionClass($curve);