[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-includes/sodium_compat/src/ -> Compat.php (summary)

Libsodium compatibility layer

File Size: 2863 lines (110 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

ParagonIE_Sodium_Compat:: (79 methods):
  bin2hex()
  compare()
  crypto_aead_aes256gcm_is_available()
  crypto_aead_aes256gcm_decrypt()
  crypto_aead_aes256gcm_encrypt()
  crypto_aead_aes256gcm_keygen()
  crypto_aead_chacha20poly1305_decrypt()
  crypto_aead_chacha20poly1305_encrypt()
  crypto_aead_chacha20poly1305_ietf_decrypt()
  crypto_aead_chacha20poly1305_keygen()
  crypto_aead_chacha20poly1305_ietf_encrypt()
  crypto_aead_chacha20poly1305_ietf_keygen()
  crypto_aead_xchacha20poly1305_ietf_decrypt()
  crypto_aead_xchacha20poly1305_ietf_encrypt()
  crypto_aead_xchacha20poly1305_ietf_keygen()
  crypto_auth()
  crypto_auth_keygen()
  crypto_auth_verify()
  crypto_box()
  crypto_box_seal()
  crypto_box_seal_open()
  crypto_box_keypair()
  crypto_box_keypair_from_secretkey_and_publickey()
  crypto_box_open()
  crypto_box_publickey()
  crypto_box_publickey_from_secretkey()
  crypto_box_secretkey()
  crypto_box_seed_keypair()
  crypto_generichash()
  crypto_generichash_final()
  crypto_generichash_init()
  crypto_generichash_update()
  crypto_generichash_keygen()
  crypto_kx()
  crypto_pwhash()
  crypto_pwhash_is_available()
  crypto_pwhash_str()
  crypto_pwhash_str_verify()
  crypto_pwhash_scryptsalsa208sha256()
  crypto_pwhash_scryptsalsa208sha256_is_available()
  crypto_pwhash_scryptsalsa208sha256_str()
  crypto_pwhash_scryptsalsa208sha256_str_verify()
  crypto_scalarmult()
  crypto_scalarmult_base()
  crypto_secretbox()
  crypto_secretbox_open()
  crypto_secretbox_keygen()
  crypto_secretbox_xchacha20poly1305()
  crypto_secretbox_xchacha20poly1305_open()
  crypto_shorthash()
  crypto_shorthash_keygen()
  crypto_sign()
  crypto_sign_open()
  crypto_sign_keypair()
  crypto_sign_seed_keypair()
  crypto_sign_publickey()
  crypto_sign_publickey_from_secretkey()
  crypto_sign_secretkey()
  crypto_sign_detached()
  crypto_sign_verify_detached()
  crypto_sign_ed25519_pk_to_curve25519()
  crypto_sign_ed25519_sk_to_curve25519()
  crypto_stream()
  crypto_stream_xor()
  crypto_stream_keygen()
  hex2bin()
  increment()
  library_version_major()
  library_version_minor()
  memcmp()
  memzero()
  polyfill_is_fast()
  randombytes_buf()
  randombytes_uniform()
  randombytes_random16()
  runtime_speed_test()
  version_string()
  use_fallback()
  useNewSodiumAPI()


Class: ParagonIE_Sodium_Compat  - X-Ref

bin2hex($string)   X-Ref
Cache-timing-safe implementation of bin2hex().

param: string $string A string (probably raw binary)
return: string        A hexadecimal-encoded string

compare($left, $right)   X-Ref
Compare two strings, in constant-time.
Compared to memcmp(), compare() is more useful for sorting.

param: string $left  The left operand; must be a string
param: string $right The right operand; must be a string
return: int          If < 0 if the left operand is less than the right

crypto_aead_aes256gcm_is_available()   X-Ref
Is AES-256-GCM even available to use?

return: bool

crypto_aead_aes256gcm_decrypt($ciphertext = '',$assocData = '',$nonce = '',$key = '')   X-Ref
Authenticated Encryption with Associated Data: Decryption

Algorithm:
AES-256-GCM

This mode uses a 64-bit random nonce with a 64-bit counter.
IETF mode uses a 96-bit random nonce with a 32-bit counter.

param: string $ciphertext Encrypted message (with Poly1305 MAC appended)
param: string $assocData  Authenticated Associated Data (unencrypted)
param: string $nonce      Number to be used only Once; must be 8 bytes
param: string $key        Encryption key
return: string|bool       The original plaintext message

crypto_aead_aes256gcm_encrypt($plaintext = '',$assocData = '',$nonce = '',$key = '')   X-Ref
Authenticated Encryption with Associated Data: Encryption

Algorithm:
AES-256-GCM

param: string $plaintext Message to be encrypted
param: string $assocData Authenticated Associated Data (unencrypted)
param: string $nonce     Number to be used only Once; must be 8 bytes
param: string $key       Encryption key
return: string           Ciphertext with a 16-byte GCM message

crypto_aead_aes256gcm_keygen()   X-Ref
Return a secure random key for use with the AES-256-GCM
symmetric AEAD interface.

return: string

crypto_aead_chacha20poly1305_decrypt($ciphertext = '',$assocData = '',$nonce = '',$key = '')   X-Ref
Authenticated Encryption with Associated Data: Decryption

Algorithm:
ChaCha20-Poly1305

This mode uses a 64-bit random nonce with a 64-bit counter.
IETF mode uses a 96-bit random nonce with a 32-bit counter.

param: string $ciphertext Encrypted message (with Poly1305 MAC appended)
param: string $assocData  Authenticated Associated Data (unencrypted)
param: string $nonce      Number to be used only Once; must be 8 bytes
param: string $key        Encryption key
return: string            The original plaintext message

crypto_aead_chacha20poly1305_encrypt($plaintext = '',$assocData = '',$nonce = '',$key = '')   X-Ref
Authenticated Encryption with Associated Data

Algorithm:
ChaCha20-Poly1305

This mode uses a 64-bit random nonce with a 64-bit counter.
IETF mode uses a 96-bit random nonce with a 32-bit counter.

param: string $plaintext Message to be encrypted
param: string $assocData Authenticated Associated Data (unencrypted)
param: string $nonce     Number to be used only Once; must be 8 bytes
param: string $key       Encryption key
return: string           Ciphertext with a 16-byte Poly1305 message

crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext = '',$assocData = '',$nonce = '',$key = '')   X-Ref
Authenticated Encryption with Associated Data: Decryption

Algorithm:
ChaCha20-Poly1305

IETF mode uses a 96-bit random nonce with a 32-bit counter.
Regular mode uses a 64-bit random nonce with a 64-bit counter.

param: string $ciphertext Encrypted message (with Poly1305 MAC appended)
param: string $assocData  Authenticated Associated Data (unencrypted)
param: string $nonce      Number to be used only Once; must be 12 bytes
param: string $key        Encryption key
return: string            The original plaintext message

crypto_aead_chacha20poly1305_keygen()   X-Ref
Return a secure random key for use with the ChaCha20-Poly1305
symmetric AEAD interface.

return: string

crypto_aead_chacha20poly1305_ietf_encrypt($plaintext = '',$assocData = '',$nonce = '',$key = '')   X-Ref
Authenticated Encryption with Associated Data

Algorithm:
ChaCha20-Poly1305

IETF mode uses a 96-bit random nonce with a 32-bit counter.
Regular mode uses a 64-bit random nonce with a 64-bit counter.

param: string $plaintext Message to be encrypted
param: string $assocData Authenticated Associated Data (unencrypted)
param: string $nonce Number to be used only Once; must be 8 bytes
param: string $key Encryption key
return: string           Ciphertext with a 16-byte Poly1305 message

crypto_aead_chacha20poly1305_ietf_keygen()   X-Ref
Return a secure random key for use with the ChaCha20-Poly1305
symmetric AEAD interface. (IETF version)

return: string

crypto_aead_xchacha20poly1305_ietf_decrypt($ciphertext = '',$assocData = '',$nonce = '',$key = '',$dontFallback = false)   X-Ref
Authenticated Encryption with Associated Data: Decryption

Algorithm:
XChaCha20-Poly1305

This mode uses a 64-bit random nonce with a 64-bit counter.
IETF mode uses a 96-bit random nonce with a 32-bit counter.

param: string $ciphertext   Encrypted message (with Poly1305 MAC appended)
param: string $assocData    Authenticated Associated Data (unencrypted)
param: string $nonce        Number to be used only Once; must be 8 bytes
param: string $key          Encryption key
param: bool   $dontFallback Don't fallback to ext/sodium
return: string|bool         The original plaintext message

crypto_aead_xchacha20poly1305_ietf_encrypt($plaintext = '',$assocData = '',$nonce = '',$key = '',$dontFallback = false)   X-Ref
Authenticated Encryption with Associated Data

Algorithm:
XChaCha20-Poly1305

This mode uses a 64-bit random nonce with a 64-bit counter.
IETF mode uses a 96-bit random nonce with a 32-bit counter.

param: string $plaintext    Message to be encrypted
param: string $assocData    Authenticated Associated Data (unencrypted)
param: string $nonce        Number to be used only Once; must be 8 bytes
param: string $key          Encryption key
param: bool   $dontFallback Don't fallback to ext/sodium
return: string           Ciphertext with a 16-byte Poly1305 message

crypto_aead_xchacha20poly1305_ietf_keygen()   X-Ref
Return a secure random key for use with the XChaCha20-Poly1305
symmetric AEAD interface.

return: string

crypto_auth($message, $key)   X-Ref
Authenticate a message. Uses symmetric-key cryptography.

Algorithm:
HMAC-SHA512-256. Which is HMAC-SHA-512 truncated to 256 bits.
Not to be confused with HMAC-SHA-512/256 which would use the
SHA-512/256 hash function (uses different initial parameters
but still truncates to 256 bits to sidestep length-extension
attacks).

param: string $message Message to be authenticated
param: string $key Symmetric authentication key
return: string         Message authentication code

crypto_auth_keygen()   X-Ref

return: string

crypto_auth_verify($mac, $message, $key)   X-Ref
Verify the MAC of a message previously authenticated with crypto_auth.

param: string $mac Message authentication code
param: string $message Message whose authenticity you are attempting to
param: string $key Symmetric authentication key
return: bool           TRUE if authenticated, FALSE otherwise

crypto_box($plaintext, $nonce, $keypair)   X-Ref
Authenticated asymmetric-key encryption. Both the sender and recipient
may decrypt messages.

Algorithm: X25519-XSalsa20-Poly1305.
X25519: Elliptic-Curve Diffie Hellman over Curve25519.
XSalsa20: Extended-nonce variant of salsa20.
Poyl1305: Polynomial MAC for one-time message authentication.

param: string $plaintext The message to be encrypted
param: string $nonce A Number to only be used Once; must be 24 bytes
param: string $keypair Your secret key and your recipient's public key
return: string           Ciphertext with 16-byte Poly1305 MAC

crypto_box_seal($plaintext, $publicKey)   X-Ref
Anonymous public-key encryption. Only the recipient may decrypt messages.

Algorithm: X25519-XSalsa20-Poly1305, as with crypto_box.
The sender's X25519 keypair is ephemeral.
Nonce is generated from the BLAKE2b hash of both public keys.

This provides ciphertext integrity.

param: string $plaintext Message to be sealed
param: string $publicKey Your recipient's public key
return: string           Sealed message that only your recipient can

crypto_box_seal_open($ciphertext, $keypair)   X-Ref
Opens a message encrypted with crypto_box_seal(). Requires
the recipient's keypair (sk || pk) to decrypt successfully.

This validates ciphertext integrity.

param: string $ciphertext Sealed message to be opened
param: string $keypair    Your crypto_box keypair
return: string            The original plaintext message

crypto_box_keypair()   X-Ref
Generate a new random X25519 keypair.

return: string A 64-byte string; the first 32 are your secret key, while

crypto_box_keypair_from_secretkey_and_publickey($secretKey, $publicKey)   X-Ref
Combine two keys into a keypair for use in library methods that expect
a keypair. This doesn't necessarily have to be the same person's keys.

param: string $secretKey Secret key
param: string $publicKey Public key
return: string    Keypair

crypto_box_open($ciphertext, $nonce, $keypair)   X-Ref
Decrypt a message previously encrypted with crypto_box().

param: string $ciphertext Encrypted message
param: string $nonce      Number to only be used Once; must be 24 bytes
param: string $keypair    Your secret key and the sender's public key
return: string            The original plaintext message

crypto_box_publickey($keypair)   X-Ref
Extract the public key from a crypto_box keypair.

param: string $keypair Keypair containing secret and public key
return: string         Your crypto_box public key

crypto_box_publickey_from_secretkey($secretKey)   X-Ref
Calculate the X25519 public key from a given X25519 secret key.

param: string $secretKey Any X25519 secret key
return: string           The corresponding X25519 public key

crypto_box_secretkey($keypair)   X-Ref
Extract the secret key from a crypto_box keypair.

param: string $keypair
return: string         Your crypto_box secret key

crypto_box_seed_keypair($seed)   X-Ref
Generate an X25519 keypair from a seed.

param: string $seed
return: string

crypto_generichash($message, $key = '', $length = self::CRYPTO_GENERICHASH_BYTES)   X-Ref
Calculates a BLAKE2b hash, with an optional key.

param: string      $message The message to be hashed
param: string|null $key     If specified, must be a string between 16
param: int         $length  Output length in bytes; must be between 16
return: string              Raw binary

crypto_generichash_final(&$ctx, $length = self::CRYPTO_GENERICHASH_BYTES)   X-Ref
Get the final BLAKE2b hash output for a given context.

param: string $ctx BLAKE2 hashing context. Generated by crypto_generichash_init().
param: int $length Hash output size.
return: string     Final BLAKE2b hash.

crypto_generichash_init($key = '', $length = self::CRYPTO_GENERICHASH_BYTES)   X-Ref
Initialize a BLAKE2b hashing context, for use in a streaming interface.

param: string|null $key If specified must be a string between 16 and 64 bytes
param: int $length      The size of the desired hash output
return: string          A BLAKE2 hashing context, encoded as a string

crypto_generichash_update(&$ctx, $message)   X-Ref
Update a BLAKE2b hashing context with additional data.

param: string $ctx    BLAKE2 hashing context. Generated by crypto_generichash_init().
param: -out string $ctx
param: string $message The message to append to the existing hash state.
return: void

crypto_generichash_keygen()   X-Ref

return: string

crypto_kx($my_secret, $their_public, $client_public, $server_public)   X-Ref
Perform a key exchange, between a designated client and a server.

Typically, you would designate one machine to be the client and the
other to be the server. The first two keys are what you'd expect for
scalarmult() below, but the latter two public keys don't swap places.

| ALICE                          | BOB                                 |
| Client                         | Server                              |
|--------------------------------|-------------------------------------|
| shared = crypto_kx(            | shared = crypto_kx(                 |
|     alice_sk,                  |     bob_sk,                         | <- contextual
|     bob_pk,                    |     alice_pk,                       | <- contextual
|     alice_pk,                  |     alice_pk,                       | <----- static
|     bob_pk                     |     bob_pk                          | <----- static
| )                              | )                                   |

They are used along with the scalarmult product to generate a 256-bit
BLAKE2b hash unique to the client and server keys.

param: string $my_secret
param: string $their_public
param: string $client_public
param: string $server_public
return: string

crypto_pwhash($outlen, $passwd, $salt, $opslimit, $memlimit, $alg = null)   X-Ref

param: int $outlen
param: string $passwd
param: string $salt
param: int $opslimit
param: int $memlimit
param: int|null $alg
return: string

crypto_pwhash_is_available()   X-Ref
!Exclusive to sodium_compat!

This returns TRUE if the native crypto_pwhash API is available by libsodium.
This returns FALSE if only sodium_compat is available.

return: bool

crypto_pwhash_str($passwd, $opslimit, $memlimit)   X-Ref

param: string $passwd
param: int $opslimit
param: int $memlimit
return: string

crypto_pwhash_str_verify($passwd, $hash)   X-Ref

param: string $passwd
param: string $hash
return: bool

crypto_pwhash_scryptsalsa208sha256($outlen, $passwd, $salt, $opslimit, $memlimit)   X-Ref

param: int $outlen
param: string $passwd
param: string $salt
param: int $opslimit
param: int $memlimit
return: string

crypto_pwhash_scryptsalsa208sha256_is_available()   X-Ref
!Exclusive to sodium_compat!

This returns TRUE if the native crypto_pwhash API is available by libsodium.
This returns FALSE if only sodium_compat is available.

return: bool

crypto_pwhash_scryptsalsa208sha256_str($passwd, $opslimit, $memlimit)   X-Ref

param: string $passwd
param: int $opslimit
param: int $memlimit
return: string

crypto_pwhash_scryptsalsa208sha256_str_verify($passwd, $hash)   X-Ref

param: string $passwd
param: string $hash
return: bool

crypto_scalarmult($secretKey, $publicKey)   X-Ref
Calculate the shared secret between your secret key and your
recipient's public key.

Algorithm: X25519 (ECDH over Curve25519)

param: string $secretKey
param: string $publicKey
return: string

crypto_scalarmult_base($secretKey)   X-Ref
Calculate an X25519 public key from an X25519 secret key.

param: string $secretKey
return: string

crypto_secretbox($plaintext, $nonce, $key)   X-Ref
Authenticated symmetric-key encryption.

Algorithm: XSalsa20-Poly1305

param: string $plaintext The message you're encrypting
param: string $nonce A Number to be used Once; must be 24 bytes
param: string $key Symmetric encryption key
return: string           Ciphertext with Poly1305 MAC

crypto_secretbox_open($ciphertext, $nonce, $key)   X-Ref
Decrypts a message previously encrypted with crypto_secretbox().

param: string $ciphertext Ciphertext with Poly1305 MAC
param: string $nonce      A Number to be used Once; must be 24 bytes
param: string $key        Symmetric encryption key
return: string            Original plaintext message

crypto_secretbox_keygen()   X-Ref
Return a secure random key for use with crypto_secretbox

return: string

crypto_secretbox_xchacha20poly1305($plaintext, $nonce, $key)   X-Ref
Authenticated symmetric-key encryption.

Algorithm: XChaCha20-Poly1305

param: string $plaintext The message you're encrypting
param: string $nonce     A Number to be used Once; must be 24 bytes
param: string $key       Symmetric encryption key
return: string           Ciphertext with Poly1305 MAC

crypto_secretbox_xchacha20poly1305_open($ciphertext, $nonce, $key)   X-Ref
Decrypts a message previously encrypted with crypto_secretbox_xchacha20poly1305().

param: string $ciphertext Ciphertext with Poly1305 MAC
param: string $nonce      A Number to be used Once; must be 24 bytes
param: string $key        Symmetric encryption key
return: string            Original plaintext message

crypto_shorthash($message, $key)   X-Ref
Calculates a SipHash-2-4 hash of a message for a given key.

param: string $message Input message
param: string $key SipHash-2-4 key
return: string         Hash

crypto_shorthash_keygen()   X-Ref
Return a secure random key for use with crypto_shorthash

return: string

crypto_sign($message, $secretKey)   X-Ref
Returns a signed message. You probably want crypto_sign_detached()
instead, which only returns the signature.

Algorithm: Ed25519 (EdDSA over Curve25519)

param: string $message Message to be signed.
param: string $secretKey Secret signing key.
return: string           Signed message (signature is prefixed).

crypto_sign_open($signedMessage, $publicKey)   X-Ref
Validates a signed message then returns the message.

param: string $signedMessage A signed message
param: string $publicKey A public key
return: string               The original message (if the signature is

crypto_sign_keypair()   X-Ref
Generate a new random Ed25519 keypair.

return: string

crypto_sign_seed_keypair($seed)   X-Ref
Generate an Ed25519 keypair from a seed.

param: string $seed Input seed
return: string      Keypair

crypto_sign_publickey($keypair)   X-Ref
Extract an Ed25519 public key from an Ed25519 keypair.

param: string $keypair Keypair
return: string         Public key

crypto_sign_publickey_from_secretkey($secretKey)   X-Ref
Calculate an Ed25519 public key from an Ed25519 secret key.

param: string $secretKey Your Ed25519 secret key
return: string           The corresponding Ed25519 public key

crypto_sign_secretkey($keypair)   X-Ref
Extract an Ed25519 secret key from an Ed25519 keypair.

param: string $keypair Keypair
return: string         Secret key

crypto_sign_detached($message, $secretKey)   X-Ref
Calculate the Ed25519 signature of a message and return ONLY the signature.

Algorithm: Ed25519 (EdDSA over Curve25519)

param: string $message Message to be signed
param: string $secretKey Secret signing key
return: string           Digital signature

crypto_sign_verify_detached($signature, $message, $publicKey)   X-Ref
Verify the Ed25519 signature of a message.

param: string $signature Digital sginature
param: string $message Message to be verified
param: string $publicKey Public key
return: bool             TRUE if this signature is good for this public key;

crypto_sign_ed25519_pk_to_curve25519($pk)   X-Ref
Convert an Ed25519 public key to a Curve25519 public key

param: string $pk
return: string

crypto_sign_ed25519_sk_to_curve25519($sk)   X-Ref
Convert an Ed25519 secret key to a Curve25519 secret key

param: string $sk
return: string

crypto_stream($len, $nonce, $key)   X-Ref
Expand a key and nonce into a keystream of pseudorandom bytes.

param: int $len Number of bytes desired
param: string $nonce Number to be used Once; must be 24 bytes
param: string $key XSalsa20 key
return: string       Pseudorandom stream that can be XORed with messages

crypto_stream_xor($message, $nonce, $key)   X-Ref
DANGER! UNAUTHENTICATED ENCRYPTION!

Unless you are following expert advice, do not used this feature.

Algorithm: XSalsa20

This DOES NOT provide ciphertext integrity.

param: string $message Plaintext message
param: string $nonce Number to be used Once; must be 24 bytes
param: string $key Encryption key
return: string         Encrypted text which is vulnerable to chosen-

crypto_stream_keygen()   X-Ref
Return a secure random key for use with crypto_stream

return: string

hex2bin($string)   X-Ref
Cache-timing-safe implementation of hex2bin().

param: string $string Hexadecimal string
return: string        Raw binary string

increment(&$var)   X-Ref
Increase a string (little endian)

param: string $var
return: void

library_version_major()   X-Ref
The equivalent to the libsodium minor version we aim to be compatible
with (sans pwhash and memzero).

return: int

library_version_minor()   X-Ref
The equivalent to the libsodium minor version we aim to be compatible
with (sans pwhash and memzero).

return: int

memcmp($left, $right)   X-Ref
Compare two strings.

param: string $left
param: string $right
return: int

memzero(&$var)   X-Ref
It's actually not possible to zero memory buffers in PHP. You need the
native library for that.

param: string|null $var
param: -out string|null $var
return: void

polyfill_is_fast()   X-Ref
Will sodium_compat run fast on the current hardware and PHP configuration?

return: bool

randombytes_buf($numBytes)   X-Ref
Generate a string of bytes from the kernel's CSPRNG.
Proudly uses /dev/urandom (if getrandom(2) is not available).

param: int $numBytes
return: string

randombytes_uniform($range)   X-Ref
Generate an integer between 0 and $range (non-inclusive).

param: int $range
return: int

randombytes_random16()   X-Ref
Generate a random 16-bit integer.

return: int

runtime_speed_test($iterations, $maxTimeout)   X-Ref
Runtime testing method for 32-bit platforms.

Usage: If runtime_speed_test() returns FALSE, then our 32-bit
implementation is to slow to use safely without risking timeouts.
If this happens, install sodium from PECL to get acceptable
performance.

param: int $iterations Number of multiplications to attempt
param: int $maxTimeout Milliseconds
return: bool           TRUE if we're fast enough, FALSE is not

version_string()   X-Ref
This emulates libsodium's version_string() function, except ours is
prefixed with 'polyfill-'.

return: string

use_fallback($sodium_func_name = '')   X-Ref
Should we use the libsodium core function instead?
This is always a good idea, if it's available. (Unless we're in the
middle of running our unit test suite.)

If ext/libsodium is available, use it. Return TRUE.
Otherwise, we have to use the code provided herein. Return FALSE.

param: string $sodium_func_name
return: bool

useNewSodiumAPI()   X-Ref
Libsodium as implemented in PHP 7.2
and/or ext/sodium (via PECL)

return: bool



Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7