@@ -71,7 +71,7 @@ |
||
71 | 71 | // The source of random data used to create keys and IV's |
72 | 72 | // Used for PHP_Crypt::createKey(), PHP_Crypt::createIV() |
73 | 73 | const RAND = "rand"; // uses mt_rand(), windows & unix |
74 | - const RAND_DEV_RAND = "/dev/random"; // unix only |
|
74 | + const RAND_DEV_RAND = "/dev/random"; // unix only |
|
75 | 75 | const RAND_DEV_URAND = "/dev/urandom"; // unix only |
76 | 76 | const RAND_WIN_COM = "wincom"; // windows only, COM extension |
77 | 77 | const RAND_DEFAULT_SZ = 32; // the default number of bytes returned |
@@ -48,8 +48,9 @@ discard block |
||
48 | 48 | parent::__construct(PHP_Crypt::MODE_CBC, $cipher); |
49 | 49 | |
50 | 50 | // this works with only block Ciphers |
51 | - if ($cipher->type() != Cipher::BLOCK) |
|
52 | - trigger_error("CBC mode requires a block cipher", E_USER_WARNING); |
|
51 | + if ($cipher->type() != Cipher::BLOCK) { |
|
52 | + trigger_error("CBC mode requires a block cipher", E_USER_WARNING); |
|
53 | + } |
|
53 | 54 | } |
54 | 55 | |
55 | 56 | |
@@ -92,8 +93,9 @@ discard block |
||
92 | 93 | $block = substr($text, $pos, $blocksz); |
93 | 94 | |
94 | 95 | // xor the block with the register |
95 | - for ($j = 0; $j < $blocksz; ++$j) |
|
96 | - $block[$j] = $block[$j] ^ $this->register[$j]; |
|
96 | + for ($j = 0; $j < $blocksz; ++$j) { |
|
97 | + $block[$j] = $block[$j] ^ $this->register[$j]; |
|
98 | + } |
|
97 | 99 | |
98 | 100 | // encrypt the block, and save it back to the register |
99 | 101 | $this->cipher->encrypt($block); |
@@ -139,8 +141,9 @@ discard block |
||
139 | 141 | $this->cipher->decrypt($block); |
140 | 142 | |
141 | 143 | // xor the block with the register |
142 | - for ($j = 0; $j < $blocksz; ++$j) |
|
143 | - $block[$j] = $block[$j] ^ $this->register[$j]; |
|
144 | + for ($j = 0; $j < $blocksz; ++$j) { |
|
145 | + $block[$j] = $block[$j] ^ $this->register[$j]; |
|
146 | + } |
|
144 | 147 | |
145 | 148 | // replace the block of cipher text with plain text |
146 | 149 | $text = substr_replace($text, $block, $pos, $blocksz); |
@@ -48,8 +48,9 @@ discard block |
||
48 | 48 | parent::__construct(PHP_Crypt::MODE_NCFB, $cipher); |
49 | 49 | |
50 | 50 | // this works with only block Ciphers |
51 | - if ($cipher->type() != Cipher::BLOCK) |
|
52 | - trigger_error("NCFB mode requires a block cipher", E_USER_WARNING); |
|
51 | + if ($cipher->type() != Cipher::BLOCK) { |
|
52 | + trigger_error("NCFB mode requires a block cipher", E_USER_WARNING); |
|
53 | + } |
|
53 | 54 | } |
54 | 55 | |
55 | 56 | |
@@ -88,8 +89,9 @@ discard block |
||
88 | 89 | // make sure we don't extend past the length of $text |
89 | 90 | $byte_len = $blocksz; |
90 | 91 | |
91 | - if (($pos + $byte_len) > $len) |
|
92 | - $byte_len -= ($pos + $byte_len) - $len; |
|
92 | + if (($pos + $byte_len) > $len) { |
|
93 | + $byte_len -= ($pos + $byte_len) - $len; |
|
94 | + } |
|
93 | 95 | |
94 | 96 | // encrypt the register |
95 | 97 | $this->enc_register = $this->register; |
@@ -99,8 +101,9 @@ discard block |
||
99 | 101 | $block = substr($text, $pos, $byte_len); |
100 | 102 | |
101 | 103 | // xor the block |
102 | - for ($j = 0; $j < $byte_len; ++$j) |
|
103 | - $block[$j] = $block[$j] ^ $this->enc_register[$j]; |
|
104 | + for ($j = 0; $j < $byte_len; ++$j) { |
|
105 | + $block[$j] = $block[$j] ^ $this->enc_register[$j]; |
|
106 | + } |
|
104 | 107 | |
105 | 108 | // replace the plain text block with the encrypted block |
106 | 109 | $text = substr_replace($text, $block, $pos, $byte_len); |
@@ -135,8 +138,9 @@ discard block |
||
135 | 138 | |
136 | 139 | // make sure we don't extend past the length of $text |
137 | 140 | $byte_len = $blocksz; |
138 | - if (($pos + $byte_len) > $len) |
|
139 | - $byte_len -= ($pos + $byte_len) - $len; |
|
141 | + if (($pos + $byte_len) > $len) { |
|
142 | + $byte_len -= ($pos + $byte_len) - $len; |
|
143 | + } |
|
140 | 144 | |
141 | 145 | // encrypt the register |
142 | 146 | $this->enc_register = $this->register; |
@@ -147,8 +151,9 @@ discard block |
||
147 | 151 | $this->register = $block; |
148 | 152 | |
149 | 153 | // xor the block |
150 | - for ($j = 0; $j < $byte_len; ++$j) |
|
151 | - $block[$j] = $block[$j] ^ $this->enc_register[$j]; |
|
154 | + for ($j = 0; $j < $byte_len; ++$j) { |
|
155 | + $block[$j] = $block[$j] ^ $this->enc_register[$j]; |
|
156 | + } |
|
152 | 157 | |
153 | 158 | // replace the encrypted block with the plain text block |
154 | 159 | $text = substr_replace($text, $block, $pos, $byte_len); |
@@ -48,8 +48,9 @@ |
||
48 | 48 | parent::__construct(PHP_Crypt::MODE_OFB, $cipher); |
49 | 49 | |
50 | 50 | // this works with only block Ciphers |
51 | - if ($cipher->type() != Cipher::BLOCK) |
|
52 | - trigger_error("OFB mode requires a block cipher", E_USER_WARNING); |
|
51 | + if ($cipher->type() != Cipher::BLOCK) { |
|
52 | + trigger_error("OFB mode requires a block cipher", E_USER_WARNING); |
|
53 | + } |
|
53 | 54 | } |
54 | 55 | |
55 | 56 |
@@ -48,8 +48,9 @@ |
||
48 | 48 | parent::__construct(PHP_Crypt::MODE_ECB, $cipher); |
49 | 49 | |
50 | 50 | // this works with only block Ciphers |
51 | - if ($cipher->type() != Cipher::BLOCK) |
|
52 | - trigger_error("ECB mode requires a block cipher", E_USER_WARNING); |
|
51 | + if ($cipher->type() != Cipher::BLOCK) { |
|
52 | + trigger_error("ECB mode requires a block cipher", E_USER_WARNING); |
|
53 | + } |
|
53 | 54 | } |
54 | 55 | |
55 | 56 |
@@ -48,8 +48,9 @@ |
||
48 | 48 | parent::__construct(PHP_Crypt::MODE_CFB, $cipher); |
49 | 49 | |
50 | 50 | // this works with only block Ciphers |
51 | - if ($cipher->type() != Cipher::BLOCK) |
|
52 | - trigger_error("CFB mode requires a block cipher", E_USER_WARNING); |
|
51 | + if ($cipher->type() != Cipher::BLOCK) { |
|
52 | + trigger_error("CFB mode requires a block cipher", E_USER_WARNING); |
|
53 | + } |
|
53 | 54 | } |
54 | 55 | |
55 | 56 |
@@ -51,8 +51,9 @@ |
||
51 | 51 | parent::__construct1(PHP_Crypt::MODE_STREAM, $cipher); |
52 | 52 | |
53 | 53 | // this works with only stream Ciphers |
54 | - if ($cipher->type() != Cipher::STREAM) |
|
55 | - trigger_error("Stream mode requires a stream cipher", E_USER_WARNING); |
|
54 | + if ($cipher->type() != Cipher::STREAM) { |
|
55 | + trigger_error("Stream mode requires a stream cipher", E_USER_WARNING); |
|
56 | + } |
|
56 | 57 | } |
57 | 58 | |
58 | 59 |
@@ -48,8 +48,9 @@ discard block |
||
48 | 48 | parent::__construct(PHP_Crypt::MODE_PCBC, $cipher); |
49 | 49 | |
50 | 50 | // this works with only block Ciphers |
51 | - if ($cipher->type() != Cipher::BLOCK) |
|
52 | - trigger_error("PCBC mode requires a block cipher", E_USER_WARNING); |
|
51 | + if ($cipher->type() != Cipher::BLOCK) { |
|
52 | + trigger_error("PCBC mode requires a block cipher", E_USER_WARNING); |
|
53 | + } |
|
53 | 54 | } |
54 | 55 | |
55 | 56 | |
@@ -86,16 +87,18 @@ discard block |
||
86 | 87 | $plain_block = $block; |
87 | 88 | |
88 | 89 | // xor the register with plain text |
89 | - for ($j = 0; $j < $blocksz; ++$j) |
|
90 | - $block[$j] = $this->register[$j] ^ $block[$j]; |
|
90 | + for ($j = 0; $j < $blocksz; ++$j) { |
|
91 | + $block[$j] = $this->register[$j] ^ $block[$j]; |
|
92 | + } |
|
91 | 93 | |
92 | 94 | // encrypt the block creating the cipher text |
93 | 95 | $this->cipher->encrypt($block); |
94 | 96 | |
95 | 97 | // xor the encrypted block with the plain text block to create |
96 | 98 | // the register in the next round |
97 | - for ($j = 0; $j < $blocksz; ++$j) |
|
98 | - $this->register[$j] = $block[$j] ^ $plain_block[$j]; |
|
99 | + for ($j = 0; $j < $blocksz; ++$j) { |
|
100 | + $this->register[$j] = $block[$j] ^ $plain_block[$j]; |
|
101 | + } |
|
99 | 102 | |
100 | 103 | // copy the encrypted block back to $text |
101 | 104 | $text = substr_replace($text, $block, $pos, $blocksz); |
@@ -130,12 +133,14 @@ discard block |
||
130 | 133 | |
131 | 134 | // xor the decrypted block with the register, to create |
132 | 135 | // the plain text block |
133 | - for ($j = 0; $j < $blocksz; ++$j) |
|
134 | - $block[$j] = $this->register[$j] ^ $block[$j]; |
|
136 | + for ($j = 0; $j < $blocksz; ++$j) { |
|
137 | + $block[$j] = $this->register[$j] ^ $block[$j]; |
|
138 | + } |
|
135 | 139 | |
136 | 140 | // now xor the $enc_block with the unencrypted $block |
137 | - for ($j = 0; $j < $blocksz; ++$j) |
|
138 | - $this->register[$j] = $block[$j] ^ $enc_block[$j]; |
|
141 | + for ($j = 0; $j < $blocksz; ++$j) { |
|
142 | + $this->register[$j] = $block[$j] ^ $enc_block[$j]; |
|
143 | + } |
|
139 | 144 | |
140 | 145 | // copy the plain text block back to $text |
141 | 146 | $text = substr_replace($text, $block, $pos, $blocksz); |
@@ -49,8 +49,9 @@ discard block |
||
49 | 49 | parent::__construct(PHP_Crypt::MODE_NOFB, $cipher); |
50 | 50 | |
51 | 51 | // this works with only block Ciphers |
52 | - if ($cipher->type() != Cipher::BLOCK) |
|
53 | - trigger_error("NOFB mode requires a block cipher", E_USER_WARNING); |
|
52 | + if ($cipher->type() != Cipher::BLOCK) { |
|
53 | + trigger_error("NOFB mode requires a block cipher", E_USER_WARNING); |
|
54 | + } |
|
54 | 55 | } |
55 | 56 | |
56 | 57 | |
@@ -84,8 +85,9 @@ discard block |
||
84 | 85 | |
85 | 86 | // make sure we don't extend past the length of $text |
86 | 87 | $byte_len = $blocksz; |
87 | - if (($pos + $blocksz) > $len) |
|
88 | - $byte_len -= ($pos + $blocksz) - $len; |
|
88 | + if (($pos + $blocksz) > $len) { |
|
89 | + $byte_len -= ($pos + $blocksz) - $len; |
|
90 | + } |
|
89 | 91 | |
90 | 92 | // encrypt the register |
91 | 93 | $this->enc_register = $this->register; |
@@ -93,8 +95,9 @@ discard block |
||
93 | 95 | |
94 | 96 | // now grab a block of text and a block of from the register, and XOR them |
95 | 97 | $block = substr($text, $pos, $byte_len); |
96 | - for ($j = 0; $j < $byte_len; ++$j) |
|
97 | - $block[$j] = $block[$j] ^ $this->enc_register[$j]; |
|
98 | + for ($j = 0; $j < $byte_len; ++$j) { |
|
99 | + $block[$j] = $block[$j] ^ $this->enc_register[$j]; |
|
100 | + } |
|
98 | 101 | |
99 | 102 | // replace the plain text block with encrypted text |
100 | 103 | $text = substr_replace($text, $block, $pos, $byte_len); |
@@ -127,8 +130,9 @@ discard block |
||
127 | 130 | |
128 | 131 | // make sure we don't extend past the length of $text |
129 | 132 | $byte_len = $blocksz; |
130 | - if (($pos + $byte_len) > $len) |
|
131 | - $byte_len -= ($pos + $byte_len) - $len; |
|
133 | + if (($pos + $byte_len) > $len) { |
|
134 | + $byte_len -= ($pos + $byte_len) - $len; |
|
135 | + } |
|
132 | 136 | |
133 | 137 | // encrypt the register |
134 | 138 | $this->enc_register = $this->register; |
@@ -140,8 +144,9 @@ discard block |
||
140 | 144 | |
141 | 145 | // now grab a block of text and xor with the register |
142 | 146 | $block = substr($text, $pos, $byte_len); |
143 | - for ($j = 0; $j < $byte_len; ++$j) |
|
144 | - $block[$j] = $block[$j] ^ $this->enc_register[$j]; |
|
147 | + for ($j = 0; $j < $byte_len; ++$j) { |
|
148 | + $block[$j] = $block[$j] ^ $this->enc_register[$j]; |
|
149 | + } |
|
145 | 150 | |
146 | 151 | // replace the encrypted block with plain text |
147 | 152 | $text = substr_replace($text, $block, $pos, $byte_len); |