@@ -136,24 +136,14 @@ receives from each sender.
136136
137137In libSRTP, a session is created using the function ` srtp_create() ` .
138138The policy to be implemented in the session is passed into this
139- function as an ` srtp_policy_t ` structure. A single one of these
140- structures describes the policy of a single stream. These structures
141- can also be linked together to form an entire session policy. A linked
142- list of ` srtp_policy_t ` structures is equivalent to a session policy.
143- In such a policy, we refer to a single ` srtp_policy_t ` as an * element* .
144-
145- An ` srtp_policy_t ` structure contains two ` srtp_crypto_policy_t ` structures
146- that describe the cryptograhic policies for RTP and RTCP, as well as
147- the SRTP master key and the SSRC value. The SSRC describes what to
148- protect (e.g. which stream), and the ` srtp_crypto_policy_t ` structures
149- describe how to protect it. The key is contained in a policy element
150- because it simplifies the interface to the library. In many cases, it
151- is desirable to use the same cryptographic policies across all of the
152- streams in a session, but to use a distinct key for each stream. A
153- ` srtp_crypto_policy_t ` structure can be initialized by using either the
154- ` srtp_crypto_policy_set_rtp_default() ` or ` srtp_crypto_policy_set_rtcp_default() `
155- functions, which set a crypto policy structure to the default policies
156- for RTP and RTCP protection, respectively.
139+ function as an opaque ` srtp_policy_t ` handle. A single policy handle
140+ describes one stream policy. To configure multiple streams, create a
141+ session and add additional policies with ` srtp_stream_add() ` .
142+
143+ A policy handle is configured with ` srtp_policy_set_* ` functions. At a
144+ minimum, this includes SSRC selection, profile selection, and key/salt
145+ material. The profile configures RTP/RTCP crypto policy settings, while the
146+ SSRC selector identifies how and where that policy is applied.
157147
158148--------------------------------------------------------------------------------
159149
@@ -181,7 +171,7 @@ traffic from a particular source a *stream*. Each stream has its own
181171SSRC, sequence number, rollover counter, and other data. A particular
182172choice of options, cryptographic mechanisms, and keys is called a
183173* policy* . Each stream within a session can have a distinct policy
184- applied to it. A session policy is a collection of stream policies.
174+ applied to it.
185175
186176A single policy can be used for all of the streams in a given session,
187177though the case in which a single * key* is shared across multiple
@@ -202,7 +192,7 @@ in which a key is used for both inbound and outbound data.
202192This library supports all of the mandatory-to-implement features of
203193SRTP (as defined in [ RFC 3711] ( https://tools.ietf.org/html/rfc3711 ) ). Some of these
204194features can be selected (or de-selected) at run time by setting an
205- appropriate policy; this is done using the structure ` srtp_policy_t ` .
195+ appropriate policy using an ` srtp_policy_t ` handle .
206196Some other behaviors of the protocol can be adapted by defining an
207197approriate event handler for the exceptional events; see the SRTPevents
208198section in the generated documentation.
@@ -467,11 +457,9 @@ set master key/salt to C1EEC3717DA76195BB878578790AF71C/4EE9F859E197A414A78D5ABC
467457<a name =" example-code " ></a >
468458## Example Code
469459
470- This section provides a simple example of how to use libSRTP. The
471- example code lacks error checking, but is functional. Here we assume
472- that the value ssrc is already set to describe the SSRC of the stream
473- that we are sending, and that the functions ` get_rtp_packet() ` and
474- ` send_srtp_packet() ` are available to us. The former puts an RTP packet
460+ This section provides a simple example of how to use libSRTP. Here we assume
461+ that the functions ` get_rtp_packet() ` and ` send_srtp_packet() ` are available
462+ to us. The former puts an RTP packet
475463into the buffer and returns the number of octets written to that
476464buffer. The latter sends the RTP packet in the buffer, given the
477465length as its second argument.
@@ -480,39 +468,41 @@ length as its second argument.
480468srtp_t session;
481469srtp_policy_t policy;
482470
483- // Set key to predetermined value
484- uint8_t key[ 30 ] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
485- 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
486- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 ,
487- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D};
471+ // Set key/salt to predetermined values.
472+ uint8_t master_key[ 16 ] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
473+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
474+ uint8_t master_salt [ 14 ] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
475+ 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D};
488476
489- // initialize libSRTP
477+ // Initialize libSRTP.
490478srtp_init ();
491479
492- // default policy values
493- memset (&policy, 0x0, sizeof(srtp_policy_t));
480+ // Create and configure an opaque policy handle.
481+ srtp_policy_create (&policy);
482+ srtp_policy_set_ssrc (policy, (srtp_ssrc_t){ssrc_any_outbound, 0});
483+ srtp_policy_set_profile (policy, srtp_profile_aes128_cm_sha1_80);
484+ srtp_policy_add_key (policy, master_key, sizeof(master_key),
485+ master_salt, sizeof(master_salt), NULL, 0);
494486
495- // set policy to describe a policy for an SRTP stream
496- srtp_crypto_policy_set_rtp_default (&policy.rtp);
497- srtp_crypto_policy_set_rtcp_default (&policy.rtcp);
498- policy.ssrc = ssrc;
499- policy.key = key;
500- policy.next = NULL;
487+ // Allocate and initialize the SRTP session.
488+ srtp_create (&session, policy);
501489
502- // allocate and initialize the SRTP session
503- srtp_create (&session, &policy);
490+ srtp_policy_destroy (policy);
504491
505- // main loop: get rtp packets, send srtp packets
492+ // Main loop: get RTP packets, send SRTP packets.
506493while (1) {
507494 char rtp_buffer[ 2048] ;
508495 size_t rtp_len;
509496 char srtp_buffer[ 2048] ;
510497 size_t srtp_len = sizeof(srtp_buffer);
511498
512- len = get_rtp_packet(rtp_buffer);
499+ rtp_len = get_rtp_packet(rtp_buffer);
513500 srtp_protect (session, rtp_buffer, rtp_len, srtp_buffer, &srtp_len);
514501 send_srtp_packet (srtp_buffer, srtp_len);
515502}
503+
504+ srtp_dealloc (session);
505+ srtp_shutdown();
516506~~~
517507
518508--------------------------------------------------------------------------------
0 commit comments