@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | $cipher = self::CIPHER_MAPPING[$cipherCode]; |
| 35 | 35 | |
| 36 | - if (false === ($encrypted = \openssl_encrypt($data, $cipher, $key, \OPENSSL_RAW_DATA|\OPENSSL_NO_PADDING, $iv))) { |
|
| 36 | + if (false === ($encrypted = \openssl_encrypt($data, $cipher, $key, \OPENSSL_RAW_DATA | \OPENSSL_NO_PADDING, $iv))) { |
|
| 37 | 37 | throw new \RuntimeException("Encryption failed with error: " . \openssl_error_string()); |
| 38 | 38 | } |
| 39 | 39 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | $cipher = self::CIPHER_MAPPING[$cipherCode]; |
| 58 | 58 | |
| 59 | - if (false === ($decrypted = \openssl_decrypt($data, $cipher, $key, \OPENSSL_RAW_DATA|\OPENSSL_NO_PADDING, $iv))) { |
|
| 59 | + if (false === ($decrypted = \openssl_decrypt($data, $cipher, $key, \OPENSSL_RAW_DATA | \OPENSSL_NO_PADDING, $iv))) { |
|
| 60 | 60 | throw new \RuntimeException("Decryption failed with error: " . \openssl_error_string()); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $dstByteOffset = 0; |
| 53 | 53 | $dst = []; |
| 54 | 54 | |
| 55 | - for ($srcByteOffset=0; $srcByteOffset<$srcSize; $srcByteOffset++) { |
|
| 55 | + for ($srcByteOffset = 0; $srcByteOffset < $srcSize; $srcByteOffset++) { |
|
| 56 | 56 | $byte = self::FILENAME_REVERSE_MAPPING[\ord($encoded[$srcByteOffset])]; |
| 57 | 57 | |
| 58 | 58 | switch ($currentBitOffset) { |
@@ -100,11 +100,11 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | $encoded = ''; |
| 103 | - for ($i=0; $i<$inputLength; $i+=3) { |
|
| 103 | + for ($i = 0; $i < $inputLength; $i += 3) { |
|
| 104 | 104 | $code1 = (\ord($decoded[$i]) >> 2) & 0x3F; |
| 105 | - $code2 = ((\ord($decoded[$i]) << 4) & 0x30) | ((\ord($decoded[$i+1]) >> 4) & 0x0F); |
|
| 106 | - $code3 = ((\ord($decoded[$i+1]) << 2) & 0x3C) | ((\ord($decoded[$i+2]) >> 6) & 0x03); |
|
| 107 | - $code4 = \ord($decoded[$i+2]) & 0x3F; |
|
| 105 | + $code2 = ((\ord($decoded[$i]) << 4) & 0x30) | ((\ord($decoded[$i + 1]) >> 4) & 0x0F); |
|
| 106 | + $code3 = ((\ord($decoded[$i + 1]) << 2) & 0x3C) | ((\ord($decoded[$i + 2]) >> 6) & 0x03); |
|
| 107 | + $code4 = \ord($decoded[$i + 2]) & 0x3F; |
|
| 108 | 108 | |
| 109 | 109 | $encoded .= self::PORTABLE_FILENAME_CHARS[$code1]; |
| 110 | 110 | $encoded .= self::PORTABLE_FILENAME_CHARS[$code2]; |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | public function generate() : string |
| 112 | 112 | { |
| 113 | 113 | return |
| 114 | - \chr(Tag3Packet::PACKET_TYPE) |
|
| 114 | + \chr(Tag3Packet::PACKET_TYPE) |
|
| 115 | 115 | . Util::generateTagPacketLength(\strlen($this->encryptedKey) + ECRYPTFS_SALT_SIZE + 5) |
| 116 | 116 | . \chr(Tag3Packet::PACKET_VERSION) |
| 117 | 117 | . \chr($this->cipherCode) |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | $cur += ECRYPTFS_SALT_SIZE; |
| 176 | 176 | |
| 177 | 177 | /* This conversion was taken straight from RFC2440 */ |
| 178 | - $hashIterations = (16 + (\ord($data[$cur]) & 15)) << ((\ord($data[$cur]) >> 4) + 6); |
|
| 178 | + $hashIterations = (16 + (\ord($data[$cur]) & 15)) << ((\ord($data[$cur]) >> 4) + 6); |
|
| 179 | 179 | $cur++; |
| 180 | 180 | |
| 181 | 181 | $encryptedKey = \substr($data, $cur, $encryptedKeySize); |
@@ -132,7 +132,7 @@ |
||
| 132 | 132 | * |
| 133 | 133 | * @link https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/fs/ecryptfs/keystore.c?h=v4.11.3#n1360 |
| 134 | 134 | */ |
| 135 | - public static function parse(string $data, int &$pos = 0) : self |
|
| 135 | + public static function parse(string $data, int & $pos = 0) : self |
|
| 136 | 136 | { |
| 137 | 137 | $cur = $pos; |
| 138 | 138 | |
@@ -123,7 +123,7 @@ |
||
| 123 | 123 | $header->encryptedFileKey = $tag3->encryptedKey; |
| 124 | 124 | |
| 125 | 125 | if (!\in_array(\strlen($header->encryptedFileKey), CryptoEngineInterface::CIPHER_KEY_SIZES[$header->cipherCode])) { |
| 126 | - throw new \RuntimeException(\sprintf("Invalid key size (%u bit) for cipher 0x%x detected, file header may be corrupt!", \strlen($header->encryptedFileKey)*8, $header->cipherCode)); |
|
| 126 | + throw new \RuntimeException(\sprintf("Invalid key size (%u bit) for cipher 0x%x detected, file header may be corrupt!", \strlen($header->encryptedFileKey) * 8, $header->cipherCode)); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | return $header; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | . \chr(self::FORMAT_SPECIFIER) |
| 62 | 62 | . \chr(\strlen(self::PACKET_FILENAME)) |
| 63 | 63 | . self::PACKET_FILENAME |
| 64 | - . \chr(0).\chr(0).\chr(0).\chr(0) |
|
| 64 | + . \chr(0) . \chr(0) . \chr(0) . \chr(0) |
|
| 65 | 65 | . $this->contents |
| 66 | 66 | ; |
| 67 | 67 | } |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | * Try to parse a Tag11 packet from the supplied data string. |
| 72 | 72 | * If the parsing was successfully, $pos will be incremented to point after the parsed data. |
| 73 | 73 | */ |
| 74 | - public static function parse(string $data, int &$pos = 0) : self |
|
| 74 | + public static function parse(string $data, int & $pos = 0) : self |
|
| 75 | 75 | { |
| 76 | 76 | $cur = $pos; |
| 77 | 77 | $remaining = \strlen($data) - $cur; |
| 78 | 78 | |
| 79 | - if ($remaining < self::MIN_PACKET_LENGTH+2) { |
|
| 79 | + if ($remaining < self::MIN_PACKET_LENGTH + 2) { |
|
| 80 | 80 | throw new ParseException('Not enough data available to read for minimum packet length.'); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | $cur += $filenameLength; |
| 112 | 112 | |
| 113 | - if (\substr($data, $cur, 4) !== \chr(0).\chr(0).\chr(0).\chr(0)) { |
|
| 113 | + if (\substr($data, $cur, 4) !== \chr(0) . \chr(0) . \chr(0) . \chr(0)) { |
|
| 114 | 114 | throw new ParseException('Expected file date to be zero.'); |
| 115 | 115 | } |
| 116 | 116 | $cur += 4; |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | if (!$correctKeySize) { |
| 185 | - throw new \RuntimeException(\sprintf("Unable to decrypt filename, filename encryption key (FNEK) invalid or invalid key length for cipher 0x%x, tested key sizes: (%s)", $this->cipherCode, \implode(', ', \array_map(function($bytes) { return $bytes*8; }, $possibleCipherKeySizes)))); |
|
| 185 | + throw new \RuntimeException(\sprintf("Unable to decrypt filename, filename encryption key (FNEK) invalid or invalid key length for cipher 0x%x, tested key sizes: (%s)", $this->cipherCode, \implode(', ', \array_map(function($bytes) { return $bytes * 8; }, $possibleCipherKeySizes)))); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | list($this->padding, $this->decryptedFilename) = \explode("\0", $decrypted, 2); |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | $prefix = ''; |
| 265 | 265 | $hash = $fnek; |
| 266 | 266 | |
| 267 | - for ($i=0; $i<\ceil($requiredBytes / self::DIGEST_SIZE); $i++) { |
|
| 267 | + for ($i = 0; $i < \ceil($requiredBytes / self::DIGEST_SIZE); $i++) { |
|
| 268 | 268 | $hash = \hash(self::DIGEST, $hash, true); |
| 269 | 269 | $prefix .= $hash; |
| 270 | 270 | } |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * |
| 292 | 292 | * @link https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/fs/ecryptfs/keystore.c?h=v4.11.3#n892 |
| 293 | 293 | */ |
| 294 | - public static function parse(string $data, int &$pos = 0) : self |
|
| 294 | + public static function parse(string $data, int & $pos = 0) : self |
|
| 295 | 295 | { |
| 296 | 296 | $cur = $pos; |
| 297 | 297 | $tag = new self(); |
@@ -205,13 +205,9 @@ |
||
| 205 | 205 | { |
| 206 | 206 | if ($cipherKeySize === null) { |
| 207 | 207 | $cipherKeySize = Util::findCipherKeySize($cipherCode, \strlen($fnek)); |
| 208 | - } |
|
| 209 | - |
|
| 210 | - elseif (\strlen($fnek) < $cipherKeySize) { |
|
| 208 | + } elseif (\strlen($fnek) < $cipherKeySize) { |
|
| 211 | 209 | throw new \InvalidArgumentException(\şprintf("Supplied key has only %u bytes but %u bytes required for encryption.", \strlen($$fnek), $cipherKeySize)); |
| 212 | - } |
|
| 213 | - |
|
| 214 | - elseif (!\in_array($cipherKeySize, CryptoEngineInterface::CIPHER_KEY_SIZES[$cipherCode])) { |
|
| 210 | + } elseif (!\in_array($cipherKeySize, CryptoEngineInterface::CIPHER_KEY_SIZES[$cipherCode])) { |
|
| 215 | 211 | throw new \InvalidArgumentException(\şprintf("Requested key size %u bytes is unsupported for cipher 0x%x.", $cipherKeySize, $cipherCode)); |
| 216 | 212 | } |
| 217 | 213 | |
@@ -33,20 +33,20 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | const CIPHER_KEY_SIZES = [ |
| 35 | 35 | // Triple-DES (DES-EDE, as per spec - 168 bit key derived from 192) |
| 36 | - RFC2440_CIPHER_DES3_EDE => [ 24 ], |
|
| 36 | + RFC2440_CIPHER_DES3_EDE => [24], |
|
| 37 | 37 | // CAST5 (128 bit key, as per RFC 2144) |
| 38 | - RFC2440_CIPHER_CAST_5 => [ 16 ], |
|
| 38 | + RFC2440_CIPHER_CAST_5 => [16], |
|
| 39 | 39 | // Blowfish (128 bit key, 16 rounds) |
| 40 | - RFC2440_CIPHER_BLOWFISH => [ 16 ], |
|
| 40 | + RFC2440_CIPHER_BLOWFISH => [16], |
|
| 41 | 41 | // AES with 128-bit key |
| 42 | - RFC2440_CIPHER_AES_128 => [ 16 ], |
|
| 42 | + RFC2440_CIPHER_AES_128 => [16], |
|
| 43 | 43 | // AES with 192-bit key |
| 44 | - RFC2440_CIPHER_AES_192 => [ 24 ], |
|
| 44 | + RFC2440_CIPHER_AES_192 => [24], |
|
| 45 | 45 | // AES with 256-bit key |
| 46 | - RFC2440_CIPHER_AES_256 => [ 32 ], |
|
| 46 | + RFC2440_CIPHER_AES_256 => [32], |
|
| 47 | 47 | // Twofish with 256-bit key |
| 48 | - RFC2440_CIPHER_TWOFISH => [ 32, 24, 16 ], |
|
| 49 | - RFC2440_CIPHER_CAST_6 => [ 32, 28, 24, 20, 16 ], |
|
| 48 | + RFC2440_CIPHER_TWOFISH => [32, 24, 16], |
|
| 49 | + RFC2440_CIPHER_CAST_6 => [32, 28, 24, 20, 16], |
|
| 50 | 50 | ]; |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | /** |
| 17 | 17 | * @link https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/include/linux/ecryptfs.h#n45 |
| 18 | 18 | */ |
| 19 | -const FC2440_CIPHER_RSA = 0x01; |
|
| 19 | +const FC2440_CIPHER_RSA = 0x01; |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * @link https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/include/linux/ecryptfs.h#n36 |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | /** |
| 27 | 27 | * @link https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/include/linux/ecryptfs.h#n37 |
| 28 | 28 | */ |
| 29 | -const RFC2440_CIPHER_CAST_5 = 0x03; |
|
| 29 | +const RFC2440_CIPHER_CAST_5 = 0x03; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * @link https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/include/linux/ecryptfs.h#n38 |
@@ -36,27 +36,27 @@ discard block |
||
| 36 | 36 | /** |
| 37 | 37 | * @link https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/include/linux/ecryptfs.h#n39 |
| 38 | 38 | */ |
| 39 | -const RFC2440_CIPHER_AES_128 = 0x07; |
|
| 39 | +const RFC2440_CIPHER_AES_128 = 0x07; |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * @link https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/include/linux/ecryptfs.h#n40 |
| 43 | 43 | */ |
| 44 | -const RFC2440_CIPHER_AES_192 = 0x08; |
|
| 44 | +const RFC2440_CIPHER_AES_192 = 0x08; |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * @link https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/include/linux/ecryptfs.h#n41 |
| 48 | 48 | */ |
| 49 | -const RFC2440_CIPHER_AES_256 = 0x09; |
|
| 49 | +const RFC2440_CIPHER_AES_256 = 0x09; |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * @link https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/include/linux/ecryptfs.h#n42 |
| 53 | 53 | */ |
| 54 | -const RFC2440_CIPHER_TWOFISH = 0x0a; |
|
| 54 | +const RFC2440_CIPHER_TWOFISH = 0x0a; |
|
| 55 | 55 | |
| 56 | 56 | /** |
| 57 | 57 | * @link https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/include/linux/ecryptfs.h#n43 |
| 58 | 58 | */ |
| 59 | -const RFC2440_CIPHER_CAST_6 = 0x0b; |
|
| 59 | +const RFC2440_CIPHER_CAST_6 = 0x0b; |
|
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | 62 | * Number of raw bytes used from signature hash |
@@ -172,7 +172,7 @@ |
||
| 172 | 172 | $startBlock = \floor(($this->position - $this->header->metadataSize) / $this->header->extentSize); |
| 173 | 173 | |
| 174 | 174 | $return = ''; |
| 175 | - for ($i=0; $i<$readBlocks && !$this->stream_eof(); $i++) { |
|
| 175 | + for ($i = 0; $i < $readBlocks && !$this->stream_eof(); $i++) { |
|
| 176 | 176 | $block = $startBlock + $i; |
| 177 | 177 | $iv = \hash("md5", $this->header->rootIv . \str_pad("$block", 16, "\0", \STR_PAD_RIGHT), true); |
| 178 | 178 | |
@@ -121,9 +121,7 @@ |
||
| 121 | 121 | // Use stream from context or open file |
| 122 | 122 | if (\array_key_exists(self::CONTEXT_STREAM, $myContext)) { |
| 123 | 123 | $this->encrypted = $myContext[self::CONTEXT_STREAM]; |
| 124 | - } |
|
| 125 | - |
|
| 126 | - else { |
|
| 124 | + } else { |
|
| 127 | 125 | $prefix = self::STREAM_NAME . '://'; |
| 128 | 126 | |
| 129 | 127 | if (\substr($path, 0, \strlen($prefix)) !== $prefix) { |