Completed
Push — development ( 362b6c...477849 )
by Nils
08:04
created
includes/libraries/Authentication/phpseclib/Crypt/RSA/PKCS.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,6 @@
 block discarded – undo
19 19
 use ParagonIE\ConstantTime\Hex;
20 20
 use phpseclib\Crypt\Common\BlockCipher;
21 21
 use phpseclib\Crypt\AES;
22
-use phpseclib\Crypt\Base;
23 22
 use phpseclib\Crypt\DES;
24 23
 use phpseclib\Crypt\TripleDES;
25 24
 use phpseclib\Math\BigInteger;
Please login to merge, or discard this patch.
includes/libraries/Authentication/phpseclib/Crypt/RSA/PKCS1.php 2 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -26,10 +26,8 @@
 block discarded – undo
26 26
 
27 27
 use ParagonIE\ConstantTime\Base64;
28 28
 use ParagonIE\ConstantTime\Hex;
29
-use phpseclib\Crypt\AES;
30 29
 use phpseclib\Crypt\DES;
31 30
 use phpseclib\Crypt\Random;
32
-use phpseclib\Crypt\TripleDES;
33 31
 use phpseclib\Math\BigInteger;
34 32
 use phpseclib\Common\Functions\ASN1;
35 33
 
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -123,15 +123,15 @@
 block discarded – undo
123 123
             $cipher->setIV($iv);
124 124
             $iv = strtoupper(Hex::encode($iv));
125 125
             $RSAPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n" .
126
-                     "Proc-Type: 4,ENCRYPTED\r\n" .
127
-                     "DEK-Info: " . self::$defaultEncryptionAlgorithm . ",$iv\r\n" .
128
-                     "\r\n" .
129
-                     chunk_split(Base64::encode($cipher->encrypt($RSAPrivateKey)), 64) .
130
-                     '-----END RSA PRIVATE KEY-----';
126
+                        "Proc-Type: 4,ENCRYPTED\r\n" .
127
+                        "DEK-Info: " . self::$defaultEncryptionAlgorithm . ",$iv\r\n" .
128
+                        "\r\n" .
129
+                        chunk_split(Base64::encode($cipher->encrypt($RSAPrivateKey)), 64) .
130
+                        '-----END RSA PRIVATE KEY-----';
131 131
         } else {
132 132
             $RSAPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n" .
133
-                     chunk_split(Base64::encode($RSAPrivateKey), 64) .
134
-                     '-----END RSA PRIVATE KEY-----';
133
+                        chunk_split(Base64::encode($RSAPrivateKey), 64) .
134
+                        '-----END RSA PRIVATE KEY-----';
135 135
         }
136 136
 
137 137
         return $RSAPrivateKey;
Please login to merge, or discard this patch.
includes/libraries/Authentication/phpseclib/Net/SSH1.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,6 @@
 block discarded – undo
48 48
 
49 49
 namespace phpseclib\Net;
50 50
 
51
-use ParagonIE\ConstantTime\Hex;
52 51
 use phpseclib\Crypt\DES;
53 52
 use phpseclib\Crypt\Random;
54 53
 use phpseclib\Crypt\TripleDES;
Please login to merge, or discard this patch.
sources/items.queries.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -79,7 +79,6 @@
 block discarded – undo
79 79
 // phpcrypt
80 80
 require_once $_SESSION['settings']['cpassman_dir'] . '/includes/libraries/phpcrypt/phpCrypt.php';
81 81
 use PHP_Crypt\PHP_Crypt as PHP_Crypt;
82
-use PHP_Crypt\Cipher as Cipher;
83 82
 
84 83
 // prepare Encryption class calls
85 84
 use \Defuse\Crypto\Crypto;
Please login to merge, or discard this patch.
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     70 => array(70, $LANG['complex_level4']),
51 51
     80 => array(80, $LANG['complex_level5']),
52 52
     90 => array(90, $LANG['complex_level6'])
53
-   );
53
+    );
54 54
 
55 55
 //Class loader
56 56
 require_once $_SESSION['settings']['cpassman_dir'].'/sources/SplClassLoader.php';
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
                         'perso' => ($dataReceived['salt_key_set'] == 1 && isset($dataReceived['salt_key_set']) && $dataReceived['is_pf'] == 1 && isset($dataReceived['is_pf'])) ? '1' : '0',
208 208
                         'anyone_can_modify' => (isset($dataReceived['anyone_can_modify']) && $dataReceived['anyone_can_modify'] == "on") ? '1' : '0',
209 209
                         'complexity_level' => $dataReceived['complexity_level']
210
-                       )
210
+                        )
211 211
                 );
212 212
                 $newID = DB::insertId();
213 213
                 $pw = $passwd['string'];
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
                             'del_enabled' => 1, // 0=deactivated;1=activated
260 260
                             'del_type' => $date_stamp != false ? 2 : 1, // 1=counter;2=date
261 261
                             'del_value' => $date_stamp != false ? $date_stamp : $dataReceived['to_be_deleted']
262
-                           )
262
+                            )
263 263
                     );
264 264
                 }
265 265
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
                             array(
272 272
                                 'role_id' => $role,
273 273
                                 'item_id' => $newID
274
-                               )
274
+                                )
275 275
                         );
276 276
                     }
277 277
                 }
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
                             array(
287 287
                                 'item_id' => $newID,
288 288
                                 'tag' => strtolower($tag)
289
-                               )
289
+                                )
290 290
                         );
291 291
                     }
292 292
                 }
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
                             prefix_table('files'),
303 303
                             array(
304 304
                                 'id_item' => $newID
305
-                               ),
305
+                                ),
306 306
                             "id=%i", $record['id']
307 307
                         );
308 308
                     }
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
                     "new_entry" => $html,
391 391
                     "array_items" => $itemsIDList,
392 392
                     "show_clipboard_small_icons" => (isset($_SESSION['settings']['copy_to_clipboard_small_icons']) && $_SESSION['settings']['copy_to_clipboard_small_icons'] == 1) ? 1 : 0
393
-                   );
393
+                    );
394 394
             } elseif (isset($_SESSION['settings']['duplicate_item']) && $_SESSION['settings']['duplicate_item'] == 0 && $itemExists == 1) {
395 395
                 $returnValues = array("error" => "item_exists");
396 396
             }
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
                     )
476 476
                     ||
477 477
                     (@in_array($_POST['id'], $_SESSION['list_folders_limited'][$_POST['folder_id']]))
478
-                 ) {
478
+                    ) {
479 479
 
480 480
                     // is pwd empty?
481 481
                     if (empty($pw) && isset($_SESSION['user_settings']['create_item_without_password']) && $_SESSION['user_settings']['create_item_without_password'] !== "1") {
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
                             'restricted_to' => $dataReceived['restricted_to'],
564 564
                             'anyone_can_modify' => (isset($dataReceived['anyone_can_modify']) && $dataReceived['anyone_can_modify'] == "on") ? '1' : '0',
565 565
                             'complexity_level' => $dataReceived['complexity_level']
566
-                           ),
566
+                            ),
567 567
                         "id=%i",
568 568
                         $dataReceived['id']
569 569
                     );
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
                                         'del_enabled' => 1,
689 689
                                         'del_type' => is_numeric($dataReceived['to_be_deleted']) ? 1 : 2,
690 690
                                         'del_value' => is_numeric($dataReceived['to_be_deleted']) ? $dataReceived['to_be_deleted'] : dateToStamp($dataReceived['to_be_deleted'])
691
-                                       )
691
+                                        )
692 692
                                 );
693 693
                                 // update LOG
694 694
                                 logItems($dataReceived['id'], $label, $_SESSION['user_id'], 'at_modification', $_SESSION['login'], 'at_automatic_del : '.$dataReceived['to_be_deleted']);
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
                                     array(
703 703
                                         'del_type' => is_numeric($dataReceived['to_be_deleted']) ? 1 : 2,
704 704
                                         'del_value' => is_numeric($dataReceived['to_be_deleted']) ? $dataReceived['to_be_deleted'] : dateToStamp($dataReceived['to_be_deleted'])
705
-                                       ),
705
+                                        ),
706 706
                                     "item_id = %i",
707 707
                                     $dataReceived['id']
708 708
                                 );
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
                                 array(
773 773
                                     'role_id' => $role,
774 774
                                     'item_id' => $dataReceived['id']
775
-                                   )
775
+                                    )
776 776
                             );
777 777
                             $dataTmp = DB::queryfirstrow("SELECT title FROM ".prefix_table("roles_title")." WHERE id= ".$role);
778 778
                             if (empty($listOfRestricted)) {
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
                                     ),
955 955
                                 'receivers' => $mailing,
956 956
                                 'status' => ''
957
-                               )
957
+                                )
958 958
                         );
959 959
                     }
960 960
 
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
                         "list_of_restricted" => $listOfRestricted,
971 971
                         "tags" => $return_tags,
972 972
                         "error" => ""
973
-                       );
973
+                        );
974 974
                 } else {
975 975
                     echo prepareExchangedData(array("error" => "ERR_NOT_ALLOWED_TO_EDIT"), "encode");
976 976
                     break;
@@ -1157,7 +1157,7 @@  discard block
 block discarded – undo
1157 1157
                             'extension' => $record['extension'],
1158 1158
                             'type' => $record['type'],
1159 1159
                             'file' => $record['file']
1160
-                           )
1160
+                            )
1161 1161
                     );
1162 1162
                 }
1163 1163
 
@@ -1169,7 +1169,7 @@  discard block
 block discarded – undo
1169 1169
                         array(
1170 1170
                             'item_id' => $newID,
1171 1171
                             'role_id' => $record['role_id']
1172
-                           )
1172
+                            )
1173 1173
                     );
1174 1174
                 }
1175 1175
 
@@ -1181,7 +1181,7 @@  discard block
 block discarded – undo
1181 1181
                         array(
1182 1182
                             'item_id' => $newID,
1183 1183
                             'tag' => $record['tag']
1184
-                           )
1184
+                            )
1185 1185
                     );
1186 1186
                 }
1187 1187
 
@@ -1548,14 +1548,14 @@  discard block
 block discarded – undo
1548 1548
                                 $pre."automatic_del",
1549 1549
                                 array(
1550 1550
                                     'del_value' => $dataDelete['del_value'] - 1
1551
-                                   ),
1551
+                                    ),
1552 1552
                                 "item_id = %i",
1553 1553
                                 $_POST['id']
1554 1554
                             );
1555 1555
                             // store value
1556 1556
                             $arrData['to_be_deleted'] = $dataDelete['del_value'] - 1;
1557 1557
                         } elseif ($dataDelete['del_type'] == 1 && $dataDelete['del_value'] <= 1 || $dataDelete['del_type'] == 2 && $dataDelete['del_value'] < time()
1558
-                               )
1558
+                                )
1559 1559
                         {
1560 1560
                             $arrData['show_details'] = 0;
1561 1561
                             // delete item
@@ -1565,7 +1565,7 @@  discard block
 block discarded – undo
1565 1565
                                 prefix_table("items"),
1566 1566
                                 array(
1567 1567
                                     'inactif' => '1',
1568
-                                   ),
1568
+                                    ),
1569 1569
                                 "id = %i",
1570 1570
                                 $_POST['id']
1571 1571
                             );
@@ -1595,7 +1595,7 @@  discard block
 block discarded – undo
1595 1595
                                 'body' => str_replace(array('#tp_item_author#', '#tp_user#', '#tp_item#'), array(" ".addslashes($arrData['author']), addslashes($_SESSION['login']), addslashes($dataItem['label'])), $LANG['email_on_open_notification_mail']),
1596 1596
                                 'receivers' => $listNotificationEmails,
1597 1597
                                 'status' => ''
1598
-                               )
1598
+                                )
1599 1599
                         );
1600 1600
                     //}
1601 1601
                 } else {
@@ -1744,7 +1744,7 @@  discard block
 block discarded – undo
1744 1744
                     prefix_table("users"),
1745 1745
                     array(
1746 1746
                         'latest_items' => implode(';', $_SESSION['latest_items'])
1747
-                       ),
1747
+                        ),
1748 1748
                     "id=".$_SESSION['user_id']
1749 1749
                 );
1750 1750
             }
@@ -1788,7 +1788,7 @@  discard block
 block discarded – undo
1788 1788
                 prefix_table("items"),
1789 1789
                 array(
1790 1790
                     'inactif' => '1',
1791
-                   ),
1791
+                    ),
1792 1792
                 "id = %i",
1793 1793
                 $_POST['id']
1794 1794
             );
@@ -1869,7 +1869,7 @@  discard block
 block discarded – undo
1869 1869
                     prefix_table("nested_tree"),
1870 1870
                     array(
1871 1871
                         'title' => $title
1872
-                       ),
1872
+                        ),
1873 1873
                     'id=%s',
1874 1874
                     $dataReceived['folder']
1875 1875
                 );
@@ -1878,7 +1878,7 @@  discard block
 block discarded – undo
1878 1878
                     prefix_table("misc"),
1879 1879
                     array(
1880 1880
                         'valeur' => $dataReceived['complexity']
1881
-                       ),
1881
+                        ),
1882 1882
                     'intitule = %s AND type = %s',
1883 1883
                     $dataReceived['folder'],
1884 1884
                     "complex"
@@ -1949,7 +1949,7 @@  discard block
 block discarded – undo
1949 1949
                     prefix_table("nested_tree"),
1950 1950
                     array(
1951 1951
                         'parent_id' => $dataReceived['target_folder_id']
1952
-                       ),
1952
+                        ),
1953 1953
                     'id=%s',
1954 1954
                     $dataReceived['source_folder_id']
1955 1955
                 );
@@ -1970,7 +1970,7 @@  discard block
 block discarded – undo
1970 1970
                 prefix_table("nested_tree"),
1971 1971
                 array(
1972 1972
                     'parent_id' => $_POST['destination']
1973
-                   ),
1973
+                    ),
1974 1974
                 'id = %i',
1975 1975
                 $_POST['source']
1976 1976
             );
@@ -2586,7 +2586,7 @@  discard block
 block discarded – undo
2586 2586
                         $_SESSION['is_admin'] == 1
2587 2587
                         || ($_SESSION['user_manager'] == 1)
2588 2588
                         || (
2589
-                           isset($_SESSION['settings']['enable_user_can_create_folders'])
2589
+                            isset($_SESSION['settings']['enable_user_can_create_folders'])
2590 2590
                            && $_SESSION['settings']['enable_user_can_create_folders'] == 1
2591 2591
                         )
2592 2592
                         || (
@@ -2762,7 +2762,7 @@  discard block
 block discarded – undo
2762 2762
                     prefix_table("users"),
2763 2763
                     array(
2764 2764
                         'favourites' => implode(';', $_SESSION['favourites'])
2765
-                       ),
2765
+                        ),
2766 2766
                     'id = %i',
2767 2767
                     $_SESSION['user_id']
2768 2768
                 );
@@ -2771,7 +2771,7 @@  discard block
 block discarded – undo
2771 2771
                 $_SESSION['favourites_tab'][$_POST['id']] = array(
2772 2772
                     'label' => $data['label'],
2773 2773
                     'url' => 'index.php?page=items&amp;group='.$data['id_tree'].'&amp;id='.$_POST['id']
2774
-                   );
2774
+                    );
2775 2775
             } elseif ($_POST['action'] == 0) {
2776 2776
                 // delete from session
2777 2777
                 foreach ($_SESSION['favourites'] as $key => $value) {
@@ -2832,7 +2832,7 @@  discard block
 block discarded – undo
2832 2832
                     prefix_table("items"),
2833 2833
                     array(
2834 2834
                         'id_tree' => $_POST['folder_id']
2835
-                       ),
2835
+                        ),
2836 2836
                     "id=%i",
2837 2837
                     $_POST['item_id']
2838 2838
                 );
@@ -2939,7 +2939,7 @@  discard block
 block discarded – undo
2939 2939
                             prefix_table("items"),
2940 2940
                             array(
2941 2941
                                 'id_tree' => $_POST['folder_id']
2942
-                               ),
2942
+                                ),
2943 2943
                             "id=%i",
2944 2944
                             $item_id
2945 2945
                         );
@@ -3051,7 +3051,7 @@  discard block
 block discarded – undo
3051 3051
                         prefix_table("items"),
3052 3052
                         array(
3053 3053
                             'inactif' => '1',
3054
-                           ),
3054
+                            ),
3055 3055
                         "id = %i",
3056 3056
                         $item_id
3057 3057
                     );
@@ -3132,7 +3132,7 @@  discard block
 block discarded – undo
3132 3132
                             prefix_table("items"),
3133 3133
                             array(
3134 3134
                                 'notification' => empty($data['notification']) ? $_POST['user_id'].";" : $data['notification'].$_POST['user_id']
3135
-                               ),
3135
+                                ),
3136 3136
                             "id=%i",
3137 3137
                             $_POST['item_id']
3138 3138
                         );
@@ -3145,7 +3145,7 @@  discard block
 block discarded – undo
3145 3145
                             prefix_table("items"),
3146 3146
                             array(
3147 3147
                                 'notification' => empty($data['notification']) ? $_POST['user_id'] : $data['notification'].";".$_POST['user_id']
3148
-                               ),
3148
+                                ),
3149 3149
                             "id=%i",
3150 3150
                             $_POST['item_id']
3151 3151
                         );
@@ -3280,7 +3280,7 @@  discard block
 block discarded – undo
3280 3280
                     'timestamp' => time(),
3281 3281
                     'originator' => intval($_SESSION['user_id']),
3282 3282
                     'code' => $otv_code
3283
-                   )
3283
+                    )
3284 3284
             );
3285 3285
             $newID = DB::insertId();
3286 3286
 
Please login to merge, or discard this patch.
sources/main.functions.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,6 @@
 block discarded – undo
25 25
     require_once $_SESSION['settings']['cpassman_dir'] . '/includes/config/settings.php';
26 26
 }
27 27
 use PHP_Crypt\PHP_Crypt as PHP_Crypt;
28
-use PHP_Crypt\Cipher as Cipher;
29 28
 
30 29
 
31 30
 // prepare Encryption class calls
Please login to merge, or discard this patch.
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
     }
160 160
 
161 161
     if (!empty($personalSalt)) {
162
-         $staticSalt = $personalSalt;
162
+            $staticSalt = $personalSalt;
163 163
     } else {
164
-         $staticSalt = SALT;
164
+            $staticSalt = SALT;
165 165
     }
166 166
 
167 167
     //set our salt to a variable
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
                     'author' => $record['id_user'],
899 899
                     'renewal_period' => isset($resNT['renewal_period']) ? $resNT['renewal_period'] : "0",
900 900
                     'timestamp' => $record['date']
901
-                   )
901
+                    )
902 902
             );
903 903
         }
904 904
         // UPDATE an item
@@ -943,7 +943,7 @@  discard block
 block discarded – undo
943 943
                 'login' => isset($data['login']) ? $data['login'] : "",
944 944
                 'folder' => $folder,
945 945
                 'author' => $_SESSION['user_id'],
946
-               ),
946
+                ),
947 947
             "id = %i",
948 948
             $id
949 949
         );
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
                 'folder' => $folder,
997 997
                 'author' => $_SESSION['user_id'],
998 998
                 'timestamp' => $data['date']
999
-               )
999
+                )
1000 1000
         );
1001 1001
         // DELETE an item
1002 1002
     } elseif ($action === "delete_value") {
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
 *
1009 1009
 */
1010 1010
 function getStatisticsData() {
1011
-     DB::query(
1011
+        DB::query(
1012 1012
         "SELECT id FROM ".prefix_table("nested_tree")." WHERE personal_folder = %i",
1013 1013
         0
1014 1014
     );
@@ -1582,7 +1582,7 @@  discard block
 block discarded – undo
1582 1582
 
1583 1583
     $cf_diff = array_diff($source_cf, $target_cf);
1584 1584
     if (count($cf_diff) > 0) {
1585
-       return false;
1585
+        return false;
1586 1586
     }
1587 1587
 
1588 1588
     return true;
@@ -1645,7 +1645,7 @@  discard block
 block discarded – undo
1645 1645
                 prefix_table('files'),
1646 1646
                 array(
1647 1647
                     'status' => 'encrypted'
1648
-                   ),
1648
+                    ),
1649 1649
                 "id=%i",
1650 1650
                 substr($_POST['uri'], 1)
1651 1651
             );
@@ -1688,7 +1688,7 @@  discard block
 block discarded – undo
1688 1688
                 prefix_table('files'),
1689 1689
                 array(
1690 1690
                     'status' => 'clear'
1691
-                   ),
1691
+                    ),
1692 1692
                 "id=%i",
1693 1693
                 substr($_POST['uri'], 1)
1694 1694
             );
Please login to merge, or discard this patch.
profile.php 1 patch
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.
install/upgrade_ajax.php 1 patch
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.
install/js/crypt/aes.class.php 1 patch
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.
install/js/crypt/aesctr.class.php 1 patch
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.