From 0b9b0074c9a7e593b9af1efebd3c31293ce76bce Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 22 Aug 2022 06:07:52 -0500 Subject: [PATCH] backport more dynamic property fixes --- phpseclib/Crypt/Common/SymmetricKey.php | 12 ++++++++++-- phpseclib/Crypt/DES.php | 8 ++++++++ phpseclib/Crypt/DH.php | 7 +++++++ phpseclib/Crypt/EC.php | 7 +++++++ phpseclib/Crypt/EC/BaseCurves/KoblitzPrime.php | 14 ++++++++++++++ phpseclib/Crypt/Hash.php | 7 +++++++ phpseclib/Crypt/RSA.php | 7 +++++++ phpseclib/Crypt/RSA/PrivateKey.php | 4 ++-- .../Engines/PHP/Reductions/EvalBarrett.php | 2 +- phpseclib/Math/PrimeField.php | 2 -- 10 files changed, 63 insertions(+), 7 deletions(-) diff --git a/phpseclib/Crypt/Common/SymmetricKey.php b/phpseclib/Crypt/Common/SymmetricKey.php index a1f6a52a..63a3af4b 100644 --- a/phpseclib/Crypt/Common/SymmetricKey.php +++ b/phpseclib/Crypt/Common/SymmetricKey.php @@ -217,6 +217,14 @@ abstract class SymmetricKey */ protected $key = false; + /** + * HMAC Key + * + * @see self::setupGCM() + * @var ?string + */ + protected $hKey = false; + /** * The Initialization Vector * @@ -3239,7 +3247,7 @@ abstract class SymmetricKey private function setupGCM() { // don't keep on re-calculating $this->h - if (!$this->h || $this->h->key != $this->key) { + if (!$this->h || $this->hKey != $this->key) { $cipher = new static('ecb'); $cipher->setKey($this->key); $cipher->disablePadding(); @@ -3247,7 +3255,7 @@ abstract class SymmetricKey $this->h = self::$gcmField->newInteger( Strings::switchEndianness($cipher->encrypt("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0")) ); - $this->h->key = $this->key; + $this->hKey = $this->key; } if (strlen($this->nonce) == 12) { diff --git a/phpseclib/Crypt/DES.php b/phpseclib/Crypt/DES.php index fc45a692..637e11bc 100644 --- a/phpseclib/Crypt/DES.php +++ b/phpseclib/Crypt/DES.php @@ -138,6 +138,14 @@ class DES extends BlockCipher */ private $keys; + /** + * Key Cache "key" + * + * @see self::setupKey() + * @var array + */ + private $kl; + /** * Shuffle table. * diff --git a/phpseclib/Crypt/DH.php b/phpseclib/Crypt/DH.php index 2547614a..876cdbf8 100644 --- a/phpseclib/Crypt/DH.php +++ b/phpseclib/Crypt/DH.php @@ -62,6 +62,13 @@ abstract class DH extends AsymmetricKey */ protected $base; + /** + * Public Key + * + * @var \phpseclib3\Math\BigInteger + */ + protected $publicKey; + /** * Create DH parameters * diff --git a/phpseclib/Crypt/EC.php b/phpseclib/Crypt/EC.php index 44d850a2..e61f0092 100644 --- a/phpseclib/Crypt/EC.php +++ b/phpseclib/Crypt/EC.php @@ -123,6 +123,13 @@ abstract class EC extends AsymmetricKey */ protected $context; + /** + * Signature Format + * + * @var string + */ + protected $sigFormat; + /** * Create public / private key pair. * diff --git a/phpseclib/Crypt/EC/BaseCurves/KoblitzPrime.php b/phpseclib/Crypt/EC/BaseCurves/KoblitzPrime.php index dba83be4..d8492ebc 100644 --- a/phpseclib/Crypt/EC/BaseCurves/KoblitzPrime.php +++ b/phpseclib/Crypt/EC/BaseCurves/KoblitzPrime.php @@ -38,6 +38,20 @@ use phpseclib3\Math\PrimeField; */ class KoblitzPrime extends Prime { + /** + * Basis + * + * @var list + */ + protected $basis; + + /** + * Beta + * + * @var PrimeField\Integer + */ + protected $beta; + // don't overwrite setCoefficients() with one that only accepts one parameter so that // one might be able to switch between KoblitzPrime and Prime more easily (for benchmarking // purposes). diff --git a/phpseclib/Crypt/Hash.php b/phpseclib/Crypt/Hash.php index 5964c57d..8f95772f 100644 --- a/phpseclib/Crypt/Hash.php +++ b/phpseclib/Crypt/Hash.php @@ -171,6 +171,13 @@ class Hash */ private $pad; + /** + * Block Size + * + * @var int + */ + private $blockSize; + /**#@+ * UMAC variables * diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index f5b6a1f1..207a9051 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -249,6 +249,13 @@ abstract class RSA extends AsymmetricKey */ private static $smallestPrime = 4096; + /** + * Public Exponent + * + * @var \phpseclib3\Math\BigInteger + */ + protected $publicExponent; + /** * Sets the public exponent for key generation * diff --git a/phpseclib/Crypt/RSA/PrivateKey.php b/phpseclib/Crypt/RSA/PrivateKey.php index 0d9c51ee..6edd366d 100644 --- a/phpseclib/Crypt/RSA/PrivateKey.php +++ b/phpseclib/Crypt/RSA/PrivateKey.php @@ -51,9 +51,9 @@ class PrivateKey extends RSA implements Common\PrivateKey /** * Public Exponent * - * @var mixed + * @var \phpseclib3\Math\BigInteger */ - protected $publicExponent = false; + protected $privateExponent; /** * RSADP diff --git a/phpseclib/Math/BigInteger/Engines/PHP/Reductions/EvalBarrett.php b/phpseclib/Math/BigInteger/Engines/PHP/Reductions/EvalBarrett.php index 39d7305b..2f2c54b5 100644 --- a/phpseclib/Math/BigInteger/Engines/PHP/Reductions/EvalBarrett.php +++ b/phpseclib/Math/BigInteger/Engines/PHP/Reductions/EvalBarrett.php @@ -64,7 +64,7 @@ abstract class EvalBarrett extends Base $lhs->value = $x; $rhs = new ' . $class . '(); $rhs->value = [' . - implode(',', array_map('self::float2string', $m->value)) . ']; + implode(',', array_map(self::class . '::float2string', $m->value)) . ']; list(, $temp) = $lhs->divide($rhs); return $temp->value; '; diff --git a/phpseclib/Math/PrimeField.php b/phpseclib/Math/PrimeField.php index 227bfd34..17ff87a0 100644 --- a/phpseclib/Math/PrimeField.php +++ b/phpseclib/Math/PrimeField.php @@ -48,8 +48,6 @@ class PrimeField extends FiniteField // throw new \UnexpectedValueException('PrimeField requires a prime number be passed to the constructor'); //} - $this->modulo = $modulo; - $this->instanceID = self::$instanceCounter++; Integer::setModulo($this->instanceID, $modulo); Integer::setRecurringModuloFunction($this->instanceID, $modulo->createRecurringModuloFunction());