From bc8e0ed636fe8cfc949beff17ab7a4cdd2d5f437 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 25 Jun 2023 00:37:37 -0500 Subject: [PATCH] BigInteger: speed up powMod() method --- phpseclib/Math/BigInteger/Engines/Engine.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpseclib/Math/BigInteger/Engines/Engine.php b/phpseclib/Math/BigInteger/Engines/Engine.php index 2b00bc37..abdf3b47 100644 --- a/phpseclib/Math/BigInteger/Engines/Engine.php +++ b/phpseclib/Math/BigInteger/Engines/Engine.php @@ -644,6 +644,11 @@ abstract class Engine implements \JsonSerializable return $this->normalize($temp->powModInner($e, $n)); } + if ($this->compare($n) > 0) { + list(, $temp) = $this->divide($n); + return $temp->powModInner($e, $n); + } + return $this->powModInner($e, $n); }