diff --git a/src/Core/AES.php b/src/Core/AES.php index de44f9c6..cade27d7 100644 --- a/src/Core/AES.php +++ b/src/Core/AES.php @@ -190,6 +190,15 @@ public static function invSbox(ParagonIE_Sodium_Core_AES_Block $q) self::processInversion($q); } + /** + * This is some boilerplate code needed to invert an S-box. Rather than repeat the code + * twice, I moved it to a protected method. + * + * Mutates $q + * + * @param ParagonIE_Sodium_Core_AES_Block $q + * @return void + */ protected static function processInversion(ParagonIE_Sodium_Core_AES_Block $q) { $q0 = (~$q[0]) & self::U32_MAX; @@ -271,6 +280,7 @@ public static function keySchedule($key) $skey[($i << 1)] = $tmp & self::U32_MAX; $skey[($i << 1) + 1] = $tmp & self::U32_MAX; if (++$j === $nk) { + /** @psalm-suppress LoopInvalidation */ $j = 0; ++$k; } @@ -395,6 +405,11 @@ public static function bitsliceEncryptBlock( self::addRoundKey($q, $skey, ($skey->getNumRounds() << 3)); } + /** + * @param ParagonIE_Sodium_Core_AES_Expanded $skey + * @param ParagonIE_Sodium_Core_AES_Block $q + * @return void + */ public static function bitsliceDecryptBlock( ParagonIE_Sodium_Core_AES_Expanded $skey, ParagonIE_Sodium_Core_AES_Block $q diff --git a/src/Core/AES/Expanded.php b/src/Core/AES/Expanded.php index 42080ff2..6deb9d59 100644 --- a/src/Core/AES/Expanded.php +++ b/src/Core/AES/Expanded.php @@ -4,6 +4,4 @@ class ParagonIE_Sodium_Core_AES_Expanded extends ParagonIE_Sodium_Core_AES_KeySc { /** @var bool $expanded */ protected $expanded = true; - - -} \ No newline at end of file +} diff --git a/src/Core/AES/KeySchedule.php b/src/Core/AES/KeySchedule.php index db32e60f..9c1b0dd9 100644 --- a/src/Core/AES/KeySchedule.php +++ b/src/Core/AES/KeySchedule.php @@ -3,7 +3,7 @@ class ParagonIE_Sodium_Core_AES_KeySchedule { /** @var array $skey -- has size 120 */ - private $skey; + protected $skey; /** @var bool $expanded */ protected $expanded = false; @@ -21,11 +21,20 @@ public function __construct(array $skey, $numRounds = 10) $this->numRounds = $numRounds; } + /** + * Get a value at an arbitrary index. Mostly used for unit testing. + * + * @param int $i + * @return int + */ public function get($i) { return $this->skey[$i]; } + /** + * @return int + */ public function getNumRounds() { return $this->numRounds;