Skip to content

Commit

Permalink
Psalm nits
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Apr 16, 2024
1 parent 2595489 commit 28d0d8b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/Core/AES.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/Core/AES/Expanded.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ class ParagonIE_Sodium_Core_AES_Expanded extends ParagonIE_Sodium_Core_AES_KeySc
{
/** @var bool $expanded */
protected $expanded = true;


}
}
11 changes: 10 additions & 1 deletion src/Core/AES/KeySchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ParagonIE_Sodium_Core_AES_KeySchedule
{
/** @var array<int, int> $skey -- has size 120 */
private $skey;
protected $skey;

/** @var bool $expanded */
protected $expanded = false;
Expand All @@ -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;
Expand Down

0 comments on commit 28d0d8b

Please sign in to comment.