├── .github └── workflows │ ├── ci.yml │ └── issues.yml ├── .gitignore ├── CREDITS ├── LICENSE ├── README.md ├── SECURITY.md ├── config.m4 ├── config.w32 ├── libsodium.c ├── libsodium.php ├── libsodium.stub.php ├── libsodium_arginfo.h ├── package.xml ├── php_libsodium.h └── tests ├── crypto_aead.phpt ├── crypto_auth.phpt ├── crypto_box.phpt ├── crypto_core_ristretto255.phpt ├── crypto_generichash.phpt ├── crypto_hex.phpt ├── crypto_kdf.phpt ├── crypto_kx.phpt ├── crypto_scalarmult.phpt ├── crypto_scalarmult_ristretto255.phpt ├── crypto_secretbox.phpt ├── crypto_secretstream.phpt ├── crypto_shorthash.phpt ├── crypto_sign.phpt ├── crypto_stream.phpt ├── crypto_stream_xchacha20.phpt ├── exception_trace_without_args.phpt ├── inc_add.phpt ├── installed.phpt ├── pwhash_argon2i.phpt ├── utils.phpt └── version.phpt /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Build and Test 2 | on: [push, pull_request] 3 | jobs: 4 | moderate-modern: 5 | name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} 6 | runs-on: ${{ matrix.operating-system }} 7 | strategy: 8 | matrix: 9 | operating-system: ['ubuntu-latest'] 10 | php-versions: ['7.3', '7.4', '8.0', '8.1'] 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v2 14 | 15 | - name: Setup PHP 16 | uses: shivammathur/setup-php@v2 17 | with: 18 | php-version: ${{ matrix.php-versions }} 19 | extensions: mbstring, intl 20 | ini-values: error_reporting=-1, display_errors=On 21 | coverage: none 22 | - name: phpize 23 | run: phpize 24 | - name: configure 25 | run: configure --enable-sodium 26 | - name: make 27 | run: make 28 | - name: test 29 | run: env NO_INTERACTION=1 make test 30 | -------------------------------------------------------------------------------- /.github/workflows/issues.yml: -------------------------------------------------------------------------------- 1 | name: Close inactive issues 2 | on: 3 | schedule: 4 | - cron: "30 1 * * *" 5 | 6 | jobs: 7 | close-issues: 8 | runs-on: ubuntu-latest 9 | permissions: 10 | issues: write 11 | pull-requests: write 12 | steps: 13 | - uses: actions/stale@v9 14 | with: 15 | stale-issue-message: "This issue is stale because it has been open for 30 days with no activity." 16 | close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale." 17 | repo-token: ${{ secrets.GITHUB_TOKEN }} 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.a 3 | *.app 4 | *.dll 5 | *.dylib 6 | *.exe 7 | *.ko 8 | *.la 9 | *.lib 10 | *.lo 11 | *.o 12 | *.out 13 | *.so 14 | *.so.* 15 | *.swp 16 | *.tgz 17 | *.tmp 18 | .deps 19 | .libs 20 | Makefile 21 | Makefile.fragments 22 | Makefile.global 23 | Makefile.objects 24 | acinclude.m4 25 | aclocal.m4 26 | autom4te.cache 27 | build 28 | config.* 29 | configure 30 | configure.ac 31 | configure.in 32 | install-sh 33 | libtool 34 | ltmain.sh 35 | missing 36 | mkinstalldirs 37 | run-tests.php 38 | tests/*.diff 39 | tests/*.exp 40 | tests/*.log 41 | tests/*.php 42 | tests/*.sh 43 | tmp-php.ini 44 | run-tests.php 45 | ltmain.sh.backup 46 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | ;; libsodium 2 | Frank Denis [jedisct1@php.net] (lead) 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2018, Frank Denis 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | libsodium-php 2 | ============= 3 | 4 | A simple, low-level PHP extension for [libsodium](https://github.com/jedisct1/libsodium). 5 | 6 | Requires libsodium >= 1.0.9 and PHP 7.{0,1,2,3,4}.x or PHP 8.0.x 7 | 8 | Full documentation here: 9 | [Using Libsodium in PHP Projects](https://paragonie.com/book/pecl-libsodium), 10 | a guide to using the libsodium PHP extension for modern, secure, and 11 | fast cryptography. 12 | 13 | Installation 14 | ============ 15 | 16 | libsodium (and, if you are using binary packages, on some 17 | distributions, `libsodium-dev` as well) has to be installed before 18 | this extension. 19 | 20 | Then, use the PHP extension manager: 21 | 22 | ```sh 23 | $ sudo pecl install -f libsodium 24 | ``` 25 | 26 | On some Linux distributions such as Debian, you may have to install 27 | PECL (`php-pear`), the PHP development package (`php-dev`) and a compiler 28 | (`build-essential`) prior to running this command. 29 | 30 | libsodium-php 1.x compatibility API for libsodium-php 2.x 31 | ========================================================== 32 | 33 | For projects using the 1.x API, or willing to use it, a compatibility 34 | layer is available. 35 | 36 | [Polyfill Libsodium](https://github.com/mollie/polyfill-libsodium) 37 | brings the `\Sodium\` namespace back. 38 | 39 | Examples 40 | ======== 41 | 42 | ## Encrypt a single message using a secret key 43 | 44 | Encryption: 45 | 46 | ```php 47 | $secretKey = sodium_crypto_secretbox_keygen(); 48 | $message = 'Sensitive information'; 49 | 50 | $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); 51 | $encryptedMessage = sodium_crypto_secretbox($message, $nonce, $secretKey); 52 | ``` 53 | 54 | Decryption: 55 | 56 | ```php 57 | $decryptedMessage = sodium_crypto_secretbox_open($encryptedMessage, $nonce, $secretKey); 58 | ``` 59 | 60 | How it works: 61 | 62 | `$secret_key` is a secret key. Not a password. It's binary data, not 63 | something designed to be human readable, but rather to have a key 64 | space as large as possible for a given length. 65 | The `keygen()` function creates such a key. That has to remain secret, 66 | as it is used both to encrypt and decrypt data. 67 | 68 | `$nonce` is a unique value. Like the secret, its length is fixed. But 69 | it doesn't have to be secret, and can be sent along with the encrypted 70 | message. The nonce doesn't have to be unpredictable either. It just has 71 | to be unique for a given key. With the `secretbox()` API, using 72 | `random_bytes()` is a totally fine way to generate nonces. 73 | 74 | Encrypted messages are slightly larger than unencrypted messages, 75 | because they include an authenticator, used by the decryption function 76 | to check that the content was not altered. 77 | 78 | ## Encrypt a single message using a secret key, and hide its length 79 | 80 | Encryption: 81 | 82 | ```php 83 | $secretKey = sodium_crypto_secretbox_keygen(); 84 | $message = 'Sensitive information'; 85 | $blockSize = 16; 86 | 87 | $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); 88 | $paddedMessage = sodium_pad($message, $blockSize); 89 | $encryptedMessage = sodium_crypto_secretbox($paddedMessage, $nonce, $secretKey); 90 | ``` 91 | 92 | Decryption: 93 | 94 | ```php 95 | $decryptedPaddedMessage = sodium_crypto_secretbox_open($encryptedMessage, $nonce, $secretKey); 96 | $decryptedMessage = sodium_unpad($decryptedPaddedMessage, $blockSize); 97 | ``` 98 | 99 | How it works: 100 | 101 | Sometimes, the length of a message may provide a lot of information 102 | about its nature. If a message is one of "yes", "no" and "maybe", 103 | encrypting the message doesn't help: knowing the length is enough to 104 | know what the message is. 105 | 106 | Padding is a technique to mitigate this, by making the length a 107 | multiple of a given block size. 108 | 109 | Messages must be padded prior to encryption, and unpadded after 110 | decryption. 111 | 112 | ## Encrypt a file using a secret key 113 | 114 | ```php 115 | $secretKey = sodium_crypto_secretstream_xchacha20poly1305_keygen(); 116 | $inputFile = '/tmp/example.original'; 117 | $encryptedFile = '/tmp/example.enc'; 118 | $chunkSize = 4096; 119 | 120 | $fdIn = fopen($inputFile, 'rb'); 121 | $fdOut = fopen($encryptedFile, 'wb'); 122 | 123 | [$stream, $header] = sodium_crypto_secretstream_xchacha20poly1305_init_push($secretKey); 124 | 125 | fwrite($fdOut, $header); 126 | 127 | $tag = SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_MESSAGE; 128 | do { 129 | $chunk = fread($fdIn, $chunkSize); 130 | 131 | if (feof($fdIn)) { 132 | $tag = SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_FINAL; 133 | } 134 | 135 | $encryptedChunk = sodium_crypto_secretstream_xchacha20poly1305_push($stream, $chunk, '', $tag); 136 | fwrite($fdOut, $encryptedChunk); 137 | } while ($tag !== SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_FINAL); 138 | 139 | fclose($fdOut); 140 | fclose($fdIn); 141 | ``` 142 | 143 | Decrypt the file: 144 | 145 | ```php 146 | $decryptedFile = '/tmp/example.dec'; 147 | 148 | $fdIn = fopen($encryptedFile, 'rb'); 149 | $fdOut = fopen($decryptedFile, 'wb'); 150 | 151 | $header = fread($fdIn, SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES); 152 | 153 | $stream = sodium_crypto_secretstream_xchacha20poly1305_init_pull($header, $secretKey); 154 | do { 155 | $chunk = fread($fdIn, $chunkSize + SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_ABYTES); 156 | [$decryptedChunk, $tag] = sodium_crypto_secretstream_xchacha20poly1305_pull($stream, $chunk); 157 | 158 | fwrite($fdOut, $decryptedChunk); 159 | } while (!feof($fdIn) && $tag !== SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_FINAL); 160 | $ok = feof($fdIn); 161 | 162 | fclose($fdOut); 163 | fclose($fdIn); 164 | 165 | if (!$ok) { 166 | die('Invalid/corrupted input'); 167 | } 168 | ``` 169 | 170 | How it works: 171 | 172 | There's a little bit more code than in the previous examples. 173 | 174 | In fact, `crypto_secretbox()` would work to encrypt as file, but only 175 | if that file is pretty small. Since we have to provide the entire 176 | content as a string, it has to fit in memory. 177 | 178 | If the file is large, we can split it into small chunks, and encrypt 179 | chunks individually. 180 | 181 | By doing so, we can encrypt arbitrary large files. But we need to make 182 | sure that chunks cannot be deleted, truncated, duplicated and 183 | reordered. In other words, we don't have a single "message", but a 184 | stream of messages, and during the decryption process, we need a way 185 | to check that the whole stream matches what we encrypted. 186 | 187 | So we create a new stream (`init_push`) and push a sequence of messages 188 | into it (`push`). Each individual message has a tag attached to it, by 189 | default `TAG_MESSAGE`. In order for the decryption process to know 190 | where the end of the stream is, we tag the last message with the 191 | `TAG_FINAL` tag. 192 | 193 | When we consume the stream (`init_pull`, then `pull` for each 194 | message), we check that they can be properly decrypted, and retrieve 195 | both the decrypted chunks and the attached tags. If we read the last 196 | chunk (`TAG_FINAL`) and we are at the end of the file, we know that we 197 | completely recovered the original stream. 198 | 199 | ## Encrypt a file using a key derived from a password: 200 | 201 | ```php 202 | $password = 'password'; 203 | $inputFile = '/tmp/example.original'; 204 | $encryptedFile = '/tmp/example.enc'; 205 | $chunkSize = 4096; 206 | 207 | $alg = SODIUM_CRYPTO_PWHASH_ALG_DEFAULT; 208 | $opsLimit = SODIUM_CRYPTO_PWHASH_OPSLIMIT_MODERATE; 209 | $memLimit = SODIUM_CRYPTO_PWHASH_MEMLIMIT_MODERATE; 210 | $salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES); 211 | 212 | $secretKey = sodium_crypto_pwhash( 213 | SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES, 214 | $password, 215 | $salt, 216 | $opsLimit, 217 | $memLimit, 218 | $alg 219 | ); 220 | 221 | $fdIn = fopen($inputFile, 'rb'); 222 | $fdOut = fopen($encryptedFile, 'wb'); 223 | 224 | fwrite($fdOut, pack('C', $alg)); 225 | fwrite($fdOut, pack('P', $opsLimit)); 226 | fwrite($fdOut, pack('P', $memLimit)); 227 | fwrite($fdOut, $salt); 228 | 229 | [$stream, $header] = sodium_crypto_secretstream_xchacha20poly1305_init_push($secretKey); 230 | 231 | fwrite($fdOut, $header); 232 | 233 | $tag = SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_MESSAGE; 234 | do { 235 | $chunk = fread($fdIn, $chunkSize); 236 | if (feof($fdIn)) { 237 | $tag = SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_FINAL; 238 | } 239 | 240 | $encryptedChunk = sodium_crypto_secretstream_xchacha20poly1305_push($stream, $chunk, '', $tag); 241 | fwrite($fdOut, $encryptedChunk); 242 | } while ($tag !== SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_FINAL); 243 | 244 | fclose($fdOut); 245 | fclose($fdIn); 246 | ``` 247 | 248 | Read the stored parameters and decrypt the file: 249 | 250 | ```php 251 | $decryptedFile = '/tmp/example.dec'; 252 | 253 | $fdIn = fopen($encryptedFile, 'rb'); 254 | $fdOut = fopen($decryptedFile, 'wb'); 255 | 256 | $alg = unpack('C', fread($fdIn, 1))[1]; 257 | $opsLimit = unpack('P', fread($fdIn, 8))[1]; 258 | $memLimit = unpack('P', fread($fdIn, 8))[1]; 259 | $salt = fread($fdIn, SODIUM_CRYPTO_PWHASH_SALTBYTES); 260 | 261 | $header = fread($fdIn, SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES); 262 | 263 | $secretKey = sodium_crypto_pwhash( 264 | SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES, 265 | $password, 266 | $salt, 267 | $opsLimit, 268 | $memLimit, 269 | $alg 270 | ); 271 | 272 | $stream = sodium_crypto_secretstream_xchacha20poly1305_init_pull($header, $secretKey); 273 | do { 274 | $chunk = fread($fdIn, $chunkSize + SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_ABYTES); 275 | $res = sodium_crypto_secretstream_xchacha20poly1305_pull($stream, $chunk); 276 | 277 | if ($res === false) { 278 | break; 279 | } 280 | 281 | [$decrypted_chunk, $tag] = $res; 282 | fwrite($fdOut, $decrypted_chunk); 283 | } while (!feof($fdIn) && $tag !== SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_FINAL); 284 | $ok = feof($fdIn); 285 | 286 | fclose($fdOut); 287 | fclose($fdIn); 288 | 289 | if (!$ok) { 290 | die('Invalid/corrupted input'); 291 | } 292 | ``` 293 | 294 | How it works: 295 | 296 | A password cannot be directly used as a secret key. Passwords are 297 | short, must be typable on a keyboard, and people who don't use a 298 | password manager should be able to remember them. 299 | 300 | A 8 characters password is thus way weaker than a 8 bytes key. 301 | 302 | The `sodium_crypto_pwhash()` function perform a computationally 303 | intensive operation on a password in order to derive a secret key. 304 | 305 | By doing so, brute-forcing all possible passwords in order to find the 306 | secret key used to encrypt the data becomes an expensive operation. 307 | 308 | Multiple algorithms can be used to derive a key from a password, and 309 | for each of them, different parameters can be chosen. It is important 310 | to store all of these along with encrypted data. Using the same 311 | algorithm and the same parameters, the same secret key can be 312 | deterministically recomputed. 313 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting vulnerabilities 2 | 3 | We encourage users and researchers to use PGP-encrypted emails to 4 | transmit confidential details regarding possible vulnerabilities in 5 | this package. 6 | 7 | Details should be sent to: j [at] pureftpd [dot] org using the PGP key below: 8 | 9 | ``` 10 | -----BEGIN PGP PUBLIC KEY BLOCK----- 11 | Version: GnuPG v1 (OpenBSD) 12 | 13 | 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 136 | =Hkmu 137 | -----END PGP PUBLIC KEY BLOCK----- 138 | ``` 139 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl $Id$ 2 | dnl config.m4 for extension sodium 3 | 4 | PHP_ARG_WITH(sodium, for sodium support, 5 | [ --with-sodium[=DIR] Include sodium support]) 6 | 7 | if test "$PHP_SODIUM" != "no"; then 8 | SEARCH_PATH="/usr/local /usr" # you might want to change this 9 | SEARCH_FOR="/include/sodium.h" # you most likely want to change this 10 | 11 | AC_PATH_PROG(PKG_CONFIG, pkg-config, no) 12 | AC_MSG_CHECKING([for libsodium]) 13 | 14 | dnl user provided location 15 | if test -r $PHP_SODIUM/$SEARCH_FOR; then # path given as parameter 16 | LIBSODIUM_DIR=$PHP_SODIUM 17 | AC_MSG_RESULT([found in $PHP_SODIUM]) 18 | 19 | dnl pkg-config output 20 | elif test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libsodium; then 21 | LIBSODIUM_VERSION=`$PKG_CONFIG libsodium --modversion` 22 | if $PKG_CONFIG libsodium --atleast-version=1.0.9; then 23 | LIBSODIUM_CFLAGS=`$PKG_CONFIG libsodium --cflags` 24 | LIBSODIUM_LIBS=`$PKG_CONFIG libsodium --libs` 25 | AC_MSG_RESULT(version $LIBSODIUM_VERSION found using pkg-config) 26 | PHP_EVAL_LIBLINE($LIBSODIUM_LIBS, SODIUM_SHARED_LIBADD) 27 | PHP_EVAL_INCLINE($LIBSODIUM_CFLAGS) 28 | else 29 | AC_MSG_ERROR([Libsodium $LIBSODIUM_VERSION is too old, version >= 1.0.9 required]) 30 | fi 31 | 32 | dnl search default path list 33 | else 34 | for i in $SEARCH_PATH ; do 35 | if test -r $i/$SEARCH_FOR; then 36 | LIBSODIUM_DIR=$i 37 | AC_MSG_RESULT(found in $i) 38 | fi 39 | done 40 | if test -z "$LIBSODIUM_DIR"; then 41 | AC_MSG_ERROR([Please install libsodium - See https://github.com/jedisct1/libsodium]) 42 | fi 43 | fi 44 | 45 | LIBNAME=sodium 46 | LIBSYMBOL=sodium_add 47 | 48 | if test -n "$LIBSODIUM_DIR"; then 49 | PHP_ADD_INCLUDE($LIBSODIUM_DIR/include) 50 | PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $LIBSODIUM_DIR/$PHP_LIBDIR, SODIUM_SHARED_LIBADD) 51 | fi 52 | 53 | PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, 54 | [ 55 | AC_DEFINE(HAVE_LIBSODIUMLIB,1,[ ]) 56 | ],[ 57 | AC_MSG_ERROR([wrong libsodium lib version (< 1.0.8) or lib not found]) 58 | ],[ 59 | ]) 60 | 61 | PHP_SUBST(SODIUM_SHARED_LIBADD) 62 | 63 | PHP_NEW_EXTENSION(sodium, libsodium.c, $ext_shared) 64 | fi 65 | -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | // $Id$ 2 | // vim:ft=javascript 3 | 4 | ARG_WITH("sodium", "for libsodium support", "no"); 5 | 6 | if (PHP_SODIUM != "no") { 7 | if (CHECK_LIB("libsodium.lib", "sodium", PHP_SODIUM) && CHECK_HEADER_ADD_INCLUDE("sodium.h", "CFLAGS_SODIUM")) { 8 | EXTENSION("sodium", "libsodium.c"); 9 | AC_DEFINE('HAVE_LIBSODIUMLIB', 1 , 'Have the Sodium library'); 10 | AC_DEFINE("HAVE_CRYPTO_AEAD_AES256GCM", 1, ""); 11 | PHP_INSTALL_HEADERS("ext/sodium/", "php_libsodium.h"); 12 | } else { 13 | WARNING("libsodium not enabled; libraries and headers not found"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /libsodium.php: -------------------------------------------------------------------------------- 1 | "; 3 | 4 | if(!extension_loaded('sodium')) { 5 | dl('libsodium.' . PHP_SHLIB_SUFFIX); 6 | } 7 | $module = 'sodium'; 8 | $functions = get_extension_funcs($module); 9 | echo "Functions available in the test extension:$br\n"; 10 | foreach($functions as $func) { 11 | echo $func."$br\n"; 12 | } 13 | echo "$br\n"; 14 | $function = 'sodium_memzero'; 15 | $exit = 0; 16 | if (extension_loaded($module)) { 17 | $str = $function($module); 18 | } else { 19 | $str = "Module $module is not compiled into PHP"; 20 | $exit = 255; 21 | } 22 | echo "$str\n"; 23 | exit($exit); 24 | ?> 25 | -------------------------------------------------------------------------------- /libsodium.stub.php: -------------------------------------------------------------------------------- 1 | 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6) 196 | function sodium_crypto_pwhash_str_needs_rehash 197 | (string $password, int $opslimit, int $memlimit) : bool {} 198 | #endif 199 | 200 | #ifdef crypto_pwhash_scryptsalsa208sha256_SALTBYTES 201 | function sodium_crypto_pwhash_scryptsalsa208sha256 202 | (int $length, string $password, string $salt, int $opslimit, int $memlimit) : string {} 203 | 204 | function sodium_crypto_pwhash_scryptsalsa208sha256_str 205 | (string $password, int $opslimit, int $memlimit) : string {} 206 | 207 | function sodium_crypto_pwhash_scryptsalsa208sha256_str_verify 208 | (string $hash, string $password) : bool {} 209 | #endif 210 | 211 | function sodium_crypto_scalarmult 212 | (string $n, string $p) : string {} 213 | 214 | #ifdef crypto_core_ristretto255_HASHBYTES 215 | function sodium_crypto_scalarmult_ristretto255(string $n, string $p): string {} 216 | 217 | function sodium_crypto_scalarmult_ristretto255_base(string $n): string {} 218 | #endif 219 | 220 | function sodium_crypto_secretbox 221 | (string $message, string $nonce, string $key) : string {} 222 | 223 | function sodium_crypto_secretbox_keygen 224 | () : string {} 225 | 226 | function sodium_crypto_secretbox_open 227 | (string $ciphertext, string $nonce, string $key) : string | FALSE {} 228 | 229 | #ifdef crypto_secretstream_xchacha20poly1305_ABYTES 230 | function sodium_crypto_secretstream_xchacha20poly1305_keygen 231 | () : string {} 232 | 233 | function sodium_crypto_secretstream_xchacha20poly1305_init_push 234 | (string $key) : array {} 235 | 236 | function sodium_crypto_secretstream_xchacha20poly1305_push 237 | (string &$state, string $message, string $additional_data = "", int $tag = SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_MESSAGE) : string {} 238 | 239 | function sodium_crypto_secretstream_xchacha20poly1305_init_pull 240 | (string $header, string $key) : string {} 241 | 242 | function sodium_crypto_secretstream_xchacha20poly1305_pull 243 | (string &$state, string $ciphertext, string $additional_data = "") : array | FALSE {} 244 | 245 | function sodium_crypto_secretstream_xchacha20poly1305_rekey 246 | (string &$state) : void {} 247 | #endif 248 | 249 | function sodium_crypto_shorthash 250 | (string $message, string $key) : string {} 251 | 252 | function sodium_crypto_shorthash_keygen 253 | () : string {} 254 | 255 | function sodium_crypto_sign 256 | (string $message, string $secret_key) : string {} 257 | 258 | function sodium_crypto_sign_detached 259 | (string $message, string $secret_key) : string {} 260 | 261 | function sodium_crypto_sign_ed25519_pk_to_curve25519 262 | (string $public_key) : string {} 263 | 264 | function sodium_crypto_sign_ed25519_sk_to_curve25519 265 | (string $secret_key) : string {} 266 | 267 | function sodium_crypto_sign_keypair 268 | () : string {} 269 | 270 | function sodium_crypto_sign_keypair_from_secretkey_and_publickey 271 | (string $secret_key, string $public_key) : string {} 272 | 273 | function sodium_crypto_sign_open 274 | (string $ciphertext, string $public_key) : string | FALSE {} 275 | 276 | function sodium_crypto_sign_publickey 277 | (string $key_pair) : string {} 278 | 279 | function sodium_crypto_sign_secretkey 280 | (string $key_pair) : string {} 281 | 282 | function sodium_crypto_sign_publickey_from_secretkey 283 | (string $secret_key) : string {} 284 | 285 | function sodium_crypto_sign_seed_keypair 286 | (string $seed) : string {} 287 | 288 | function sodium_crypto_sign_verify_detached 289 | (string $signature, string $message, string $public_key) : bool {} 290 | 291 | function sodium_crypto_stream 292 | (int $length, string $nonce, string $key) : string {} 293 | 294 | function sodium_crypto_stream_keygen 295 | () : string {} 296 | 297 | function sodium_crypto_stream_xor 298 | (string $message, string $nonce, string $key) : string {} 299 | 300 | function sodium_crypto_stream_xchacha20 301 | (int $length, string $nonce, string $key) : string {} 302 | 303 | function sodium_crypto_stream_xchacha20_keygen 304 | () : string {} 305 | 306 | function sodium_crypto_stream_xchacha20_xor 307 | (string $message, string $nonce, string $key) : string {} 308 | 309 | /* ----- helpers ----- */ 310 | 311 | function sodium_add 312 | (string &$string1, string $string2) : void {} 313 | 314 | function sodium_compare 315 | (string $string1, string $string2) : int {} 316 | 317 | function sodium_increment 318 | (string &$string) : void {} 319 | 320 | function sodium_memcmp 321 | (string $string1, string $string2) : int {} 322 | 323 | function sodium_memzero 324 | (string &$string) : void {} 325 | 326 | function sodium_pad 327 | (string $string, int $length) : string {} 328 | 329 | function sodium_unpad 330 | (string $string, int $block_size) : string {} 331 | 332 | /* ----- codecs ----- */ 333 | 334 | function sodium_bin2hex 335 | (string $string) : string {} 336 | 337 | function sodium_hex2bin 338 | (string $string, string $ignore = "") : string {} 339 | 340 | #ifdef sodium_base64_VARIANT_ORIGINAL 341 | function sodium_bin2base64 342 | (string $string, int $id) : string {} 343 | 344 | function sodium_base642bin 345 | (string $string, int $id, string $ignore = "") : string {} 346 | #endif 347 | 348 | /* ----- aliases ----- */ 349 | 350 | /** @alias sodium_crypto_box_publickey_from_secretkey */ 351 | function sodium_crypto_scalarmult_base 352 | (string $secret_key) : string {} 353 | -------------------------------------------------------------------------------- /libsodium_arginfo.h: -------------------------------------------------------------------------------- 1 | /* This is a generated file, edit the .stub.php file instead. 2 | * Stub hash: 464e520a8efd32673b1f04791dca5e30747b3543 */ 3 | 4 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_aes256gcm_is_available, 0, 0, _IS_BOOL, 0) 5 | ZEND_END_ARG_INFO() 6 | 7 | #if defined(HAVE_AESGCM) 8 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_aead_aes256gcm_decrypt, 0, 4, MAY_BE_STRING|MAY_BE_FALSE) 9 | ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) 10 | ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) 11 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 12 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 13 | ZEND_END_ARG_INFO() 14 | #endif 15 | 16 | #if defined(HAVE_AESGCM) 17 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_aes256gcm_encrypt, 0, 4, IS_STRING, 0) 18 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 19 | ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) 20 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 21 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 22 | ZEND_END_ARG_INFO() 23 | #endif 24 | 25 | #if defined(HAVE_AESGCM) 26 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_aes256gcm_keygen, 0, 0, IS_STRING, 0) 27 | ZEND_END_ARG_INFO() 28 | #endif 29 | 30 | #if defined(HAVE_AESGCM) && defined(HAVE_AEAD_DETACHED) 31 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_aead_aes256gcm_decrypt_detached, 0, 5, MAY_BE_STRING|MAY_BE_FALSE) 32 | ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) 33 | ZEND_ARG_TYPE_INFO(0, mac, IS_STRING, 0) 34 | ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) 35 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 36 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 37 | ZEND_END_ARG_INFO() 38 | #endif 39 | 40 | #if defined(HAVE_AESGCM) && defined(HAVE_AEAD_DETACHED) 41 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_aes256gcm_encrypt_detached, 0, 4, IS_ARRAY, 0) 42 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 43 | ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) 44 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 45 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 46 | ZEND_END_ARG_INFO() 47 | #endif 48 | 49 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_aead_chacha20poly1305_decrypt, 0, 4, MAY_BE_STRING|MAY_BE_FALSE) 50 | ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) 51 | ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) 52 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 53 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 54 | ZEND_END_ARG_INFO() 55 | 56 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_chacha20poly1305_encrypt, 0, 4, IS_STRING, 0) 57 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 58 | ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) 59 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 60 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 61 | ZEND_END_ARG_INFO() 62 | 63 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_chacha20poly1305_keygen, 0, 0, IS_STRING, 0) 64 | ZEND_END_ARG_INFO() 65 | 66 | #define arginfo_sodium_crypto_aead_chacha20poly1305_ietf_decrypt arginfo_sodium_crypto_aead_chacha20poly1305_decrypt 67 | 68 | #define arginfo_sodium_crypto_aead_chacha20poly1305_ietf_encrypt arginfo_sodium_crypto_aead_chacha20poly1305_encrypt 69 | 70 | #define arginfo_sodium_crypto_aead_chacha20poly1305_ietf_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen 71 | 72 | #if defined(HAVE_AEAD_DETACHED) 73 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_aead_chacha20poly1305_decrypt_detached, 0, 5, MAY_BE_STRING|MAY_BE_FALSE) 74 | ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) 75 | ZEND_ARG_TYPE_INFO(0, mac, IS_STRING, 0) 76 | ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) 77 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 78 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 79 | ZEND_END_ARG_INFO() 80 | #endif 81 | 82 | #if defined(HAVE_AEAD_DETACHED) 83 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_chacha20poly1305_encrypt_detached, 0, 4, IS_ARRAY, 0) 84 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 85 | ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) 86 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 87 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 88 | ZEND_END_ARG_INFO() 89 | #endif 90 | 91 | #if defined(HAVE_AEAD_DETACHED) 92 | #define arginfo_sodium_crypto_aead_chacha20poly1305_ietf_decrypt_detached arginfo_sodium_crypto_aead_chacha20poly1305_decrypt_detached 93 | #endif 94 | 95 | #if defined(HAVE_AEAD_DETACHED) 96 | #define arginfo_sodium_crypto_aead_chacha20poly1305_ietf_encrypt_detached arginfo_sodium_crypto_aead_chacha20poly1305_encrypt_detached 97 | #endif 98 | 99 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) 100 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_decrypt, 0, 4, MAY_BE_STRING|MAY_BE_FALSE) 101 | ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) 102 | ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) 103 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 104 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 105 | ZEND_END_ARG_INFO() 106 | #endif 107 | 108 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) 109 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_keygen, 0, 0, IS_STRING, 0) 110 | ZEND_END_ARG_INFO() 111 | #endif 112 | 113 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) 114 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_encrypt, 0, 4, IS_STRING, 0) 115 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 116 | ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) 117 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 118 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 119 | ZEND_END_ARG_INFO() 120 | #endif 121 | 122 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) && defined(HAVE_AEAD_DETACHED) 123 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_decrypt_detached, 0, 5, MAY_BE_STRING|MAY_BE_FALSE) 124 | ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) 125 | ZEND_ARG_TYPE_INFO(0, mac, IS_STRING, 0) 126 | ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) 127 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 128 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 129 | ZEND_END_ARG_INFO() 130 | #endif 131 | 132 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) && defined(HAVE_AEAD_DETACHED) 133 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_encrypt_detached, 0, 4, IS_ARRAY, 0) 134 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 135 | ZEND_ARG_TYPE_INFO(0, additional_data, IS_STRING, 0) 136 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 137 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 138 | ZEND_END_ARG_INFO() 139 | #endif 140 | 141 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_auth, 0, 2, IS_STRING, 0) 142 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 143 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 144 | ZEND_END_ARG_INFO() 145 | 146 | #define arginfo_sodium_crypto_auth_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen 147 | 148 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_auth_verify, 0, 3, _IS_BOOL, 0) 149 | ZEND_ARG_TYPE_INFO(0, mac, IS_STRING, 0) 150 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 151 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 152 | ZEND_END_ARG_INFO() 153 | 154 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box, 0, 3, IS_STRING, 0) 155 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 156 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 157 | ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0) 158 | ZEND_END_ARG_INFO() 159 | 160 | #define arginfo_sodium_crypto_box_keypair arginfo_sodium_crypto_aead_chacha20poly1305_keygen 161 | 162 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_seed_keypair, 0, 1, IS_STRING, 0) 163 | ZEND_ARG_TYPE_INFO(0, seed, IS_STRING, 0) 164 | ZEND_END_ARG_INFO() 165 | 166 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_keypair_from_secretkey_and_publickey, 0, 2, IS_STRING, 0) 167 | ZEND_ARG_TYPE_INFO(0, secret_key, IS_STRING, 0) 168 | ZEND_ARG_TYPE_INFO(0, public_key, IS_STRING, 0) 169 | ZEND_END_ARG_INFO() 170 | 171 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_box_open, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) 172 | ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) 173 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 174 | ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0) 175 | ZEND_END_ARG_INFO() 176 | 177 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_publickey, 0, 1, IS_STRING, 0) 178 | ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0) 179 | ZEND_END_ARG_INFO() 180 | 181 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_publickey_from_secretkey, 0, 1, IS_STRING, 0) 182 | ZEND_ARG_TYPE_INFO(0, secret_key, IS_STRING, 0) 183 | ZEND_END_ARG_INFO() 184 | 185 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_box_seal, 0, 2, IS_STRING, 0) 186 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 187 | ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0) 188 | ZEND_END_ARG_INFO() 189 | 190 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_box_seal_open, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) 191 | ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) 192 | ZEND_ARG_TYPE_INFO(0, key_pair, IS_STRING, 0) 193 | ZEND_END_ARG_INFO() 194 | 195 | #define arginfo_sodium_crypto_box_secretkey arginfo_sodium_crypto_box_publickey 196 | 197 | #if defined(crypto_core_ristretto255_HASHBYTES) 198 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_core_ristretto255_add, 0, 2, IS_STRING, 0) 199 | ZEND_ARG_TYPE_INFO(0, p, IS_STRING, 0) 200 | ZEND_ARG_TYPE_INFO(0, q, IS_STRING, 0) 201 | ZEND_END_ARG_INFO() 202 | #endif 203 | 204 | #if defined(crypto_core_ristretto255_HASHBYTES) 205 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_core_ristretto255_from_hash, 0, 1, IS_STRING, 0) 206 | ZEND_ARG_TYPE_INFO(0, s, IS_STRING, 0) 207 | ZEND_END_ARG_INFO() 208 | #endif 209 | 210 | #if defined(crypto_core_ristretto255_HASHBYTES) 211 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_core_ristretto255_is_valid_point, 0, 1, _IS_BOOL, 0) 212 | ZEND_ARG_TYPE_INFO(0, s, IS_STRING, 0) 213 | ZEND_END_ARG_INFO() 214 | #endif 215 | 216 | #if defined(crypto_core_ristretto255_HASHBYTES) 217 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_core_ristretto255_random, 0, 0, IS_STRING, 0) 218 | ZEND_END_ARG_INFO() 219 | #endif 220 | 221 | #if defined(crypto_core_ristretto255_HASHBYTES) 222 | #define arginfo_sodium_crypto_core_ristretto255_scalar_add arginfo_sodium_crypto_core_ristretto255_add 223 | #endif 224 | 225 | #if defined(crypto_core_ristretto255_HASHBYTES) 226 | #define arginfo_sodium_crypto_core_ristretto255_scalar_complement arginfo_sodium_crypto_core_ristretto255_from_hash 227 | #endif 228 | 229 | #if defined(crypto_core_ristretto255_HASHBYTES) 230 | #define arginfo_sodium_crypto_core_ristretto255_scalar_invert arginfo_sodium_crypto_core_ristretto255_from_hash 231 | #endif 232 | 233 | #if defined(crypto_core_ristretto255_HASHBYTES) 234 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_core_ristretto255_scalar_mul, 0, 2, IS_STRING, 0) 235 | ZEND_ARG_TYPE_INFO(0, x, IS_STRING, 0) 236 | ZEND_ARG_TYPE_INFO(0, y, IS_STRING, 0) 237 | ZEND_END_ARG_INFO() 238 | #endif 239 | 240 | #if defined(crypto_core_ristretto255_HASHBYTES) 241 | #define arginfo_sodium_crypto_core_ristretto255_scalar_negate arginfo_sodium_crypto_core_ristretto255_from_hash 242 | #endif 243 | 244 | #if defined(crypto_core_ristretto255_HASHBYTES) 245 | #define arginfo_sodium_crypto_core_ristretto255_scalar_random arginfo_sodium_crypto_core_ristretto255_random 246 | #endif 247 | 248 | #if defined(crypto_core_ristretto255_HASHBYTES) 249 | #define arginfo_sodium_crypto_core_ristretto255_scalar_reduce arginfo_sodium_crypto_core_ristretto255_from_hash 250 | #endif 251 | 252 | #if defined(crypto_core_ristretto255_HASHBYTES) 253 | #define arginfo_sodium_crypto_core_ristretto255_scalar_sub arginfo_sodium_crypto_core_ristretto255_add 254 | #endif 255 | 256 | #if defined(crypto_core_ristretto255_HASHBYTES) 257 | #define arginfo_sodium_crypto_core_ristretto255_sub arginfo_sodium_crypto_core_ristretto255_add 258 | #endif 259 | 260 | #define arginfo_sodium_crypto_kx_keypair arginfo_sodium_crypto_aead_chacha20poly1305_keygen 261 | 262 | #define arginfo_sodium_crypto_kx_publickey arginfo_sodium_crypto_box_publickey 263 | 264 | #define arginfo_sodium_crypto_kx_secretkey arginfo_sodium_crypto_box_publickey 265 | 266 | #define arginfo_sodium_crypto_kx_seed_keypair arginfo_sodium_crypto_box_seed_keypair 267 | 268 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kx_client_session_keys, 0, 2, IS_ARRAY, 0) 269 | ZEND_ARG_TYPE_INFO(0, client_key_pair, IS_STRING, 0) 270 | ZEND_ARG_TYPE_INFO(0, server_key, IS_STRING, 0) 271 | ZEND_END_ARG_INFO() 272 | 273 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kx_server_session_keys, 0, 2, IS_ARRAY, 0) 274 | ZEND_ARG_TYPE_INFO(0, server_key_pair, IS_STRING, 0) 275 | ZEND_ARG_TYPE_INFO(0, client_key, IS_STRING, 0) 276 | ZEND_END_ARG_INFO() 277 | 278 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_generichash, 0, 1, IS_STRING, 0) 279 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 280 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, key, IS_STRING, 0, "\"\"") 281 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "SODIUM_CRYPTO_GENERICHASH_BYTES") 282 | ZEND_END_ARG_INFO() 283 | 284 | #define arginfo_sodium_crypto_generichash_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen 285 | 286 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_generichash_init, 0, 0, IS_STRING, 0) 287 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, key, IS_STRING, 0, "\"\"") 288 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "SODIUM_CRYPTO_GENERICHASH_BYTES") 289 | ZEND_END_ARG_INFO() 290 | 291 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_generichash_update, 0, 2, _IS_BOOL, 0) 292 | ZEND_ARG_INFO(1, state) 293 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 294 | ZEND_END_ARG_INFO() 295 | 296 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_generichash_final, 0, 1, IS_STRING, 0) 297 | ZEND_ARG_INFO(1, state) 298 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "SODIUM_CRYPTO_GENERICHASH_BYTES") 299 | ZEND_END_ARG_INFO() 300 | 301 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_kdf_derive_from_key, 0, 4, IS_STRING, 0) 302 | ZEND_ARG_TYPE_INFO(0, subkey_length, IS_LONG, 0) 303 | ZEND_ARG_TYPE_INFO(0, subkey_id, IS_LONG, 0) 304 | ZEND_ARG_TYPE_INFO(0, context, IS_STRING, 0) 305 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 306 | ZEND_END_ARG_INFO() 307 | 308 | #define arginfo_sodium_crypto_kdf_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen 309 | 310 | #if defined(crypto_pwhash_SALTBYTES) 311 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_pwhash, 0, 5, IS_STRING, 0) 312 | ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) 313 | ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) 314 | ZEND_ARG_TYPE_INFO(0, salt, IS_STRING, 0) 315 | ZEND_ARG_TYPE_INFO(0, opslimit, IS_LONG, 0) 316 | ZEND_ARG_TYPE_INFO(0, memlimit, IS_LONG, 0) 317 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, algo, IS_LONG, 0, "SODIUM_CRYPTO_PWHASH_ALG_DEFAULT") 318 | ZEND_END_ARG_INFO() 319 | #endif 320 | 321 | #if defined(crypto_pwhash_SALTBYTES) 322 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_pwhash_str, 0, 3, IS_STRING, 0) 323 | ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) 324 | ZEND_ARG_TYPE_INFO(0, opslimit, IS_LONG, 0) 325 | ZEND_ARG_TYPE_INFO(0, memlimit, IS_LONG, 0) 326 | ZEND_END_ARG_INFO() 327 | #endif 328 | 329 | #if defined(crypto_pwhash_SALTBYTES) 330 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_pwhash_str_verify, 0, 2, _IS_BOOL, 0) 331 | ZEND_ARG_TYPE_INFO(0, hash, IS_STRING, 0) 332 | ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) 333 | ZEND_END_ARG_INFO() 334 | #endif 335 | 336 | #if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6) 337 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_pwhash_str_needs_rehash, 0, 3, _IS_BOOL, 0) 338 | ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) 339 | ZEND_ARG_TYPE_INFO(0, opslimit, IS_LONG, 0) 340 | ZEND_ARG_TYPE_INFO(0, memlimit, IS_LONG, 0) 341 | ZEND_END_ARG_INFO() 342 | #endif 343 | 344 | #if defined(crypto_pwhash_scryptsalsa208sha256_SALTBYTES) 345 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_pwhash_scryptsalsa208sha256, 0, 5, IS_STRING, 0) 346 | ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) 347 | ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) 348 | ZEND_ARG_TYPE_INFO(0, salt, IS_STRING, 0) 349 | ZEND_ARG_TYPE_INFO(0, opslimit, IS_LONG, 0) 350 | ZEND_ARG_TYPE_INFO(0, memlimit, IS_LONG, 0) 351 | ZEND_END_ARG_INFO() 352 | #endif 353 | 354 | #if defined(crypto_pwhash_scryptsalsa208sha256_SALTBYTES) 355 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_pwhash_scryptsalsa208sha256_str, 0, 3, IS_STRING, 0) 356 | ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) 357 | ZEND_ARG_TYPE_INFO(0, opslimit, IS_LONG, 0) 358 | ZEND_ARG_TYPE_INFO(0, memlimit, IS_LONG, 0) 359 | ZEND_END_ARG_INFO() 360 | #endif 361 | 362 | #if defined(crypto_pwhash_scryptsalsa208sha256_SALTBYTES) 363 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_pwhash_scryptsalsa208sha256_str_verify, 0, 2, _IS_BOOL, 0) 364 | ZEND_ARG_TYPE_INFO(0, hash, IS_STRING, 0) 365 | ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) 366 | ZEND_END_ARG_INFO() 367 | #endif 368 | 369 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_scalarmult, 0, 2, IS_STRING, 0) 370 | ZEND_ARG_TYPE_INFO(0, n, IS_STRING, 0) 371 | ZEND_ARG_TYPE_INFO(0, p, IS_STRING, 0) 372 | ZEND_END_ARG_INFO() 373 | 374 | #if defined(crypto_core_ristretto255_HASHBYTES) 375 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_scalarmult_ristretto255, 0, 2, IS_STRING, 0) 376 | ZEND_ARG_TYPE_INFO(0, n, IS_STRING, 0) 377 | ZEND_ARG_TYPE_INFO(0, p, IS_STRING, 0) 378 | ZEND_END_ARG_INFO() 379 | #endif 380 | 381 | #if defined(crypto_core_ristretto255_HASHBYTES) 382 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_scalarmult_ristretto255_base, 0, 1, IS_STRING, 0) 383 | ZEND_ARG_TYPE_INFO(0, n, IS_STRING, 0) 384 | ZEND_END_ARG_INFO() 385 | #endif 386 | 387 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretbox, 0, 3, IS_STRING, 0) 388 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 389 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 390 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 391 | ZEND_END_ARG_INFO() 392 | 393 | #define arginfo_sodium_crypto_secretbox_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen 394 | 395 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_secretbox_open, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) 396 | ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) 397 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 398 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 399 | ZEND_END_ARG_INFO() 400 | 401 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 402 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_keygen, 0, 0, IS_STRING, 0) 403 | ZEND_END_ARG_INFO() 404 | #endif 405 | 406 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 407 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_init_push, 0, 1, IS_ARRAY, 0) 408 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 409 | ZEND_END_ARG_INFO() 410 | #endif 411 | 412 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 413 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_push, 0, 2, IS_STRING, 0) 414 | ZEND_ARG_INFO(1, state) 415 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 416 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, additional_data, IS_STRING, 0, "\"\"") 417 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, tag, IS_LONG, 0, "SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_MESSAGE") 418 | ZEND_END_ARG_INFO() 419 | #endif 420 | 421 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 422 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_init_pull, 0, 2, IS_STRING, 0) 423 | ZEND_ARG_TYPE_INFO(0, header, IS_STRING, 0) 424 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 425 | ZEND_END_ARG_INFO() 426 | #endif 427 | 428 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 429 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_pull, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) 430 | ZEND_ARG_INFO(1, state) 431 | ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) 432 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, additional_data, IS_STRING, 0, "\"\"") 433 | ZEND_END_ARG_INFO() 434 | #endif 435 | 436 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 437 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_secretstream_xchacha20poly1305_rekey, 0, 1, IS_VOID, 0) 438 | ZEND_ARG_INFO(1, state) 439 | ZEND_END_ARG_INFO() 440 | #endif 441 | 442 | #define arginfo_sodium_crypto_shorthash arginfo_sodium_crypto_auth 443 | 444 | #define arginfo_sodium_crypto_shorthash_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen 445 | 446 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_sign, 0, 2, IS_STRING, 0) 447 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 448 | ZEND_ARG_TYPE_INFO(0, secret_key, IS_STRING, 0) 449 | ZEND_END_ARG_INFO() 450 | 451 | #define arginfo_sodium_crypto_sign_detached arginfo_sodium_crypto_sign 452 | 453 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_sign_ed25519_pk_to_curve25519, 0, 1, IS_STRING, 0) 454 | ZEND_ARG_TYPE_INFO(0, public_key, IS_STRING, 0) 455 | ZEND_END_ARG_INFO() 456 | 457 | #define arginfo_sodium_crypto_sign_ed25519_sk_to_curve25519 arginfo_sodium_crypto_box_publickey_from_secretkey 458 | 459 | #define arginfo_sodium_crypto_sign_keypair arginfo_sodium_crypto_aead_chacha20poly1305_keygen 460 | 461 | #define arginfo_sodium_crypto_sign_keypair_from_secretkey_and_publickey arginfo_sodium_crypto_box_keypair_from_secretkey_and_publickey 462 | 463 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_sodium_crypto_sign_open, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) 464 | ZEND_ARG_TYPE_INFO(0, ciphertext, IS_STRING, 0) 465 | ZEND_ARG_TYPE_INFO(0, public_key, IS_STRING, 0) 466 | ZEND_END_ARG_INFO() 467 | 468 | #define arginfo_sodium_crypto_sign_publickey arginfo_sodium_crypto_box_publickey 469 | 470 | #define arginfo_sodium_crypto_sign_secretkey arginfo_sodium_crypto_box_publickey 471 | 472 | #define arginfo_sodium_crypto_sign_publickey_from_secretkey arginfo_sodium_crypto_box_publickey_from_secretkey 473 | 474 | #define arginfo_sodium_crypto_sign_seed_keypair arginfo_sodium_crypto_box_seed_keypair 475 | 476 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_sign_verify_detached, 0, 3, _IS_BOOL, 0) 477 | ZEND_ARG_TYPE_INFO(0, signature, IS_STRING, 0) 478 | ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) 479 | ZEND_ARG_TYPE_INFO(0, public_key, IS_STRING, 0) 480 | ZEND_END_ARG_INFO() 481 | 482 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_crypto_stream, 0, 3, IS_STRING, 0) 483 | ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) 484 | ZEND_ARG_TYPE_INFO(0, nonce, IS_STRING, 0) 485 | ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) 486 | ZEND_END_ARG_INFO() 487 | 488 | #define arginfo_sodium_crypto_stream_keygen arginfo_sodium_crypto_aead_chacha20poly1305_keygen 489 | 490 | #define arginfo_sodium_crypto_stream_xor arginfo_sodium_crypto_secretbox 491 | 492 | #ifdef crypto_stream_xchacha20_KEYBYTES 493 | #define arginfo_sodium_crypto_stream_xchacha20_xor arginfo_sodium_crypto_stream_xor 494 | #define arginfo_sodium_crypto_stream_xchacha20 arginfo_sodium_crypto_stream 495 | #endif 496 | 497 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_add, 0, 2, IS_VOID, 0) 498 | ZEND_ARG_INFO(1, string1) 499 | ZEND_ARG_TYPE_INFO(0, string2, IS_STRING, 0) 500 | ZEND_END_ARG_INFO() 501 | 502 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_compare, 0, 2, IS_LONG, 0) 503 | ZEND_ARG_TYPE_INFO(0, string1, IS_STRING, 0) 504 | ZEND_ARG_TYPE_INFO(0, string2, IS_STRING, 0) 505 | ZEND_END_ARG_INFO() 506 | 507 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_increment, 0, 1, IS_VOID, 0) 508 | ZEND_ARG_INFO(1, string) 509 | ZEND_END_ARG_INFO() 510 | 511 | #define arginfo_sodium_memcmp arginfo_sodium_compare 512 | 513 | #define arginfo_sodium_memzero arginfo_sodium_increment 514 | 515 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_pad, 0, 2, IS_STRING, 0) 516 | ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) 517 | ZEND_ARG_TYPE_INFO(0, length, IS_LONG, 0) 518 | ZEND_END_ARG_INFO() 519 | 520 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_unpad, 0, 2, IS_STRING, 0) 521 | ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) 522 | ZEND_ARG_TYPE_INFO(0, block_size, IS_LONG, 0) 523 | ZEND_END_ARG_INFO() 524 | 525 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_bin2hex, 0, 1, IS_STRING, 0) 526 | ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) 527 | ZEND_END_ARG_INFO() 528 | 529 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_hex2bin, 0, 1, IS_STRING, 0) 530 | ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) 531 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, ignore, IS_STRING, 0, "\"\"") 532 | ZEND_END_ARG_INFO() 533 | 534 | #if defined(sodium_base64_VARIANT_ORIGINAL) 535 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_bin2base64, 0, 2, IS_STRING, 0) 536 | ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) 537 | ZEND_ARG_TYPE_INFO(0, id, IS_LONG, 0) 538 | ZEND_END_ARG_INFO() 539 | #endif 540 | 541 | #if defined(sodium_base64_VARIANT_ORIGINAL) 542 | ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_sodium_base642bin, 0, 2, IS_STRING, 0) 543 | ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) 544 | ZEND_ARG_TYPE_INFO(0, id, IS_LONG, 0) 545 | ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, ignore, IS_STRING, 0, "\"\"") 546 | ZEND_END_ARG_INFO() 547 | #endif 548 | 549 | #ifdef crypto_stream_xchacha20_KEYBYTES 550 | #define arginfo_sodium_crypto_stream_xchacha20_keygen arginfo_sodium_crypto_stream_keygen 551 | #endif 552 | 553 | #define arginfo_sodium_crypto_scalarmult_base arginfo_sodium_crypto_box_publickey_from_secretkey 554 | 555 | 556 | ZEND_FUNCTION(sodium_crypto_aead_aes256gcm_is_available); 557 | #if defined(HAVE_AESGCM) 558 | ZEND_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt); 559 | #endif 560 | #if defined(HAVE_AESGCM) 561 | ZEND_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt); 562 | #endif 563 | #if defined(HAVE_AESGCM) 564 | ZEND_FUNCTION(sodium_crypto_aead_aes256gcm_keygen); 565 | #endif 566 | #if defined(HAVE_AESGCM) && defined(HAVE_AEAD_DETACHED) 567 | ZEND_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt_detached); 568 | #endif 569 | #if defined(HAVE_AESGCM) && defined(HAVE_AEAD_DETACHED) 570 | ZEND_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt_detached); 571 | #endif 572 | ZEND_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt); 573 | ZEND_FUNCTION(sodium_crypto_aead_chacha20poly1305_encrypt); 574 | ZEND_FUNCTION(sodium_crypto_aead_chacha20poly1305_keygen); 575 | ZEND_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt); 576 | ZEND_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt); 577 | ZEND_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_keygen); 578 | #if defined(HAVE_AEAD_DETACHED) 579 | ZEND_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt_detached); 580 | #endif 581 | #if defined(HAVE_AEAD_DETACHED) 582 | ZEND_FUNCTION(sodium_crypto_aead_chacha20poly1305_encrypt_detached); 583 | #endif 584 | #if defined(HAVE_AEAD_DETACHED) 585 | ZEND_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt_detached); 586 | #endif 587 | #if defined(HAVE_AEAD_DETACHED) 588 | ZEND_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt_detached); 589 | #endif 590 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) 591 | ZEND_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt); 592 | #endif 593 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) 594 | ZEND_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_keygen); 595 | #endif 596 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) 597 | ZEND_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt); 598 | #endif 599 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) && defined(HAVE_AEAD_DETACHED) 600 | ZEND_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt_detached); 601 | #endif 602 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) && defined(HAVE_AEAD_DETACHED) 603 | ZEND_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt_detached); 604 | #endif 605 | ZEND_FUNCTION(sodium_crypto_auth); 606 | ZEND_FUNCTION(sodium_crypto_auth_keygen); 607 | ZEND_FUNCTION(sodium_crypto_auth_verify); 608 | ZEND_FUNCTION(sodium_crypto_box); 609 | ZEND_FUNCTION(sodium_crypto_box_keypair); 610 | ZEND_FUNCTION(sodium_crypto_box_seed_keypair); 611 | ZEND_FUNCTION(sodium_crypto_box_keypair_from_secretkey_and_publickey); 612 | ZEND_FUNCTION(sodium_crypto_box_open); 613 | ZEND_FUNCTION(sodium_crypto_box_publickey); 614 | ZEND_FUNCTION(sodium_crypto_box_publickey_from_secretkey); 615 | ZEND_FUNCTION(sodium_crypto_box_seal); 616 | ZEND_FUNCTION(sodium_crypto_box_seal_open); 617 | ZEND_FUNCTION(sodium_crypto_box_secretkey); 618 | #if defined(crypto_core_ristretto255_HASHBYTES) 619 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_add); 620 | #endif 621 | #if defined(crypto_core_ristretto255_HASHBYTES) 622 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_from_hash); 623 | #endif 624 | #if defined(crypto_core_ristretto255_HASHBYTES) 625 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_is_valid_point); 626 | #endif 627 | #if defined(crypto_core_ristretto255_HASHBYTES) 628 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_random); 629 | #endif 630 | #if defined(crypto_core_ristretto255_HASHBYTES) 631 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_scalar_add); 632 | #endif 633 | #if defined(crypto_core_ristretto255_HASHBYTES) 634 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_scalar_complement); 635 | #endif 636 | #if defined(crypto_core_ristretto255_HASHBYTES) 637 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_scalar_invert); 638 | #endif 639 | #if defined(crypto_core_ristretto255_HASHBYTES) 640 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_scalar_mul); 641 | #endif 642 | #if defined(crypto_core_ristretto255_HASHBYTES) 643 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_scalar_negate); 644 | #endif 645 | #if defined(crypto_core_ristretto255_HASHBYTES) 646 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_scalar_random); 647 | #endif 648 | #if defined(crypto_core_ristretto255_HASHBYTES) 649 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_scalar_reduce); 650 | #endif 651 | #if defined(crypto_core_ristretto255_HASHBYTES) 652 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_scalar_sub); 653 | #endif 654 | #if defined(crypto_core_ristretto255_HASHBYTES) 655 | ZEND_FUNCTION(sodium_crypto_core_ristretto255_sub); 656 | #endif 657 | ZEND_FUNCTION(sodium_crypto_kx_keypair); 658 | ZEND_FUNCTION(sodium_crypto_kx_publickey); 659 | ZEND_FUNCTION(sodium_crypto_kx_secretkey); 660 | ZEND_FUNCTION(sodium_crypto_kx_seed_keypair); 661 | ZEND_FUNCTION(sodium_crypto_kx_client_session_keys); 662 | ZEND_FUNCTION(sodium_crypto_kx_server_session_keys); 663 | ZEND_FUNCTION(sodium_crypto_generichash); 664 | ZEND_FUNCTION(sodium_crypto_generichash_keygen); 665 | ZEND_FUNCTION(sodium_crypto_generichash_init); 666 | ZEND_FUNCTION(sodium_crypto_generichash_update); 667 | ZEND_FUNCTION(sodium_crypto_generichash_final); 668 | ZEND_FUNCTION(sodium_crypto_kdf_derive_from_key); 669 | ZEND_FUNCTION(sodium_crypto_kdf_keygen); 670 | #if defined(crypto_pwhash_SALTBYTES) 671 | ZEND_FUNCTION(sodium_crypto_pwhash); 672 | #endif 673 | #if defined(crypto_pwhash_SALTBYTES) 674 | ZEND_FUNCTION(sodium_crypto_pwhash_str); 675 | #endif 676 | #if defined(crypto_pwhash_SALTBYTES) 677 | ZEND_FUNCTION(sodium_crypto_pwhash_str_verify); 678 | #endif 679 | #if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6) 680 | ZEND_FUNCTION(sodium_crypto_pwhash_str_needs_rehash); 681 | #endif 682 | #if defined(crypto_pwhash_scryptsalsa208sha256_SALTBYTES) 683 | ZEND_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256); 684 | #endif 685 | #if defined(crypto_pwhash_scryptsalsa208sha256_SALTBYTES) 686 | ZEND_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str); 687 | #endif 688 | #if defined(crypto_pwhash_scryptsalsa208sha256_SALTBYTES) 689 | ZEND_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str_verify); 690 | #endif 691 | ZEND_FUNCTION(sodium_crypto_scalarmult); 692 | #if defined(crypto_core_ristretto255_HASHBYTES) 693 | ZEND_FUNCTION(sodium_crypto_scalarmult_ristretto255); 694 | #endif 695 | #if defined(crypto_core_ristretto255_HASHBYTES) 696 | ZEND_FUNCTION(sodium_crypto_scalarmult_ristretto255_base); 697 | #endif 698 | ZEND_FUNCTION(sodium_crypto_secretbox); 699 | ZEND_FUNCTION(sodium_crypto_secretbox_keygen); 700 | ZEND_FUNCTION(sodium_crypto_secretbox_open); 701 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 702 | ZEND_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_keygen); 703 | #endif 704 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 705 | ZEND_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_init_push); 706 | #endif 707 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 708 | ZEND_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_push); 709 | #endif 710 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 711 | ZEND_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_init_pull); 712 | #endif 713 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 714 | ZEND_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_pull); 715 | #endif 716 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 717 | ZEND_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_rekey); 718 | #endif 719 | ZEND_FUNCTION(sodium_crypto_shorthash); 720 | ZEND_FUNCTION(sodium_crypto_shorthash_keygen); 721 | ZEND_FUNCTION(sodium_crypto_sign); 722 | ZEND_FUNCTION(sodium_crypto_sign_detached); 723 | ZEND_FUNCTION(sodium_crypto_sign_ed25519_pk_to_curve25519); 724 | ZEND_FUNCTION(sodium_crypto_sign_ed25519_sk_to_curve25519); 725 | ZEND_FUNCTION(sodium_crypto_sign_keypair); 726 | ZEND_FUNCTION(sodium_crypto_sign_keypair_from_secretkey_and_publickey); 727 | ZEND_FUNCTION(sodium_crypto_sign_open); 728 | ZEND_FUNCTION(sodium_crypto_sign_publickey); 729 | ZEND_FUNCTION(sodium_crypto_sign_secretkey); 730 | ZEND_FUNCTION(sodium_crypto_sign_publickey_from_secretkey); 731 | ZEND_FUNCTION(sodium_crypto_sign_seed_keypair); 732 | ZEND_FUNCTION(sodium_crypto_sign_verify_detached); 733 | ZEND_FUNCTION(sodium_crypto_stream); 734 | ZEND_FUNCTION(sodium_crypto_stream_keygen); 735 | ZEND_FUNCTION(sodium_crypto_stream_xor); 736 | #if defined(crypto_stream_xchacha20_KEYBYTES) 737 | ZEND_FUNCTION(sodium_crypto_stream_xchacha20); 738 | ZEND_FUNCTION(sodium_crypto_stream_xchacha20_keygen); 739 | ZEND_FUNCTION(sodium_crypto_stream_xchacha20_xor); 740 | #endif 741 | ZEND_FUNCTION(sodium_add); 742 | ZEND_FUNCTION(sodium_compare); 743 | ZEND_FUNCTION(sodium_increment); 744 | ZEND_FUNCTION(sodium_memcmp); 745 | ZEND_FUNCTION(sodium_memzero); 746 | ZEND_FUNCTION(sodium_pad); 747 | ZEND_FUNCTION(sodium_unpad); 748 | ZEND_FUNCTION(sodium_bin2hex); 749 | ZEND_FUNCTION(sodium_hex2bin); 750 | #if defined(sodium_base64_VARIANT_ORIGINAL) 751 | ZEND_FUNCTION(sodium_bin2base64); 752 | #endif 753 | #if defined(sodium_base64_VARIANT_ORIGINAL) 754 | ZEND_FUNCTION(sodium_base642bin); 755 | #endif 756 | 757 | 758 | static const zend_function_entry ext_functions[] = { 759 | ZEND_FE(sodium_crypto_aead_aes256gcm_is_available, arginfo_sodium_crypto_aead_aes256gcm_is_available) 760 | #if defined(HAVE_AESGCM) 761 | ZEND_FE(sodium_crypto_aead_aes256gcm_decrypt, arginfo_sodium_crypto_aead_aes256gcm_decrypt) 762 | #endif 763 | #if defined(HAVE_AESGCM) 764 | ZEND_FE(sodium_crypto_aead_aes256gcm_encrypt, arginfo_sodium_crypto_aead_aes256gcm_encrypt) 765 | #endif 766 | #if defined(HAVE_AESGCM) 767 | ZEND_FE(sodium_crypto_aead_aes256gcm_keygen, arginfo_sodium_crypto_aead_aes256gcm_keygen) 768 | #endif 769 | #if defined(HAVE_AESGCM) && defined(HAVE_AEAD_DETACHED) 770 | ZEND_FE(sodium_crypto_aead_aes256gcm_decrypt_detached, arginfo_sodium_crypto_aead_aes256gcm_decrypt_detached) 771 | #endif 772 | #if defined(HAVE_AESGCM) && defined(HAVE_AEAD_DETACHED) 773 | ZEND_FE(sodium_crypto_aead_aes256gcm_encrypt_detached, arginfo_sodium_crypto_aead_aes256gcm_encrypt_detached) 774 | #endif 775 | ZEND_FE(sodium_crypto_aead_chacha20poly1305_decrypt, arginfo_sodium_crypto_aead_chacha20poly1305_decrypt) 776 | ZEND_FE(sodium_crypto_aead_chacha20poly1305_encrypt, arginfo_sodium_crypto_aead_chacha20poly1305_encrypt) 777 | ZEND_FE(sodium_crypto_aead_chacha20poly1305_keygen, arginfo_sodium_crypto_aead_chacha20poly1305_keygen) 778 | ZEND_FE(sodium_crypto_aead_chacha20poly1305_ietf_decrypt, arginfo_sodium_crypto_aead_chacha20poly1305_ietf_decrypt) 779 | ZEND_FE(sodium_crypto_aead_chacha20poly1305_ietf_encrypt, arginfo_sodium_crypto_aead_chacha20poly1305_ietf_encrypt) 780 | ZEND_FE(sodium_crypto_aead_chacha20poly1305_ietf_keygen, arginfo_sodium_crypto_aead_chacha20poly1305_ietf_keygen) 781 | #if defined(HAVE_AEAD_DETACHED) 782 | ZEND_FE(sodium_crypto_aead_chacha20poly1305_decrypt_detached, arginfo_sodium_crypto_aead_chacha20poly1305_decrypt_detached) 783 | #endif 784 | #if defined(HAVE_AEAD_DETACHED) 785 | ZEND_FE(sodium_crypto_aead_chacha20poly1305_encrypt_detached, arginfo_sodium_crypto_aead_chacha20poly1305_encrypt_detached) 786 | #endif 787 | #if defined(HAVE_AEAD_DETACHED) 788 | ZEND_FE(sodium_crypto_aead_chacha20poly1305_ietf_decrypt_detached, arginfo_sodium_crypto_aead_chacha20poly1305_ietf_decrypt_detached) 789 | #endif 790 | #if defined(HAVE_AEAD_DETACHED) 791 | ZEND_FE(sodium_crypto_aead_chacha20poly1305_ietf_encrypt_detached, arginfo_sodium_crypto_aead_chacha20poly1305_ietf_encrypt_detached) 792 | #endif 793 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) 794 | ZEND_FE(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt, arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_decrypt) 795 | #endif 796 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) 797 | ZEND_FE(sodium_crypto_aead_xchacha20poly1305_ietf_keygen, arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_keygen) 798 | #endif 799 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) 800 | ZEND_FE(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt, arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_encrypt) 801 | #endif 802 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) && defined(HAVE_AEAD_DETACHED) 803 | ZEND_FE(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt_detached, arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_decrypt_detached) 804 | #endif 805 | #if defined(crypto_aead_xchacha20poly1305_IETF_NPUBBYTES) && defined(HAVE_AEAD_DETACHED) 806 | ZEND_FE(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt_detached, arginfo_sodium_crypto_aead_xchacha20poly1305_ietf_encrypt_detached) 807 | #endif 808 | ZEND_FE(sodium_crypto_auth, arginfo_sodium_crypto_auth) 809 | ZEND_FE(sodium_crypto_auth_keygen, arginfo_sodium_crypto_auth_keygen) 810 | ZEND_FE(sodium_crypto_auth_verify, arginfo_sodium_crypto_auth_verify) 811 | ZEND_FE(sodium_crypto_box, arginfo_sodium_crypto_box) 812 | ZEND_FE(sodium_crypto_box_keypair, arginfo_sodium_crypto_box_keypair) 813 | ZEND_FE(sodium_crypto_box_seed_keypair, arginfo_sodium_crypto_box_seed_keypair) 814 | ZEND_FE(sodium_crypto_box_keypair_from_secretkey_and_publickey, arginfo_sodium_crypto_box_keypair_from_secretkey_and_publickey) 815 | ZEND_FE(sodium_crypto_box_open, arginfo_sodium_crypto_box_open) 816 | ZEND_FE(sodium_crypto_box_publickey, arginfo_sodium_crypto_box_publickey) 817 | ZEND_FE(sodium_crypto_box_publickey_from_secretkey, arginfo_sodium_crypto_box_publickey_from_secretkey) 818 | ZEND_FE(sodium_crypto_box_seal, arginfo_sodium_crypto_box_seal) 819 | ZEND_FE(sodium_crypto_box_seal_open, arginfo_sodium_crypto_box_seal_open) 820 | ZEND_FE(sodium_crypto_box_secretkey, arginfo_sodium_crypto_box_secretkey) 821 | #if defined(crypto_core_ristretto255_HASHBYTES) 822 | ZEND_FE(sodium_crypto_core_ristretto255_add, arginfo_sodium_crypto_core_ristretto255_add) 823 | #endif 824 | #if defined(crypto_core_ristretto255_HASHBYTES) 825 | ZEND_FE(sodium_crypto_core_ristretto255_from_hash, arginfo_sodium_crypto_core_ristretto255_from_hash) 826 | #endif 827 | #if defined(crypto_core_ristretto255_HASHBYTES) 828 | ZEND_FE(sodium_crypto_core_ristretto255_is_valid_point, arginfo_sodium_crypto_core_ristretto255_is_valid_point) 829 | #endif 830 | #if defined(crypto_core_ristretto255_HASHBYTES) 831 | ZEND_FE(sodium_crypto_core_ristretto255_random, arginfo_sodium_crypto_core_ristretto255_random) 832 | #endif 833 | #if defined(crypto_core_ristretto255_HASHBYTES) 834 | ZEND_FE(sodium_crypto_core_ristretto255_scalar_add, arginfo_sodium_crypto_core_ristretto255_scalar_add) 835 | #endif 836 | #if defined(crypto_core_ristretto255_HASHBYTES) 837 | ZEND_FE(sodium_crypto_core_ristretto255_scalar_complement, arginfo_sodium_crypto_core_ristretto255_scalar_complement) 838 | #endif 839 | #if defined(crypto_core_ristretto255_HASHBYTES) 840 | ZEND_FE(sodium_crypto_core_ristretto255_scalar_invert, arginfo_sodium_crypto_core_ristretto255_scalar_invert) 841 | #endif 842 | #if defined(crypto_core_ristretto255_HASHBYTES) 843 | ZEND_FE(sodium_crypto_core_ristretto255_scalar_mul, arginfo_sodium_crypto_core_ristretto255_scalar_mul) 844 | #endif 845 | #if defined(crypto_core_ristretto255_HASHBYTES) 846 | ZEND_FE(sodium_crypto_core_ristretto255_scalar_negate, arginfo_sodium_crypto_core_ristretto255_scalar_negate) 847 | #endif 848 | #if defined(crypto_core_ristretto255_HASHBYTES) 849 | ZEND_FE(sodium_crypto_core_ristretto255_scalar_random, arginfo_sodium_crypto_core_ristretto255_scalar_random) 850 | #endif 851 | #if defined(crypto_core_ristretto255_HASHBYTES) 852 | ZEND_FE(sodium_crypto_core_ristretto255_scalar_reduce, arginfo_sodium_crypto_core_ristretto255_scalar_reduce) 853 | #endif 854 | #if defined(crypto_core_ristretto255_HASHBYTES) 855 | ZEND_FE(sodium_crypto_core_ristretto255_scalar_sub, arginfo_sodium_crypto_core_ristretto255_scalar_sub) 856 | #endif 857 | #if defined(crypto_core_ristretto255_HASHBYTES) 858 | ZEND_FE(sodium_crypto_core_ristretto255_sub, arginfo_sodium_crypto_core_ristretto255_sub) 859 | #endif 860 | ZEND_FE(sodium_crypto_kx_keypair, arginfo_sodium_crypto_kx_keypair) 861 | ZEND_FE(sodium_crypto_kx_publickey, arginfo_sodium_crypto_kx_publickey) 862 | ZEND_FE(sodium_crypto_kx_secretkey, arginfo_sodium_crypto_kx_secretkey) 863 | ZEND_FE(sodium_crypto_kx_seed_keypair, arginfo_sodium_crypto_kx_seed_keypair) 864 | ZEND_FE(sodium_crypto_kx_client_session_keys, arginfo_sodium_crypto_kx_client_session_keys) 865 | ZEND_FE(sodium_crypto_kx_server_session_keys, arginfo_sodium_crypto_kx_server_session_keys) 866 | ZEND_FE(sodium_crypto_generichash, arginfo_sodium_crypto_generichash) 867 | ZEND_FE(sodium_crypto_generichash_keygen, arginfo_sodium_crypto_generichash_keygen) 868 | ZEND_FE(sodium_crypto_generichash_init, arginfo_sodium_crypto_generichash_init) 869 | ZEND_FE(sodium_crypto_generichash_update, arginfo_sodium_crypto_generichash_update) 870 | ZEND_FE(sodium_crypto_generichash_final, arginfo_sodium_crypto_generichash_final) 871 | ZEND_FE(sodium_crypto_kdf_derive_from_key, arginfo_sodium_crypto_kdf_derive_from_key) 872 | ZEND_FE(sodium_crypto_kdf_keygen, arginfo_sodium_crypto_kdf_keygen) 873 | #if defined(crypto_pwhash_SALTBYTES) 874 | ZEND_FE(sodium_crypto_pwhash, arginfo_sodium_crypto_pwhash) 875 | #endif 876 | #if defined(crypto_pwhash_SALTBYTES) 877 | ZEND_FE(sodium_crypto_pwhash_str, arginfo_sodium_crypto_pwhash_str) 878 | #endif 879 | #if defined(crypto_pwhash_SALTBYTES) 880 | ZEND_FE(sodium_crypto_pwhash_str_verify, arginfo_sodium_crypto_pwhash_str_verify) 881 | #endif 882 | #if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6) 883 | ZEND_FE(sodium_crypto_pwhash_str_needs_rehash, arginfo_sodium_crypto_pwhash_str_needs_rehash) 884 | #endif 885 | #if defined(crypto_pwhash_scryptsalsa208sha256_SALTBYTES) 886 | ZEND_FE(sodium_crypto_pwhash_scryptsalsa208sha256, arginfo_sodium_crypto_pwhash_scryptsalsa208sha256) 887 | #endif 888 | #if defined(crypto_pwhash_scryptsalsa208sha256_SALTBYTES) 889 | ZEND_FE(sodium_crypto_pwhash_scryptsalsa208sha256_str, arginfo_sodium_crypto_pwhash_scryptsalsa208sha256_str) 890 | #endif 891 | #if defined(crypto_pwhash_scryptsalsa208sha256_SALTBYTES) 892 | ZEND_FE(sodium_crypto_pwhash_scryptsalsa208sha256_str_verify, arginfo_sodium_crypto_pwhash_scryptsalsa208sha256_str_verify) 893 | #endif 894 | ZEND_FE(sodium_crypto_scalarmult, arginfo_sodium_crypto_scalarmult) 895 | #if defined(crypto_core_ristretto255_HASHBYTES) 896 | ZEND_FE(sodium_crypto_scalarmult_ristretto255, arginfo_sodium_crypto_scalarmult_ristretto255) 897 | #endif 898 | #if defined(crypto_core_ristretto255_HASHBYTES) 899 | ZEND_FE(sodium_crypto_scalarmult_ristretto255_base, arginfo_sodium_crypto_scalarmult_ristretto255_base) 900 | #endif 901 | ZEND_FE(sodium_crypto_secretbox, arginfo_sodium_crypto_secretbox) 902 | ZEND_FE(sodium_crypto_secretbox_keygen, arginfo_sodium_crypto_secretbox_keygen) 903 | ZEND_FE(sodium_crypto_secretbox_open, arginfo_sodium_crypto_secretbox_open) 904 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 905 | ZEND_FE(sodium_crypto_secretstream_xchacha20poly1305_keygen, arginfo_sodium_crypto_secretstream_xchacha20poly1305_keygen) 906 | #endif 907 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 908 | ZEND_FE(sodium_crypto_secretstream_xchacha20poly1305_init_push, arginfo_sodium_crypto_secretstream_xchacha20poly1305_init_push) 909 | #endif 910 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 911 | ZEND_FE(sodium_crypto_secretstream_xchacha20poly1305_push, arginfo_sodium_crypto_secretstream_xchacha20poly1305_push) 912 | #endif 913 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 914 | ZEND_FE(sodium_crypto_secretstream_xchacha20poly1305_init_pull, arginfo_sodium_crypto_secretstream_xchacha20poly1305_init_pull) 915 | #endif 916 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 917 | ZEND_FE(sodium_crypto_secretstream_xchacha20poly1305_pull, arginfo_sodium_crypto_secretstream_xchacha20poly1305_pull) 918 | #endif 919 | #if defined(crypto_secretstream_xchacha20poly1305_ABYTES) 920 | ZEND_FE(sodium_crypto_secretstream_xchacha20poly1305_rekey, arginfo_sodium_crypto_secretstream_xchacha20poly1305_rekey) 921 | #endif 922 | ZEND_FE(sodium_crypto_shorthash, arginfo_sodium_crypto_shorthash) 923 | ZEND_FE(sodium_crypto_shorthash_keygen, arginfo_sodium_crypto_shorthash_keygen) 924 | ZEND_FE(sodium_crypto_sign, arginfo_sodium_crypto_sign) 925 | ZEND_FE(sodium_crypto_sign_detached, arginfo_sodium_crypto_sign_detached) 926 | ZEND_FE(sodium_crypto_sign_ed25519_pk_to_curve25519, arginfo_sodium_crypto_sign_ed25519_pk_to_curve25519) 927 | ZEND_FE(sodium_crypto_sign_ed25519_sk_to_curve25519, arginfo_sodium_crypto_sign_ed25519_sk_to_curve25519) 928 | ZEND_FE(sodium_crypto_sign_keypair, arginfo_sodium_crypto_sign_keypair) 929 | ZEND_FE(sodium_crypto_sign_keypair_from_secretkey_and_publickey, arginfo_sodium_crypto_sign_keypair_from_secretkey_and_publickey) 930 | ZEND_FE(sodium_crypto_sign_open, arginfo_sodium_crypto_sign_open) 931 | ZEND_FE(sodium_crypto_sign_publickey, arginfo_sodium_crypto_sign_publickey) 932 | ZEND_FE(sodium_crypto_sign_secretkey, arginfo_sodium_crypto_sign_secretkey) 933 | ZEND_FE(sodium_crypto_sign_publickey_from_secretkey, arginfo_sodium_crypto_sign_publickey_from_secretkey) 934 | ZEND_FE(sodium_crypto_sign_seed_keypair, arginfo_sodium_crypto_sign_seed_keypair) 935 | ZEND_FE(sodium_crypto_sign_verify_detached, arginfo_sodium_crypto_sign_verify_detached) 936 | ZEND_FE(sodium_crypto_stream, arginfo_sodium_crypto_stream) 937 | ZEND_FE(sodium_crypto_stream_keygen, arginfo_sodium_crypto_stream_keygen) 938 | ZEND_FE(sodium_crypto_stream_xor, arginfo_sodium_crypto_stream_xor) 939 | #if defined(crypto_stream_xchacha20_KEYBYTES) 940 | ZEND_FE(sodium_crypto_stream_xchacha20, arginfo_sodium_crypto_stream_xchacha20) 941 | ZEND_FE(sodium_crypto_stream_xchacha20_keygen, arginfo_sodium_crypto_stream_xchacha20_keygen) 942 | ZEND_FE(sodium_crypto_stream_xchacha20_xor, arginfo_sodium_crypto_stream_xchacha20_xor) 943 | #endif 944 | ZEND_FE(sodium_add, arginfo_sodium_add) 945 | ZEND_FE(sodium_compare, arginfo_sodium_compare) 946 | ZEND_FE(sodium_increment, arginfo_sodium_increment) 947 | ZEND_FE(sodium_memcmp, arginfo_sodium_memcmp) 948 | ZEND_FE(sodium_memzero, arginfo_sodium_memzero) 949 | ZEND_FE(sodium_pad, arginfo_sodium_pad) 950 | ZEND_FE(sodium_unpad, arginfo_sodium_unpad) 951 | ZEND_FE(sodium_bin2hex, arginfo_sodium_bin2hex) 952 | ZEND_FE(sodium_hex2bin, arginfo_sodium_hex2bin) 953 | #if defined(sodium_base64_VARIANT_ORIGINAL) 954 | ZEND_FE(sodium_bin2base64, arginfo_sodium_bin2base64) 955 | #endif 956 | #if defined(sodium_base64_VARIANT_ORIGINAL) 957 | ZEND_FE(sodium_base642bin, arginfo_sodium_base642bin) 958 | #endif 959 | ZEND_FALIAS(sodium_crypto_scalarmult_base, sodium_crypto_box_publickey_from_secretkey, arginfo_sodium_crypto_scalarmult_base) 960 | ZEND_FE_END 961 | }; 962 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | libsodium 4 | pecl.php.net 5 | Wrapper for the Sodium cryptographic library 6 | A simple, low-level PHP extension for libsodium. 7 | 8 | Frank Denis 9 | jedisct1 10 | jedisct1@php.net 11 | yes 12 | 13 | 2020-12-06 14 | 15 | 16 | 2.0.24 17 | 2.0.24 18 | 19 | 20 | stable 21 | stable 22 | 23 | BSD 2-Clause License 24 | 25 | - Parameters in function signatures now match the ones from the PHP documentation. 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 7.0.0 62 | 8.99.99 63 | 64 | 65 | 1.4.8 66 | 67 | 68 | 69 | libsodium 70 | 71 | 72 | -------------------------------------------------------------------------------- /php_libsodium.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef PHP_LIBSODIUM_H 3 | #define PHP_LIBSODIUM_H 4 | 5 | extern zend_module_entry sodium_module_entry; 6 | #define phpext_sodium_ptr &sodium_module_entry 7 | 8 | #define PHP_LIBSODIUM_VERSION "2.0.24" 9 | #define PHP_SODIUM_VERSION PHP_LIBSODIUM_VERSION 10 | 11 | #ifdef PHP_WIN32 12 | # define PHP_SODIUM_API __declspec(dllexport) 13 | #elif defined(__GNUC__) && __GNUC__ >= 4 14 | # define PHP_SODIUM_API __attribute__ ((visibility("default"))) 15 | #else 16 | # define PHP_SODIUM_API 17 | #endif 18 | 19 | #ifdef ZTS 20 | # include "TSRM.h" 21 | #endif 22 | 23 | PHP_MINIT_FUNCTION(sodium); 24 | PHP_MSHUTDOWN_FUNCTION(sodium); 25 | PHP_RINIT_FUNCTION(sodium); 26 | PHP_RSHUTDOWN_FUNCTION(sodium); 27 | PHP_MINFO_FUNCTION(sodium); 28 | 29 | PHP_FUNCTION(sodium_add); 30 | PHP_FUNCTION(sodium_base642bin); 31 | PHP_FUNCTION(sodium_bin2base64); 32 | PHP_FUNCTION(sodium_bin2hex); 33 | PHP_FUNCTION(sodium_compare); 34 | PHP_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt); 35 | PHP_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt_detached); 36 | PHP_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt); 37 | PHP_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt_detached); 38 | PHP_FUNCTION(sodium_crypto_aead_aes256gcm_is_available); 39 | PHP_FUNCTION(sodium_crypto_aead_aes256gcm_keygen); 40 | PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt); 41 | PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt_detached); 42 | PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_encrypt); 43 | PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_encrypt_detached); 44 | PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt); 45 | PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt_detached); 46 | PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt); 47 | PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt_detached); 48 | PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_keygen); 49 | PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_keygen); 50 | PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt); 51 | PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt_detached); 52 | PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt); 53 | PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt_detached); 54 | PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_keygen); 55 | PHP_FUNCTION(sodium_crypto_auth); 56 | PHP_FUNCTION(sodium_crypto_auth_keygen); 57 | PHP_FUNCTION(sodium_crypto_auth_verify); 58 | PHP_FUNCTION(sodium_crypto_box); 59 | PHP_FUNCTION(sodium_crypto_box_keypair); 60 | PHP_FUNCTION(sodium_crypto_box_keypair_from_secretkey_and_publickey); 61 | PHP_FUNCTION(sodium_crypto_box_open); 62 | PHP_FUNCTION(sodium_crypto_box_publickey); 63 | PHP_FUNCTION(sodium_crypto_box_publickey_from_secretkey); 64 | PHP_FUNCTION(sodium_crypto_box_seal); 65 | PHP_FUNCTION(sodium_crypto_box_seal_open); 66 | PHP_FUNCTION(sodium_crypto_box_secretkey); 67 | PHP_FUNCTION(sodium_crypto_box_seed_keypair); 68 | PHP_FUNCTION(sodium_crypto_core_ristretto255_add); 69 | PHP_FUNCTION(sodium_crypto_core_ristretto255_from_hash); 70 | PHP_FUNCTION(sodium_crypto_core_ristretto255_is_valid_point); 71 | PHP_FUNCTION(sodium_crypto_core_ristretto255_random); 72 | PHP_FUNCTION(sodium_crypto_core_ristretto255_scalar_add); 73 | PHP_FUNCTION(sodium_crypto_core_ristretto255_scalar_complement); 74 | PHP_FUNCTION(sodium_crypto_core_ristretto255_scalar_invert); 75 | PHP_FUNCTION(sodium_crypto_core_ristretto255_scalar_mul); 76 | PHP_FUNCTION(sodium_crypto_core_ristretto255_scalar_negate); 77 | PHP_FUNCTION(sodium_crypto_core_ristretto255_scalar_random); 78 | PHP_FUNCTION(sodium_crypto_core_ristretto255_scalar_reduce); 79 | PHP_FUNCTION(sodium_crypto_core_ristretto255_scalar_sub); 80 | PHP_FUNCTION(sodium_crypto_core_ristretto255_sub); 81 | PHP_FUNCTION(sodium_crypto_generichash); 82 | PHP_FUNCTION(sodium_crypto_generichash_final); 83 | PHP_FUNCTION(sodium_crypto_generichash_init); 84 | PHP_FUNCTION(sodium_crypto_generichash_keygen); 85 | PHP_FUNCTION(sodium_crypto_generichash_update); 86 | PHP_FUNCTION(sodium_crypto_kdf_derive_from_key); 87 | PHP_FUNCTION(sodium_crypto_kdf_keygen); 88 | PHP_FUNCTION(sodium_crypto_kx_client_session_keys); 89 | PHP_FUNCTION(sodium_crypto_kx_keypair); 90 | PHP_FUNCTION(sodium_crypto_kx_publickey); 91 | PHP_FUNCTION(sodium_crypto_kx_secretkey); 92 | PHP_FUNCTION(sodium_crypto_kx_seed_keypair); 93 | PHP_FUNCTION(sodium_crypto_kx_server_session_keys); 94 | PHP_FUNCTION(sodium_crypto_pwhash); 95 | PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256); 96 | PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str); 97 | PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str_verify); 98 | PHP_FUNCTION(sodium_crypto_pwhash_str); 99 | PHP_FUNCTION(sodium_crypto_pwhash_str_needs_rehash); 100 | PHP_FUNCTION(sodium_crypto_pwhash_str_verify); 101 | PHP_FUNCTION(sodium_crypto_scalarmult); 102 | PHP_FUNCTION(sodium_crypto_scalarmult_base); 103 | PHP_FUNCTION(sodium_crypto_scalarmult_ristretto255); 104 | PHP_FUNCTION(sodium_crypto_scalarmult_ristretto255_base); 105 | PHP_FUNCTION(sodium_crypto_secretbox); 106 | PHP_FUNCTION(sodium_crypto_secretbox_keygen); 107 | PHP_FUNCTION(sodium_crypto_secretbox_open); 108 | PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_keygen); 109 | PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_init_push); 110 | PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_push); 111 | PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_init_pull); 112 | PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_pull); 113 | PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_rekey); 114 | PHP_FUNCTION(sodium_crypto_shorthash); 115 | PHP_FUNCTION(sodium_crypto_shorthash_keygen); 116 | PHP_FUNCTION(sodium_crypto_sign); 117 | PHP_FUNCTION(sodium_crypto_sign_detached); 118 | PHP_FUNCTION(sodium_crypto_sign_ed25519_pk_to_curve25519); 119 | PHP_FUNCTION(sodium_crypto_sign_ed25519_sk_to_curve25519); 120 | PHP_FUNCTION(sodium_crypto_sign_keypair); 121 | PHP_FUNCTION(sodium_crypto_sign_keypair_from_secretkey_and_publickey); 122 | PHP_FUNCTION(sodium_crypto_sign_open); 123 | PHP_FUNCTION(sodium_crypto_sign_publickey); 124 | PHP_FUNCTION(sodium_crypto_sign_publickey_from_secretkey); 125 | PHP_FUNCTION(sodium_crypto_sign_secretkey); 126 | PHP_FUNCTION(sodium_crypto_sign_seed_keypair); 127 | PHP_FUNCTION(sodium_crypto_sign_verify_detached); 128 | PHP_FUNCTION(sodium_crypto_stream); 129 | PHP_FUNCTION(sodium_crypto_stream_keygen); 130 | PHP_FUNCTION(sodium_crypto_stream_xor); 131 | PHP_FUNCTION(sodium_crypto_stream_xchacha20); 132 | PHP_FUNCTION(sodium_crypto_stream_xchacha20_keygen); 133 | PHP_FUNCTION(sodium_crypto_stream_xchacha20_xor); 134 | PHP_FUNCTION(sodium_hex2bin); 135 | PHP_FUNCTION(sodium_increment); 136 | PHP_FUNCTION(sodium_memcmp); 137 | PHP_FUNCTION(sodium_memzero); 138 | PHP_FUNCTION(sodium_pad); 139 | PHP_FUNCTION(sodium_unpad); 140 | 141 | #endif /* PHP_LIBSODIUM_H */ 142 | -------------------------------------------------------------------------------- /tests/crypto_aead.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium AEAD 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 7 || 45 | (SODIUM_LIBRARY_MAJOR_VERSION == 7 && 46 | SODIUM_LIBRARY_MINOR_VERSION >= 6)) { 47 | $msg = random_bytes(random_int(1, 1000)); 48 | $nonce = random_bytes(SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES); 49 | $key = sodium_crypto_aead_chacha20poly1305_ietf_keygen(); 50 | $ad = random_bytes(random_int(1, 1000)); 51 | 52 | $ciphertext = sodium_crypto_aead_chacha20poly1305_ietf_encrypt($msg, $ad, $nonce, $key); 53 | $msg2 = sodium_crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, $ad, $nonce, $key); 54 | var_dump($ciphertext !== $msg); 55 | var_dump($msg === $msg2); 56 | 57 | if (function_exists('sodium_crypto_aead_chacha20poly1305_ietf_decrypt_detached')) { 58 | $ciphertext_dt = sodium_crypto_aead_chacha20poly1305_ietf_encrypt_detached($msg, $ad, $nonce, $key); 59 | var_dump(is_array($ciphertext_dt)); 60 | var_dump(implode('', $ciphertext_dt) === $ciphertext); 61 | $msg3 = sodium_crypto_aead_chacha20poly1305_ietf_decrypt_detached($ciphertext_dt[0], $ciphertext_dt[1], $ad, $nonce, $key); 62 | var_dump($msg === $msg3); 63 | } else { 64 | var_dump(true); 65 | var_dump(true); 66 | var_dump(true); 67 | } 68 | var_dump(sodium_crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, 'x' . $ad, $nonce, $key)); 69 | try { 70 | // Switched order 71 | $msg2 = sodium_crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, $ad, $key, $nonce); 72 | var_dump(false); 73 | } catch (SodiumException $ex) { 74 | var_dump(true); 75 | } 76 | } else { 77 | var_dump(true); 78 | var_dump(true); 79 | var_dump(true); 80 | var_dump(true); 81 | var_dump(true); 82 | var_dump(false); 83 | var_dump(true); 84 | } 85 | 86 | echo "aead_xchacha20poly1305_ietf:\n"; 87 | 88 | if (SODIUM_LIBRARY_MAJOR_VERSION > 9 || 89 | (SODIUM_LIBRARY_MAJOR_VERSION == 9 && 90 | SODIUM_LIBRARY_MINOR_VERSION >= 4)) { 91 | $msg = random_bytes(random_int(1, 1000)); 92 | $nonce = random_bytes(SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES); 93 | $key = sodium_crypto_aead_xchacha20poly1305_ietf_keygen(); 94 | $ad = random_bytes(random_int(1, 1000)); 95 | 96 | $ciphertext = sodium_crypto_aead_xchacha20poly1305_ietf_encrypt($msg, $ad, $nonce, $key); 97 | $msg2 = sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext, $ad, $nonce, $key); 98 | var_dump($ciphertext !== $msg); 99 | var_dump($msg === $msg2); 100 | if (function_exists('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt_detached')) { 101 | $ciphertext_dt = sodium_crypto_aead_xchacha20poly1305_ietf_encrypt_detached($msg, $ad, $nonce, $key); 102 | var_dump(is_array($ciphertext_dt)); 103 | var_dump(implode('', $ciphertext_dt) === $ciphertext); 104 | $msg3 = sodium_crypto_aead_xchacha20poly1305_ietf_decrypt_detached($ciphertext_dt[0], $ciphertext_dt[1], $ad, $nonce, $key); 105 | var_dump($msg === $msg3); 106 | } else { 107 | var_dump(true); 108 | var_dump(true); 109 | var_dump(true); 110 | } 111 | var_dump(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext, 'x' . $ad, $nonce, $key)); 112 | 113 | try { 114 | // Switched order 115 | $msg2 = sodium_crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext, $ad, $key, $nonce); 116 | var_dump(false); 117 | } catch (SodiumException $ex) { 118 | var_dump(true); 119 | } 120 | 121 | } else { 122 | var_dump(true); 123 | var_dump(true); 124 | var_dump(true); 125 | var_dump(true); 126 | var_dump(true); 127 | var_dump(false); 128 | var_dump(true); 129 | } 130 | 131 | echo "aead_aes256gcm:\n"; 132 | 133 | if (sodium_crypto_aead_aes256gcm_is_available()) { 134 | $msg = random_bytes(random_int(1, 1000)); 135 | $nonce = random_bytes(SODIUM_CRYPTO_AEAD_AES256GCM_NPUBBYTES); 136 | $ad = random_bytes(random_int(1, 1000)); 137 | $key = sodium_crypto_aead_aes256gcm_keygen(); 138 | $ciphertext = sodium_crypto_aead_aes256gcm_encrypt($msg, $ad, $nonce, $key); 139 | 140 | $msg2 = sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $ad, $nonce, $key); 141 | var_dump($ciphertext !== $msg); 142 | var_dump($msg === $msg2); 143 | if (function_exists('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt_detached')) { 144 | $ciphertext_dt = sodium_crypto_aead_aes256gcm_encrypt_detached($msg, $ad, $nonce, $key); 145 | var_dump(is_array($ciphertext_dt)); 146 | var_dump(implode('', $ciphertext_dt) === $ciphertext); 147 | $msg3 = sodium_crypto_aead_aes256gcm_decrypt_detached($ciphertext_dt[0], $ciphertext_dt[1], $ad, $nonce, $key); 148 | var_dump($msg === $msg3); 149 | } else { 150 | var_dump(true); 151 | var_dump(true); 152 | var_dump(true); 153 | } 154 | var_dump(sodium_crypto_aead_aes256gcm_decrypt($ciphertext, 'x' . $ad, $nonce, $key)); 155 | try { 156 | // Switched order 157 | $msg2 = sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $ad, $key, $nonce); 158 | var_dump(false); 159 | } catch (SodiumException $ex) { 160 | var_dump(true); 161 | } 162 | } else { 163 | var_dump(true); 164 | var_dump(true); 165 | var_dump(true); 166 | var_dump(true); 167 | var_dump(true); 168 | var_dump(false); 169 | var_dump(true); 170 | } 171 | ?> 172 | --EXPECT-- 173 | aead_chacha20poly1305: 174 | bool(true) 175 | bool(true) 176 | bool(true) 177 | bool(true) 178 | bool(true) 179 | bool(false) 180 | bool(true) 181 | aead_chacha20poly1305_ietf: 182 | bool(true) 183 | bool(true) 184 | bool(true) 185 | bool(true) 186 | bool(true) 187 | bool(false) 188 | bool(true) 189 | aead_xchacha20poly1305_ietf: 190 | bool(true) 191 | bool(true) 192 | bool(true) 193 | bool(true) 194 | bool(true) 195 | bool(false) 196 | bool(true) 197 | aead_aes256gcm: 198 | bool(true) 199 | bool(true) 200 | bool(true) 201 | bool(true) 202 | bool(true) 203 | bool(false) 204 | bool(true) 205 | -------------------------------------------------------------------------------- /tests/crypto_auth.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium auth 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getMessage(), PHP_EOL; 20 | } 21 | 22 | // Flip the first bit 23 | $badmsg = $msg; 24 | $badmsg[0] = \chr(\ord($badmsg[0]) ^ 0x80); 25 | var_dump(sodium_crypto_auth_verify($mac, $badmsg, $key)); 26 | 27 | // Let's flip a bit pseudo-randomly 28 | $badmsg = $msg; 29 | $badmsg[$i=mt_rand(0, 999)] = \chr( 30 | \ord($msg[$i]) ^ ( 31 | 1 << mt_rand(0, 7) 32 | ) 33 | ); 34 | 35 | var_dump(sodium_crypto_auth_verify($mac, $badmsg, $key)); 36 | 37 | // Now let's change a bit in the MAC 38 | $badmac = $mac; 39 | $badmac[0] = \chr(\ord($badmac[0]) ^ 0x80); 40 | var_dump(sodium_crypto_auth_verify($badmac, $msg, $key)); 41 | ?> 42 | --EXPECT-- 43 | bool(true) 44 | key must be SODIUM_CRYPTO_AUTH_KEYBYTES bytes 45 | bool(false) 46 | bool(false) 47 | bool(false) 48 | -------------------------------------------------------------------------------- /tests/crypto_box.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium box 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getMessage(), PHP_EOL; 53 | } 54 | 55 | sodium_memzero($alice_box_kp); 56 | sodium_memzero($bob_box_kp); 57 | 58 | $alice_box_kp = sodium_crypto_box_seed_keypair($seed_x); 59 | $bob_box_kp = sodium_crypto_box_seed_keypair($seed_y); 60 | 61 | $alice_box_publickey = sodium_crypto_box_publickey($alice_box_kp); 62 | $bob_box_secretkey = sodium_crypto_box_secretkey($bob_box_kp); 63 | 64 | $bob_to_alice_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey( 65 | $bob_box_secretkey, 66 | $alice_box_publickey 67 | ); 68 | 69 | $plaintext = sodium_crypto_box_open( 70 | $ciphertext, 71 | $message_nonce, 72 | $bob_to_alice_kp 73 | ); 74 | 75 | var_dump($msg === $plaintext); 76 | 77 | $alice_kp = sodium_crypto_box_keypair(); 78 | $alice_secretkey = sodium_crypto_box_secretkey($alice_kp); 79 | $alice_publickey = sodium_crypto_box_publickey($alice_kp); 80 | 81 | $bob_kp = sodium_crypto_box_keypair(); 82 | $bob_secretkey = sodium_crypto_box_secretkey($bob_kp); 83 | $bob_publickey = sodium_crypto_box_publickey($bob_kp); 84 | 85 | $alice_to_bob_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey 86 | ($alice_secretkey, $bob_publickey); 87 | 88 | $bob_to_alice_kp = sodium_crypto_box_keypair_from_secretkey_and_publickey 89 | ($bob_secretkey, $alice_publickey); 90 | 91 | $alice_to_bob_message_nonce = random_bytes(SODIUM_CRYPTO_BOX_NONCEBYTES); 92 | 93 | $alice_to_bob_ciphertext = sodium_crypto_box('Hi, this is Alice', 94 | $alice_to_bob_message_nonce, 95 | $alice_to_bob_kp); 96 | 97 | $alice_message_decrypted_by_bob = sodium_crypto_box_open($alice_to_bob_ciphertext, 98 | $alice_to_bob_message_nonce, 99 | $bob_to_alice_kp); 100 | 101 | $bob_to_alice_message_nonce = random_bytes(SODIUM_CRYPTO_BOX_NONCEBYTES); 102 | 103 | $bob_to_alice_ciphertext = sodium_crypto_box('Hi Alice! This is Bob', 104 | $bob_to_alice_message_nonce, 105 | $bob_to_alice_kp); 106 | 107 | $bob_message_decrypted_by_alice = sodium_crypto_box_open($bob_to_alice_ciphertext, 108 | $bob_to_alice_message_nonce, 109 | $alice_to_bob_kp); 110 | 111 | var_dump($alice_message_decrypted_by_bob); 112 | var_dump($bob_message_decrypted_by_alice); 113 | 114 | if (SODIUM_LIBRARY_MAJOR_VERSION > 7 || 115 | (SODIUM_LIBRARY_MAJOR_VERSION == 7 && 116 | SODIUM_LIBRARY_MINOR_VERSION >= 5)) { 117 | $anonymous_message_to_alice = sodium_crypto_box_seal('Anonymous message', 118 | $alice_publickey); 119 | 120 | $decrypted_message = sodium_crypto_box_seal_open($anonymous_message_to_alice, 121 | $alice_kp); 122 | } else { 123 | $decrypted_message = 'Anonymous message'; 124 | } 125 | var_dump($decrypted_message); 126 | 127 | $msg = sodium_hex2bin( 128 | '7375f4094f1151640bd853cb13dbc1a0ee9e13b0287a89d34fa2f6732be9de13f88457553d'. 129 | '768347116522d6d32c9cb353ef07aa7c83bd129b2bb5db35b28334c935b24f2639405a0604' 130 | ); 131 | $kp = sodium_hex2bin( 132 | '36a6c2b96a650d80bf7e025e0f58f3d636339575defb370801a54213bd54582d'. 133 | '5aecbcf7866e7a4d58a6c1317e2b955f54ecbe2fcbbf7d262c10636ed524480c' 134 | ); 135 | var_dump(sodium_crypto_box_seal_open($msg, $kp)); 136 | ?> 137 | --EXPECT-- 138 | bool(true) 139 | bool(true) 140 | bool(true) 141 | bool(true) 142 | bool(true) 143 | bool(true) 144 | bool(true) 145 | keypair size should be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes 146 | bool(true) 147 | string(17) "Hi, this is Alice" 148 | string(21) "Hi Alice! This is Bob" 149 | string(17) "Anonymous message" 150 | string(26) "This is for your eyes only" 151 | -------------------------------------------------------------------------------- /tests/crypto_core_ristretto255.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium scalarmult ristretto255 3 | --EXTENSIONS-- 4 | sodium 5 | --SKIPIF-- 6 | 9 | --FILE-- 10 | 92 | --EXPECT-- 93 | bool(false) 94 | bool(false) 95 | bool(false) 96 | bool(false) 97 | bool(false) 98 | bool(false) 99 | bool(false) 100 | bool(false) 101 | bool(false) 102 | bool(false) 103 | bool(false) 104 | bool(false) 105 | bool(false) 106 | bool(false) 107 | bool(false) 108 | bool(false) 109 | string(64) "3066f82a1a747d45120d1740f14358531a8f04bbffe6a819f86dfe50f44a0a46" 110 | bool(true) 111 | bool(false) 112 | bool(true) 113 | bool(true) 114 | bool(true) 115 | -------------------------------------------------------------------------------- /tests/crypto_generichash.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium generichash 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 51 | --EXPECT-- 52 | string(64) "96a7ed8861db0abc006f473f9e64687875f3d9df8e723adae9f53a02b2aec378" 53 | string(64) "ba03e32a94ece425a77b350f029e0a3d37e6383158aa7cefa2b1b9470a7fcb7a" 54 | string(128) "8ccd640462e7380010c5722d7f3c2354781d1360430197ff233509c27353fd2597c8d689bfe769467056a0655b3faba6af4e4ade248558f7c53538c4d5b94806" 55 | string(128) "30f0e5f1e3beb7e0340976ac05a94043cce082d870e28e03c906e8fe9a88786271c6ba141eee2885e7444a870fac498cc78a13b0c53aefaec01bf38ebfe73b3f" 56 | string(64) "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8" 57 | string(64) "96a7ed8861db0abc006f473f9e64687875f3d9df8e723adae9f53a02b2aec378" 58 | string(64) "ba03e32a94ece425a77b350f029e0a3d37e6383158aa7cefa2b1b9470a7fcb7a" 59 | string(128) "8ccd640462e7380010c5722d7f3c2354781d1360430197ff233509c27353fd2597c8d689bfe769467056a0655b3faba6af4e4ade248558f7c53538c4d5b94806" 60 | string(128) "9ef702f51114c9dc2cc7521746e8beebe0a3ca9bb29ec729e16682ca982e7f69ff70235a46659a9a6c28f92fbd990288301b9a6b5517f1f2ba6518074af19a5a" 61 | string(128) "9ef702f51114c9dc2cc7521746e8beebe0a3ca9bb29ec729e16682ca982e7f69ff70235a46659a9a6c28f92fbd990288301b9a6b5517f1f2ba6518074af19a5a" 62 | bool(true) 63 | bool(true) 64 | bool(true) 65 | -------------------------------------------------------------------------------- /tests/crypto_hex.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium bin2hex 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 18 | --EXPECT-- 19 | int(0) 20 | bool(true) 21 | bool(true) 22 | -------------------------------------------------------------------------------- /tests/crypto_kdf.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium KDF 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 45 | --EXPECT-- 46 | bool(true) 47 | bool(true) 48 | bool(true) 49 | bool(true) 50 | bool(true) 51 | bool(true) 52 | bool(true) 53 | bool(true) 54 | bool(true) 55 | -------------------------------------------------------------------------------- /tests/crypto_kx.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium-based key exchange 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 28 | --EXPECT-- 29 | string(128) "b85c84f9828524519d32b97cd3dda961fdba2dbf407ae4601e2129229aa463c224eaf70f070a925d6d5176f20495d4d90867624d9a10379e2a9aef0955c9bf4e" 30 | string(128) "016e814c32b8b66225a403db45bf50fdd1966fb802c3115bf8aa90738c6a02de420ccdb534930fed9aaff12188bedc76e66251f399c404f2e4a15678fd4a484a" 31 | string(64) "99a430e61d718b71979ebcea6735c4648bc828cfb456890aeda4b628b77d5ac7" 32 | string(64) "99a430e61d718b71979ebcea6735c4648bc828cfb456890aeda4b628b77d5ac7" 33 | string(64) "876bef865a5ab3f4ae569ea5aaefe5014c3ec22a558c0a2f0274aa9985bd328d" 34 | string(64) "876bef865a5ab3f4ae569ea5aaefe5014c3ec22a558c0a2f0274aa9985bd328d" 35 | -------------------------------------------------------------------------------- /tests/crypto_scalarmult.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium scalarmult 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 18 | --EXPECT-- 19 | string(64) "4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742" 20 | bool(true) 21 | -------------------------------------------------------------------------------- /tests/crypto_scalarmult_ristretto255.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium scalarmult ristretto255 3 | --EXTENSIONS-- 4 | sodium 5 | --SKIPIF-- 6 | 9 | --FILE-- 10 | 28 | --EXPECT-- 29 | string(64) "2a684afd8de19c6964fffd28509294e2752fdbb79e13a58dec3aff51de65505e" 30 | string(64) "e08ec8d22c0901c1746da3844857e9bc25b77cfe14a412e7bcd2b4017aff0556" 31 | bool(true) 32 | string(64) "188101d76706b149e38523f7100891d0cc83e784d8499ca4899a9fe3a194ae6a" 33 | -------------------------------------------------------------------------------- /tests/crypto_secretbox.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium secretbox 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 23 | --EXPECT-- 24 | string(8) "74657374" 25 | bool(false) 26 | bool(true) 27 | -------------------------------------------------------------------------------- /tests/crypto_secretstream.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium secretstream 3 | --SKIPIF-- 4 | 8 | --FILE-- 9 | 5 | --FILE-- 6 | 24 | --EXPECT-- 25 | e0ad6fdbf8b9a191 26 | c667b37af201a2d9 27 | d27fa3fc70b45b72 28 | bool(true) 29 | -------------------------------------------------------------------------------- /tests/crypto_sign.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium ed25519 signatures 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 66 | --EXPECT-- 67 | bool(true) 68 | bool(true) 69 | bool(true) 70 | bool(true) 71 | bool(true) 72 | bool(true) 73 | bool(true) 74 | bool(true) 75 | bool(true) 76 | bool(true) 77 | bool(true) 78 | bool(false) 79 | bool(true) 80 | bool(true) 81 | bool(true) 82 | -------------------------------------------------------------------------------- /tests/crypto_stream.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium stream 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42 | --EXPECT-- 43 | int(100) 44 | bool(true) 45 | bool(true) 46 | bool(true) 47 | bool(true) 48 | bool(true) 49 | bool(true) 50 | bool(true) 51 | bool(true) 52 | bool(true) 53 | -------------------------------------------------------------------------------- /tests/crypto_stream_xchacha20.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium stream 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 42 | --EXPECT-- 43 | int(100) 44 | bool(true) 45 | bool(true) 46 | bool(true) 47 | bool(true) 48 | bool(true) 49 | bool(true) 50 | bool(true) 51 | bool(true) 52 | bool(true) 53 | -------------------------------------------------------------------------------- /tests/exception_trace_without_args.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | SodiumException backtraces do not contain function arguments 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 16 | --EXPECTF-- 17 | Fatal error: Uncaught SodiumException: a PHP string is required in %s:%d 18 | Stack trace: 19 | #0 %s(%d): sodium_memzero() 20 | #1 %s(%d): do_memzero() 21 | #2 {main} 22 | thrown in %s on line %d 23 | -------------------------------------------------------------------------------- /tests/inc_add.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | increment and add edge cases 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | getMessage(), "\n"; 13 | } 14 | 15 | $str = "abc"; 16 | $str2 = $str; 17 | sodium_increment($str); 18 | var_dump($str, $str2); 19 | 20 | $str = "ab" . ($x = "c"); 21 | $str2 = $str; 22 | sodium_increment($str); 23 | var_dump($str, $str2); 24 | 25 | $addStr = "\2\0\0"; 26 | 27 | $notStr = 123; 28 | try { 29 | sodium_add($notStr, $addStr); 30 | } catch (SodiumException $e) { 31 | echo $e->getMessage(), "\n"; 32 | } 33 | 34 | $str = "abc"; 35 | $str2 = $str; 36 | sodium_add($str, $addStr); 37 | var_dump($str, $str2); 38 | 39 | $str = "ab" . ($x = "c"); 40 | $str2 = $str; 41 | sodium_add($str, $addStr); 42 | var_dump($str, $str2); 43 | 44 | ?> 45 | --EXPECT-- 46 | a PHP string is required 47 | string(3) "bbc" 48 | string(3) "abc" 49 | string(3) "bbc" 50 | string(3) "abc" 51 | PHP strings are required 52 | string(3) "cbc" 53 | string(3) "abc" 54 | string(3) "cbc" 55 | string(3) "abc" 56 | -------------------------------------------------------------------------------- /tests/installed.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for sodium presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 20 | --EXPECT-- 21 | sodium extension is available 22 | -------------------------------------------------------------------------------- /tests/pwhash_argon2i.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium argon2i 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | 44 | --EXPECT-- 45 | bool(true) 46 | bool(true) 47 | bool(false) 48 | bool(true) 49 | bool(false) 50 | bool(true) 51 | bool(true) 52 | -------------------------------------------------------------------------------- /tests/utils.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium utils 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 7 || 30 | (SODIUM_LIBRARY_MAJOR_VERSION == 7 && 31 | SODIUM_LIBRARY_MINOR_VERSION >= 6)) { 32 | $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"; 33 | $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"; 34 | $v_1 .= ''; 35 | var_dump(sodium_compare($v_1, $v_2)); 36 | sodium_increment($v_1); 37 | var_dump(sodium_compare($v_1, $v_2)); 38 | sodium_increment($v_1); 39 | var_dump(sodium_compare($v_1, $v_2)); 40 | } else { 41 | // Dummy test results for libsodium < 1.0.4 42 | var_dump(-1, 0, 1); 43 | } 44 | 45 | $str = 'stdClass'; 46 | sodium_memzero($str); 47 | $obj = (object)array('foo' => 'bar'); 48 | var_dump($obj); 49 | 50 | $str = 'xyz'; 51 | $str_padded = sodium_pad($str, 16); 52 | var_dump(sodium_bin2hex($str_padded)); 53 | 54 | $str_unpadded = sodium_unpad($str_padded, 16); 55 | var_dump($str_unpadded == $str); 56 | 57 | if (defined('SODIUM_BASE64_VARIANT_ORIGINAL')) { 58 | for ($i = 0; $i < 100; $i++) { 59 | $bin = $i == 0 ? '' : random_bytes($i); 60 | $b64 = base64_encode($bin); 61 | $b64_ = sodium_bin2base64($bin, SODIUM_BASE64_VARIANT_ORIGINAL); 62 | if ($b64 !== $b64_) { 63 | echo "frombin[$b64] != frombin_[$b64_]\n"; 64 | } 65 | $bin_ = sodium_base642bin($b64, SODIUM_BASE64_VARIANT_ORIGINAL); 66 | if ($bin !== $bin_) { 67 | echo "frombase64([$b64]) != frombase64_[$b64]\n"; 68 | } 69 | $bin_ = sodium_base642bin(" $b64\n", SODIUM_BASE64_VARIANT_ORIGINAL, " \n"); 70 | if ($bin !== $bin_) { 71 | echo "frombase64([$b64]) != frombase64_([ $b64\\n])\n"; 72 | } 73 | } 74 | try { 75 | var_dump(sodium_base642bin('O1R', SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING)); 76 | } catch (Exception $e) { 77 | var_dump('base64("O1R") case passed'); 78 | } 79 | try { 80 | var_dump(sodium_base642bin('O1', SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING)); 81 | } catch (Exception $e) { 82 | var_dump('base64("O1") case passed'); 83 | } 84 | try { 85 | var_dump(sodium_base642bin('O', SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING)); 86 | } catch (Exception $e) { 87 | var_dump('base64("O") case passed'); 88 | } 89 | var_dump(sodium_base642bin('YWJjZA', SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING)); 90 | } else { 91 | var_dump('base64("O1R") case passed'); 92 | var_dump('base64("O1") case passed'); 93 | var_dump('base64("O") case passed'); 94 | var_dump('abcd'); 95 | } 96 | 97 | function foo() 98 | { 99 | throw new SodiumException('test'); 100 | } 101 | try { 102 | foo(); 103 | } catch (SodiumException $ex) { 104 | var_dump($ex->getMessage()); 105 | } 106 | 107 | ?> 108 | --EXPECT-- 109 | 0 110 | bool(true) 111 | bool(false) 112 | string(22) "0000810102030405060708" 113 | string(22) "0102840507090b0d000305" 114 | int(-1) 115 | int(0) 116 | int(1) 117 | object(stdClass)#1 (1) { 118 | ["foo"]=> 119 | string(3) "bar" 120 | } 121 | string(32) "78797a80000000000000000000000000" 122 | bool(true) 123 | string(25) "base64("O1R") case passed" 124 | string(24) "base64("O1") case passed" 125 | string(23) "base64("O") case passed" 126 | string(4) "abcd" 127 | string(4) "test" 128 | -------------------------------------------------------------------------------- /tests/version.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for libsodium version 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | = 5; 8 | echo "\n"; 9 | echo SODIUM_LIBRARY_MAJOR_VERSION >= 4; 10 | echo "\n"; 11 | echo SODIUM_LIBRARY_MINOR_VERSION >= 0; 12 | ?> 13 | --EXPECT-- 14 | 1 15 | 1 16 | 1 17 | 18 | --------------------------------------------------------------------------------