From ef4f383667b890849b21f4f17084d9dca3b967b8 Mon Sep 17 00:00:00 2001 From: Joni Eskelinen Date: Wed, 15 May 2019 08:53:08 +0300 Subject: [PATCH] Change comparisons to strict --- lib/AESKW/Algorithm.php | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/lib/AESKW/Algorithm.php b/lib/AESKW/Algorithm.php index 2134d74..149c5a0 100644 --- a/lib/AESKW/Algorithm.php +++ b/lib/AESKW/Algorithm.php @@ -43,7 +43,7 @@ abstract class Algorithm implements AESKeyWrapAlgorithm */ public function __construct(string $iv = self::DEFAULT_IV) { - if (8 != strlen($iv)) { + if (8 !== strlen($iv)) { throw new \UnexpectedValueException('IV size must be 64 bits.'); } $this->_iv = $iv; @@ -143,7 +143,7 @@ public function wrapPad(string $key, string $kek): string // If the padded key contains exactly eight octets, // let the ciphertext be: // C[0] | C[1] = ENC(K, A | P[1]). - if (8 == strlen($key)) { + if (8 === strlen($key)) { return $this->_encrypt($kek, $aiv . $key); } // build plaintext blocks and apply normal wrapping with AIV as an @@ -212,8 +212,8 @@ abstract protected function _keySize(): int; protected function _checkKEKSize(string $kek): self { $len = $this->_keySize(); - if (strlen($kek) != $len) { - throw new \UnexpectedValueException("KEK size must be ${len} bytes."); + if (strlen($kek) !== $len) { + throw new \UnexpectedValueException("KEK size must be {$len} bytes."); } return $this; } @@ -225,13 +225,11 @@ protected function _checkKEKSize(string $kek): self * * @see https://tools.ietf.org/html/rfc3394#section-2.2.1 * - * @param string[] $P Plaintext, n 64-bit values {P1, P2, ..., - * Pn} + * @param string[] $P Plaintext, n 64-bit values {P1, P2, ..., Pn} * @param string $kek Key encryption key * @param string $iv Initial value * - * @return string[] Ciphertext, (n+1) 64-bit values {C0, C1, ..., - * Cn} + * @return string[] Ciphertext, (n+1) 64-bit values {C0, C1, ..., Cn} */ protected function _wrapBlocks(array $P, string $kek, string $iv): array { @@ -280,7 +278,7 @@ protected function _unwrapPaddedCiphertext(string $ciphertext, string $kek): arr $n = count($C) - 1; // if key consists of only one block, recover AIV and padded key as: // A | P[1] = DEC(K, C[0] | C[1]) - if (1 == $n) { + if (1 === $n) { $P = str_split($this->_decrypt($kek, $C[0] . $C[1]), 8); $A = $P[0]; unset($P[0]); @@ -302,14 +300,12 @@ protected function _unwrapPaddedCiphertext(string $ciphertext, string $kek): arr * * @see https://tools.ietf.org/html/rfc3394#section-2.2.2 * - * @param string[] $C Ciphertext, (n+1) 64-bit values {C0, C1, ..., - * Cn} + * @param string[] $C Ciphertext, (n+1) 64-bit values {C0, C1, ..., Cn} * @param string $kek Key encryption key * * @throws \UnexpectedValueException * - * @return array Tuple of integrity value A and register - * R + * @return array Tuple of integrity value A and register R */ protected function _unwrapBlocks(array $C, string $kek): array { @@ -349,7 +345,7 @@ protected function _padKey(string $key): array { $len = strlen($key); // append padding - if (0 != $len % 8) { + if (0 !== $len % 8) { $key .= str_repeat("\0", 8 - $len % 8); } // compute AIV @@ -376,8 +372,7 @@ protected function _checkPaddedIntegrity(string $A): void /** * Verify that the padding of the plaintext is valid. * - * @param array $P Plaintext, n 64-bit values {P1, P2, ..., - * Pn} + * @param array $P Plaintext, n 64-bit values {P1, P2, ..., Pn} * @param string $A Integrity check value * * @throws \UnexpectedValueException @@ -400,7 +395,7 @@ protected function _verifyPadding(array $P, string $A): int // last block (note that the first index in P is 1) $Pn = $P[$n]; // check that padding consists of zeroes - if (substr($Pn, -$b) != str_repeat("\0", $b)) { + if (substr($Pn, -$b) !== str_repeat("\0", $b)) { throw new \UnexpectedValueException('Invalid padding.'); } }