ExSRTP (ExSRTP v0.4.1)
View SourceExSRTP
Elixir implementation of Secure Real-time Transport Protocol (SRTP) and Secure Real-time Transport Control Protocol (SRTCP).
It implements the following references:
- RFC 3711 - The Secure Real-time Transport Protocol (SRTP).
- RFC 7714 - AES-GCM Authenticated Encryption in the Secure Real-time Transport Protocol
Supported Crypto Profiles
The library currently supports the following SRTP crypto profiles:
- AES_CM_128_HMAC_SHA1_80
- AES_CM_128_HMAC_SHA1_32
- AES_GCM_128
Backends
The library supports multiple backends for cryptographic operations:
elixir- Using Erlang's built-in crypto module (default)rust- A Rust-based backend for improved performance.
Rust Backend
For the rust backend, we offer precompiled NIFs for various platforms, so if your platform is supported, you can use the rust backend without needing to compile anything. However, if your platform is not supported or you want to compile from source, you need to have the rust toolchain installed on your system. You need aslo to add rustler dependency and set force build config:
{:ex_srtp, "~> 0.4.1", system_env: %{"EXSRTP_BUILD" => "1"}}
{:rustler, "~> 0.37.0"}Rust Backend and AES-GCM
The rust backend is using graviola for aes-gcm which only works on aarch64 and x86_64 architecture with some CPU features. If you are using an older CPU or different architecture, you should use the elixir backend or do not use AES_GCM crypto profile.
Installation
The package can be installed by adding ex_srtp to your list of dependencies in mix.exs:
def deps do
[
{:rustler, "~> 0.37", runtime: false} # Optional, if you want to compile the rust backend from source
{:ex_srtp, "~> 0.4.1"}
]
end
Summary
Functions
Creates a new SRTP session.
Creates a new SRTP session from a key and profile.
Same as new/1 but raises an error in case of failure.
Same as new/2 but raises an error in case of failure.
Protects (encrypts and authenticates) an RTP packet.
Same as protect/2 but raises an error in case of failure.
Protects (encrypts and authenticates) RTCP packets.
Same as protect_rtcp/2 but raises an error in case of failure.
Unprotects (decrypts and verifies) an RTP packet.
Same as unprotect/2 but raises an error in case of failure.
Unprotects (decrypts and verifies) RTCP packets.
Same as unprotect_rtcp/2 but raises an error in case of failure
Types
@type t() :: ExSRTP.Backend.state()
Functions
@spec new(ExSRTP.Policy.t()) :: {:ok, t()} | {:error, term()}
Creates a new SRTP session.
@spec new(binary(), ExSRTP.Policy.profile()) :: {:ok, t()} | {:error, term()}
Creates a new SRTP session from a key and profile.
iex> {:ok, srtp} = ExSRTP.new(<<1::128>>, :aes_cm_128_hmac_sha1_80)
iex> srtp != nil
true
iex> {:ok, srtp} = ExSRTP.new(<<1::128, 2::112>>, :aes_cm_128_hmac_sha1_80)
iex> srtp != nil
true
iex> ExSRTP.new(<<0::128>>, :invalid_profile)
{:error, :invalid_profile}
iex> ExSRTP.new(<<2::64>>, :aes_cm_128_hmac_sha1_80)
{:error, :invalid_key_size}
@spec new!(ExSRTP.Policy.t()) :: t()
Same as new/1 but raises an error in case of failure.
@spec new!(binary(), ExSRTP.Policy.profile()) :: t()
Same as new/2 but raises an error in case of failure.
@spec protect(ExRTP.Packet.t(), t()) :: ExSRTP.Backend.protect_return()
Protects (encrypts and authenticates) an RTP packet.
@spec protect!(ExRTP.Packet.t(), t()) :: {binary(), t()}
Same as protect/2 but raises an error in case of failure.
@spec protect_rtcp([ExRTCP.Packet.packet()], t()) :: ExSRTP.Backend.protect_return()
Protects (encrypts and authenticates) RTCP packets.
@spec protect_rtcp!([ExRTCP.Packet.packet()], t()) :: {binary(), t()}
Same as protect_rtcp/2 but raises an error in case of failure.
@spec unprotect(binary(), t()) :: {:ok, ExRTP.Packet.t(), t()} | {:error, term()}
Unprotects (decrypts and verifies) an RTP packet.
@spec unprotect!(binary(), t()) :: {ExRTP.Packet.t(), t()}
Same as unprotect/2 but raises an error in case of failure.
@spec unprotect_rtcp(binary(), t()) :: {:ok, [ExRTCP.Packet.packet()], t()} | {:error, term()}
Unprotects (decrypts and verifies) RTCP packets.
@spec unprotect_rtcp!(binary(), t()) :: {[ExRTCP.Packet.packet()], t()}
Same as unprotect_rtcp/2 but raises an error in case of failure