EDA.Voice.Crypto (EDA v0.3.0)

Copy Markdown View Source

Encryption dispatch for Discord voice.

Selects the appropriate encryption module based on the negotiated mode and handles RTP packet construction.

Summary

Functions

Decrypts a received voice packet.

Encrypts an opus frame with the RTP header prepended.

Selects the best encryption mode from the server's available modes.

Functions

decrypt_packet(packet, secret_key, mode)

@spec decrypt_packet(binary(), binary(), String.t()) :: {:ok, binary()} | :error

Decrypts a received voice packet.

For _rtpsize modes, the AAD is the RTP header + extension preamble (if present). The extension elements themselves are encrypted and must be stripped after decryption.

Returns {:ok, opus_data} or :error.

encrypt_packet(opus_frame, sequence, timestamp, ssrc, secret_key, mode, nonce)

@spec encrypt_packet(
  binary(),
  integer(),
  integer(),
  integer(),
  binary(),
  String.t(),
  integer()
) ::
  binary()

Encrypts an opus frame with the RTP header prepended.

Returns the full encrypted packet ready to send over UDP.

rtp_header(sequence, timestamp, ssrc)

@spec rtp_header(integer(), integer(), integer()) :: binary()

Builds an RTP header.

Format: <<0x80, 0x78, sequence::16-big, timestamp::32-big, ssrc::32-big>>

select_mode(available_modes)

@spec select_mode([String.t()]) :: {:ok, String.t()} | :error

Selects the best encryption mode from the server's available modes.

Returns {:ok, mode} or :error if no supported mode is available.