Completed
Push — development ( 362b6c...477849 )
by Nils
08:04
created
profile.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -158,7 +158,7 @@
 block discarded – undo
158 158
 
159 159
 // if DUOSecurity enabled then changing PWD is not allowed
160 160
 if (!isset($_SESSION['settings']['duo']) || $_SESSION['settings']['duo'] == 0)
161
-   echo '
161
+    echo '
162 162
     <div id="div_change_password" style="display:none; padding:5px;" class="ui-widget ui-state-default">
163 163
         <div style="text-align:center;margin:5px;padding:3px;" id="change_pwd_complexPw" class="ui-widget ui-state-active ui-corner-all"></div>
164 164
         <label for="new_pw" class="form_label">'.$LANG['index_new_pw'].' :</label>
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -95,8 +95,10 @@  discard block
 block discarded – undo
95 95
       <li class="menu_150" style="padding:4px; text-align:left;"><i class="fa fa-bars fa-fw"></i>&nbsp;'.$LANG['admin_actions_title'].'
96 96
          <ul class="menu_250" style="text-align:left;">
97 97
             <li id="but_pickfiles_photo"><i class="fa fa-camera fa-fw"></i> &nbsp;'.$LANG['upload_new_avatar'].'</li>';
98
-            if (!isset($_SESSION['settings']['duo']) || $_SESSION['settings']['duo'] == 0) echo '
98
+            if (!isset($_SESSION['settings']['duo']) || $_SESSION['settings']['duo'] == 0) {
99
+                echo '
99 100
             <li id="but_change_password"><i class="fa fa-key fa-fw"></i> &nbsp;'.$LANG['index_change_pw'].'</li>';
101
+            }
100 102
             echo '
101 103
             <li id="but_change_psk"><i class="fa fa-lock fa-fw"></i> &nbsp;'.$LANG['menu_title_new_personal_saltkey'].'</li>
102 104
             <li id="but_reset_psk"><i class="fa fa-eraser fa-fw"></i> &nbsp;'.$LANG['personal_saltkey_lost'].'</li>
@@ -157,7 +159,7 @@  discard block
 block discarded – undo
157 159
     <div id="filelist_photo" style="display:none;"></div>';
158 160
 
159 161
 // if DUOSecurity enabled then changing PWD is not allowed
160
-if (!isset($_SESSION['settings']['duo']) || $_SESSION['settings']['duo'] == 0)
162
+if (!isset($_SESSION['settings']['duo']) || $_SESSION['settings']['duo'] == 0) {
161 163
    echo '
162 164
     <div id="div_change_password" style="display:none; padding:5px;" class="ui-widget ui-state-default">
163 165
         <div style="text-align:center;margin:5px;padding:3px;" id="change_pwd_complexPw" class="ui-widget ui-state-active ui-corner-all"></div>
@@ -171,6 +173,7 @@  discard block
 block discarded – undo
171 173
         <span class="button" id="button_change_pw">'.$LANG['index_change_pw_button'].'</span>&nbsp;
172 174
         <span id="password_change_wait" style="display:none;"><i class="fa fa-cog fa-spin"></i>&nbsp;'.$LANG['please_wait'].'</span>
173 175
     </div>';
176
+}
174 177
 
175 178
 //change the saltkey dialogbox
176 179
 echo '
Please login to merge, or discard this patch.
install/upgrade_ajax.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -469,7 +469,7 @@
 block discarded – undo
469 469
                 } else {
470 470
                     // user said that database has not being used for an older version
471 471
                     // no old sk is available
472
-                     $tmp = mysqli_num_rows(mysqli_query(
472
+                        $tmp = mysqli_num_rows(mysqli_query(
473 473
                             $dbTmp,
474 474
                             "SELECT * FROM `".$var['tbl_prefix']."misc` WHERE type = 'admin' AND intitule = 'saltkey_ante_2127'"
475 475
                         ));
Please login to merge, or discard this patch.
Braces   +7 added lines, -4 removed lines patch added patch discarded remove patch
@@ -100,9 +100,12 @@  discard block
 block discarded – undo
100 100
         AND table_name = '$tablename'"
101 101
     );
102 102
 
103
-    if ($res > 0) return true;
104
-    else return false;
105
-}
103
+    if ($res > 0) {
104
+        return true;
105
+    } else {
106
+        return false;
107
+    }
108
+    }
106 109
 
107 110
 //define pbkdf2 iteration count
108 111
 @define('ITCOUNT', '2072');
@@ -852,7 +855,7 @@  discard block
 block discarded – undo
852 855
                         }
853 856
                         if(($r+1) == $row_count || ($r % 400) == 399){
854 857
                             $contents .= ");\n\n";
855
-                        }else{
858
+                        } else{
856 859
                             $contents .= "),\n";
857 860
                         }
858 861
                         $r++;
Please login to merge, or discard this patch.
install/js/crypt/aes.class.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -6,15 +6,15 @@  discard block
 block discarded – undo
6 6
 
7 7
 class Aes
8 8
 {
9
-  /**
10
-   * AES Cipher function: encrypt 'input' with Rijndael algorithm
11
-   *
12
-   * @param input message as byte-array (16 bytes)
13
-   * @param w     key schedule as 2D byte-array (Nr+1 x Nb bytes) -
14
-   *              generated from the cipher key by keyExpansion()
15
-   * @return      ciphertext as byte-array (16 bytes)
16
-   */
17
-  public static function cipher($input, $w) {    // main cipher function [é5.1]
9
+    /**
10
+     * AES Cipher function: encrypt 'input' with Rijndael algorithm
11
+     *
12
+     * @param input message as byte-array (16 bytes)
13
+     * @param w     key schedule as 2D byte-array (Nr+1 x Nb bytes) -
14
+     *              generated from the cipher key by keyExpansion()
15
+     * @return      ciphertext as byte-array (16 bytes)
16
+     */
17
+    public static function cipher($input, $w) {    // main cipher function [é5.1]
18 18
     $Nb = 4;                 // block size (in words): no of columns in state (fixed at 4 for AES)
19 19
     $Nr = count($w)/$Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys
20 20
 
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
     $state = self::addRoundKey($state, $w, 0, $Nb);
25 25
 
26 26
     for ($round=1; $round<$Nr; $round++) {  // apply Nr rounds
27
-      $state = self::subBytes($state, $Nb);
28
-      $state = self::shiftRows($state, $Nb);
29
-      $state = self::mixColumns($state, $Nb);
30
-      $state = self::addRoundKey($state, $w, $round, $Nb);
27
+        $state = self::subBytes($state, $Nb);
28
+        $state = self::shiftRows($state, $Nb);
29
+        $state = self::mixColumns($state, $Nb);
30
+        $state = self::addRoundKey($state, $w, $round, $Nb);
31 31
     }
32 32
 
33 33
     $state = self::subBytes($state, $Nb);
@@ -38,59 +38,59 @@  discard block
 block discarded – undo
38 38
     for ($i=0; $i<4*$Nb; $i++) $output[$i] = $state[$i%4][floor($i/4)];
39 39
 
40 40
     return $output;
41
-  }
41
+    }
42 42
 
43
-  private static function addRoundKey($state, $w, $rnd, $Nb) {  // xor Round Key into state S [é5.1.4]
43
+    private static function addRoundKey($state, $w, $rnd, $Nb) {  // xor Round Key into state S [é5.1.4]
44 44
     for ($r=0; $r<4; $r++) {
45
-      for ($c=0; $c<$Nb; $c++) $state[$r][$c] ^= $w[$rnd*4+$c][$r];
45
+        for ($c=0; $c<$Nb; $c++) $state[$r][$c] ^= $w[$rnd*4+$c][$r];
46 46
     }
47 47
 
48 48
     return $state;
49
-  }
49
+    }
50 50
 
51
-  private static function subBytes($s, $Nb) {    // apply SBox to state S [é5.1.1]
51
+    private static function subBytes($s, $Nb) {    // apply SBox to state S [é5.1.1]
52 52
     for ($r=0; $r<4; $r++) {
53
-      for ($c=0; $c<$Nb; $c++) $s[$r][$c] = self::$sBox[$s[$r][$c]];
53
+        for ($c=0; $c<$Nb; $c++) $s[$r][$c] = self::$sBox[$s[$r][$c]];
54 54
     }
55 55
 
56 56
     return $s;
57
-  }
57
+    }
58 58
 
59
-  private static function shiftRows($s, $Nb) {    // shift row r of state S left by r bytes [é5.1.2]
59
+    private static function shiftRows($s, $Nb) {    // shift row r of state S left by r bytes [é5.1.2]
60 60
     $t = array(4);
61 61
     for ($r=1; $r<4; $r++) {
62
-      for ($c=0; $c<4; $c++) $t[$c] = $s[$r][($c+$r)%$Nb];  // shift into temp copy
63
-      for ($c=0; $c<4; $c++) $s[$r][$c] = $t[$c];           // and copy back
62
+        for ($c=0; $c<4; $c++) $t[$c] = $s[$r][($c+$r)%$Nb];  // shift into temp copy
63
+        for ($c=0; $c<4; $c++) $s[$r][$c] = $t[$c];           // and copy back
64 64
     }          // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES):
65 65
     return $s;  // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf
66
-  }
66
+    }
67 67
 
68
-  private static function mixColumns($s, $Nb) {   // combine bytes of each col of state S [é5.1.3]
68
+    private static function mixColumns($s, $Nb) {   // combine bytes of each col of state S [é5.1.3]
69 69
     for ($c=0; $c<4; $c++) {
70
-      $a = array(4);  // 'a' is a copy of the current column from 's'
71
-      $b = array(4);  // 'b' is aé{02} in GF(2^8)
72
-      for ($i=0; $i<4; $i++) {
70
+        $a = array(4);  // 'a' is a copy of the current column from 's'
71
+        $b = array(4);  // 'b' is aé{02} in GF(2^8)
72
+        for ($i=0; $i<4; $i++) {
73 73
         $a[$i] = $s[$i][$c];
74 74
         $b[$i] = $s[$i][$c]&0x80 ? $s[$i][$c]<<1 ^ 0x011b : $s[$i][$c]<<1;
75
-      }
76
-      // a[n] ^ b[n] is aé{03} in GF(2^8)
77
-      $s[0][$c] = $b[0] ^ $a[1] ^ $b[1] ^ $a[2] ^ $a[3]; // 2*a0 + 3*a1 + a2 + a3
78
-      $s[1][$c] = $a[0] ^ $b[1] ^ $a[2] ^ $b[2] ^ $a[3]; // a0 * 2*a1 + 3*a2 + a3
79
-      $s[2][$c] = $a[0] ^ $a[1] ^ $b[2] ^ $a[3] ^ $b[3]; // a0 + a1 + 2*a2 + 3*a3
80
-      $s[3][$c] = $a[0] ^ $b[0] ^ $a[1] ^ $a[2] ^ $b[3]; // 3*a0 + a1 + a2 + 2*a3
75
+        }
76
+        // a[n] ^ b[n] is aé{03} in GF(2^8)
77
+        $s[0][$c] = $b[0] ^ $a[1] ^ $b[1] ^ $a[2] ^ $a[3]; // 2*a0 + 3*a1 + a2 + a3
78
+        $s[1][$c] = $a[0] ^ $b[1] ^ $a[2] ^ $b[2] ^ $a[3]; // a0 * 2*a1 + 3*a2 + a3
79
+        $s[2][$c] = $a[0] ^ $a[1] ^ $b[2] ^ $a[3] ^ $b[3]; // a0 + a1 + 2*a2 + 3*a3
80
+        $s[3][$c] = $a[0] ^ $b[0] ^ $a[1] ^ $a[2] ^ $b[3]; // 3*a0 + a1 + a2 + 2*a3
81 81
     }
82 82
 
83 83
     return $s;
84
-  }
85
-
86
-  /**
87
-   * Key expansion for Rijndael cipher(): performs key expansion on cipher key
88
-   * to generate a key schedule
89
-   *
90
-   * @param key cipher key byte-array (16 bytes)
91
-   * @return    key schedule as 2D byte-array (Nr+1 x Nb bytes)
92
-   */
93
-  public static function keyExpansion($key) {  // generate Key Schedule from Cipher Key [é5.2]
84
+    }
85
+
86
+    /**
87
+     * Key expansion for Rijndael cipher(): performs key expansion on cipher key
88
+     * to generate a key schedule
89
+     *
90
+     * @param key cipher key byte-array (16 bytes)
91
+     * @return    key schedule as 2D byte-array (Nr+1 x Nb bytes)
92
+     */
93
+    public static function keyExpansion($key) {  // generate Key Schedule from Cipher Key [é5.2]
94 94
     $Nb = 4;              // block size (in words): no of columns in state (fixed at 4 for AES)
95 95
     $Nk = count($key)/4;  // key length (in words): 4/6/8 for 128/192/256-bit keys
96 96
     $Nr = $Nk + 6;        // no of rounds: 10/12/14 for 128/192/256-bit keys
@@ -99,41 +99,41 @@  discard block
 block discarded – undo
99 99
     $temp = array();
100 100
 
101 101
     for ($i=0; $i<$Nk; $i++) {
102
-      $r = array($key[4*$i], $key[4*$i+1], $key[4*$i+2], $key[4*$i+3]);
103
-      $w[$i] = $r;
102
+        $r = array($key[4*$i], $key[4*$i+1], $key[4*$i+2], $key[4*$i+3]);
103
+        $w[$i] = $r;
104 104
     }
105 105
 
106 106
     for ($i=$Nk; $i<($Nb*($Nr+1)); $i++) {
107
-      $w[$i] = array();
108
-      for ($t=0; $t<4; $t++) $temp[$t] = $w[$i-1][$t];
109
-      if ($i % $Nk == 0) {
107
+        $w[$i] = array();
108
+        for ($t=0; $t<4; $t++) $temp[$t] = $w[$i-1][$t];
109
+        if ($i % $Nk == 0) {
110 110
         $temp = self::subWord(self::rotWord($temp));
111 111
         for ($t=0; $t<4; $t++) $temp[$t] ^= self::$rCon[$i/$Nk][$t];
112
-      } elseif ($Nk > 6 && $i%$Nk == 4) {
112
+        } elseif ($Nk > 6 && $i%$Nk == 4) {
113 113
         $temp = self::subWord($temp);
114
-      }
115
-      for ($t=0; $t<4; $t++) $w[$i][$t] = $w[$i-$Nk][$t] ^ $temp[$t];
114
+        }
115
+        for ($t=0; $t<4; $t++) $w[$i][$t] = $w[$i-$Nk][$t] ^ $temp[$t];
116 116
     }
117 117
 
118 118
     return $w;
119
-  }
119
+    }
120 120
 
121
-  private static function subWord($w) {    // apply SBox to 4-byte word w
121
+    private static function subWord($w) {    // apply SBox to 4-byte word w
122 122
     for ($i=0; $i<4; $i++) $w[$i] = self::$sBox[$w[$i]];
123 123
 
124 124
     return $w;
125
-  }
125
+    }
126 126
 
127
-  private static function rotWord($w) {    // rotate 4-byte word w left by one byte
127
+    private static function rotWord($w) {    // rotate 4-byte word w left by one byte
128 128
     $tmp = $w[0];
129 129
     for ($i=0; $i<3; $i++) $w[$i] = $w[$i+1];
130 130
     $w[3] = $tmp;
131 131
 
132 132
     return $w;
133
-  }
133
+    }
134 134
 
135
-  // sBox is pre-computed multiplicative inverse in GF(2^8) used in subBytes and keyExpansion [é5.1.1]
136
-  private static $sBox = array(
135
+    // sBox is pre-computed multiplicative inverse in GF(2^8) used in subBytes and keyExpansion [é5.1.1]
136
+    private static $sBox = array(
137 137
     0x63,0x7c,0x77,0x7b,0xf2,0x6b,0x6f,0xc5,0x30,0x01,0x67,0x2b,0xfe,0xd7,0xab,0x76,
138 138
     0xca,0x82,0xc9,0x7d,0xfa,0x59,0x47,0xf0,0xad,0xd4,0xa2,0xaf,0x9c,0xa4,0x72,0xc0,
139 139
     0xb7,0xfd,0x93,0x26,0x36,0x3f,0xf7,0xcc,0x34,0xa5,0xe5,0xf1,0x71,0xd8,0x31,0x15,
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
     0xe1,0xf8,0x98,0x11,0x69,0xd9,0x8e,0x94,0x9b,0x1e,0x87,0xe9,0xce,0x55,0x28,0xdf,
152 152
     0x8c,0xa1,0x89,0x0d,0xbf,0xe6,0x42,0x68,0x41,0x99,0x2d,0x0f,0xb0,0x54,0xbb,0x16);
153 153
 
154
-  // rCon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [é5.2]
155
-  private static $rCon = array(
154
+    // rCon is Round Constant used for the Key Expansion [1st col is 2^(r-1) in GF(2^8)] [é5.2]
155
+    private static $rCon = array(
156 156
     array(0x00, 0x00, 0x00, 0x00),
157 157
     array(0x01, 0x00, 0x00, 0x00),
158 158
     array(0x02, 0x00, 0x00, 0x00),
Please login to merge, or discard this patch.
Braces   +35 added lines, -11 removed lines patch added patch discarded remove patch
@@ -19,7 +19,9 @@  discard block
 block discarded – undo
19 19
     $Nr = count($w)/$Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys
20 20
 
21 21
     $state = array();  // initialise 4xNb byte-array 'state' with input [é3.4]
22
-    for ($i=0; $i<4*$Nb; $i++) $state[$i%4][floor($i/4)] = $input[$i];
22
+    for ($i=0; $i<4*$Nb; $i++) {
23
+        $state[$i%4][floor($i/4)] = $input[$i];
24
+    }
23 25
 
24 26
     $state = self::addRoundKey($state, $w, 0, $Nb);
25 27
 
@@ -35,14 +37,18 @@  discard block
 block discarded – undo
35 37
     $state = self::addRoundKey($state, $w, $Nr, $Nb);
36 38
 
37 39
     $output = array(4*$Nb);  // convert state to 1-d array before returning [é3.4]
38
-    for ($i=0; $i<4*$Nb; $i++) $output[$i] = $state[$i%4][floor($i/4)];
40
+    for ($i=0; $i<4*$Nb; $i++) {
41
+        $output[$i] = $state[$i%4][floor($i/4)];
42
+    }
39 43
 
40 44
     return $output;
41 45
   }
42 46
 
43 47
   private static function addRoundKey($state, $w, $rnd, $Nb) {  // xor Round Key into state S [é5.1.4]
44 48
     for ($r=0; $r<4; $r++) {
45
-      for ($c=0; $c<$Nb; $c++) $state[$r][$c] ^= $w[$rnd*4+$c][$r];
49
+      for ($c=0; $c<$Nb; $c++) {
50
+          $state[$r][$c] ^= $w[$rnd*4+$c][$r];
51
+      }
46 52
     }
47 53
 
48 54
     return $state;
@@ -50,7 +56,9 @@  discard block
 block discarded – undo
50 56
 
51 57
   private static function subBytes($s, $Nb) {    // apply SBox to state S [é5.1.1]
52 58
     for ($r=0; $r<4; $r++) {
53
-      for ($c=0; $c<$Nb; $c++) $s[$r][$c] = self::$sBox[$s[$r][$c]];
59
+      for ($c=0; $c<$Nb; $c++) {
60
+          $s[$r][$c] = self::$sBox[$s[$r][$c]];
61
+      }
54 62
     }
55 63
 
56 64
     return $s;
@@ -59,8 +67,14 @@  discard block
 block discarded – undo
59 67
   private static function shiftRows($s, $Nb) {    // shift row r of state S left by r bytes [é5.1.2]
60 68
     $t = array(4);
61 69
     for ($r=1; $r<4; $r++) {
62
-      for ($c=0; $c<4; $c++) $t[$c] = $s[$r][($c+$r)%$Nb];  // shift into temp copy
63
-      for ($c=0; $c<4; $c++) $s[$r][$c] = $t[$c];           // and copy back
70
+      for ($c=0; $c<4; $c++) {
71
+          $t[$c] = $s[$r][($c+$r)%$Nb];
72
+      }
73
+      // shift into temp copy
74
+      for ($c=0; $c<4; $c++) {
75
+          $s[$r][$c] = $t[$c];
76
+      }
77
+      // and copy back
64 78
     }          // note that this will work for Nb=4,5,6, but not 7,8 (always 4 for AES):
65 79
     return $s;  // see fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.311.pdf
66 80
   }
@@ -105,28 +119,38 @@  discard block
 block discarded – undo
105 119
 
106 120
     for ($i=$Nk; $i<($Nb*($Nr+1)); $i++) {
107 121
       $w[$i] = array();
108
-      for ($t=0; $t<4; $t++) $temp[$t] = $w[$i-1][$t];
122
+      for ($t=0; $t<4; $t++) {
123
+          $temp[$t] = $w[$i-1][$t];
124
+      }
109 125
       if ($i % $Nk == 0) {
110 126
         $temp = self::subWord(self::rotWord($temp));
111
-        for ($t=0; $t<4; $t++) $temp[$t] ^= self::$rCon[$i/$Nk][$t];
127
+        for ($t=0; $t<4; $t++) {
128
+            $temp[$t] ^= self::$rCon[$i/$Nk][$t];
129
+        }
112 130
       } elseif ($Nk > 6 && $i%$Nk == 4) {
113 131
         $temp = self::subWord($temp);
114 132
       }
115
-      for ($t=0; $t<4; $t++) $w[$i][$t] = $w[$i-$Nk][$t] ^ $temp[$t];
133
+      for ($t=0; $t<4; $t++) {
134
+          $w[$i][$t] = $w[$i-$Nk][$t] ^ $temp[$t];
135
+      }
116 136
     }
117 137
 
118 138
     return $w;
119 139
   }
120 140
 
121 141
   private static function subWord($w) {    // apply SBox to 4-byte word w
122
-    for ($i=0; $i<4; $i++) $w[$i] = self::$sBox[$w[$i]];
142
+    for ($i=0; $i<4; $i++) {
143
+        $w[$i] = self::$sBox[$w[$i]];
144
+    }
123 145
 
124 146
     return $w;
125 147
   }
126 148
 
127 149
   private static function rotWord($w) {    // rotate 4-byte word w left by one byte
128 150
     $tmp = $w[0];
129
-    for ($i=0; $i<3; $i++) $w[$i] = $w[$i+1];
151
+    for ($i=0; $i<3; $i++) {
152
+        $w[$i] = $w[$i+1];
153
+    }
130 154
     $w[3] = $tmp;
131 155
 
132 156
     return $w;
Please login to merge, or discard this patch.
install/js/crypt/aesctr.class.php 2 patches
Indentation   +51 added lines, -51 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          encrypted 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          encrypted 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)) return '';  // standard allows 128/192/256 bit keys
25 25
     // note PHP (5) gives us plaintext and password in UTF8 encoding!
@@ -53,22 +53,22 @@  discard block
 block discarded – undo
53 53
     $ciphertxt = array();  // ciphertext as array of strings
54 54
 
55 55
     for ($b=0; $b<$blockCount; $b++) {
56
-      // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
57
-      // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB)
58
-      for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff;
59
-      for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8);
56
+        // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
57
+        // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB)
58
+        for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff;
59
+        for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs($b/0x100000000, $c*8);
60 60
 
61
-      $cipherCntr = Aes::cipher($counterBlock, $keySchedule);  // -- encrypt counter block --
61
+        $cipherCntr = Aes::cipher($counterBlock, $keySchedule);  // -- encrypt counter block --
62 62
 
63
-      // block size is reduced on final block
64
-      $blockLength = $b<$blockCount-1 ? $blockSize : (strlen($plaintext)-1)%$blockSize+1;
65
-      $cipherByte = array();
63
+        // block size is reduced on final block
64
+        $blockLength = $b<$blockCount-1 ? $blockSize : (strlen($plaintext)-1)%$blockSize+1;
65
+        $cipherByte = array();
66 66
 
67
-      for ($i=0; $i<$blockLength; $i++) {  // -- xor plaintext with ciphered counter byte-by-byte --
67
+        for ($i=0; $i<$blockLength; $i++) {  // -- xor plaintext with ciphered counter byte-by-byte --
68 68
         $cipherByte[$i] = $cipherCntr[$i] ^ ord(substr($plaintext, $b*$blockSize+$i, 1));
69 69
         $cipherByte[$i] = chr($cipherByte[$i]);
70
-      }
71
-      $ciphertxt[$b] = implode('', $cipherByte);  // escape troublesome characters in ciphertext
70
+        }
71
+        $ciphertxt[$b] = implode('', $cipherByte);  // escape troublesome characters in ciphertext
72 72
     }
73 73
 
74 74
     // implode is more efficient than repeated string concatenation
@@ -76,18 +76,18 @@  discard block
 block discarded – undo
76 76
     $ciphertext = base64_encode($ciphertext);
77 77
 
78 78
     return $ciphertext;
79
-  }
79
+    }
80 80
 
81
-  /**
82
-   * Decrypt a text encrypted by AES in counter mode of operation
83
-   *
84
-   * @param ciphertext source text to be decrypted
85
-   * @param password   the password to use to generate a key
86
-   * @param nBits      number of bits to be used in the key (128, 192, or 256)
87
-   * @return           decrypted text
88
-   */
89
-  public static function decrypt($ciphertext, $password, $nBits)
90
-  {
81
+    /**
82
+     * Decrypt a text encrypted by AES in counter mode of operation
83
+     *
84
+     * @param ciphertext source text to be decrypted
85
+     * @param password   the password to use to generate a key
86
+     * @param nBits      number of bits to be used in the key (128, 192, or 256)
87
+     * @return           decrypted text
88
+     */
89
+    public static function decrypt($ciphertext, $password, $nBits)
90
+    {
91 91
     $blockSize = 16;  // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
92 92
     if (!($nBits==128 || $nBits==192 || $nBits==256)) return '';  // standard allows 128/192/256 bit keys
93 93
     $ciphertext = base64_decode($ciphertext);
@@ -117,47 +117,47 @@  discard block
 block discarded – undo
117 117
     $plaintxt = array();
118 118
 
119 119
     for ($b=0; $b<$nBlocks; $b++) {
120
-      // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
121
-      for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff;
122
-      for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff;
120
+        // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
121
+        for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff;
122
+        for ($c=0; $c<4; $c++) $counterBlock[15-$c-4] = self::urs(($b+1)/0x100000000-1, $c*8) & 0xff;
123 123
 
124
-      $cipherCntr = Aes::cipher($counterBlock, $keySchedule);  // encrypt counter block
124
+        $cipherCntr = Aes::cipher($counterBlock, $keySchedule);  // encrypt counter block
125 125
 
126
-      $plaintxtByte = array();
127
-      for ($i=0; $i<strlen($ciphertext[$b]); $i++) {
126
+        $plaintxtByte = array();
127
+        for ($i=0; $i<strlen($ciphertext[$b]); $i++) {
128 128
         // -- xor plaintext with ciphered counter byte-by-byte --
129 129
         $plaintxtByte[$i] = $cipherCntr[$i] ^ ord(substr($ciphertext[$b],$i,1));
130 130
         $plaintxtByte[$i] = chr($plaintxtByte[$i]);
131 131
 
132
-      }
133
-      $plaintxt[$b] = implode('', $plaintxtByte);
132
+        }
133
+        $plaintxt[$b] = implode('', $plaintxtByte);
134 134
     }
135 135
 
136 136
     // join array of blocks into single plaintext string
137 137
     $plaintext = implode('',$plaintxt);
138 138
 
139 139
     return $plaintext;
140
-  }
140
+    }
141 141
 
142
-  /*
142
+    /*
143 143
    * Unsigned right shift function, since PHP has neither >>> operator nor unsigned ints
144 144
    *
145 145
    * @param a  number to be shifted (32-bit integer)
146 146
    * @param b  number of bits to shift a to the right (0..31)
147 147
    * @return   a right-shifted and zero-filled by b bits
148 148
    */
149
-  private static function urs($a, $b)
150
-  {
149
+    private static function urs($a, $b)
150
+    {
151 151
     $a &= 0xffffffff; $b &= 0x1f;  // (bounds check)
152 152
     if ($a&0x80000000 && $b>0) {   // if left-most bit set
153
-      $a = ($a>>1) & 0x7fffffff;   //   right-shift one bit & clear left-most bit
154
-      $a = $a >> ($b-1);           //   remaining right-shifts
153
+        $a = ($a>>1) & 0x7fffffff;   //   right-shift one bit & clear left-most bit
154
+        $a = $a >> ($b-1);           //   remaining right-shifts
155 155
     } else {                       // otherwise
156
-      $a = ($a>>$b);               //   use normal right-shift
156
+        $a = ($a>>$b);               //   use normal right-shift
157 157
     }
158 158
 
159 159
     return $a;
160
-  }
160
+    }
161 161
 
162 162
 }
163 163
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */
Please login to merge, or discard this patch.
Braces   +41 added lines, -13 removed lines patch added patch discarded remove patch
@@ -21,14 +21,19 @@  discard block
 block discarded – undo
21 21
   public static function encrypt($plaintext, $password, $nBits)
22 22
   {
23 23
     $blockSize = 16;  // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
24
-    if (!($nBits==128 || $nBits==192 || $nBits==256)) return '';  // standard allows 128/192/256 bit keys
24
+    if (!($nBits==128 || $nBits==192 || $nBits==256)) {
25
+        return '';
26
+    }
27
+    // standard allows 128/192/256 bit keys
25 28
     // note PHP (5) gives us plaintext and password in UTF8 encoding!
26 29
 
27 30
     // use AES itself to encrypt password to get cipher key (using plain password as source for
28 31
     // key expansion) - gives us well encrypted key
29 32
     $nBytes = $nBits/8;  // no bytes in key
30 33
     $pwBytes = array();
31
-    for ($i=0; $i<$nBytes; $i++) $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
+    }
32 37
     $key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes));
33 38
     $key = array_merge($key, array_slice($key, 0, $nBytes-16));  // expand key to 16/24/32 bytes long
34 39
 
@@ -39,11 +44,17 @@  discard block
 block discarded – undo
39 44
     $nonceSec = floor($nonce/1000);
40 45
     $nonceMs = $nonce%1000;
41 46
     // encode nonce with seconds in 1st 4 bytes, and (repeated) ms part filling 2nd 4 bytes
42
-    for ($i=0; $i<4; $i++) $counterBlock[$i] = self::urs($nonceSec, $i*8) & 0xff;
43
-    for ($i=0; $i<4; $i++) $counterBlock[$i+4] = $nonceMs & 0xff;
47
+    for ($i=0; $i<4; $i++) {
48
+        $counterBlock[$i] = self::urs($nonceSec, $i*8) & 0xff;
49
+    }
50
+    for ($i=0; $i<4; $i++) {
51
+        $counterBlock[$i+4] = $nonceMs & 0xff;
52
+    }
44 53
     // and convert it to a string to go on the front of the ciphertext
45 54
     $ctrTxt = '';
46
-    for ($i=0; $i<8; $i++) $ctrTxt .= chr($counterBlock[$i]);
55
+    for ($i=0; $i<8; $i++) {
56
+        $ctrTxt .= chr($counterBlock[$i]);
57
+    }
47 58
 
48 59
     // generate key schedule - an expansion of the key into distinct Key Rounds for each round
49 60
     $keySchedule = Aes::keyExpansion($key);
@@ -55,8 +66,12 @@  discard block
 block discarded – undo
55 66
     for ($b=0; $b<$blockCount; $b++) {
56 67
       // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
57 68
       // done in two stages for 32-bit ops: using two words allows us to go past 2^32 blocks (68GB)
58
-      for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff;
59
-      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
+      }
60 75
 
61 76
       $cipherCntr = Aes::cipher($counterBlock, $keySchedule);  // -- encrypt counter block --
62 77
 
@@ -89,20 +104,27 @@  discard block
 block discarded – undo
89 104
   public static function decrypt($ciphertext, $password, $nBits)
90 105
   {
91 106
     $blockSize = 16;  // block size fixed at 16 bytes / 128 bits (Nb=4) for AES
92
-    if (!($nBits==128 || $nBits==192 || $nBits==256)) return '';  // standard allows 128/192/256 bit keys
107
+    if (!($nBits==128 || $nBits==192 || $nBits==256)) {
108
+        return '';
109
+    }
110
+    // standard allows 128/192/256 bit keys
93 111
     $ciphertext = base64_decode($ciphertext);
94 112
 
95 113
     // use AES to encrypt password (mirroring encrypt routine)
96 114
     $nBytes = $nBits/8;  // no bytes in key
97 115
     $pwBytes = array();
98
-    for ($i=0; $i<$nBytes; $i++) $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff;
116
+    for ($i=0; $i<$nBytes; $i++) {
117
+        $pwBytes[$i] = ord(substr($password,$i,1)) & 0xff;
118
+    }
99 119
     $key = Aes::cipher($pwBytes, Aes::keyExpansion($pwBytes));
100 120
     $key = array_merge($key, array_slice($key, 0, $nBytes-16));  // expand key to 16/24/32 bytes long
101 121
 
102 122
     // recover nonce from 1st element of ciphertext
103 123
     $counterBlock = array();
104 124
     $ctrTxt = substr($ciphertext, 0, 8);
105
-    for ($i=0; $i<8; $i++) $counterBlock[$i] = ord(substr($ctrTxt,$i,1));
125
+    for ($i=0; $i<8; $i++) {
126
+        $counterBlock[$i] = ord(substr($ctrTxt,$i,1));
127
+    }
106 128
 
107 129
     // generate key schedule
108 130
     $keySchedule = Aes::keyExpansion($key);
@@ -110,7 +132,9 @@  discard block
 block discarded – undo
110 132
     // separate ciphertext into blocks (skipping past initial 8 bytes)
111 133
     $nBlocks = ceil((strlen($ciphertext)-8) / $blockSize);
112 134
     $ct = array();
113
-    for ($b=0; $b<$nBlocks; $b++) $ct[$b] = substr($ciphertext, 8+$b*$blockSize, 16);
135
+    for ($b=0; $b<$nBlocks; $b++) {
136
+        $ct[$b] = substr($ciphertext, 8+$b*$blockSize, 16);
137
+    }
114 138
     $ciphertext = $ct;  // ciphertext is now array of block-length strings
115 139
 
116 140
     // plaintext will get generated block-by-block into array of block-length strings
@@ -118,8 +142,12 @@  discard block
 block discarded – undo
118 142
 
119 143
     for ($b=0; $b<$nBlocks; $b++) {
120 144
       // set counter (block #) in last 8 bytes of counter block (leaving nonce in 1st 8 bytes)
121
-      for ($c=0; $c<4; $c++) $counterBlock[15-$c] = self::urs($b, $c*8) & 0xff;
122
-      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
+      }
123 151
 
124 152
       $cipherCntr = Aes::cipher($counterBlock, $keySchedule);  // encrypt counter block
125 153
 
Please login to merge, or discard this patch.
install/install.queries.php 1 patch
Braces   +15 added lines, -10 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
         }
@@ -40,8 +42,9 @@  discard block
 block discarded – undo
40 42
         }
41 43
     }
42 44
     closedir($dp);
43
-    if (is_dir($dir) && $res)
44
-        $res = @chmod($dir, $dirPermissions);
45
+    if (is_dir($dir) && $res) {
46
+            $res = @chmod($dir, $dirPermissions);
47
+    }
45 48
 
46 49
     return $res;
47 50
 }
@@ -995,10 +998,12 @@  discard block
 block discarded – undo
995 998
                     if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
996 999
                         // Change directory permissions
997 1000
                         $result = chmod_r($_SESSION['abspath'], 0770, 0740);
998
-                        if ($result )
999
-                            $result = chmod_r($_SESSION['abspath'].'/files', 0770, 0770);
1000
-                        if  ($result)
1001
-                            $result = chmod_r($_SESSION['abspath'].'/upload', 0770, 0770);
1001
+                        if ($result ) {
1002
+                                                    $result = chmod_r($_SESSION['abspath'].'/files', 0770, 0770);
1003
+                        }
1004
+                        if  ($result) {
1005
+                                                    $result = chmod_r($_SESSION['abspath'].'/upload', 0770, 0770);
1006
+                        }
1002 1007
                     }
1003 1008
 
1004 1009
                     if ($result === false) {
Please login to merge, or discard this patch.
install/upgrade_run_db_original.php 1 patch
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -89,9 +89,12 @@
 block discarded – undo
89 89
         AND table_name = '$tablename'"
90 90
     );
91 91
 
92
-    if ($res > 0) return true;
93
-    else return false;
94
-}
92
+    if ($res > 0) {
93
+        return true;
94
+    } else {
95
+        return false;
96
+    }
97
+    }
95 98
 
96 99
 //define pbkdf2 iteration count
97 100
 @define('ITCOUNT', '2072');
Please login to merge, or discard this patch.
install/upgrade_run_2.1.26.php 1 patch
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -103,9 +103,12 @@
 block discarded – undo
103 103
         AND table_name = '$tablename'"
104 104
     );
105 105
 
106
-    if ($res > 0) return true;
107
-    else return false;
108
-}
106
+    if ($res > 0) {
107
+        return true;
108
+    } else {
109
+        return false;
110
+    }
111
+    }
109 112
 
110 113
 //define pbkdf2 iteration count
111 114
 @define('ITCOUNT', '2072');
Please login to merge, or discard this patch.
install/upgrade_run_final.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -101,8 +101,12 @@
 block discarded – undo
101 101
         }
102 102
 
103 103
         // temp data
104
-        if (!isset($record['login'])) $record['login'] = "";
105
-        if (!isset($resNT['renewal_period'])) $resNT['renewal_period'] = "0";
104
+        if (!isset($record['login'])) {
105
+            $record['login'] = "";
106
+        }
107
+        if (!isset($resNT['renewal_period'])) {
108
+            $resNT['renewal_period'] = "0";
109
+        }
106 110
 
107 111
         // store data
108 112
         $res = mysqli_query($dbTmp,
Please login to merge, or discard this patch.
install/upgrade_run_2.1.27.php 1 patch
Braces   +18 added lines, -7 removed lines patch added patch discarded remove patch
@@ -83,16 +83,27 @@
 block discarded – undo
83 83
         AND table_name = '$tablename'"
84 84
     );
85 85
 
86
-    if ($res > 0) return true;
87
-    else return false;
88
-}
86
+    if ($res > 0) {
87
+        return true;
88
+    } else {
89
+        return false;
90
+    }
91
+    }
89 92
 
90 93
 function cleanFields($txt) {
91 94
     $tmp = str_replace(",", ";", trim($txt));
92
-    if (empty($tmp)) return $tmp;
93
-    if ($tmp === ";") return "";
94
-    if (strpos($tmp, ';') === 0) $tmp = substr($tmp, 1);
95
-    if (substr($tmp, -1) !== ";") $tmp = $tmp.";";
95
+    if (empty($tmp)) {
96
+        return $tmp;
97
+    }
98
+    if ($tmp === ";") {
99
+        return "";
100
+    }
101
+    if (strpos($tmp, ';') === 0) {
102
+        $tmp = substr($tmp, 1);
103
+    }
104
+    if (substr($tmp, -1) !== ";") {
105
+        $tmp = $tmp.";";
106
+    }
96 107
     return $tmp;
97 108
 }
98 109
 
Please login to merge, or discard this patch.