Completed
Push — development ( 6a24df...5afdf5 )
by Nils
07:52
created
install/js/crypt/aesctr.class.php 3 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,19 +7,19 @@  discard block
 block discarded – undo
7 7
 
8 8
 class AesCtr extends Aes
9 9
 {
10
-  /**
11
-   * Encrypt a text using AES encryption in Counter mode of operation
12
-   *  - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
13
-   *
14
-   * Unicode multi-byte character safe
15
-   *
16
-   * @param plaintext source text to be encrypted
17
-   * @param password  the password to use to generate a key
18
-   * @param nBits     number of bits to be used in the key (128, 192, or 256)
19
-   * @return          string text
20
-   */
21
-  public static function encrypt($plaintext, $password, $nBits)
22
-  {
10
+    /**
11
+     * Encrypt a text using AES encryption in Counter mode of operation
12
+     *  - see http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
13
+     *
14
+     * Unicode multi-byte character safe
15
+     *
16
+     * @param plaintext source text to be encrypted
17
+     * @param password  the password to use to generate a key
18
+     * @param nBits     number of bits to be used in the key (128, 192, or 256)
19
+     * @return          string text
20
+     */
21
+    public static function encrypt($plaintext, $password, $nBits)
22
+    {
23 23
     $blockSize = 16;  // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
24 24
     if (!($nBits==128 || $nBits==192 || $nBits==256)) {
25 25
         return '';
@@ -87,18 +87,18 @@  discard block
 block discarded – undo
87 87
     $ciphertext = base64_encode($ciphertext);
88 88
 
89 89
     return $ciphertext;
90
-  }
90
+    }
91 91
 
92
-  /**
93
-   * Decrypt a text encrypted by AES in counter mode of operation
94
-   *
95
-   * @param ciphertext source text to be decrypted
96
-   * @param password   the password to use to generate a key
97
-   * @param nBits      number of bits to be used in the key (128, 192, or 256)
98
-   * @return           string text
99
-   */
100
-  public static function decrypt($ciphertext, $password, $nBits)
101
-  {
92
+    /**
93
+     * Decrypt a text encrypted by AES in counter mode of operation
94
+     *
95
+     * @param ciphertext source text to be decrypted
96
+     * @param password   the password to use to generate a key
97
+     * @param nBits      number of bits to be used in the key (128, 192, or 256)
98
+     * @return           string text
99
+     */
100
+    public static function decrypt($ciphertext, $password, $nBits)
101
+    {
102 102
     $blockSize = 16;  // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
103 103
     if (!($nBits==128 || $nBits==192 || $nBits==256)) {
104 104
         return '';
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
    */
21 21
   public static function encrypt($plaintext, $password, $nBits)
22 22
   {
23
-    $blockSize = 16;  // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
24
-    if (!($nBits==128 || $nBits==192 || $nBits==256)) {
23
+    $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
24
+    if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) {
25 25
         return '';
26 26
     }
27 27
     // standard allows 128/192/256 bit keys
@@ -29,30 +29,30 @@  discard block
 block discarded – undo
29 29
 
30 30
     // use AES itself to encrypt password to get cipher key (using plain password as source for
31 31
     // key expansion) - gives us well encrypted key
32
-    $nBytes = $nBits/8;  // no bytes in key
32
+    $nBytes = $nBits / 8; // no bytes in key
33 33
     $pwBytes = array();
34
-    for ($i=0; $i<$nBytes; $i++) {
35
-        $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff;
34
+    for ($i = 0; $i < $nBytes; $i++) {
35
+        $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff;
36 36
     }
37 37
     $key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes));
38
-    $key = array_merge($key, array_slice($key, 0, $nBytes-16));  // expand key to 16/24/32 bytes long
38
+    $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long
39 39
 
40 40
     // initialise counter block (NIST SP800-38A §B.2): millisecond time-stamp for nonce in
41 41
     // 1st 8 bytes, block counter in 2nd 8 bytes
42 42
     $counterBlock = array();
43
-    $nonce = floor(microtime(true)*1000);   // timestamp: milliseconds since 1-Jan-1970
44
-    $nonceSec = floor($nonce/1000);
45
-    $nonceMs = $nonce%1000;
43
+    $nonce = floor(microtime(true) * 1000); // timestamp: milliseconds since 1-Jan-1970
44
+    $nonceSec = floor($nonce / 1000);
45
+    $nonceMs = $nonce % 1000;
46 46
     // encode nonce with seconds in 1st 4 bytes, and (repeated) ms part filling 2nd 4 bytes
47
-    for ($i=0; $i<4; $i++) {
48
-        $counterBlock[$i] = self::urs($nonceSec, $i*8) & 0xff;
47
+    for ($i = 0; $i < 4; $i++) {
48
+        $counterBlock[$i] = self::urs($nonceSec, $i * 8) & 0xff;
49 49
     }
50
-    for ($i=0; $i<4; $i++) {
51
-        $counterBlock[$i+4] = $nonceMs & 0xff;
50
+    for ($i = 0; $i < 4; $i++) {
51
+        $counterBlock[$i + 4] = $nonceMs & 0xff;
52 52
     }
53 53
     // and convert it to a string to go on the front of the ciphertext
54 54
     $ctrTxt = '';
55
-    for ($i=0; $i<8; $i++) {
55
+    for ($i = 0; $i < 8; $i++) {
56 56
         $ctrTxt .= chr($counterBlock[$i]);
57 57
     }
58 58
 
@@ -60,26 +60,26 @@  discard block
 block discarded – undo
60 60
     $keySchedule = Aes::keyExpansion($key);
61 61
     //print_r($keySchedule);
62 62
 
63
-    $blockCount = ceil(strlen($plaintext)/$blockSize);
64
-    $ciphertxt = array();  // ciphertext as array of strings
63
+    $blockCount = ceil(strlen($plaintext) / $blockSize);
64
+    $ciphertxt = array(); // ciphertext as array of strings
65 65
 
66
-    for ($b=0; $b<$blockCount; $b++) {
66
+    for ($b = 0; $b < $blockCount; $b++) {
67 67
         // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
68 68
         // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB)
69
-        for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff;
70
-        for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8);
69
+        for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff;
70
+        for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs($b / 0x100000000, $c * 8);
71 71
 
72
-        $cipherCntr = Aes::cipher($counterBlock, $keySchedule);  // -- encrypt counter block --
72
+        $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // -- encrypt counter block --
73 73
 
74 74
         // block size is reduced on final block
75
-        $blockLength = $b<$blockCount-1 ? $blockSize : (strlen($plaintext)-1)%$blockSize+1;
75
+        $blockLength = $b < $blockCount - 1 ? $blockSize : (strlen($plaintext) - 1) % $blockSize + 1;
76 76
         $cipherByte = array();
77 77
 
78
-        for ($i=0; $i<$blockLength; $i++) {  // -- xor plaintext with ciphered counter byte-by-byte --
79
-        $cipherByte[$i] = $cipherCntr[$i] ^ ord(substr($plaintext, $b*$blockSize+$i, 1));
78
+        for ($i = 0; $i < $blockLength; $i++) {  // -- xor plaintext with ciphered counter byte-by-byte --
79
+        $cipherByte[$i] = $cipherCntr[$i] ^ ord(substr($plaintext, $b * $blockSize + $i, 1));
80 80
         $cipherByte[$i] = chr($cipherByte[$i]);
81 81
         }
82
-        $ciphertxt[$b] = implode('', $cipherByte);  // escape troublesome characters in ciphertext
82
+        $ciphertxt[$b] = implode('', $cipherByte); // escape troublesome characters in ciphertext
83 83
     }
84 84
 
85 85
     // implode is more efficient than repeated string concatenation
@@ -99,54 +99,54 @@  discard block
 block discarded – undo
99 99
    */
100 100
   public static function decrypt($ciphertext, $password, $nBits)
101 101
   {
102
-    $blockSize = 16;  // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
103
-    if (!($nBits==128 || $nBits==192 || $nBits==256)) {
102
+    $blockSize = 16; // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
103
+    if (!($nBits == 128 || $nBits == 192 || $nBits == 256)) {
104 104
         return '';
105 105
     }
106 106
     // standard allows 128/192/256 bit keys
107 107
     $ciphertext = base64_decode($ciphertext);
108 108
 
109 109
     // use AES to encrypt password (mirroring encrypt routine)
110
-    $nBytes = $nBits/8;  // no bytes in key
110
+    $nBytes = $nBits / 8; // no bytes in key
111 111
     $pwBytes = array();
112
-    for ($i=0; $i<$nBytes; $i++) {
113
-        $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff;
112
+    for ($i = 0; $i < $nBytes; $i++) {
113
+        $pwBytes[$i] = ord(substr($password, $i, 1)) & 0xff;
114 114
     }
115 115
     $key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes));
116
-    $key = array_merge($key, array_slice($key, 0, $nBytes-16));  // expand key to 16/24/32 bytes long
116
+    $key = array_merge($key, array_slice($key, 0, $nBytes - 16)); // expand key to 16/24/32 bytes long
117 117
 
118 118
     // recover nonce from 1st element of ciphertext
119 119
     $counterBlock = array();
120 120
     $ctrTxt = substr($ciphertext, 0, 8);
121
-    for ($i=0; $i<8; $i++) {
122
-        $counterBlock[$i] = ord(substr($ctrTxt,$i,1));
121
+    for ($i = 0; $i < 8; $i++) {
122
+        $counterBlock[$i] = ord(substr($ctrTxt, $i, 1));
123 123
     }
124 124
 
125 125
     // generate key schedule
126 126
     $keySchedule = Aes::keyExpansion($key);
127 127
 
128 128
     // separate ciphertext into blocks (skipping past initial 8 bytes)
129
-    $nBlocks = ceil((strlen($ciphertext)-8) / $blockSize);
129
+    $nBlocks = ceil((strlen($ciphertext) - 8) / $blockSize);
130 130
     $ct = array();
131
-    for ($b=0; $b<$nBlocks; $b++) {
132
-        $ct[$b] = substr($ciphertext, 8+$b*$blockSize, 16);
131
+    for ($b = 0; $b < $nBlocks; $b++) {
132
+        $ct[$b] = substr($ciphertext, 8 + $b * $blockSize, 16);
133 133
     }
134
-    $ciphertext = $ct;  // ciphertext is now array of block-length strings
134
+    $ciphertext = $ct; // ciphertext is now array of block-length strings
135 135
 
136 136
     // plaintext will get generated block-by-block into array of block-length strings
137 137
     $plaintxt = array();
138 138
 
139
-    for ($b=0; $b<$nBlocks; $b++) {
139
+    for ($b = 0; $b < $nBlocks; $b++) {
140 140
         // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
141
-        for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff;
142
-        for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff;
141
+        for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c] = self::urs($b, $c * 8) & 0xff;
142
+        for ($c = 0; $c < 4; $c++) $counterBlock[15 - $c - 4] = self::urs(($b + 1) / 0x100000000 - 1, $c * 8) & 0xff;
143 143
 
144
-        $cipherCntr = Aes::cipher($counterBlock, $keySchedule);  // encrypt counter block
144
+        $cipherCntr = Aes::cipher($counterBlock, $keySchedule); // encrypt counter block
145 145
 
146 146
         $plaintxtByte = array();
147
-        for ($i=0; $i<strlen($ciphertext[$b]); $i++) {
147
+        for ($i = 0; $i < strlen($ciphertext[$b]); $i++) {
148 148
         // -- xor plaintext with ciphered counter byte-by-byte --
149
-        $plaintxtByte[$i] = $cipherCntr[$i] ^ ord(substr($ciphertext[$b],$i,1));
149
+        $plaintxtByte[$i] = $cipherCntr[$i] ^ ord(substr($ciphertext[$b], $i, 1));
150 150
         $plaintxtByte[$i] = chr($plaintxtByte[$i]);
151 151
 
152 152
         }
@@ -168,12 +168,12 @@  discard block
 block discarded – undo
168 168
    */
169 169
     private static function urs($a, $b)
170 170
     {
171
-    $a &= 0xffffffff; $b &= 0x1f;  // (bounds check)
172
-    if ($a&0x80000000 && $b>0) {   // if left-most bit set
173
-        $a = ($a>>1) & 0x7fffffff;   //   right-shift one bit & clear left-most bit
174
-        $a = $a >> ($b-1);           //   remaining right-shifts
171
+    $a &= 0xffffffff; $b &= 0x1f; // (bounds check)
172
+    if ($a & 0x80000000 && $b > 0) {   // if left-most bit set
173
+        $a = ($a >> 1) & 0x7fffffff; //   right-shift one bit & clear left-most bit
174
+        $a = $a >> ($b - 1); //   remaining right-shifts
175 175
     } else {                       // otherwise
176
-        $a = ($a>>$b);               //   use normal right-shift
176
+        $a = ($a >> $b); //   use normal right-shift
177 177
     }
178 178
 
179 179
     return $a;
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -66,8 +66,12 @@  discard block
 block discarded – undo
66 66
     for ($b=0; $b<$blockCount; $b++) {
67 67
         // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
68 68
         // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB)
69
-        for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff;
70
-        for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8);
69
+        for ($c=0; $c<4; $c++) {
70
+            $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff;
71
+        }
72
+        for ($c=0; $c<4; $c++) {
73
+            $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8);
74
+        }
71 75
 
72 76
         $cipherCntr = Aes::cipher($counterBlock, $keySchedule);  // -- encrypt counter block --
73 77
 
@@ -138,8 +142,12 @@  discard block
 block discarded – undo
138 142
 
139 143
     for ($b=0; $b<$nBlocks; $b++) {
140 144
         // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
141
-        for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff;
142
-        for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff;
145
+        for ($c=0; $c<4; $c++) {
146
+            $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff;
147
+        }
148
+        for ($c=0; $c<4; $c++) {
149
+            $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff;
150
+        }
143 151
 
144 152
         $cipherCntr = Aes::cipher($counterBlock, $keySchedule);  // encrypt counter block
145 153
 
Please login to merge, or discard this patch.
install/install.queries.php 1 patch
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -23,14 +23,16 @@  discard block
 block discarded – undo
23 23
     $dp = opendir($dir);
24 24
     $res = true;
25 25
     while ($file = readdir($dp)) {
26
-        if (($file == ".") || ($file == ".."))
27
-            continue;
26
+        if (($file == ".") || ($file == "..")) {
27
+                    continue;
28
+        }
28 29
 
29 30
         $fullPath = $dir."/".$file;
30 31
 
31 32
         if (is_dir($fullPath)) {
32
-            if ($res = @chmod($fullPath, $dirPermissions))
33
-                $res = @chmod_r($fullPath, $dirPermissions, $filePermissions);
33
+            if ($res = @chmod($fullPath, $dirPermissions)) {
34
+                            $res = @chmod_r($fullPath, $dirPermissions, $filePermissions);
35
+            }
34 36
         } else {
35 37
             $res = chmod($fullPath, $filePermissions);
36 38
         }
@@ -997,10 +999,12 @@  discard block
 block discarded – undo
997 999
                     if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
998 1000
                         // Change directory permissions
999 1001
                         $result = chmod_r($_SESSION['abspath'], 0770, 0740);
1000
-                        if ($result)
1001
-                            $result = chmod_r($_SESSION['abspath'].'/files', 0770, 0770);
1002
-                        if ($result)
1003
-                            $result = chmod_r($_SESSION['abspath'].'/upload', 0770, 0770);
1002
+                        if ($result) {
1003
+                                                    $result = chmod_r($_SESSION['abspath'].'/files', 0770, 0770);
1004
+                        }
1005
+                        if ($result) {
1006
+                                                    $result = chmod_r($_SESSION['abspath'].'/upload', 0770, 0770);
1007
+                        }
1004 1008
                     }
1005 1009
 
1006 1010
                     if ($result === false) {
Please login to merge, or discard this patch.
backups/script.ssh.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@
 block discarded – undo
85 85
         $ssh = new Net_SSH2($parse['host'], $parse['port']);
86 86
         if (!$ssh->login($record['login'], $oldPwClear['string'])) {
87 87
             $log .= "   ERR - Login failed.\n   Error description:".$_SESSION['sshError']."\n\n";
88
-        }else{
88
+        } else {
89 89
             // send ssh script for user change
90 90
             $ret_server = $ssh->exec('echo -e "'.$new_pwd.'\n'.$new_pwd.'" | passwd '.$record['login']);
91 91
             if (strpos($ret_server, "updated successfully") !== false) {
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@
 block discarded – undo
85 85
         $ssh = new Net_SSH2($parse['host'], $parse['port']);
86 86
         if (!$ssh->login($record['login'], $oldPwClear['string'])) {
87 87
             $log .= "   ERR - Login failed.\n   Error description:".$_SESSION['sshError']."\n\n";
88
-        }else{
88
+        } else{
89 89
             // send ssh script for user change
90 90
             $ret_server = $ssh->exec('echo -e "'.$new_pwd.'\n'.$new_pwd.'" | passwd '.$record['login']);
91 91
             if (strpos($ret_server, "updated successfully") !== false) {
Please login to merge, or discard this patch.
admin.settings_api.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -219,7 +219,7 @@
 block discarded – undo
219 219
               </tbody>
220 220
             </table>
221 221
             ';
222
-            }else {
222
+            } else {
223 223
             echo $LANG['settings_api_world_open'];
224 224
             }
225 225
         echo '
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -219,7 +219,7 @@
 block discarded – undo
219 219
               </tbody>
220 220
             </table>
221 221
             ';
222
-            }else {
222
+            } else {
223 223
             echo $LANG['settings_api_world_open'];
224 224
             }
225 225
         echo '
Please login to merge, or discard this patch.