@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | * If you are using this library, you should be using |
13 | 13 | * ParagonIE_Sodium_Compat in your code, not this class. |
14 | 14 | */ |
15 | -abstract class ParagonIE_Sodium_Crypto |
|
16 | -{ |
|
15 | +abstract class ParagonIE_Sodium_Crypto { |
|
17 | 16 | const aead_chacha20poly1305_KEYBYTES = 32; |
18 | 17 | const aead_chacha20poly1305_NSECBYTES = 0; |
19 | 18 | const aead_chacha20poly1305_NPUBBYTES = 8; |
@@ -381,8 +380,7 @@ discard block |
||
381 | 380 | * @return string |
382 | 381 | * @throws TypeError |
383 | 382 | */ |
384 | - public static function auth($message, $key) |
|
385 | - { |
|
383 | + public static function auth($message, $key) { |
|
386 | 384 | return ParagonIE_Sodium_Core_Util::substr( |
387 | 385 | hash_hmac('sha512', $message, $key, true), |
388 | 386 | 0, |
@@ -402,8 +400,7 @@ discard block |
||
402 | 400 | * @throws SodiumException |
403 | 401 | * @throws TypeError |
404 | 402 | */ |
405 | - public static function auth_verify($mac, $message, $key) |
|
406 | - { |
|
403 | + public static function auth_verify($mac, $message, $key) { |
|
407 | 404 | return ParagonIE_Sodium_Core_Util::hashEquals( |
408 | 405 | $mac, |
409 | 406 | self::auth($message, $key) |
@@ -422,8 +419,7 @@ discard block |
||
422 | 419 | * @throws SodiumException |
423 | 420 | * @throws TypeError |
424 | 421 | */ |
425 | - public static function box($plaintext, $nonce, $keypair) |
|
426 | - { |
|
422 | + public static function box($plaintext, $nonce, $keypair) { |
|
427 | 423 | $c = self::secretbox( |
428 | 424 | $plaintext, |
429 | 425 | $nonce, |
@@ -446,8 +442,7 @@ discard block |
||
446 | 442 | * @throws SodiumException |
447 | 443 | * @throws TypeError |
448 | 444 | */ |
449 | - public static function box_seal($message, $publicKey) |
|
450 | - { |
|
445 | + public static function box_seal($message, $publicKey) { |
|
451 | 446 | /** @var string $ephemeralKeypair */ |
452 | 447 | $ephemeralKeypair = self::box_keypair(); |
453 | 448 | |
@@ -492,8 +487,7 @@ discard block |
||
492 | 487 | * @throws SodiumException |
493 | 488 | * @throws TypeError |
494 | 489 | */ |
495 | - public static function box_seal_open($message, $keypair) |
|
496 | - { |
|
490 | + public static function box_seal_open($message, $keypair) { |
|
497 | 491 | /** @var string $ephemeralPK */ |
498 | 492 | $ephemeralPK = ParagonIE_Sodium_Core_Util::substr($message, 0, 32); |
499 | 493 | |
@@ -541,8 +535,7 @@ discard block |
||
541 | 535 | * @throws SodiumException |
542 | 536 | * @throws TypeError |
543 | 537 | */ |
544 | - public static function box_beforenm($sk, $pk) |
|
545 | - { |
|
538 | + public static function box_beforenm($sk, $pk) { |
|
546 | 539 | return ParagonIE_Sodium_Core_HSalsa20::hsalsa20( |
547 | 540 | str_repeat("\x00", 16), |
548 | 541 | self::scalarmult($sk, $pk) |
@@ -557,8 +550,7 @@ discard block |
||
557 | 550 | * @throws SodiumException |
558 | 551 | * @throws TypeError |
559 | 552 | */ |
560 | - public static function box_keypair() |
|
561 | - { |
|
553 | + public static function box_keypair() { |
|
562 | 554 | $sKey = random_bytes(32); |
563 | 555 | $pKey = self::scalarmult_base($sKey); |
564 | 556 | return $sKey . $pKey; |
@@ -570,8 +562,7 @@ discard block |
||
570 | 562 | * @throws SodiumException |
571 | 563 | * @throws TypeError |
572 | 564 | */ |
573 | - public static function box_seed_keypair($seed) |
|
574 | - { |
|
565 | + public static function box_seed_keypair($seed) { |
|
575 | 566 | $sKey = ParagonIE_Sodium_Core_Util::substr( |
576 | 567 | hash('sha512', $seed, true), |
577 | 568 | 0, |
@@ -589,8 +580,7 @@ discard block |
||
589 | 580 | * @return string |
590 | 581 | * @throws TypeError |
591 | 582 | */ |
592 | - public static function box_keypair_from_secretkey_and_publickey($sKey, $pKey) |
|
593 | - { |
|
583 | + public static function box_keypair_from_secretkey_and_publickey($sKey, $pKey) { |
|
594 | 584 | return ParagonIE_Sodium_Core_Util::substr($sKey, 0, 32) . |
595 | 585 | ParagonIE_Sodium_Core_Util::substr($pKey, 0, 32); |
596 | 586 | } |
@@ -603,8 +593,7 @@ discard block |
||
603 | 593 | * @throws RangeException |
604 | 594 | * @throws TypeError |
605 | 595 | */ |
606 | - public static function box_secretkey($keypair) |
|
607 | - { |
|
596 | + public static function box_secretkey($keypair) { |
|
608 | 597 | if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== 64) { |
609 | 598 | throw new RangeException( |
610 | 599 | 'Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES bytes long.' |
@@ -621,8 +610,7 @@ discard block |
||
621 | 610 | * @throws RangeException |
622 | 611 | * @throws TypeError |
623 | 612 | */ |
624 | - public static function box_publickey($keypair) |
|
625 | - { |
|
613 | + public static function box_publickey($keypair) { |
|
626 | 614 | if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES) { |
627 | 615 | throw new RangeException( |
628 | 616 | 'Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES bytes long.' |
@@ -640,8 +628,7 @@ discard block |
||
640 | 628 | * @throws SodiumException |
641 | 629 | * @throws TypeError |
642 | 630 | */ |
643 | - public static function box_publickey_from_secretkey($sKey) |
|
644 | - { |
|
631 | + public static function box_publickey_from_secretkey($sKey) { |
|
645 | 632 | if (ParagonIE_Sodium_Core_Util::strlen($sKey) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_SECRETKEYBYTES) { |
646 | 633 | throw new RangeException( |
647 | 634 | 'Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_SECRETKEYBYTES bytes long.' |
@@ -662,8 +649,7 @@ discard block |
||
662 | 649 | * @throws SodiumException |
663 | 650 | * @throws TypeError |
664 | 651 | */ |
665 | - public static function box_open($ciphertext, $nonce, $keypair) |
|
666 | - { |
|
652 | + public static function box_open($ciphertext, $nonce, $keypair) { |
|
667 | 653 | return self::secretbox_open( |
668 | 654 | $ciphertext, |
669 | 655 | $nonce, |
@@ -687,8 +673,7 @@ discard block |
||
687 | 673 | * @throws SodiumException |
688 | 674 | * @throws TypeError |
689 | 675 | */ |
690 | - public static function generichash($message, $key = '', $outlen = 32) |
|
691 | - { |
|
676 | + public static function generichash($message, $key = '', $outlen = 32) { |
|
692 | 677 | // This ensures that ParagonIE_Sodium_Core_BLAKE2b::$iv is initialized |
693 | 678 | ParagonIE_Sodium_Core_BLAKE2b::pseudoConstructor(); |
694 | 679 | |
@@ -728,8 +713,7 @@ discard block |
||
728 | 713 | * @throws SodiumException |
729 | 714 | * @throws TypeError |
730 | 715 | */ |
731 | - public static function generichash_final($ctx, $outlen = 32) |
|
732 | - { |
|
716 | + public static function generichash_final($ctx, $outlen = 32) { |
|
733 | 717 | if (!is_string($ctx)) { |
734 | 718 | throw new TypeError('Context must be a string'); |
735 | 719 | } |
@@ -758,8 +742,7 @@ discard block |
||
758 | 742 | * @throws SodiumException |
759 | 743 | * @throws TypeError |
760 | 744 | */ |
761 | - public static function generichash_init($key = '', $outputLength = 32) |
|
762 | - { |
|
745 | + public static function generichash_init($key = '', $outputLength = 32) { |
|
763 | 746 | // This ensures that ParagonIE_Sodium_Core_BLAKE2b::$iv is initialized |
764 | 747 | ParagonIE_Sodium_Core_BLAKE2b::pseudoConstructor(); |
765 | 748 | |
@@ -835,8 +818,7 @@ discard block |
||
835 | 818 | * @throws SodiumException |
836 | 819 | * @throws TypeError |
837 | 820 | */ |
838 | - public static function generichash_update($ctx, $message) |
|
839 | - { |
|
821 | + public static function generichash_update($ctx, $message) { |
|
840 | 822 | // This ensures that ParagonIE_Sodium_Core_BLAKE2b::$iv is initialized |
841 | 823 | ParagonIE_Sodium_Core_BLAKE2b::pseudoConstructor(); |
842 | 824 | |
@@ -864,8 +846,7 @@ discard block |
||
864 | 846 | * @throws SodiumException |
865 | 847 | * @throws TypeError |
866 | 848 | */ |
867 | - public static function keyExchange($my_sk, $their_pk, $client_pk, $server_pk) |
|
868 | - { |
|
849 | + public static function keyExchange($my_sk, $their_pk, $client_pk, $server_pk) { |
|
869 | 850 | return ParagonIE_Sodium_Compat::crypto_generichash( |
870 | 851 | ParagonIE_Sodium_Compat::crypto_scalarmult($my_sk, $their_pk) . |
871 | 852 | $client_pk . |
@@ -885,8 +866,7 @@ discard block |
||
885 | 866 | * @throws SodiumException |
886 | 867 | * @throws TypeError |
887 | 868 | */ |
888 | - public static function scalarmult($sKey, $pKey) |
|
889 | - { |
|
869 | + public static function scalarmult($sKey, $pKey) { |
|
890 | 870 | $q = ParagonIE_Sodium_Core_X25519::crypto_scalarmult_curve25519_ref10($sKey, $pKey); |
891 | 871 | self::scalarmult_throw_if_zero($q); |
892 | 872 | return $q; |
@@ -902,8 +882,7 @@ discard block |
||
902 | 882 | * @throws SodiumException |
903 | 883 | * @throws TypeError |
904 | 884 | */ |
905 | - public static function scalarmult_base($secret) |
|
906 | - { |
|
885 | + public static function scalarmult_base($secret) { |
|
907 | 886 | $q = ParagonIE_Sodium_Core_X25519::crypto_scalarmult_curve25519_ref10_base($secret); |
908 | 887 | self::scalarmult_throw_if_zero($q); |
909 | 888 | return $q; |
@@ -917,8 +896,7 @@ discard block |
||
917 | 896 | * @throws SodiumException |
918 | 897 | * @throws TypeError |
919 | 898 | */ |
920 | - protected static function scalarmult_throw_if_zero($q) |
|
921 | - { |
|
899 | + protected static function scalarmult_throw_if_zero($q) { |
|
922 | 900 | $d = 0; |
923 | 901 | for ($i = 0; $i < self::box_curve25519xsalsa20poly1305_SECRETKEYBYTES; ++$i) { |
924 | 902 | $d |= ParagonIE_Sodium_Core_Util::chrToInt($q[$i]); |
@@ -942,8 +920,7 @@ discard block |
||
942 | 920 | * @throws SodiumException |
943 | 921 | * @throws TypeError |
944 | 922 | */ |
945 | - public static function secretbox($plaintext, $nonce, $key) |
|
946 | - { |
|
923 | + public static function secretbox($plaintext, $nonce, $key) { |
|
947 | 924 | /** @var string $subkey */ |
948 | 925 | $subkey = ParagonIE_Sodium_Core_HSalsa20::hsalsa20($nonce, $key); |
949 | 926 | |
@@ -1017,8 +994,7 @@ discard block |
||
1017 | 994 | * @throws SodiumException |
1018 | 995 | * @throws TypeError |
1019 | 996 | */ |
1020 | - public static function secretbox_open($ciphertext, $nonce, $key) |
|
1021 | - { |
|
997 | + public static function secretbox_open($ciphertext, $nonce, $key) { |
|
1022 | 998 | /** @var string $mac */ |
1023 | 999 | $mac = ParagonIE_Sodium_Core_Util::substr( |
1024 | 1000 | $ciphertext, |
@@ -1090,8 +1066,7 @@ discard block |
||
1090 | 1066 | * @throws SodiumException |
1091 | 1067 | * @throws TypeError |
1092 | 1068 | */ |
1093 | - public static function secretbox_xchacha20poly1305($plaintext, $nonce, $key) |
|
1094 | - { |
|
1069 | + public static function secretbox_xchacha20poly1305($plaintext, $nonce, $key) { |
|
1095 | 1070 | /** @var string $subkey */ |
1096 | 1071 | $subkey = ParagonIE_Sodium_Core_HChaCha20::hChaCha20( |
1097 | 1072 | ParagonIE_Sodium_Core_Util::substr($nonce, 0, 16), |
@@ -1169,8 +1144,7 @@ discard block |
||
1169 | 1144 | * @throws SodiumException |
1170 | 1145 | * @throws TypeError |
1171 | 1146 | */ |
1172 | - public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key) |
|
1173 | - { |
|
1147 | + public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key) { |
|
1174 | 1148 | /** @var string $mac */ |
1175 | 1149 | $mac = ParagonIE_Sodium_Core_Util::substr( |
1176 | 1150 | $ciphertext, |
@@ -1238,8 +1212,7 @@ discard block |
||
1238 | 1212 | * @throws Exception |
1239 | 1213 | * @throws SodiumException |
1240 | 1214 | */ |
1241 | - public static function secretstream_xchacha20poly1305_init_push($key) |
|
1242 | - { |
|
1215 | + public static function secretstream_xchacha20poly1305_init_push($key) { |
|
1243 | 1216 | # randombytes_buf(out, crypto_secretstream_xchacha20poly1305_HEADERBYTES); |
1244 | 1217 | $out = random_bytes(24); |
1245 | 1218 | |
@@ -1268,8 +1241,7 @@ discard block |
||
1268 | 1241 | * @return string Returns a state. |
1269 | 1242 | * @throws Exception |
1270 | 1243 | */ |
1271 | - public static function secretstream_xchacha20poly1305_init_pull($key, $header) |
|
1272 | - { |
|
1244 | + public static function secretstream_xchacha20poly1305_init_pull($key, $header) { |
|
1273 | 1245 | # crypto_core_hchacha20(state->k, in, k, NULL); |
1274 | 1246 | $subkey = ParagonIE_Sodium_Core_HChaCha20::hChaCha20( |
1275 | 1247 | ParagonIE_Sodium_Core_Util::substr($header, 0, 16), |
@@ -1295,8 +1267,7 @@ discard block |
||
1295 | 1267 | * @return string |
1296 | 1268 | * @throws SodiumException |
1297 | 1269 | */ |
1298 | - public static function secretstream_xchacha20poly1305_push(&$state, $msg, $aad = '', $tag = 0) |
|
1299 | - { |
|
1270 | + public static function secretstream_xchacha20poly1305_push(&$state, $msg, $aad = '', $tag = 0) { |
|
1300 | 1271 | $st = ParagonIE_Sodium_Core_SecretStream_State::fromString($state); |
1301 | 1272 | # crypto_onetimeauth_poly1305_state poly1305_state; |
1302 | 1273 | # unsigned char block[64U]; |
@@ -1424,8 +1395,7 @@ discard block |
||
1424 | 1395 | * @return bool|array{0: string, 1: int} |
1425 | 1396 | * @throws SodiumException |
1426 | 1397 | */ |
1427 | - public static function secretstream_xchacha20poly1305_pull(&$state, $cipher, $aad = '') |
|
1428 | - { |
|
1398 | + public static function secretstream_xchacha20poly1305_pull(&$state, $cipher, $aad = '') { |
|
1429 | 1399 | $st = ParagonIE_Sodium_Core_SecretStream_State::fromString($state); |
1430 | 1400 | |
1431 | 1401 | $cipherlen = ParagonIE_Sodium_Core_Util::strlen($cipher); |
@@ -1547,8 +1517,7 @@ discard block |
||
1547 | 1517 | * @return void |
1548 | 1518 | * @throws SodiumException |
1549 | 1519 | */ |
1550 | - public static function secretstream_xchacha20poly1305_rekey(&$state) |
|
1551 | - { |
|
1520 | + public static function secretstream_xchacha20poly1305_rekey(&$state) { |
|
1552 | 1521 | $st = ParagonIE_Sodium_Core_SecretStream_State::fromString($state); |
1553 | 1522 | # unsigned char new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + |
1554 | 1523 | # crypto_secretstream_xchacha20poly1305_INONCEBYTES]; |
@@ -1599,8 +1568,7 @@ discard block |
||
1599 | 1568 | * @throws SodiumException |
1600 | 1569 | * @throws TypeError |
1601 | 1570 | */ |
1602 | - public static function sign_detached($message, $sk) |
|
1603 | - { |
|
1571 | + public static function sign_detached($message, $sk) { |
|
1604 | 1572 | return ParagonIE_Sodium_Core_Ed25519::sign_detached($message, $sk); |
1605 | 1573 | } |
1606 | 1574 | |
@@ -1615,8 +1583,7 @@ discard block |
||
1615 | 1583 | * @throws SodiumException |
1616 | 1584 | * @throws TypeError |
1617 | 1585 | */ |
1618 | - public static function sign($message, $sk) |
|
1619 | - { |
|
1586 | + public static function sign($message, $sk) { |
|
1620 | 1587 | return ParagonIE_Sodium_Core_Ed25519::sign($message, $sk); |
1621 | 1588 | } |
1622 | 1589 | |
@@ -1631,8 +1598,7 @@ discard block |
||
1631 | 1598 | * @throws SodiumException |
1632 | 1599 | * @throws TypeError |
1633 | 1600 | */ |
1634 | - public static function sign_open($signedMessage, $pk) |
|
1635 | - { |
|
1601 | + public static function sign_open($signedMessage, $pk) { |
|
1636 | 1602 | return ParagonIE_Sodium_Core_Ed25519::sign_open($signedMessage, $pk); |
1637 | 1603 | } |
1638 | 1604 | |
@@ -1648,8 +1614,7 @@ discard block |
||
1648 | 1614 | * @throws SodiumException |
1649 | 1615 | * @throws TypeError |
1650 | 1616 | */ |
1651 | - public static function sign_verify_detached($signature, $message, $pk) |
|
1652 | - { |
|
1617 | + public static function sign_verify_detached($signature, $message, $pk) { |
|
1653 | 1618 | return ParagonIE_Sodium_Core_Ed25519::verify_detached($signature, $message, $pk); |
1654 | 1619 | } |
1655 | 1620 | } |
@@ -23,8 +23,7 @@ discard block |
||
23 | 23 | * SplFixedArray constructor. |
24 | 24 | * @param int $size |
25 | 25 | */ |
26 | - public function __construct($size = 0) |
|
27 | - { |
|
26 | + public function __construct($size = 0) { |
|
28 | 27 | $this->size = $size; |
29 | 28 | $this->internalArray = array(); |
30 | 29 | } |
@@ -32,16 +31,14 @@ discard block |
||
32 | 31 | /** |
33 | 32 | * @return int |
34 | 33 | */ |
35 | - public function count() |
|
36 | - { |
|
34 | + public function count() { |
|
37 | 35 | return count($this->internalArray); |
38 | 36 | } |
39 | 37 | |
40 | 38 | /** |
41 | 39 | * @return array |
42 | 40 | */ |
43 | - public function toArray() |
|
44 | - { |
|
41 | + public function toArray() { |
|
45 | 42 | ksort($this->internalArray); |
46 | 43 | return (array) $this->internalArray; |
47 | 44 | } |
@@ -52,8 +49,7 @@ discard block |
||
52 | 49 | * @return SplFixedArray |
53 | 50 | * @psalm-suppress MixedAssignment |
54 | 51 | */ |
55 | - public static function fromArray(array $array, $save_indexes = true) |
|
56 | - { |
|
52 | + public static function fromArray(array $array, $save_indexes = true) { |
|
57 | 53 | $self = new SplFixedArray(count($array)); |
58 | 54 | if($save_indexes) { |
59 | 55 | foreach($array as $key => $value) { |
@@ -72,8 +68,7 @@ discard block |
||
72 | 68 | /** |
73 | 69 | * @return int |
74 | 70 | */ |
75 | - public function getSize() |
|
76 | - { |
|
71 | + public function getSize() { |
|
77 | 72 | return $this->size; |
78 | 73 | } |
79 | 74 | |
@@ -81,8 +76,7 @@ discard block |
||
81 | 76 | * @param int $size |
82 | 77 | * @return bool |
83 | 78 | */ |
84 | - public function setSize($size) |
|
85 | - { |
|
79 | + public function setSize($size) { |
|
86 | 80 | $this->size = $size; |
87 | 81 | return true; |
88 | 82 | } |
@@ -91,8 +85,7 @@ discard block |
||
91 | 85 | * @param string|int $index |
92 | 86 | * @return bool |
93 | 87 | */ |
94 | - public function offsetExists($index) |
|
95 | - { |
|
88 | + public function offsetExists($index) { |
|
96 | 89 | return array_key_exists((int) $index, $this->internalArray); |
97 | 90 | } |
98 | 91 | |
@@ -100,8 +93,7 @@ discard block |
||
100 | 93 | * @param string|int $index |
101 | 94 | * @return mixed |
102 | 95 | */ |
103 | - public function offsetGet($index) |
|
104 | - { |
|
96 | + public function offsetGet($index) { |
|
105 | 97 | /** @psalm-suppress MixedReturnStatement */ |
106 | 98 | return $this->internalArray[(int) $index]; |
107 | 99 | } |
@@ -111,16 +103,14 @@ discard block |
||
111 | 103 | * @param mixed $newval |
112 | 104 | * @psalm-suppress MixedAssignment |
113 | 105 | */ |
114 | - public function offsetSet($index, $newval) |
|
115 | - { |
|
106 | + public function offsetSet($index, $newval) { |
|
116 | 107 | $this->internalArray[(int) $index] = $newval; |
117 | 108 | } |
118 | 109 | |
119 | 110 | /** |
120 | 111 | * @param string|int $index |
121 | 112 | */ |
122 | - public function offsetUnset($index) |
|
123 | - { |
|
113 | + public function offsetUnset($index) { |
|
124 | 114 | unset($this->internalArray[(int) $index]); |
125 | 115 | } |
126 | 116 | |
@@ -130,8 +120,7 @@ discard block |
||
130 | 120 | * @return void |
131 | 121 | * @since 5.3.0 |
132 | 122 | */ |
133 | - public function rewind() |
|
134 | - { |
|
123 | + public function rewind() { |
|
135 | 124 | reset($this->internalArray); |
136 | 125 | } |
137 | 126 | |
@@ -141,8 +130,7 @@ discard block |
||
141 | 130 | * @return mixed The current element value. |
142 | 131 | * @since 5.3.0 |
143 | 132 | */ |
144 | - public function current() |
|
145 | - { |
|
133 | + public function current() { |
|
146 | 134 | /** @psalm-suppress MixedReturnStatement */ |
147 | 135 | return current($this->internalArray); |
148 | 136 | } |
@@ -151,16 +139,14 @@ discard block |
||
151 | 139 | * Return current array index |
152 | 140 | * @return int The current array index. |
153 | 141 | */ |
154 | - public function key() |
|
155 | - { |
|
142 | + public function key() { |
|
156 | 143 | return key($this->internalArray); |
157 | 144 | } |
158 | 145 | |
159 | 146 | /** |
160 | 147 | * @return void |
161 | 148 | */ |
162 | - public function next() |
|
163 | - { |
|
149 | + public function next() { |
|
164 | 150 | next($this->internalArray); |
165 | 151 | } |
166 | 152 | |
@@ -169,8 +155,7 @@ discard block |
||
169 | 155 | * @link https://php.net/manual/en/splfixedarray.valid.php |
170 | 156 | * @return bool true if the array contains any more elements, false otherwise. |
171 | 157 | */ |
172 | - public function valid() |
|
173 | - { |
|
158 | + public function valid() { |
|
174 | 159 | if (empty($this->internalArray)) { |
175 | 160 | return false; |
176 | 161 | } |
@@ -182,8 +167,7 @@ discard block |
||
182 | 167 | /** |
183 | 168 | * Do nothing. |
184 | 169 | */ |
185 | - public function __wakeup() |
|
186 | - { |
|
170 | + public function __wakeup() { |
|
187 | 171 | // NOP |
188 | 172 | } |
189 | 173 | } |
190 | 174 | \ No newline at end of file |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | * If you are using this library, you should be using |
13 | 13 | * ParagonIE_Sodium_Compat in your code, not this class. |
14 | 14 | */ |
15 | -abstract class ParagonIE_Sodium_Crypto32 |
|
16 | -{ |
|
15 | +abstract class ParagonIE_Sodium_Crypto32 { |
|
17 | 16 | const aead_chacha20poly1305_KEYBYTES = 32; |
18 | 17 | const aead_chacha20poly1305_NSECBYTES = 0; |
19 | 18 | const aead_chacha20poly1305_NPUBBYTES = 8; |
@@ -381,8 +380,7 @@ discard block |
||
381 | 380 | * @return string |
382 | 381 | * @throws TypeError |
383 | 382 | */ |
384 | - public static function auth($message, $key) |
|
385 | - { |
|
383 | + public static function auth($message, $key) { |
|
386 | 384 | return ParagonIE_Sodium_Core32_Util::substr( |
387 | 385 | hash_hmac('sha512', $message, $key, true), |
388 | 386 | 0, |
@@ -402,8 +400,7 @@ discard block |
||
402 | 400 | * @throws SodiumException |
403 | 401 | * @throws TypeError |
404 | 402 | */ |
405 | - public static function auth_verify($mac, $message, $key) |
|
406 | - { |
|
403 | + public static function auth_verify($mac, $message, $key) { |
|
407 | 404 | return ParagonIE_Sodium_Core32_Util::hashEquals( |
408 | 405 | $mac, |
409 | 406 | self::auth($message, $key) |
@@ -422,8 +419,7 @@ discard block |
||
422 | 419 | * @throws SodiumException |
423 | 420 | * @throws TypeError |
424 | 421 | */ |
425 | - public static function box($plaintext, $nonce, $keypair) |
|
426 | - { |
|
422 | + public static function box($plaintext, $nonce, $keypair) { |
|
427 | 423 | return self::secretbox( |
428 | 424 | $plaintext, |
429 | 425 | $nonce, |
@@ -445,8 +441,7 @@ discard block |
||
445 | 441 | * @throws SodiumException |
446 | 442 | * @throws TypeError |
447 | 443 | */ |
448 | - public static function box_seal($message, $publicKey) |
|
449 | - { |
|
444 | + public static function box_seal($message, $publicKey) { |
|
450 | 445 | /** @var string $ephemeralKeypair */ |
451 | 446 | $ephemeralKeypair = self::box_keypair(); |
452 | 447 | |
@@ -491,8 +486,7 @@ discard block |
||
491 | 486 | * @throws SodiumException |
492 | 487 | * @throws TypeError |
493 | 488 | */ |
494 | - public static function box_seal_open($message, $keypair) |
|
495 | - { |
|
489 | + public static function box_seal_open($message, $keypair) { |
|
496 | 490 | /** @var string $ephemeralPK */ |
497 | 491 | $ephemeralPK = ParagonIE_Sodium_Core32_Util::substr($message, 0, 32); |
498 | 492 | |
@@ -540,8 +534,7 @@ discard block |
||
540 | 534 | * @throws SodiumException |
541 | 535 | * @throws TypeError |
542 | 536 | */ |
543 | - public static function box_beforenm($sk, $pk) |
|
544 | - { |
|
537 | + public static function box_beforenm($sk, $pk) { |
|
545 | 538 | return ParagonIE_Sodium_Core32_HSalsa20::hsalsa20( |
546 | 539 | str_repeat("\x00", 16), |
547 | 540 | self::scalarmult($sk, $pk) |
@@ -556,8 +549,7 @@ discard block |
||
556 | 549 | * @throws SodiumException |
557 | 550 | * @throws TypeError |
558 | 551 | */ |
559 | - public static function box_keypair() |
|
560 | - { |
|
552 | + public static function box_keypair() { |
|
561 | 553 | $sKey = random_bytes(32); |
562 | 554 | $pKey = self::scalarmult_base($sKey); |
563 | 555 | return $sKey . $pKey; |
@@ -569,8 +561,7 @@ discard block |
||
569 | 561 | * @throws SodiumException |
570 | 562 | * @throws TypeError |
571 | 563 | */ |
572 | - public static function box_seed_keypair($seed) |
|
573 | - { |
|
564 | + public static function box_seed_keypair($seed) { |
|
574 | 565 | $sKey = ParagonIE_Sodium_Core32_Util::substr( |
575 | 566 | hash('sha512', $seed, true), |
576 | 567 | 0, |
@@ -588,8 +579,7 @@ discard block |
||
588 | 579 | * @return string |
589 | 580 | * @throws TypeError |
590 | 581 | */ |
591 | - public static function box_keypair_from_secretkey_and_publickey($sKey, $pKey) |
|
592 | - { |
|
582 | + public static function box_keypair_from_secretkey_and_publickey($sKey, $pKey) { |
|
593 | 583 | return ParagonIE_Sodium_Core32_Util::substr($sKey, 0, 32) . |
594 | 584 | ParagonIE_Sodium_Core32_Util::substr($pKey, 0, 32); |
595 | 585 | } |
@@ -602,8 +592,7 @@ discard block |
||
602 | 592 | * @throws RangeException |
603 | 593 | * @throws TypeError |
604 | 594 | */ |
605 | - public static function box_secretkey($keypair) |
|
606 | - { |
|
595 | + public static function box_secretkey($keypair) { |
|
607 | 596 | if (ParagonIE_Sodium_Core32_Util::strlen($keypair) !== 64) { |
608 | 597 | throw new RangeException( |
609 | 598 | 'Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES bytes long.' |
@@ -620,8 +609,7 @@ discard block |
||
620 | 609 | * @throws RangeException |
621 | 610 | * @throws TypeError |
622 | 611 | */ |
623 | - public static function box_publickey($keypair) |
|
624 | - { |
|
612 | + public static function box_publickey($keypair) { |
|
625 | 613 | if (ParagonIE_Sodium_Core32_Util::strlen($keypair) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES) { |
626 | 614 | throw new RangeException( |
627 | 615 | 'Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_KEYPAIRBYTES bytes long.' |
@@ -639,8 +627,7 @@ discard block |
||
639 | 627 | * @throws SodiumException |
640 | 628 | * @throws TypeError |
641 | 629 | */ |
642 | - public static function box_publickey_from_secretkey($sKey) |
|
643 | - { |
|
630 | + public static function box_publickey_from_secretkey($sKey) { |
|
644 | 631 | if (ParagonIE_Sodium_Core32_Util::strlen($sKey) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_SECRETKEYBYTES) { |
645 | 632 | throw new RangeException( |
646 | 633 | 'Must be ParagonIE_Sodium_Compat::CRYPTO_BOX_SECRETKEYBYTES bytes long.' |
@@ -661,8 +648,7 @@ discard block |
||
661 | 648 | * @throws SodiumException |
662 | 649 | * @throws TypeError |
663 | 650 | */ |
664 | - public static function box_open($ciphertext, $nonce, $keypair) |
|
665 | - { |
|
651 | + public static function box_open($ciphertext, $nonce, $keypair) { |
|
666 | 652 | return self::secretbox_open( |
667 | 653 | $ciphertext, |
668 | 654 | $nonce, |
@@ -686,8 +672,7 @@ discard block |
||
686 | 672 | * @throws SodiumException |
687 | 673 | * @throws TypeError |
688 | 674 | */ |
689 | - public static function generichash($message, $key = '', $outlen = 32) |
|
690 | - { |
|
675 | + public static function generichash($message, $key = '', $outlen = 32) { |
|
691 | 676 | // This ensures that ParagonIE_Sodium_Core32_BLAKE2b::$iv is initialized |
692 | 677 | ParagonIE_Sodium_Core32_BLAKE2b::pseudoConstructor(); |
693 | 678 | |
@@ -727,8 +712,7 @@ discard block |
||
727 | 712 | * @throws SodiumException |
728 | 713 | * @throws TypeError |
729 | 714 | */ |
730 | - public static function generichash_final($ctx, $outlen = 32) |
|
731 | - { |
|
715 | + public static function generichash_final($ctx, $outlen = 32) { |
|
732 | 716 | if (!is_string($ctx)) { |
733 | 717 | throw new TypeError('Context must be a string'); |
734 | 718 | } |
@@ -757,8 +741,7 @@ discard block |
||
757 | 741 | * @throws SodiumException |
758 | 742 | * @throws TypeError |
759 | 743 | */ |
760 | - public static function generichash_init($key = '', $outputLength = 32) |
|
761 | - { |
|
744 | + public static function generichash_init($key = '', $outputLength = 32) { |
|
762 | 745 | // This ensures that ParagonIE_Sodium_Core32_BLAKE2b::$iv is initialized |
763 | 746 | ParagonIE_Sodium_Core32_BLAKE2b::pseudoConstructor(); |
764 | 747 | |
@@ -834,8 +817,7 @@ discard block |
||
834 | 817 | * @throws SodiumException |
835 | 818 | * @throws TypeError |
836 | 819 | */ |
837 | - public static function generichash_update($ctx, $message) |
|
838 | - { |
|
820 | + public static function generichash_update($ctx, $message) { |
|
839 | 821 | // This ensures that ParagonIE_Sodium_Core32_BLAKE2b::$iv is initialized |
840 | 822 | ParagonIE_Sodium_Core32_BLAKE2b::pseudoConstructor(); |
841 | 823 | |
@@ -863,8 +845,7 @@ discard block |
||
863 | 845 | * @throws SodiumException |
864 | 846 | * @throws TypeError |
865 | 847 | */ |
866 | - public static function keyExchange($my_sk, $their_pk, $client_pk, $server_pk) |
|
867 | - { |
|
848 | + public static function keyExchange($my_sk, $their_pk, $client_pk, $server_pk) { |
|
868 | 849 | return self::generichash( |
869 | 850 | self::scalarmult($my_sk, $their_pk) . |
870 | 851 | $client_pk . |
@@ -884,8 +865,7 @@ discard block |
||
884 | 865 | * @throws SodiumException |
885 | 866 | * @throws TypeError |
886 | 867 | */ |
887 | - public static function scalarmult($sKey, $pKey) |
|
888 | - { |
|
868 | + public static function scalarmult($sKey, $pKey) { |
|
889 | 869 | $q = ParagonIE_Sodium_Core32_X25519::crypto_scalarmult_curve25519_ref10($sKey, $pKey); |
890 | 870 | self::scalarmult_throw_if_zero($q); |
891 | 871 | return $q; |
@@ -901,8 +881,7 @@ discard block |
||
901 | 881 | * @throws SodiumException |
902 | 882 | * @throws TypeError |
903 | 883 | */ |
904 | - public static function scalarmult_base($secret) |
|
905 | - { |
|
884 | + public static function scalarmult_base($secret) { |
|
906 | 885 | $q = ParagonIE_Sodium_Core32_X25519::crypto_scalarmult_curve25519_ref10_base($secret); |
907 | 886 | self::scalarmult_throw_if_zero($q); |
908 | 887 | return $q; |
@@ -916,8 +895,7 @@ discard block |
||
916 | 895 | * @throws SodiumException |
917 | 896 | * @throws TypeError |
918 | 897 | */ |
919 | - protected static function scalarmult_throw_if_zero($q) |
|
920 | - { |
|
898 | + protected static function scalarmult_throw_if_zero($q) { |
|
921 | 899 | $d = 0; |
922 | 900 | for ($i = 0; $i < self::box_curve25519xsalsa20poly1305_SECRETKEYBYTES; ++$i) { |
923 | 901 | $d |= ParagonIE_Sodium_Core32_Util::chrToInt($q[$i]); |
@@ -941,8 +919,7 @@ discard block |
||
941 | 919 | * @throws SodiumException |
942 | 920 | * @throws TypeError |
943 | 921 | */ |
944 | - public static function secretbox($plaintext, $nonce, $key) |
|
945 | - { |
|
922 | + public static function secretbox($plaintext, $nonce, $key) { |
|
946 | 923 | /** @var string $subkey */ |
947 | 924 | $subkey = ParagonIE_Sodium_Core32_HSalsa20::hsalsa20($nonce, $key); |
948 | 925 | |
@@ -1016,8 +993,7 @@ discard block |
||
1016 | 993 | * @throws SodiumException |
1017 | 994 | * @throws TypeError |
1018 | 995 | */ |
1019 | - public static function secretbox_open($ciphertext, $nonce, $key) |
|
1020 | - { |
|
996 | + public static function secretbox_open($ciphertext, $nonce, $key) { |
|
1021 | 997 | /** @var string $mac */ |
1022 | 998 | $mac = ParagonIE_Sodium_Core32_Util::substr( |
1023 | 999 | $ciphertext, |
@@ -1089,8 +1065,7 @@ discard block |
||
1089 | 1065 | * @throws SodiumException |
1090 | 1066 | * @throws TypeError |
1091 | 1067 | */ |
1092 | - public static function secretbox_xchacha20poly1305($plaintext, $nonce, $key) |
|
1093 | - { |
|
1068 | + public static function secretbox_xchacha20poly1305($plaintext, $nonce, $key) { |
|
1094 | 1069 | /** @var string $subkey */ |
1095 | 1070 | $subkey = ParagonIE_Sodium_Core32_HChaCha20::hChaCha20( |
1096 | 1071 | ParagonIE_Sodium_Core32_Util::substr($nonce, 0, 16), |
@@ -1168,8 +1143,7 @@ discard block |
||
1168 | 1143 | * @throws SodiumException |
1169 | 1144 | * @throws TypeError |
1170 | 1145 | */ |
1171 | - public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key) |
|
1172 | - { |
|
1146 | + public static function secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key) { |
|
1173 | 1147 | /** @var string $mac */ |
1174 | 1148 | $mac = ParagonIE_Sodium_Core32_Util::substr( |
1175 | 1149 | $ciphertext, |
@@ -1237,8 +1211,7 @@ discard block |
||
1237 | 1211 | * @throws Exception |
1238 | 1212 | * @throws SodiumException |
1239 | 1213 | */ |
1240 | - public static function secretstream_xchacha20poly1305_init_push($key) |
|
1241 | - { |
|
1214 | + public static function secretstream_xchacha20poly1305_init_push($key) { |
|
1242 | 1215 | # randombytes_buf(out, crypto_secretstream_xchacha20poly1305_HEADERBYTES); |
1243 | 1216 | $out = random_bytes(24); |
1244 | 1217 | |
@@ -1267,8 +1240,7 @@ discard block |
||
1267 | 1240 | * @return string Returns a state. |
1268 | 1241 | * @throws Exception |
1269 | 1242 | */ |
1270 | - public static function secretstream_xchacha20poly1305_init_pull($key, $header) |
|
1271 | - { |
|
1243 | + public static function secretstream_xchacha20poly1305_init_pull($key, $header) { |
|
1272 | 1244 | # crypto_core_hchacha20(state->k, in, k, NULL); |
1273 | 1245 | $subkey = ParagonIE_Sodium_Core32_HChaCha20::hChaCha20( |
1274 | 1246 | ParagonIE_Sodium_Core32_Util::substr($header, 0, 16), |
@@ -1294,8 +1266,7 @@ discard block |
||
1294 | 1266 | * @return string |
1295 | 1267 | * @throws SodiumException |
1296 | 1268 | */ |
1297 | - public static function secretstream_xchacha20poly1305_push(&$state, $msg, $aad = '', $tag = 0) |
|
1298 | - { |
|
1269 | + public static function secretstream_xchacha20poly1305_push(&$state, $msg, $aad = '', $tag = 0) { |
|
1299 | 1270 | $st = ParagonIE_Sodium_Core32_SecretStream_State::fromString($state); |
1300 | 1271 | # crypto_onetimeauth_poly1305_state poly1305_state; |
1301 | 1272 | # unsigned char block[64U]; |
@@ -1423,8 +1394,7 @@ discard block |
||
1423 | 1394 | * @return bool|array{0: string, 1: int} |
1424 | 1395 | * @throws SodiumException |
1425 | 1396 | */ |
1426 | - public static function secretstream_xchacha20poly1305_pull(&$state, $cipher, $aad = '') |
|
1427 | - { |
|
1397 | + public static function secretstream_xchacha20poly1305_pull(&$state, $cipher, $aad = '') { |
|
1428 | 1398 | $st = ParagonIE_Sodium_Core32_SecretStream_State::fromString($state); |
1429 | 1399 | |
1430 | 1400 | $cipherlen = ParagonIE_Sodium_Core32_Util::strlen($cipher); |
@@ -1546,8 +1516,7 @@ discard block |
||
1546 | 1516 | * @return void |
1547 | 1517 | * @throws SodiumException |
1548 | 1518 | */ |
1549 | - public static function secretstream_xchacha20poly1305_rekey(&$state) |
|
1550 | - { |
|
1519 | + public static function secretstream_xchacha20poly1305_rekey(&$state) { |
|
1551 | 1520 | $st = ParagonIE_Sodium_Core32_SecretStream_State::fromString($state); |
1552 | 1521 | # unsigned char new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + |
1553 | 1522 | # crypto_secretstream_xchacha20poly1305_INONCEBYTES]; |
@@ -1598,8 +1567,7 @@ discard block |
||
1598 | 1567 | * @throws SodiumException |
1599 | 1568 | * @throws TypeError |
1600 | 1569 | */ |
1601 | - public static function sign_detached($message, $sk) |
|
1602 | - { |
|
1570 | + public static function sign_detached($message, $sk) { |
|
1603 | 1571 | return ParagonIE_Sodium_Core32_Ed25519::sign_detached($message, $sk); |
1604 | 1572 | } |
1605 | 1573 | |
@@ -1614,8 +1582,7 @@ discard block |
||
1614 | 1582 | * @throws SodiumException |
1615 | 1583 | * @throws TypeError |
1616 | 1584 | */ |
1617 | - public static function sign($message, $sk) |
|
1618 | - { |
|
1585 | + public static function sign($message, $sk) { |
|
1619 | 1586 | return ParagonIE_Sodium_Core32_Ed25519::sign($message, $sk); |
1620 | 1587 | } |
1621 | 1588 | |
@@ -1630,8 +1597,7 @@ discard block |
||
1630 | 1597 | * @throws SodiumException |
1631 | 1598 | * @throws TypeError |
1632 | 1599 | */ |
1633 | - public static function sign_open($signedMessage, $pk) |
|
1634 | - { |
|
1600 | + public static function sign_open($signedMessage, $pk) { |
|
1635 | 1601 | return ParagonIE_Sodium_Core32_Ed25519::sign_open($signedMessage, $pk); |
1636 | 1602 | } |
1637 | 1603 | |
@@ -1647,8 +1613,7 @@ discard block |
||
1647 | 1613 | * @throws SodiumException |
1648 | 1614 | * @throws TypeError |
1649 | 1615 | */ |
1650 | - public static function sign_verify_detached($signature, $message, $pk) |
|
1651 | - { |
|
1616 | + public static function sign_verify_detached($signature, $message, $pk) { |
|
1652 | 1617 | return ParagonIE_Sodium_Core32_Ed25519::verify_detached($signature, $message, $pk); |
1653 | 1618 | } |
1654 | 1619 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_Ed25519 |
9 | 9 | */ |
10 | -abstract class ParagonIE_Sodium_Core_Ed25519 extends ParagonIE_Sodium_Core_Curve25519 |
|
11 | -{ |
|
10 | +abstract class ParagonIE_Sodium_Core_Ed25519 extends ParagonIE_Sodium_Core_Curve25519 { |
|
12 | 11 | const KEYPAIR_BYTES = 96; |
13 | 12 | const SEED_BYTES = 32; |
14 | 13 | const SCALAR_BYTES = 32; |
@@ -21,8 +20,7 @@ discard block |
||
21 | 20 | * @throws SodiumException |
22 | 21 | * @throws TypeError |
23 | 22 | */ |
24 | - public static function keypair() |
|
25 | - { |
|
23 | + public static function keypair() { |
|
26 | 24 | $seed = random_bytes(self::SEED_BYTES); |
27 | 25 | $pk = ''; |
28 | 26 | $sk = ''; |
@@ -40,8 +38,7 @@ discard block |
||
40 | 38 | * @throws SodiumException |
41 | 39 | * @throws TypeError |
42 | 40 | */ |
43 | - public static function seed_keypair(&$pk, &$sk, $seed) |
|
44 | - { |
|
41 | + public static function seed_keypair(&$pk, &$sk, $seed) { |
|
45 | 42 | if (self::strlen($seed) !== self::SEED_BYTES) { |
46 | 43 | throw new RangeException('crypto_sign keypair seed must be 32 bytes long'); |
47 | 44 | } |
@@ -59,8 +56,7 @@ discard block |
||
59 | 56 | * @return string |
60 | 57 | * @throws TypeError |
61 | 58 | */ |
62 | - public static function secretkey($keypair) |
|
63 | - { |
|
59 | + public static function secretkey($keypair) { |
|
64 | 60 | if (self::strlen($keypair) !== self::KEYPAIR_BYTES) { |
65 | 61 | throw new RangeException('crypto_sign keypair must be 96 bytes long'); |
66 | 62 | } |
@@ -74,8 +70,7 @@ discard block |
||
74 | 70 | * @return string |
75 | 71 | * @throws TypeError |
76 | 72 | */ |
77 | - public static function publickey($keypair) |
|
78 | - { |
|
73 | + public static function publickey($keypair) { |
|
79 | 74 | if (self::strlen($keypair) !== self::KEYPAIR_BYTES) { |
80 | 75 | throw new RangeException('crypto_sign keypair must be 96 bytes long'); |
81 | 76 | } |
@@ -90,8 +85,7 @@ discard block |
||
90 | 85 | * @throws SodiumException |
91 | 86 | * @throws TypeError |
92 | 87 | */ |
93 | - public static function publickey_from_secretkey($sk) |
|
94 | - { |
|
88 | + public static function publickey_from_secretkey($sk) { |
|
95 | 89 | /** @var string $sk */ |
96 | 90 | $sk = hash('sha512', self::substr($sk, 0, 32), true); |
97 | 91 | $sk[0] = self::intToChr( |
@@ -109,8 +103,7 @@ discard block |
||
109 | 103 | * @throws SodiumException |
110 | 104 | * @throws TypeError |
111 | 105 | */ |
112 | - public static function pk_to_curve25519($pk) |
|
113 | - { |
|
106 | + public static function pk_to_curve25519($pk) { |
|
114 | 107 | if (self::small_order($pk)) { |
115 | 108 | throw new SodiumException('Public key is on a small order'); |
116 | 109 | } |
@@ -150,8 +143,7 @@ discard block |
||
150 | 143 | * @throws SodiumException |
151 | 144 | * @throws TypeError |
152 | 145 | */ |
153 | - public static function sk_to_pk($sk) |
|
154 | - { |
|
146 | + public static function sk_to_pk($sk) { |
|
155 | 147 | return self::ge_p3_tobytes( |
156 | 148 | self::ge_scalarmult_base( |
157 | 149 | self::substr($sk, 0, 32) |
@@ -168,8 +160,7 @@ discard block |
||
168 | 160 | * @throws SodiumException |
169 | 161 | * @throws TypeError |
170 | 162 | */ |
171 | - public static function sign($message, $sk) |
|
172 | - { |
|
163 | + public static function sign($message, $sk) { |
|
173 | 164 | /** @var string $signature */ |
174 | 165 | $signature = self::sign_detached($message, $sk); |
175 | 166 | return $signature . $message; |
@@ -184,8 +175,7 @@ discard block |
||
184 | 175 | * @throws SodiumException |
185 | 176 | * @throws TypeError |
186 | 177 | */ |
187 | - public static function sign_open($message, $pk) |
|
188 | - { |
|
178 | + public static function sign_open($message, $pk) { |
|
189 | 179 | /** @var string $signature */ |
190 | 180 | $signature = self::substr($message, 0, 64); |
191 | 181 | |
@@ -207,8 +197,7 @@ discard block |
||
207 | 197 | * @throws SodiumException |
208 | 198 | * @throws TypeError |
209 | 199 | */ |
210 | - public static function sign_detached($message, $sk) |
|
211 | - { |
|
200 | + public static function sign_detached($message, $sk) { |
|
212 | 201 | # crypto_hash_sha512(az, sk, 32); |
213 | 202 | $az = hash('sha512', self::substr($sk, 0, 32), true); |
214 | 203 | |
@@ -272,8 +261,7 @@ discard block |
||
272 | 261 | * @throws SodiumException |
273 | 262 | * @throws TypeError |
274 | 263 | */ |
275 | - public static function verify_detached($sig, $message, $pk) |
|
276 | - { |
|
264 | + public static function verify_detached($sig, $message, $pk) { |
|
277 | 265 | if (self::strlen($sig) < 64) { |
278 | 266 | throw new SodiumException('Signature is too short'); |
279 | 267 | } |
@@ -339,8 +327,7 @@ discard block |
||
339 | 327 | * @throws SodiumException |
340 | 328 | * @throws TypeError |
341 | 329 | */ |
342 | - public static function check_S_lt_L($S) |
|
343 | - { |
|
330 | + public static function check_S_lt_L($S) { |
|
344 | 331 | if (self::strlen($S) < 32) { |
345 | 332 | throw new SodiumException('Signature must be 32 bytes'); |
346 | 333 | } |
@@ -375,8 +362,7 @@ discard block |
||
375 | 362 | * @throws SodiumException |
376 | 363 | * @throws TypeError |
377 | 364 | */ |
378 | - public static function small_order($R) |
|
379 | - { |
|
365 | + public static function small_order($R) { |
|
380 | 366 | /** @var array<int, array<int, int>> $blocklist */ |
381 | 367 | $blocklist = array( |
382 | 368 | /* 0 (order 4) */ |
@@ -484,8 +470,7 @@ discard block |
||
484 | 470 | * @return string |
485 | 471 | * @throws SodiumException |
486 | 472 | */ |
487 | - public static function scalar_complement($s) |
|
488 | - { |
|
473 | + public static function scalar_complement($s) { |
|
489 | 474 | $t_ = self::L . str_repeat("\x00", 32); |
490 | 475 | sodium_increment($t_); |
491 | 476 | $s_ = $s . str_repeat("\x00", 32); |
@@ -497,8 +482,7 @@ discard block |
||
497 | 482 | * @return string |
498 | 483 | * @throws SodiumException |
499 | 484 | */ |
500 | - public static function scalar_random() |
|
501 | - { |
|
485 | + public static function scalar_random() { |
|
502 | 486 | do { |
503 | 487 | $r = ParagonIE_Sodium_Compat::randombytes_buf(self::SCALAR_BYTES); |
504 | 488 | $r[self::SCALAR_BYTES - 1] = self::intToChr( |
@@ -515,8 +499,7 @@ discard block |
||
515 | 499 | * @return string |
516 | 500 | * @throws SodiumException |
517 | 501 | */ |
518 | - public static function scalar_negate($s) |
|
519 | - { |
|
502 | + public static function scalar_negate($s) { |
|
520 | 503 | $t_ = self::L . str_repeat("\x00", 32) ; |
521 | 504 | $s_ = $s . str_repeat("\x00", 32) ; |
522 | 505 | ParagonIE_Sodium_Compat::sub($t_, $s_); |
@@ -529,8 +512,7 @@ discard block |
||
529 | 512 | * @return string |
530 | 513 | * @throws SodiumException |
531 | 514 | */ |
532 | - public static function scalar_add($a, $b) |
|
533 | - { |
|
515 | + public static function scalar_add($a, $b) { |
|
534 | 516 | $a_ = $a . str_repeat("\x00", 32); |
535 | 517 | $b_ = $b . str_repeat("\x00", 32); |
536 | 518 | ParagonIE_Sodium_Compat::add($a_, $b_); |
@@ -543,8 +525,7 @@ discard block |
||
543 | 525 | * @return string |
544 | 526 | * @throws SodiumException |
545 | 527 | */ |
546 | - public static function scalar_sub($x, $y) |
|
547 | - { |
|
528 | + public static function scalar_sub($x, $y) { |
|
548 | 529 | $yn = self::scalar_negate($y); |
549 | 530 | return self::scalar_add($x, $yn); |
550 | 531 | } |
@@ -9,8 +9,7 @@ discard block |
||
9 | 9 | * |
10 | 10 | * Only uses 32-bit arithmetic, while the original SipHash used 64-bit integers |
11 | 11 | */ |
12 | -class ParagonIE_Sodium_Core_SipHash extends ParagonIE_Sodium_Core_Util |
|
13 | -{ |
|
12 | +class ParagonIE_Sodium_Core_SipHash extends ParagonIE_Sodium_Core_Util { |
|
14 | 13 | /** |
15 | 14 | * @internal You should not use this directly from another application |
16 | 15 | * |
@@ -18,8 +17,7 @@ discard block |
||
18 | 17 | * @return int[] |
19 | 18 | * |
20 | 19 | */ |
21 | - public static function sipRound(array $v) |
|
22 | - { |
|
20 | + public static function sipRound(array $v) { |
|
23 | 21 | # v0 += v1; |
24 | 22 | list($v[0], $v[1]) = self::add( |
25 | 23 | array($v[0], $v[1]), |
@@ -90,8 +88,7 @@ discard block |
||
90 | 88 | * @param int[] $b |
91 | 89 | * @return array<int, mixed> |
92 | 90 | */ |
93 | - public static function add(array $a, array $b) |
|
94 | - { |
|
91 | + public static function add(array $a, array $b) { |
|
95 | 92 | /** @var int $x1 */ |
96 | 93 | $x1 = $a[1] + $b[1]; |
97 | 94 | /** @var int $c */ |
@@ -112,8 +109,7 @@ discard block |
||
112 | 109 | * @param int $c |
113 | 110 | * @return array<int, mixed> |
114 | 111 | */ |
115 | - public static function rotl_64($int0, $int1, $c) |
|
116 | - { |
|
112 | + public static function rotl_64($int0, $int1, $c) { |
|
117 | 113 | $int0 &= 0xffffffff; |
118 | 114 | $int1 &= 0xffffffff; |
119 | 115 | $c &= 63; |
@@ -160,8 +156,7 @@ discard block |
||
160 | 156 | * @throws SodiumException |
161 | 157 | * @throws TypeError |
162 | 158 | */ |
163 | - public static function sipHash24($in, $key) |
|
164 | - { |
|
159 | + public static function sipHash24($in, $key) { |
|
165 | 160 | $inlen = self::strlen($in); |
166 | 161 | |
167 | 162 | # /* "somepseudorandomlygeneratedbytes" */ |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_XChaCha20 |
9 | 9 | */ |
10 | -class ParagonIE_Sodium_Core_XChaCha20 extends ParagonIE_Sodium_Core_HChaCha20 |
|
11 | -{ |
|
10 | +class ParagonIE_Sodium_Core_XChaCha20 extends ParagonIE_Sodium_Core_HChaCha20 { |
|
12 | 11 | /** |
13 | 12 | * @internal You should not use this directly from another application |
14 | 13 | * |
@@ -19,8 +18,7 @@ discard block |
||
19 | 18 | * @throws SodiumException |
20 | 19 | * @throws TypeError |
21 | 20 | */ |
22 | - public static function stream($len = 64, $nonce = '', $key = '') |
|
23 | - { |
|
21 | + public static function stream($len = 64, $nonce = '', $key = '') { |
|
24 | 22 | if (self::strlen($nonce) !== 24) { |
25 | 23 | throw new SodiumException('Nonce must be 24 bytes long'); |
26 | 24 | } |
@@ -46,8 +44,7 @@ discard block |
||
46 | 44 | * @throws SodiumException |
47 | 45 | * @throws TypeError |
48 | 46 | */ |
49 | - public static function ietfStream($len = 64, $nonce = '', $key = '') |
|
50 | - { |
|
47 | + public static function ietfStream($len = 64, $nonce = '', $key = '') { |
|
51 | 48 | if (self::strlen($nonce) !== 24) { |
52 | 49 | throw new SodiumException('Nonce must be 24 bytes long'); |
53 | 50 | } |
@@ -74,8 +71,7 @@ discard block |
||
74 | 71 | * @throws SodiumException |
75 | 72 | * @throws TypeError |
76 | 73 | */ |
77 | - public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
78 | - { |
|
74 | + public static function streamXorIc($message, $nonce = '', $key = '', $ic = '') { |
|
79 | 75 | if (self::strlen($nonce) !== 24) { |
80 | 76 | throw new SodiumException('Nonce must be 24 bytes long'); |
81 | 77 | } |
@@ -100,8 +96,7 @@ discard block |
||
100 | 96 | * @throws SodiumException |
101 | 97 | * @throws TypeError |
102 | 98 | */ |
103 | - public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '') |
|
104 | - { |
|
99 | + public static function ietfStreamXorIc($message, $nonce = '', $key = '', $ic = '') { |
|
105 | 100 | if (self::strlen($nonce) !== 24) { |
106 | 101 | throw new SodiumException('Nonce must be 24 bytes long'); |
107 | 102 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_X25519 |
9 | 9 | */ |
10 | -abstract class ParagonIE_Sodium_Core_X25519 extends ParagonIE_Sodium_Core_Curve25519 |
|
11 | -{ |
|
10 | +abstract class ParagonIE_Sodium_Core_X25519 extends ParagonIE_Sodium_Core_Curve25519 { |
|
12 | 11 | /** |
13 | 12 | * Alters the objects passed to this method in place. |
14 | 13 | * |
@@ -84,8 +83,7 @@ discard block |
||
84 | 83 | * @param ParagonIE_Sodium_Core_Curve25519_Fe $f |
85 | 84 | * @return ParagonIE_Sodium_Core_Curve25519_Fe |
86 | 85 | */ |
87 | - public static function fe_mul121666(ParagonIE_Sodium_Core_Curve25519_Fe $f) |
|
88 | - { |
|
86 | + public static function fe_mul121666(ParagonIE_Sodium_Core_Curve25519_Fe $f) { |
|
89 | 87 | $h = array( |
90 | 88 | self::mul((int) $f[0], 121666, 17), |
91 | 89 | self::mul((int) $f[1], 121666, 17), |
@@ -158,8 +156,7 @@ discard block |
||
158 | 156 | * @throws SodiumException |
159 | 157 | * @throws TypeError |
160 | 158 | */ |
161 | - public static function crypto_scalarmult_curve25519_ref10($n, $p) |
|
162 | - { |
|
159 | + public static function crypto_scalarmult_curve25519_ref10($n, $p) { |
|
163 | 160 | # for (i = 0;i < 32;++i) e[i] = n[i]; |
164 | 161 | $e = '' . $n; |
165 | 162 | # e[0] &= 248; |
@@ -297,8 +294,7 @@ discard block |
||
297 | 294 | * @throws SodiumException |
298 | 295 | * @throws TypeError |
299 | 296 | */ |
300 | - public static function crypto_scalarmult_curve25519_ref10_base($n) |
|
301 | - { |
|
297 | + public static function crypto_scalarmult_curve25519_ref10_base($n) { |
|
302 | 298 | # for (i = 0;i < 32;++i) e[i] = n[i]; |
303 | 299 | $e = '' . $n; |
304 | 300 |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_Poly1305 |
9 | 9 | */ |
10 | -abstract class ParagonIE_Sodium_Core_Poly1305 extends ParagonIE_Sodium_Core_Util |
|
11 | -{ |
|
10 | +abstract class ParagonIE_Sodium_Core_Poly1305 extends ParagonIE_Sodium_Core_Util { |
|
12 | 11 | const BLOCK_SIZE = 16; |
13 | 12 | |
14 | 13 | /** |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | * @throws SodiumException |
21 | 20 | * @throws TypeError |
22 | 21 | */ |
23 | - public static function onetimeauth($m, $key) |
|
24 | - { |
|
22 | + public static function onetimeauth($m, $key) { |
|
25 | 23 | if (self::strlen($key) < 32) { |
26 | 24 | throw new InvalidArgumentException( |
27 | 25 | 'Key must be 32 bytes long.' |
@@ -45,8 +43,7 @@ discard block |
||
45 | 43 | * @throws SodiumException |
46 | 44 | * @throws TypeError |
47 | 45 | */ |
48 | - public static function onetimeauth_verify($mac, $m, $key) |
|
49 | - { |
|
46 | + public static function onetimeauth_verify($mac, $m, $key) { |
|
50 | 47 | if (self::strlen($key) < 32) { |
51 | 48 | throw new InvalidArgumentException( |
52 | 49 | 'Key must be 32 bytes long.' |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Class ParagonIE_Sodium_Core_XSalsa20 |
9 | 9 | */ |
10 | -abstract class ParagonIE_Sodium_Core_XSalsa20 extends ParagonIE_Sodium_Core_HSalsa20 |
|
11 | -{ |
|
10 | +abstract class ParagonIE_Sodium_Core_XSalsa20 extends ParagonIE_Sodium_Core_HSalsa20 { |
|
12 | 11 | /** |
13 | 12 | * Expand a key and nonce into an xsalsa20 keystream. |
14 | 13 | * |
@@ -21,8 +20,7 @@ discard block |
||
21 | 20 | * @throws SodiumException |
22 | 21 | * @throws TypeError |
23 | 22 | */ |
24 | - public static function xsalsa20($len, $nonce, $key) |
|
25 | - { |
|
23 | + public static function xsalsa20($len, $nonce, $key) { |
|
26 | 24 | $ret = self::salsa20( |
27 | 25 | $len, |
28 | 26 | self::substr($nonce, 16, 8), |
@@ -43,8 +41,7 @@ discard block |
||
43 | 41 | * @throws SodiumException |
44 | 42 | * @throws TypeError |
45 | 43 | */ |
46 | - public static function xsalsa20_xor($message, $nonce, $key) |
|
47 | - { |
|
44 | + public static function xsalsa20_xor($message, $nonce, $key) { |
|
48 | 45 | return self::xorStrings( |
49 | 46 | $message, |
50 | 47 | self::xsalsa20( |