A pure rust implementation of Secure Real-time Transport Protocol (SRTP)
This crate implements RFC 3711, RFC 6188 and RFC 7714
Features
This library supports all the mandatory features from RFC 3711, RFC 6188 and RFC 7714. The following optional features are not supported:
- key derivation rates
- AES in f8 mode
- master key selection based on packet index
This library aims to support the same set of features supported by Cisco's SRTP C library libsrtp.
Features list
- Support for protection profiles:
- Null Cipher with full auth tag. RFC 3711
- AES128 Counter mode - with no, short or full auth tag. RFC 3711
- AES192/256 Counter mode - with no, short or full auth tag. RFC6188
- AES128/256 GCM with 16 bytes auth tag. RFC7714
- Notes:
- for RTCP, short or no auth tag is not supported as specified in RFC 3711
- auth tag only is not supported for GCM. The only way avoid encryption while authenticating is to use the NullCipherHmacSha180 profile.
- Master Key Identifier (MKI)
- Replay protection (default window size is 128) - opt out possible on RTP sending side
- Keys lifetime
- keys lifetime can be set on a master key basis. The default values are 248 for RTP and 231 for RTCP, they can only be lowered.
- keys lifetime is decreased on a stream/master key base, even for stream spawned from template and thus sharing the master key. Each templated stream gets it own life count, one for each mki(when used).
- Any key reaching its end of life(on RTP or RCTP) will disable all keys derived from the same master key including:
- the other component of the stream: RTP end of life disables RTCP, RTCP end of life disables RTP
- the other streams spwaned from the same master key if any
- when using mki, keys derived from others master key are not affected
- Index rollback
- due to re-keying (which does not reset RTP nor RTCP indexes), a key end of life does not necessarily happens on index rollback.
- RTCP index rollback is supported: after sending 2^31 RTCP packets, provided several mkis were used, the next RTCP packet index will roll back to 0.
- RTP index being on 48 bits, a rollback seem very unlikely in real life and is not supported.
- Key limit alert
- When provided, a key limit handler is called when a key life is nearing the end (2^16 lives left by default) or is over.
- When a key reaches its end of life, any operation using it will:
- call the key limit handler
- fail returning a KeyLimit error
- Multithreading
- full support for multithreading operations
- sessions can be shared among different thread, so each stream can run in its own thread
Non supported features list
The following features are supported by Cisco's libsrtp but not yet by this library:
- Encryption of Header Extensions RFC 6904
- Completely Encrypting RTP Header Extensions and Contributing Sources RFC 9335
Implementation note
The base cryptographic operations (HMAC-SHA1, AES-CTR, AES-GCM) are provided by RustCrypto crates.
Testing
Testing requires helpers crates found on this repository
Interoperability test with cisco's libsrtp are provided in a dedicated crate
Example
use ;
#
License
This library is distributed under either of:
Copyright (c) 2025 Johan Pascal