]> granicus.if.org Git - php/commitdiff
ext/sodium: untab tests
authorFrank Denis <github@pureftpd.org>
Mon, 2 Oct 2017 20:28:46 +0000 (22:28 +0200)
committerFrank Denis <github@pureftpd.org>
Mon, 2 Oct 2017 20:28:46 +0000 (22:28 +0200)
14 files changed:
ext/sodium/tests/crypto_aead.phpt
ext/sodium/tests/crypto_auth.phpt
ext/sodium/tests/crypto_box.phpt
ext/sodium/tests/crypto_generichash.phpt
ext/sodium/tests/crypto_scalarmult.phpt
ext/sodium/tests/crypto_secretbox.phpt
ext/sodium/tests/crypto_shorthash.phpt
ext/sodium/tests/crypto_sign.phpt
ext/sodium/tests/crypto_stream.phpt
ext/sodium/tests/exception_trace_without_args.phpt
ext/sodium/tests/inc_add.phpt
ext/sodium/tests/installed.phpt
ext/sodium/tests/pwhash_argon2i.phpt
ext/sodium/tests/utils.phpt

index 059eefbde845be4f07a6f9630775fb0b17cbafab..a54a1c7dc67582d654ff8c9e825952c231e2b3e1 100644 (file)
@@ -20,95 +20,95 @@ var_dump($ciphertext !== $msg);
 var_dump($msg === $msg2);
 var_dump(sodium_crypto_aead_chacha20poly1305_decrypt($ciphertext, 'x' . $ad, $nonce, $key));
 try {
-       // Switched order
-       $msg2 = sodium_crypto_aead_chacha20poly1305_decrypt($ciphertext, $ad, $key, $nonce);
-       var_dump(false);
+    // Switched order
+    $msg2 = sodium_crypto_aead_chacha20poly1305_decrypt($ciphertext, $ad, $key, $nonce);
+    var_dump(false);
 } catch (SodiumException $ex) {
-       var_dump(true);
+    var_dump(true);
 }
 
 echo "aead_chacha20poly1305_ietf:\n";
 
 if (SODIUM_LIBRARY_MAJOR_VERSION > 7 ||
-       (SODIUM_LIBRARY_MAJOR_VERSION == 7 &&
-        SODIUM_LIBRARY_MINOR_VERSION >= 6)) {
-       $msg = random_bytes(random_int(1, 1000));
-       $nonce = random_bytes(SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES);
-       $key = sodium_crypto_aead_chacha20poly1305_ietf_keygen();
-       $ad = random_bytes(random_int(1, 1000));
+    (SODIUM_LIBRARY_MAJOR_VERSION == 7 &&
+     SODIUM_LIBRARY_MINOR_VERSION >= 6)) {
+    $msg = random_bytes(random_int(1, 1000));
+    $nonce = random_bytes(SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES);
+    $key = sodium_crypto_aead_chacha20poly1305_ietf_keygen();
+    $ad = random_bytes(random_int(1, 1000));
 
-       $ciphertext = sodium_crypto_aead_chacha20poly1305_ietf_encrypt($msg, $ad, $nonce, $key);
-       $msg2 = sodium_crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, $ad, $nonce, $key);
-       var_dump($ciphertext !== $msg);
-       var_dump($msg === $msg2);
-       var_dump(sodium_crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, 'x' . $ad, $nonce, $key));
-       try {
-               // Switched order
-               $msg2 = sodium_crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, $ad, $key, $nonce);
-               var_dump(false);
-       } catch (SodiumException $ex) {
-               var_dump(true);
-       }
+    $ciphertext = sodium_crypto_aead_chacha20poly1305_ietf_encrypt($msg, $ad, $nonce, $key);
+    $msg2 = sodium_crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, $ad, $nonce, $key);
+    var_dump($ciphertext !== $msg);
+    var_dump($msg === $msg2);
+    var_dump(sodium_crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, 'x' . $ad, $nonce, $key));
+    try {
+        // Switched order
+        $msg2 = sodium_crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, $ad, $key, $nonce);
+        var_dump(false);
+    } catch (SodiumException $ex) {
+        var_dump(true);
+    }
 } else {
-       var_dump(true);
-       var_dump(true);
-       var_dump(false);
-       var_dump(true);
+    var_dump(true);
+    var_dump(true);
+    var_dump(false);
+    var_dump(true);
 }
 
 echo "aead_xchacha20poly1305_ietf:\n";
 
 if (SODIUM_LIBRARY_MAJOR_VERSION > 9 ||
-       (SODIUM_LIBRARY_MAJOR_VERSION == 9 &&
-        SODIUM_LIBRARY_MINOR_VERSION >= 4)) {
-       $msg = random_bytes(random_int(1, 1000));
-       $nonce = random_bytes(SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES);
-       $key = sodium_crypto_aead_xchacha20poly1305_ietf_keygen();
-       $ad = random_bytes(random_int(1, 1000));
+    (SODIUM_LIBRARY_MAJOR_VERSION == 9 &&
+     SODIUM_LIBRARY_MINOR_VERSION >= 4)) {
+    $msg = random_bytes(random_int(1, 1000));
+    $nonce = random_bytes(SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES);
+    $key = sodium_crypto_aead_xchacha20poly1305_ietf_keygen();
+    $ad = random_bytes(random_int(1, 1000));
 
-       $ciphertext = sodium_crypto_aead_xchacha20poly1305_ietf_encrypt($msg, $ad, $nonce, $key);
-       $msg2 = sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext, $ad, $nonce, $key);
-       var_dump($ciphertext !== $msg);
-       var_dump($msg === $msg2);
-       var_dump(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext, 'x' . $ad, $nonce, $key));
-       try {
-               // Switched order
-               $msg2 = sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext, $ad, $key, $nonce);
-               var_dump(false);
-       } catch (SodiumException $ex) {
-               var_dump(true);
-       }
+    $ciphertext = sodium_crypto_aead_xchacha20poly1305_ietf_encrypt($msg, $ad, $nonce, $key);
+    $msg2 = sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext, $ad, $nonce, $key);
+    var_dump($ciphertext !== $msg);
+    var_dump($msg === $msg2);
+    var_dump(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext, 'x' . $ad, $nonce, $key));
+    try {
+        // Switched order
+        $msg2 = sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext, $ad, $key, $nonce);
+        var_dump(false);
+    } catch (SodiumException $ex) {
+        var_dump(true);
+    }
 } else {
-       var_dump(true);
-       var_dump(true);
-       var_dump(false);
-       var_dump(true);
+    var_dump(true);
+    var_dump(true);
+    var_dump(false);
+    var_dump(true);
 }
 
 echo "aead_aes256gcm:\n";
 
 if (sodium_crypto_aead_aes256gcm_is_available()) {
-       $msg = random_bytes(random_int(1, 1000));
-       $nonce = random_bytes(SODIUM_CRYPTO_AEAD_AES256GCM_NPUBBYTES);
-       $ad = random_bytes(random_int(1, 1000));
-       $key = sodium_crypto_aead_aes256gcm_keygen();
-       $ciphertext = sodium_crypto_aead_aes256gcm_encrypt($msg, $ad, $nonce, $key);
-       $msg2 = sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $ad, $nonce, $key);
-       var_dump($ciphertext !== $msg);
-       var_dump($msg === $msg2);
-       var_dump(sodium_crypto_aead_aes256gcm_decrypt($ciphertext, 'x' . $ad, $nonce, $key));
-       try {
-               // Switched order
-               $msg2 = sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $ad, $key, $nonce);
-               var_dump(false);
-       } catch (SodiumException $ex) {
-               var_dump(true);
-       }
+    $msg = random_bytes(random_int(1, 1000));
+    $nonce = random_bytes(SODIUM_CRYPTO_AEAD_AES256GCM_NPUBBYTES);
+    $ad = random_bytes(random_int(1, 1000));
+    $key = sodium_crypto_aead_aes256gcm_keygen();
+    $ciphertext = sodium_crypto_aead_aes256gcm_encrypt($msg, $ad, $nonce, $key);
+    $msg2 = sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $ad, $nonce, $key);
+    var_dump($ciphertext !== $msg);
+    var_dump($msg === $msg2);
+    var_dump(sodium_crypto_aead_aes256gcm_decrypt($ciphertext, 'x' . $ad, $nonce, $key));
+    try {
+        // Switched order
+        $msg2 = sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $ad, $key, $nonce);
+        var_dump(false);
+    } catch (SodiumException $ex) {
+        var_dump(true);
+    }
 } else {
-       var_dump(true);
-       var_dump(true);
-       var_dump(false);
-       var_dump(true);
+    var_dump(true);
+    var_dump(true);
+    var_dump(false);
+    var_dump(true);
 }
 ?>
 --EXPECT--
index a9a8c3a9f3943a2f86cbe989efbf60824bcfeedc..3c6e75098a03139120aea3795f9d501325e83596 100644 (file)
@@ -13,8 +13,8 @@ var_dump(sodium_crypto_auth_verify($mac, $msg, $key));
 
 $bad_key = random_bytes(SODIUM_CRYPTO_AUTH_KEYBYTES - 1);
 try {
-       $mac = sodium_crypto_auth($msg, $bad_key);
-       echo 'Fail!', PHP_EOL;
+    $mac = sodium_crypto_auth($msg, $bad_key);
+    echo 'Fail!', PHP_EOL;
 } catch (SodiumException $ex) {
   echo $ex->getMessage(), PHP_EOL;
 }
@@ -27,9 +27,9 @@ var_dump(sodium_crypto_auth_verify($mac, $badmsg, $key));
 // Let's flip a bit pseudo-randomly
 $badmsg = $msg;
 $badmsg[$i=mt_rand(0, 999)] = \chr(
-       \ord($msg[$i]) ^ (
-               1 << mt_rand(0, 7)
-       )
+    \ord($msg[$i]) ^ (
+        1 << mt_rand(0, 7)
+    )
 );
 
 var_dump(sodium_crypto_auth_verify($mac, $badmsg, $key));
index 6cf68f3303498b2242b73d76c6d1977ce454ef89..392fad1d91b1a933630f181bbe4429a5568e4482 100644 (file)
@@ -28,8 +28,8 @@ $alice_box_secretkey = sodium_crypto_box_secretkey($alice_box_kp);
 $bob_box_publickey = sodium_crypto_box_publickey($bob_box_kp);
 
 $alice_to_bob_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey(
-       $alice_box_secretkey,
-       $bob_box_publickey
+    $alice_box_secretkey,
+    $bob_box_publickey
 );
 
 $msg = "Here is another message, to be signed using Alice's secret key, and " .
@@ -37,19 +37,19 @@ $msg = "Here is another message, to be signed using Alice's secret key, and " .
   "since they are derived from a fixed seeds";
 
 $ciphertext = sodium_crypto_box(
-       $msg,
-       $message_nonce,
-       $alice_to_bob_kp
+    $msg,
+    $message_nonce,
+    $alice_to_bob_kp
 );
 
 try {
   $ciphertext = sodium_crypto_box(
-         $msg,
-         $message_nonce,
-         substr($alice_to_bob_kp, 1)
+      $msg,
+      $message_nonce,
+      substr($alice_to_bob_kp, 1)
   );
 } catch (SodiumException $ex) {
-       echo $ex->getMessage(), PHP_EOL;
+    echo $ex->getMessage(), PHP_EOL;
 }
 
 sodium_memzero($alice_box_kp);
@@ -62,14 +62,14 @@ $alice_box_publickey = sodium_crypto_box_publickey($alice_box_kp);
 $bob_box_secretkey = sodium_crypto_box_secretkey($bob_box_kp);
 
 $bob_to_alice_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey(
-       $bob_box_secretkey,
-       $alice_box_publickey
+    $bob_box_secretkey,
+    $alice_box_publickey
 );
 
 $plaintext = sodium_crypto_box_open(
-       $ciphertext,
-       $message_nonce,
-       $bob_to_alice_kp
+    $ciphertext,
+    $message_nonce,
+    $bob_to_alice_kp
 );
 
 var_dump($msg === $plaintext);
@@ -91,46 +91,46 @@ $bob_to_alice_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey
 $alice_to_bob_message_nonce = random_bytes(SODIUM_CRYPTO_BOX_NONCEBYTES);
 
 $alice_to_bob_ciphertext = sodium_crypto_box('Hi, this is Alice',
-                                                                                         $alice_to_bob_message_nonce,
-                                                                                         $alice_to_bob_kp);
+                                              $alice_to_bob_message_nonce,
+                                              $alice_to_bob_kp);
 
 $alice_message_decrypted_by_bob = sodium_crypto_box_open($alice_to_bob_ciphertext,
-                                                                                                                 $alice_to_bob_message_nonce,
-                                                                                                                 $bob_to_alice_kp);
+                                                          $alice_to_bob_message_nonce,
+                                                          $bob_to_alice_kp);
 
 $bob_to_alice_message_nonce = random_bytes(SODIUM_CRYPTO_BOX_NONCEBYTES);
 
 $bob_to_alice_ciphertext = sodium_crypto_box('Hi Alice! This is Bob',
-                                                                                         $bob_to_alice_message_nonce,
-                                                                                         $bob_to_alice_kp);
+                                              $bob_to_alice_message_nonce,
+                                              $bob_to_alice_kp);
 
 $bob_message_decrypted_by_alice = sodium_crypto_box_open($bob_to_alice_ciphertext,
-                                                                                                                 $bob_to_alice_message_nonce,
-                                                                                                                 $alice_to_bob_kp);
+                                                          $bob_to_alice_message_nonce,
+                                                          $alice_to_bob_kp);
 
 var_dump($alice_message_decrypted_by_bob);
 var_dump($bob_message_decrypted_by_alice);
 
 if (SODIUM_LIBRARY_MAJOR_VERSION > 7 ||
-       (SODIUM_LIBRARY_MAJOR_VERSION == 7 &&
-        SODIUM_LIBRARY_MINOR_VERSION >= 5)) {
-       $anonymous_message_to_alice = sodium_crypto_box_seal('Anonymous message',
-                                                                                                                 $alice_publickey);
+    (SODIUM_LIBRARY_MAJOR_VERSION == 7 &&
+     SODIUM_LIBRARY_MINOR_VERSION >= 5)) {
+    $anonymous_message_to_alice = sodium_crypto_box_seal('Anonymous message',
+                                                          $alice_publickey);
 
-       $decrypted_message = sodium_crypto_box_seal_open($anonymous_message_to_alice,
-                                                                                                         $alice_kp);
+    $decrypted_message = sodium_crypto_box_seal_open($anonymous_message_to_alice,
+                                                      $alice_kp);
 } else {
-       $decrypted_message = 'Anonymous message';
+    $decrypted_message = 'Anonymous message';
 }
 var_dump($decrypted_message);
 
 $msg = sodium_hex2bin(
-       '7375f4094f1151640bd853cb13dbc1a0ee9e13b0287a89d34fa2f6732be9de13f88457553d'.
-       '768347116522d6d32c9cb353ef07aa7c83bd129b2bb5db35b28334c935b24f2639405a0604'
+    '7375f4094f1151640bd853cb13dbc1a0ee9e13b0287a89d34fa2f6732be9de13f88457553d'.
+    '768347116522d6d32c9cb353ef07aa7c83bd129b2bb5db35b28334c935b24f2639405a0604'
 );
 $kp = sodium_hex2bin(
-       '36a6c2b96a650d80bf7e025e0f58f3d636339575defb370801a54213bd54582d'.
-       '5aecbcf7866e7a4d58a6c1317e2b955f54ecbe2fcbbf7d262c10636ed524480c'
+    '36a6c2b96a650d80bf7e025e0f58f3d636339575defb370801a54213bd54582d'.
+    '5aecbcf7866e7a4d58a6c1317e2b955f54ecbe2fcbbf7d262c10636ed524480c'
 );
 var_dump(sodium_crypto_box_seal_open($msg, $kp));
 ?>
index 364c5dc5eca443449391dfa4170067ba180f9ace..5a7b0c4285048fca243e5db014c9ac1cb5a05c41 100644 (file)
@@ -36,14 +36,14 @@ $q = sodium_crypto_generichash_final($state2, 64);
 $exp = bin2hex($q);
 var_dump($exp);
 $act = bin2hex(
-       sodium_crypto_generichash('msg2', '0123456789abcdef', 64)
+    sodium_crypto_generichash('msg2', '0123456789abcdef', 64)
 );
 var_dump($act);
 var_dump($exp === $act);
 try {
-       $hash = sodium_crypto_generichash('test', '', 128);
+    $hash = sodium_crypto_generichash('test', '', 128);
 } catch (SodiumException $ex) {
-       var_dump(true);
+    var_dump(true);
 }
 ?>
 --EXPECT--
index 22496cd669ec56f07330281bce55cc08207e5008..2636963e32d8bd33916fe45e39c99608ead9a496 100644 (file)
@@ -10,9 +10,9 @@ $q = sodium_crypto_scalarmult($n, $p);
 
 var_dump(sodium_bin2hex($q));
 try {
-       sodium_crypto_scalarmult(substr($n, 1), $p);
+    sodium_crypto_scalarmult(substr($n, 1), $p);
 } catch (SodiumException $ex) {
-       var_dump(true);
+    var_dump(true);
 }
 ?>
 --EXPECT--
index ac34ea65ef199333c06a6c811f5c30ca95625aa9..b9d4d1ccfe5dc61d5869020ac9bc9dfabd12bb8f 100644 (file)
@@ -14,9 +14,9 @@ $y = sodium_crypto_secretbox_open("\0" . $a, $nonce, $key);
 var_dump($y);
 
 try {
-       sodium_crypto_secretbox('test', substr($nonce, 1), $key);
+    sodium_crypto_secretbox('test', substr($nonce, 1), $key);
 } catch (SodiumException $ex) {
-       var_dump(true);
+    var_dump(true);
 }
 
 ?>
index 3398def06ea33c0d5ce1e87132f4d882806ba419..68bffc823b00b0562038e16eb6e1f432eb1e2e15 100644 (file)
@@ -16,9 +16,9 @@ $h3 = sodium_crypto_shorthash($m2, $k2);
 echo bin2hex($h3) . "\n";
 
 try {
-       sodium_crypto_shorthash($m1, $k1 . $k2);
+    sodium_crypto_shorthash($m1, $k1 . $k2);
 } catch (SodiumException $ex) {
-       var_dump(true);
+    var_dump(true);
 }
 ?>
 --EXPECT--
index 55fe8920bf6c4c3102d9f0b8577e1320fbbb72ab..14e0c49e91e18e1d57f6ce57c6cc165e088453b1 100644 (file)
@@ -46,9 +46,9 @@ var_dump($msg_orig === $msg);
 $signature = sodium_crypto_sign_detached($msg, $alice_secretkey);
 var_dump(strlen($signature) === SODIUM_CRYPTO_SIGN_BYTES);
 var_dump(sodium_crypto_sign_verify_detached($signature,
-                                                                                        $msg, $alice_publickey));
+                                             $msg, $alice_publickey));
 var_dump(sodium_crypto_sign_verify_detached($signature,
-                                                                                        $msg . "\0", $alice_publickey));
+                                             $msg . "\0", $alice_publickey));
 
 $calc_pubkey = sodium_crypto_sign_publickey_from_secretkey($alice_secretkey);
 var_dump(sodium_memcmp($calc_pubkey, $alice_publickey) === 0);
@@ -58,9 +58,9 @@ $curve25519key = sodium_crypto_sign_ed25519_sk_to_curve25519($ed25519key);
 var_dump($curve25519key === sodium_hex2bin("381b2be5e3d38820deb1243fb58b4be654da30dd3ccde492cb88f937eb489363"));
 
 try {
-       sodium_crypto_sign($msg, substr($alice_secretkey, 1));
+    sodium_crypto_sign($msg, substr($alice_secretkey, 1));
 } catch (SodiumException $ex) {
-       var_dump(true);
+    var_dump(true);
 }
 ?>
 --EXPECT--
index 0bf481b73e68a7a3224a696962639430e9f90c77..27e163c071aa71f63e462f3ad86f920f72399779 100644 (file)
@@ -33,9 +33,9 @@ $stream6 = sodium_crypto_stream_xor($stream5, $nonce, $key);
 var_dump($stream6 === $stream);
 
 try {
-       sodium_crypto_stream($len, substr($nonce, 1), $key);
+    sodium_crypto_stream($len, substr($nonce, 1), $key);
 } catch (SodiumException $ex) {
-       var_dump(true);
+    var_dump(true);
 }
 
 ?>
index f8f172c544322f329c714fa3ccfdd67d8fe648c7..4885f9309331da33e66314b3aa4d71f165e70220 100644 (file)
@@ -6,7 +6,7 @@ SodiumException backtraces do not contain function arguments
 <?php
 
 function do_memzero($x) {
-       sodium_memzero($x);
+    sodium_memzero($x);
 }
 
 $x = 42;
index 4397bdc44f06138e2b842839cf3eb3bff974e206..23410d140c7b809e00b3a34b6e153a39c846e4ac 100644 (file)
@@ -7,9 +7,9 @@ increment and add edge cases
 
 $notStr = 123;
 try {
-       sodium_increment($notStr);
+    sodium_increment($notStr);
 } catch (SodiumException $e) {
-       echo $e->getMessage(), "\n";
+    echo $e->getMessage(), "\n";
 }
 
 $str = "abc";
@@ -26,9 +26,9 @@ $addStr = "\2\0\0";
 
 $notStr = 123;
 try {
-       sodium_add($notStr, $addStr);
+    sodium_add($notStr, $addStr);
 } catch (SodiumException $e) {
-       echo $e->getMessage(), "\n";
+    echo $e->getMessage(), "\n";
 }
 
 $str = "abc";
index 43ad4fdd8628bd7fff2a84537d9d11643ff4d14b..e548b5f8dcceb6c68f440f803ae8c78d60331d34 100644 (file)
@@ -1,21 +1,21 @@
 --TEST--
-Check for libsodium presence
+Check for sodium presence
 --SKIPIF--
 <?php if (!extension_loaded("sodium")) print "skip"; ?>
 --FILE--
 <?php
-echo "libsodium extension is available";
+echo "sodium extension is available";
 /*
-               you can add regression tests for your extension here
+        you can add regression tests for your extension here
 
   the output of your test code has to be equal to the
   text in the --EXPECT-- section below for the tests
   to pass, differences between the output and the
   expected text are interpreted as failure
 
-               see php5/README.TESTING for further information on
+        see php7/README.TESTING for further information on
   writing regression tests
 */
 ?>
 --EXPECT--
-libsodium extension is available
+sodium extension is available
index 5f3c88aaef9de2d7411e85ae50fcd08bbd719b41..aee90bd6face5fbfb6e8a65a9a1c9ee1b7a44d16 100644 (file)
@@ -9,9 +9,9 @@ $passwd = 'password';
 
 $hash = sodium_crypto_pwhash_str
   ($passwd, SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
-                       SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE);
+            SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE);
 var_dump(substr($hash, 0, strlen(SODIUM_CRYPTO_PWHASH_STRPREFIX)) ===
-                SODIUM_CRYPTO_PWHASH_STRPREFIX);
+         SODIUM_CRYPTO_PWHASH_STRPREFIX);
 
 $testHash = '$argon2i$v=19$m=4096,t=3,p=1$MzE4ODFiZWFlMjAzOWUAAA$FWUV6tsyJ32qThiLi1cCsLIbf3dIOG/RwXcTzt536KY';
 $c = sodium_crypto_pwhash_str_verify($testHash, $passwd);
index 610ce99c16bb15b3144d05193d3c07f1e8b08fb4..ff380ff78ca3ef74f2d4a3131a3534e3323e49c5 100644 (file)
@@ -27,19 +27,19 @@ sodium_add($v, $w);
 var_dump(bin2hex($v));
 
 if (SODIUM_LIBRARY_MAJOR_VERSION > 7 ||
-       (SODIUM_LIBRARY_MAJOR_VERSION == 7 &&
-        SODIUM_LIBRARY_MINOR_VERSION >= 6)) {
-       $v_1 = "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
-       $v_2 = ""."\x02\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
-       $v_1 .= '';
-       var_dump(sodium_compare($v_1, $v_2));
-       sodium_increment($v_1);
-       var_dump(sodium_compare($v_1, $v_2));
-       sodium_increment($v_1);
-       var_dump(sodium_compare($v_1, $v_2));
+    (SODIUM_LIBRARY_MAJOR_VERSION == 7 &&
+     SODIUM_LIBRARY_MINOR_VERSION >= 6)) {
+    $v_1 = "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
+    $v_2 = ""."\x02\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
+    $v_1 .= '';
+    var_dump(sodium_compare($v_1, $v_2));
+    sodium_increment($v_1);
+    var_dump(sodium_compare($v_1, $v_2));
+    sodium_increment($v_1);
+    var_dump(sodium_compare($v_1, $v_2));
 } else {
-       // Dummy test results for libsodium < 1.0.4
-       var_dump(-1, 0, 1);
+    // Dummy test results for libsodium < 1.0.4
+    var_dump(-1, 0, 1);
 }
 
 $str = 'stdClass';
@@ -53,6 +53,41 @@ var_dump(bin2hex($str_padded));
 
 $str_unpadded = sodium_unpad($str_padded, 16);
 var_dump($str_unpadded == $str);
+
+if (defined('SODIUM_BASE64_VARIANT_ORIGINAL')) {
+    for ($i = 0; $i < 100; $i++) {
+        $bin = $i == 0 ? '' : random_bytes($i);
+        $b64 = base64_encode($bin);
+        $b64_ = sodium_bin2base64($bin, SODIUM_BASE64_VARIANT_ORIGINAL);
+        if ($b64 !== $b64_) {
+            echo "frombin[$b64] != frombin_[$b64_]\n";
+        }
+        $bin_ = sodium_base642bin($b64, SODIUM_BASE64_VARIANT_ORIGINAL);
+        if ($bin !== $bin_) {
+            echo "frombase64([$b64]) != frombase64_[$b64]\n";
+        }
+        $bin_ = sodium_base642bin(" $b64\n", SODIUM_BASE64_VARIANT_ORIGINAL, " \n");
+        if ($bin !== $bin_) {
+            echo "frombase64([$b64]) != frombase64_([ $b64\\n])\n";
+        }
+    }
+    try {
+        var_dump(sodium_base642bin('O1R', SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING));
+    } catch (Exception $e) {
+        var_dump('base64("O1R") case passed');
+    }
+    try {
+        var_dump(sodium_base642bin('O1', SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING));
+    } catch (Exception $e) {
+        var_dump('base64("O1") case passed');
+    }
+    try {
+        var_dump(sodium_base642bin('O', SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING));
+    } catch (Exception $e) {
+        var_dump('base64("O") case passed');
+    }
+}
+
 ?>
 --EXPECT--
 0
@@ -69,3 +104,6 @@ object(stdClass)#1 (1) {
 }
 string(32) "78797a80000000000000000000000000"
 bool(true)
+string(25) "base64("O1R") case passed"
+string(24) "base64("O1") case passed"
+string(23) "base64("O") case passed"