EncryptionMode
: string
in package
The voice transport encryption modes this library can negotiate.
Both are "rtpsize" AEAD modes with the same packet layout:
[RTP header][ciphertext][16-byte auth tag][4-byte nonce]. The RTP header, up to and
including the extension preamble, is the additional data, and the 32-bit nonce counter
appended to the packet is zero-padded to the cipher's nonce length.
Cases are declared in order of preference; self::negotiate() relies on it.
Tags
Table of Contents
Cases
- AEAD_AES256_GCM_RTPSIZE = 'aead_aes256_gcm_rtpsize'
- AES-256-GCM. Discord's preferred mode, but libsodium only offers it on CPUs with hardware AES.
- AEAD_XCHACHA20_POLY1305_RTPSIZE = 'aead_xchacha20_poly1305_rtpsize'
- XChaCha20-Poly1305. Discord requires every client to support it.
Methods
- decrypt() : string|false
- Decrypts and authenticates a frame.
- encrypt() : string
- Encrypts a frame, returning the ciphertext with the 16-byte auth tag appended.
- isAvailable() : bool
- Returns true if libsodium on this machine implements the mode's cipher.
- negotiate() : self|null
- Picks the mode to select from the voice server's offer: the most preferred mode that is both offered and available on this machine.
- nonceLength() : int
- Returns the cipher's nonce length in bytes: 12 for AES-256-GCM, 24 for XChaCha20-Poly1305.
Cases
AEAD_AES256_GCM_RTPSIZE
AES-256-GCM. Discord's preferred mode, but libsodium only offers it on CPUs with hardware AES.
AEAD_XCHACHA20_POLY1305_RTPSIZE
XChaCha20-Poly1305. Discord requires every client to support it.
Methods
decrypt()
Decrypts and authenticates a frame.
public
decrypt(string $ciphertext, string $additionalData, string $nonce, string $key) : string|false
Parameters
- $ciphertext : string
-
The ciphertext with the 16-byte auth tag appended.
- $additionalData : string
-
The RTP header.
- $nonce : string
-
The nonce, already padded to self::nonceLength().
- $key : string
-
The 32-byte secret key from the session description.
Tags
Return values
string|false —The plaintext, or false if authentication fails.
encrypt()
Encrypts a frame, returning the ciphertext with the 16-byte auth tag appended.
public
encrypt(string $message, string $additionalData, string $nonce, string $key) : string
Parameters
- $message : string
-
The plaintext frame.
- $additionalData : string
-
The RTP header.
- $nonce : string
-
The nonce, already padded to self::nonceLength().
- $key : string
-
The 32-byte secret key from the session description.
Tags
Return values
stringisAvailable()
Returns true if libsodium on this machine implements the mode's cipher.
public
isAvailable() : bool
Return values
boolnegotiate()
Picks the mode to select from the voice server's offer: the most preferred mode that is both offered and available on this machine.
public
static negotiate(array<string|int, string> $offered) : self|null
Parameters
- $offered : array<string|int, string>
-
The
modeslist from the voice Ready payload (op 2).
Return values
self|null —Null when the offer contains no mode this machine can run.
nonceLength()
Returns the cipher's nonce length in bytes: 12 for AES-256-GCM, 24 for XChaCha20-Poly1305.
public
nonceLength() : int