@@ -207,9 +207,6 @@ public static function base642bin(
207207
208208 /** @var string $encoded */
209209 $ encoded = (string ) $ encoded ;
210- if (ParagonIE_Sodium_Core_Util::strlen ($ encoded ) === 0 ) {
211- return '' ;
212- }
213210
214211 // Just strip before decoding
215212 if (!empty ($ ignore )) {
@@ -233,7 +230,7 @@ public static function base642bin(
233230 if ($ ex instanceof SodiumException) {
234231 throw $ ex ;
235232 }
236- throw new SodiumException ('invalid base64 string ' );
233+ throw new SodiumException ('invalid base64 string ' , 0 , $ ex );
237234 }
238235 }
239236
@@ -359,7 +356,7 @@ public static function crypto_aead_aegis128l_decrypt(
359356
360357 /* Input validation: */
361358 if (ParagonIE_Sodium_Core_Util::strlen ($ nonce ) !== self ::CRYPTO_AEAD_AEGIS128L_NPUBBYTES ) {
362- throw new SodiumException ('Nonce must be CRYPTO_AEAD_AEGIS_128L_NPUBBYTES long ' );
359+ throw new SodiumException ('Nonce must be CRYPTO_AEAD_AEGIS128L_NPUBBYTES long ' );
363360 }
364361 if (ParagonIE_Sodium_Core_Util::strlen ($ key ) !== self ::CRYPTO_AEAD_AEGIS128L_KEYBYTES ) {
365362 throw new SodiumException ('Key must be CRYPTO_AEAD_AEGIS128L_KEYBYTES long ' );
@@ -413,7 +410,7 @@ public static function crypto_aead_aegis128l_encrypt(
413410
414411 /* Input validation: */
415412 if (ParagonIE_Sodium_Core_Util::strlen ($ nonce ) !== self ::CRYPTO_AEAD_AEGIS128L_NPUBBYTES ) {
416- throw new SodiumException ('Nonce must be CRYPTO_AEAD_AEGIS128L_KEYBYTES long ' );
413+ throw new SodiumException ('Nonce must be CRYPTO_AEAD_AEGIS128L_NPUBBYTES long ' );
417414 }
418415 if (ParagonIE_Sodium_Core_Util::strlen ($ key ) !== self ::CRYPTO_AEAD_AEGIS128L_KEYBYTES ) {
419416 throw new SodiumException ('Key must be CRYPTO_AEAD_AEGIS128L_KEYBYTES long ' );
@@ -522,10 +519,10 @@ public static function crypto_aead_aegis256_encrypt(
522519
523520 /* Input validation: */
524521 if (ParagonIE_Sodium_Core_Util::strlen ($ nonce ) !== self ::CRYPTO_AEAD_AEGIS256_NPUBBYTES ) {
525- throw new SodiumException ('Nonce must be CRYPTO_AEAD_AEGIS128L_KEYBYTES long ' );
522+ throw new SodiumException ('Nonce must be CRYPTO_AEAD_AEGIS256_NPUBBYTES long ' );
526523 }
527524 if (ParagonIE_Sodium_Core_Util::strlen ($ key ) !== self ::CRYPTO_AEAD_AEGIS256_KEYBYTES ) {
528- throw new SodiumException ('Key must be CRYPTO_AEAD_AEGIS128L_KEYBYTES long ' );
525+ throw new SodiumException ('Key must be CRYPTO_AEAD_AEGIS256_KEYBYTES long ' );
529526 }
530527
531528 list ($ ct , $ tag ) = ParagonIE_Sodium_Core_AEGIS256::encrypt ($ plaintext , $ assocData , $ key , $ nonce );
@@ -565,6 +562,9 @@ public static function crypto_aead_aes256gcm_is_available()
565562 // OpenSSL doesn't support AEAD before 7.1.0
566563 return false ;
567564 }
565+ if (!extension_loaded ('openssl ' )) {
566+ return false ;
567+ }
568568 if (!is_callable ('openssl_encrypt ' ) || !is_callable ('openssl_decrypt ' )) {
569569 // OpenSSL isn't installed
570570 return false ;
@@ -618,6 +618,9 @@ public static function crypto_aead_aes256gcm_decrypt(
618618 if (ParagonIE_Sodium_Core_Util::strlen ($ ciphertext ) < self ::CRYPTO_AEAD_AES256GCM_ABYTES ) {
619619 throw new SodiumException ('Message must be at least CRYPTO_AEAD_AES256GCM_ABYTES long ' );
620620 }
621+ if (!extension_loaded ('openssl ' )) {
622+ throw new SodiumException ('The OpenSSL extension is not installed ' );
623+ }
621624 if (!is_callable ('openssl_decrypt ' )) {
622625 throw new SodiumException ('The OpenSSL extension is not installed, or openssl_decrypt() is not available ' );
623626 }
@@ -678,6 +681,9 @@ public static function crypto_aead_aes256gcm_encrypt(
678681 throw new SodiumException ('Key must be CRYPTO_AEAD_AES256GCM_KEYBYTES long ' );
679682 }
680683
684+ if (!extension_loaded ('openssl ' )) {
685+ throw new SodiumException ('The OpenSSL extension is not installed ' );
686+ }
681687 if (!is_callable ('openssl_encrypt ' )) {
682688 throw new SodiumException ('The OpenSSL extension is not installed, or openssl_encrypt() is not available ' );
683689 }
@@ -826,10 +832,10 @@ public static function crypto_aead_chacha20poly1305_encrypt(
826832
827833 /* Input validation: */
828834 if (ParagonIE_Sodium_Core_Util::strlen ($ nonce ) !== self ::CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES ) {
829- throw new SodiumException ('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES long ' );
835+ throw new SodiumException ('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES long ' );
830836 }
831837 if (ParagonIE_Sodium_Core_Util::strlen ($ key ) !== self ::CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES ) {
832- throw new SodiumException ('Key must be CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES long ' );
838+ throw new SodiumException ('Key must be CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES long ' );
833839 }
834840
835841 if (self ::useNewSodiumAPI ()) {
@@ -904,10 +910,10 @@ public static function crypto_aead_chacha20poly1305_ietf_decrypt(
904910 throw new SodiumException ('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES long ' );
905911 }
906912 if (ParagonIE_Sodium_Core_Util::strlen ($ key ) !== self ::CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES ) {
907- throw new SodiumException ('Key must be CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES long ' );
913+ throw new SodiumException ('Key must be CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES long ' );
908914 }
909915 if (ParagonIE_Sodium_Core_Util::strlen ($ ciphertext ) < self ::CRYPTO_AEAD_CHACHA20POLY1305_ABYTES ) {
910- throw new SodiumException ('Message must be at least CRYPTO_AEAD_CHACHA20POLY1305_ABYTES long ' );
916+ throw new SodiumException ('Message must be at least CRYPTO_AEAD_CHACHA20POLY1305_IETF_ABYTES long ' );
911917 }
912918
913919 if (self ::useNewSodiumAPI ()) {
@@ -2784,6 +2790,9 @@ public static function crypto_secretbox_xchacha20poly1305_open(
27842790 if (ParagonIE_Sodium_Core_Util::strlen ($ key ) !== self ::CRYPTO_SECRETBOX_KEYBYTES ) {
27852791 throw new SodiumException ('Argument 3 must be CRYPTO_SECRETBOX_KEYBYTES long. ' );
27862792 }
2793+ if (ParagonIE_Sodium_Core_Util::strlen ($ ciphertext ) < self ::CRYPTO_SECRETBOX_MACBYTES ) {
2794+ throw new SodiumException ("Ciphertext must be at least CRYPTO_SECRETBOX_MACBYTES long " );
2795+ }
27872796
27882797 if (PHP_INT_SIZE === 4 ) {
27892798 return ParagonIE_Sodium_Crypto32::secretbox_xchacha20poly1305_open ($ ciphertext , $ nonce , $ key );
@@ -3714,6 +3723,9 @@ public static function increment(
37143723 }
37153724
37163725 $ len = ParagonIE_Sodium_Core_Util::strlen ($ var );
3726+ if ($ len < 1 ) {
3727+ throw new SodiumException ('Argument 1 cannot be empty ' );
3728+ }
37173729 $ c = 1 ;
37183730 $ copy = '' ;
37193731 for ($ i = 0 ; $ i < $ len ; ++$ i ) {
0 commit comments