Introduction to libSRTP
This package provides an implementation of the Secure Real-time
Transport Protocol (SRTP), the Universal Security Transform (UST), and
a supporting cryptographic kernel. The SRTP API is documented in include/srtp.h,
and the library is in libsrtp2.a (after compilation).
This document describes libSRTP, the Open Source Secure RTP library
from Cisco Systems, Inc. RTP is the Real-time Transport Protocol, an
IETF standard for the transport of real-time data such as telephony,
audio, and video, defined by RFC 3550.
Secure RTP (SRTP) is an RTP profile for providing confidentiality to RTP data
and authentication to the RTP header and payload. SRTP is an IETF Standard,
defined in RFC 3711, and was developed
in the IETF Audio/Video Transport (AVT) Working Group. This library supports
all of the mandatory features of SRTP, but not all of the optional features. See
the Supported Features section for more detailed information.
This document is also used to generate the documentation files in the /doc/
folder where a more detailed reference to the libSRTP API and related functions
can be created (requires installing doxygen.). The reference material is created
automatically from comments embedded in some of the C header files. The
documentation is organized into modules in order to improve its clarity. These
modules do not directly correspond to files. An underlying cryptographic kernel
provides much of the basic functionality of libSRTP but is mostly undocumented
because it does its work behind the scenes.
Contact Us
Contents
License and Disclaimer
libSRTP is distributed under the following license, which is included
in the source code distribution. It is reproduced in the manual in
case you got the library from another source.
Copyright (c) 2001-2017 Cisco Systems, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
- Neither the name of the Cisco Systems, Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
libSRTP Overview
libSRTP provides functions for protecting RTP and RTCP. RTP packets
can be encrypted and authenticated (using the srtp_protect()
function), turning them into SRTP packets. Similarly, SRTP packets
can be decrypted and have their authentication verified (using the
srtp_unprotect() function), turning them into RTP packets. Similar
functions apply security to RTCP packets.
The typedef srtp_stream_t points to a structure holding all of the
state associated with an SRTP stream, including the keys and
parameters for cipher and message authentication functions and the
anti-replay data. A particular srtp_stream_t holds the information
needed to protect a particular RTP and RTCP stream. This datatype
is intentionally opaque in order to better separate the libSRTP
API from its implementation.
Within an SRTP session, there can be multiple streams, each
originating from a particular sender. Each source uses a distinct
stream context to protect the RTP and RTCP stream that it is
originating. The typedef srtp_t points to a structure holding all of
the state associated with an SRTP session. There can be multiple
stream contexts associated with a single srtp_t. A stream context
cannot exist indepent from an srtp_t, though of course an srtp_t can
be created that contains only a single stream context. A device
participating in an SRTP session must have a stream context for each
source in that session, so that it can process the data that it
receives from each sender.
In libSRTP, a session is created using the function srtp_create().
The policy to be implemented in the session is passed into this
function as an opaque srtp_policy_t handle. A single policy handle
describes one stream policy. To configure multiple streams, create a
session and add additional policies with srtp_stream_add().
A policy handle is configured with srtp_policy_set_* functions. At a
minimum, this includes SSRC selection, profile selection, and key/salt
material. The profile configures RTP/RTCP crypto policy settings, while the
SSRC selector identifies how and where that policy is applied.
Secure RTP Background
In this section we review SRTP and introduce some terms that are used
in libSRTP. An RTP session is defined by a pair of destination
transport addresses, that is, a network address plus a pair of UDP
ports for RTP and RTCP. RTCP, the RTP control protocol, is used to
coordinate between the participants in an RTP session, e.g. to provide
feedback from receivers to senders. An SRTP session is
similarly defined; it is just an RTP session for which the SRTP
profile is being used. An SRTP session consists of the traffic sent
to the SRTP or SRTCP destination transport addresses. Each
participant in a session is identified by a synchronization source
(SSRC) identifier. Some participants may not send any SRTP traffic;
they are called receivers, even though they send out SRTCP traffic,
such as receiver reports.
RTP allows multiple sources to send RTP and RTCP traffic during the
same session. The synchronization source identifier (SSRC) is used to
distinguish these sources. In libSRTP, we call the SRTP and SRTCP
traffic from a particular source a stream. Each stream has its own
SSRC, sequence number, rollover counter, and other data. A particular
choice of options, cryptographic mechanisms, and keys is called a
policy. Each stream within a session can have a distinct policy
applied to it.
A single policy can be used for all of the streams in a given session,
though the case in which a single key is shared across multiple
streams requires care. When key sharing is used, the SSRC values that
identify the streams must be distinct. This requirement can be
enforced by using the convention that each SRTP and SRTCP key is used
for encryption by only a single sender. In other words, the key is
shared only across streams that originate from a particular device (of
course, other SRTP participants will need to use the key for
decryption). libSRTP supports this enforcement by detecting the case
in which a key is used for both inbound and outbound data.
Supported Features
This library supports all of the mandatory-to-implement features of
SRTP (as defined in RFC 3711). Some of these
features can be selected (or de-selected) at run time by setting an
appropriate policy using an srtp_policy_t handle.
Some other behaviors of the protocol can be adapted by defining an
approriate event handler for the exceptional events; see the SRTPevents
section in the generated documentation.
Some options that are described in the SRTP specification are not
supported. This includes
- key derivation rates other than zero,
- the cipher F8,
- the use of the packet index to select between master keys.
The user should be aware that it is possible to misuse this library,
and that the result may be that the security level it provides is
inadequate. If you are implementing a feature using this library, you
will want to read the Security Considerations section of RFC 3711.
In addition, it is important that you read and understand the
terms outlined in the License and Disclaimer section.
This library also supports the AES-GCM Authenticated Encryption methods
described in RFC 7714
Implementation Notes
- It is possible to configure which 3rd party crypto backend (OpenSSL, wolfSSL,
NSS or mbedTLS) libSRTP will be built with, see Build Options.
If the
internal crypto library is selected then libSRTP provides
an internal implementation of AES and SHA1. The internal implementation only
supports AES-128 & AES-256, so to use AES-192 or the AES-GCM group of ciphers a
3rd party crypto backend must be configured. After srtp_init(),
srtp_profile_supported() reports whether AES-192 or AES-GCM is loaded.
For this and performance reasons it
is highly recommended to use a 3rd party crypto backend.
- The
srtp_protect() function assumes that the buffer holding the
rtp packet has enough storage allocated that the authentication
tag can be written to the end of that packet. If this assumption
is not valid, memory corruption will ensue.
- Automated tests for the crypto functions are provided through
the
cipher_type_self_test() and auth_type_self_test() functions.
These functions should be used to test each port of this code
to a new platform.
- Replay protection is contained in the crypto engine, and
tests for it are provided.
- This implementation provides calls to initialize, protect, and
unprotect RTP packets, and makes as few as possible assumptions
about how these functions will be called. For example, the
caller is not expected to provide packets in order (though if
they're called more than 65k out of sequence, synchronization
will be lost).
- The sequence number in the rtp packet is used as the low 16 bits
of the sender's local packet index. Note that RTP will start its
sequence number in a random place, and the SRTP layer just jumps
forward to that number at its first invocation. An earlier
version of this library used initial sequence numbers that are
less than 32,768; this trick is no longer required as the
rdbx_estimate_index(...) function has been made smarter as of
version 1.0.1.
- The replay window for (S)RTCP is hardcoded to 128 bits in length.
Installing and Building libSRTP
To install libSRTP, download the latest release of the distribution
from https://github.com/cisco/libsrtp/releases.
You probably want to get the most recent release. Unpack the distribution and
extract the source files; the directory into which the source files
will go is named libsrtp-A-B-C where A is the version number, B is the
major release number and C is the minor release number.
libSRTP can be built with CMake, Meson or
Autotools. CMake is the primary build system. The options
that select what is built are listed for all three tools in
Build Options.
Using CMake
CMake can be downloaded here: https://cmake.org/ . Configure, build, test and
install from the libsrtp directory:
# Configure, the build files are put in the build subdirectory
cmake -S . -B build
# Build the project
cmake --build build
# Run tests
ctest --test-dir build
# Optionally, install
cmake --install build
Options are set at configure time with -DNAME=value, see
Build Options.
The dev preset selects a debug build with the address and undefined behavior
sanitizers enabled:
cmake --preset dev
cmake --build --preset dev
ctest --preset dev
Using Visual Studio
On Windows, Visual Studio can be used through CMake. Select the generator that
matches the installed Visual Studio version, for example:
# Create the project files
cmake -S . -B build -G "Visual Studio 17 2022"
# Build and test, Visual Studio is a multi-configuration generator
cmake --build build --config Release
ctest --test-dir build -C Release
cmake --help lists the available generators.
Using Meson
On all platforms including Windows, one can build using Meson