diff --git a/stub/Sodium.stub.php b/stub/Sodium.stub.php index 77b3cd3..d81d7af 100644 --- a/stub/Sodium.stub.php +++ b/stub/Sodium.stub.php @@ -2,6 +2,9 @@ declare(strict_types=1); namespace Sodium; +if (\extension_loaded('libsodium')) { + return; +} const CRYPTO_AEAD_AES256GCM_KEYBYTES = 32; const CRYPTO_AEAD_AES256GCM_NSECBYTES = 0; const CRYPTO_AEAD_AES256GCM_NPUBBYTES = 12; @@ -57,18 +60,11 @@ const CRYPTO_STREAM_KEYBYTES = 32; const CRYPTO_STREAM_NONCEBYTES = 24; -/** - * To silence the phpstorm "unknown namespace" errors. - * - * This does nothing if the libsodium extension is loaded, so it's harmless. - * - * This file alone is released under CC0 and WTFPL dual licensing. - */ if (!\extension_loaded('libsodium')) { /** * Can you access AES-256-GCM? This is only available if you have supported * hardware. - * + * * @return bool */ function crypto_aead_aes256gcm_is_available(): bool @@ -82,7 +78,7 @@ function crypto_aead_aes256gcm_is_available(): bool /** * Authenticated Encryption with Associated Data (decrypt) * AES-256-GCM - * + * * @param string $msg encrypted message * @param string $nonce * @param string $key @@ -104,7 +100,7 @@ function crypto_aead_aes256gcm_decrypt( /** * Authenticated Encryption with Associated Data (encrypt) * AES-256-GCM - * + * * @param string $msg plaintext message * @param string $nonce * @param string $key @@ -126,7 +122,7 @@ function crypto_aead_aes256gcm_encrypt( /** * Authenticated Encryption with Associated Data (decrypt) * ChaCha20 + Poly1305 - * + * * @param string $msg encrypted message * @param string $nonce * @param string $key @@ -148,7 +144,7 @@ function crypto_aead_chacha20poly1305_decrypt( /** * Authenticated Encryption with Associated Data (encrypt) * ChaCha20 + Poly1305 - * + * * @param string $msg plaintext message * @param string $nonce * @param string $key @@ -170,7 +166,7 @@ function crypto_aead_chacha20poly1305_encrypt( /** * Secret-key message authentication * HMAC SHA-512/256 - * + * * @param string $msg * @param string $key * @return string @@ -188,7 +184,7 @@ function crypto_auth( /** * Secret-key message verification * HMAC SHA-512/256 - * + * * @param string $mac * @param string $msg * @param string $key @@ -208,7 +204,7 @@ function crypto_auth_verify( /** * Public-key authenticated encryption (encrypt) * X25519 + Xsalsa20 + Poly1305 - * + * * @param string $msg * @param string $nonce * @param string $keypair @@ -227,7 +223,7 @@ function crypto_box( /** * Generate an X25519 keypair for use with the crypto_box API - * + * * @return string */ function crypto_box_keypair(): string { @@ -239,7 +235,7 @@ function crypto_box_keypair(): string { /** * Derive an X25519 keypair for use with the crypto_box API from a seed - * + * * @param string $seed * @return string */ @@ -254,7 +250,7 @@ function crypto_box_seed_keypair( /** * Create an X25519 keypair from an X25519 secret key and X25519 public key - * + * * @param string $secretkey * @param string $publickey * @return string @@ -272,7 +268,7 @@ function crypto_box_keypair_from_secretkey_and_publickey( /** * Public-key authenticated encryption (decrypt) * X25519 + Xsalsa20 + Poly1305 - * + * * @param string $msg * @param string $nonce * @param string $keypair @@ -291,7 +287,7 @@ function crypto_box_open( /** * Get an X25519 public key from an X25519 keypair - * + * * @param string $keypair * @return string */ @@ -306,7 +302,7 @@ function crypto_box_publickey( /** * Derive an X25519 public key from an X25519 secret key - * + * * @param string $secretkey * @return string */ @@ -322,7 +318,7 @@ function crypto_box_publickey_from_secretkey( /** * Anonymous public-key encryption (encrypt) * X25519 + Xsalsa20 + Poly1305 + BLAKE2b - * + * * @param string $message * @param string $publickey * @return string @@ -336,11 +332,11 @@ function crypto_box_seal( } return ''; } - + /** * Anonymous public-key encryption (decrypt) * X25519 + Xsalsa20 + Poly1305 + BLAKE2b - * + * * @param string $encrypted * @param string $keypair * @return string @@ -354,10 +350,10 @@ function crypto_box_seal_open( } return ''; } - + /** * Extract the X25519 secret key from an X25519 keypair - * + * * @param string $keypair * @return string */ @@ -372,7 +368,7 @@ function crypto_box_secretkey(string $keypair): string /** * Elliptic Curve Diffie Hellman Key Exchange * X25519 - * + * * @param string $secretkey * @param string $publickey * @param string $client_publickey @@ -390,10 +386,10 @@ function crypto_kx( } return ''; } - + /** * Fast and secure cryptographic hash - * + * * @param string $input * @param string $key * @param int $length @@ -413,7 +409,7 @@ function crypto_generichash( /** * Create a new hash state (e.g. to use for streams) * BLAKE2b - * + * * @param string $key * @param int $length * @return string @@ -431,7 +427,7 @@ function crypto_generichash_init( /** * Update the hash state with some data * BLAKE2b - * + * * @param &string $hashState * @param string $append * @return bool @@ -448,7 +444,7 @@ function crypto_generichash_update( /** * Get the final hash * BLAKE2b - * + * * @param string $hashState * @param int $length * @return string @@ -466,7 +462,7 @@ function crypto_generichash_final( /** * Secure password-based key derivation function * Argon2i - * + * * @param int $out_len * @param string $passwd * @param string $salt @@ -490,7 +486,7 @@ function crypto_pwhash( /** * Get a formatted password hash (for storage) * Argon2i - * + * * @param string $passwd * @param int $opslimit * @param int $memlimit @@ -510,7 +506,7 @@ function crypto_pwhash_str( /** * Verify a password against a hash * Argon2i - * + * * @param string $hash * @param string $passwd * @return bool @@ -528,7 +524,7 @@ function crypto_pwhash_str_verify( /** * Secure password-based key derivation function * Scrypt - * + * * @param int $out_len * @param string $passwd * @param string $salt @@ -552,7 +548,7 @@ function crypto_pwhash_scryptsalsa208sha256( /** * Get a formatted password hash (for storage) * Scrypt - * + * * @param string $passwd * @param int $opslimit * @param int $memlimit @@ -572,7 +568,7 @@ function crypto_pwhash_scryptsalsa208sha256_str( /** * Verify a password against a hash * Scrypt - * + * * @param string $hash * @param string $passwd * @return bool @@ -590,7 +586,7 @@ function crypto_pwhash_scryptsalsa208sha256_str_verify( /** * Elliptic Curve Diffie Hellman over Curve25519 * X25519 - * + * * @param string $ecdhA * @param string $ecdhB * @return string @@ -608,7 +604,7 @@ function crypto_scalarmult( /** * Authenticated secret-key encryption (encrypt) * Xsals20 + Poly1305 - * + * * @param string $plaintext * @param string $nonce * @param string $key @@ -628,7 +624,7 @@ function crypto_secretbox( /** * Authenticated secret-key encryption (decrypt) * Xsals20 + Poly1305 - * + * * @param string $ciphertext * @param string $nonce * @param string $key @@ -648,7 +644,7 @@ function crypto_secretbox_open( /** * A short keyed hash suitable for data structures * SipHash-2-4 - * + * * @param string $message * @param string $key * @return string @@ -666,7 +662,7 @@ function crypto_shorthash( /** * Digital Signature * Ed25519 - * + * * @param string $message * @param string $secretkey * @return string @@ -684,7 +680,7 @@ function crypto_sign( /** * Digital Signature (detached) * Ed25519 - * + * * @param string $message * @param string $secretkey * @return string @@ -701,7 +697,7 @@ function crypto_sign_detached( /** * Convert an Ed25519 public key to an X25519 public key - * + * * @param string $sign_pk * @return string */ @@ -716,7 +712,7 @@ function crypto_sign_ed25519_pk_to_curve25519( /** * Convert an Ed25519 secret key to an X25519 secret key - * + * * @param string $sign_sk * @return string */ @@ -732,7 +728,7 @@ function crypto_sign_ed25519_sk_to_curve25519( /** * Generate an Ed25519 keypair for use with the crypto_sign API - * + * * @return string */ function crypto_sign_keypair(): string @@ -746,7 +742,7 @@ function crypto_sign_keypair(): string /** * Create an Ed25519 keypair from an Ed25519 secret key + Ed25519 public key - * + * * @param string $secretkey * @param string $publickey * @return string @@ -763,7 +759,7 @@ function crypto_sign_keypair_from_secretkey_and_publickey( /** * Verify a signed message and return the plaintext - * + * * @param string $signed_message * @param string $publickey * @return string @@ -780,7 +776,7 @@ function crypto_sign_open( /** * Get the public key from an Ed25519 keypair - * + * * @param string $keypair * @return string */ @@ -795,7 +791,7 @@ function crypto_sign_publickey( /** * Get the secret key from an Ed25519 keypair - * + * * @param string $keypair * @return string */ @@ -810,7 +806,7 @@ function crypto_sign_secretkey( /** * Derive an Ed25519 public key from an Ed25519 secret key - * + * * @param string $secretkey * @return string */ @@ -825,7 +821,7 @@ function crypto_sign_publickey_from_secretkey( /** * Derive an Ed25519 keypair for use with the crypto_sign API from a seed - * + * * @param string $seed * @return string */ @@ -840,7 +836,7 @@ function crypto_sign_seed_keypair( /** * Verify a detached signature - * + * * @param string $signature * @param string $msg * @param string $publickey @@ -860,7 +856,7 @@ function crypto_sign_verify_detached( /** * Create a keystream from a key and nonce * Xsalsa20 - * + * * @param int $length * @param string $nonce * @param string $key @@ -880,7 +876,7 @@ function crypto_stream( /** * Encrypt a message using a stream cipher * Xsalsa20 - * + * * @param string $plaintext * @param string $nonce * @param string $key @@ -900,7 +896,7 @@ function crypto_stream_xor( /** * Generate a string of random bytes * /dev/urandom - * + * * @param int $length * @return string */ @@ -913,7 +909,7 @@ function randombytes_buf( /** * Generate a 16-bit integer * /dev/urandom - * + * * @return int */ function randombytes_random16(): int @@ -924,7 +920,7 @@ function randombytes_random16(): int /** * Generate an unbiased random integer between 0 and a specified value * /dev/urandom - * + * * @param int $upperBoundNonInclusive * @return int */ @@ -936,7 +932,7 @@ function randombytes_uniform( /** * Convert to hex without side-chanels - * + * * @param string $binary * @return string */ @@ -951,7 +947,7 @@ function bin2hex( /** * Compare two strings in constant time - * + * * @param string $left * @param string $right * @return int @@ -968,7 +964,7 @@ function compare( /** * Convert from hex without side-chanels - * + * * @param string $binary * @return string */ @@ -980,10 +976,10 @@ function hex2bin( } return ''; } - + /** * Increment a string in little-endian - * + * * @param &string $nonce * @return string */ @@ -997,7 +993,7 @@ function increment(string &$nonce) /** * Add the right operand to the left - * + * * @param string &$left * @param string $right * @return string @@ -1033,10 +1029,10 @@ function library_version_minor(): int { } return 0; } - + /** * Compare two strings in constant time - * + * * @param string $left * @param string $right * @return int @@ -1053,7 +1049,7 @@ function memcmp( /** * Wipe a buffer - * + * * @param &string $nonce */ function memzero( @@ -1067,7 +1063,7 @@ function memzero( /** * Get the version string - * + * * @return string */ function version_string(): string { @@ -1079,7 +1075,7 @@ function version_string(): string { /** * Scalar multiplication of the base point and your key - * + * * @param string $sk * @return string */