| Crates.io | libsrtp |
| lib.rs | libsrtp |
| version | 0.1.0 |
| created_at | 2025-09-22 07:42:18.433439+00 |
| updated_at | 2025-09-22 07:42:18.433439+00 |
| description | a pure rust implementation of SRTP |
| homepage | https://github.com/jeannotlapin/libsrtp-rs/tree/master/libsrtp |
| repository | https://github.com/jeannotlapin/libsrtp-rs |
| max_upload_size | |
| id | 1849633 |
| size | 242,516 |
A pure rust implementation of Secure Real-time Transport Protocol (SRTP)
This crate implements RFC 3711, RFC 6188 and RFC 7714
This library supports all the mandatory features from RFC 3711, RFC 6188 and RFC 7714. The following optional features are not supported:
This library aims to support the same set of features supported by Cisco's SRTP C library libsrtp.
The following features are supported by Cisco's libsrtp but not yet by this library:
The base cryptographic operations (HMAC-SHA1, AES-CTR, AES-GCM) are provided by RustCrypto crates.
Testing requires helpers crates found on this repository
Interoperability test with cisco's libsrtp are provided in a dedicated crate
use libsrtp::{MasterKey, ProtectionProfile, RecvSession, SendSession, SrtpError, StreamConfig};
# fn main() {
# let master_key = vec![
# 0xe1, 0xf9, 0x7a, 0x0d, 0x3e, 0x01, 0x8b, 0xe0, 0xd6, 0x4f, 0xa3, 0x2c, 0x06, 0xde,
# 0x41, 0x39,
# ];
# let master_salt = vec![
# 0x0e, 0xc6, 0x75, 0xad, 0x49, 0x8a, 0xfe, 0xeb, 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6,
# ];
# let mut packet = vec![
# 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad, 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab,
# 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
# ];
# let ssrc : u32 = 0xcafebabe;
// create a stream configuration
// master_key and master_salt must be Vec<u8> of size matching the selected profiles
let config = StreamConfig::new(
// we use one master key, no mki
vec![MasterKey::new(&master_key, &master_salt, &None)],
// RTP and RTCP protection profiles are set to AES128CM with HmacSha1-80 authentication
&ProtectionProfile::Aes128CmHmacSha180,
&ProtectionProfile::Aes128CmHmacSha180,
);
/************ Sender Side *************************/
// create a sender session and add a stream to it
// this stream is added specifying its SSRC.
// It will process only the packets with this SSRC in their header
let mut s = SendSession::new();
s.add_stream(Some(ssrc), &config).unwrap();
// encrypt and authenticate the packet
// the encryption is performed in place (get and give back the ownership)
// packet is a Vec<u8> holding the whole RTP packet - header included
packet = s.rtp_protect(packet).unwrap();
/************ Receiver Side ***********************/
// create a receiver session and add a stream to it
// in a real context this would be performed on the other endpoint
let mut r = RecvSession::new();
// this stream is added without specifying a SSRC, it is a template stream
// upon decryption of a packet with an unknown SSRC, it will spawn a stream for it
r.add_stream(None, &config).unwrap();
// authenticate and decrypt the packet
// decryption is performed in place
packet = r.rtp_unprotect(packet).unwrap();
# }
This library is distributed under either of:
Copyright (c) 2025 Johan Pascal