Class SRtpUtils
Static class that provides static functions for performing various Secure RTP (SRTP) calculations.
Inherited Members
Namespace: SipLib.RtpCrypto
Assembly: SipLib.dll
Syntax
public static class SRtpUtils
Fields
| Edit this page View Sourcen_a
Default size of the authentication key in bits. See Section 5.2 of RFC 3711.
Declaration
public const int n_a = 160
Field Value
Type | Description |
---|---|
int |
n_aB
Default size of the authentication key in bytes. See Section 5.2 of RFC 3711.
Declaration
public const int n_aB = 20
Field Value
Type | Description |
---|---|
int |
n_b
Bit size of the block for the block cipher
Declaration
public const int n_b = 128
Field Value
Type | Description |
---|---|
int |
n_e
Bit size of the encryption key.
Declaration
public const int n_e = 128
Field Value
Type | Description |
---|---|
int |
n_eB
Byte size of the encryption key
Declaration
public const int n_eB = 16
Field Value
Type | Description |
---|---|
int |
n_s
Bit size of the session salting key
Declaration
public const int n_s = 112
Field Value
Type | Description |
---|---|
int |
n_sB
Byte size of the session salting key
Declaration
public const int n_sB = 14
Field Value
Type | Description |
---|---|
int |
n_tag
Default bit size of the authentication tag.
Declaration
public const int n_tag = 80
Field Value
Type | Description |
---|---|
int |
n_tagB
Default byte size of the authentication tag.
Declaration
public const int n_tagB = 10
Field Value
Type | Description |
---|---|
int |
Methods
| Edit this page View SourceAuthRtpPacket(byte[], byte[], uint, byte[], byte[])
Authenticates an SRTP or an SRTCP packet. See Section 4.2 of RFC 3711. This function computes the authentication tag for the packet using the HMAC-SHA1 algorithm and compares it to the authentication tag that was sent with the SRTP or SRTCP packet.
Declaration
public static bool AuthRtpPacket(byte[] HdrBytes, byte[] PacketPayload, uint ROCorSRTCPIndex, byte[] k_a, byte[] AuthTag)
Parameters
Type | Name | Description |
---|---|---|
byte[] | HdrBytes | Byte array containing the RTP or RTCP packet header. |
byte[] | PacketPayload | Byte array containing the payload of the RTP or RTCP packet. This is the encrypted portion of the packet. |
uint | ROCorSRTCPIndex | Roll Over Counter (ROC) value or the SRTCP Index. |
byte[] | k_a | Byte array containing the session authentication key. |
byte[] | AuthTag | Byte array containing the authentication tag read from the SRTP packet. |
Returns
Type | Description |
---|---|
bool | Returns true if the packet is successfully authenticated, i.e. the computed authentication tag matches the received authentication tag. |
CalcAesCmIV(byte[], uint, ulong)
Calculates the Initialization Vector (IV) for AES in Counter Mode (AES-CM) as specified in Section 4.1.1 AES in Counter Mode of RFC 3711.
Declaration
public static byte[] CalcAesCmIV(byte[] k_s, uint SSRC, ulong i)
Parameters
Type | Name | Description |
---|---|---|
byte[] | k_s | Session salting key. Must be at least n_sB bytes in length. |
uint | SSRC | SSRC value from the RTCP packet. |
ulong | i | Packet index for the RTP packet. Calculated as using the PacketIndex() function as specifed in Section 3.3.1 and Appendix A of RFC 3711. |
Returns
Type | Description |
---|---|
byte[] | Returns the IV array, which is n_eB (16) bytes in length. |
CalcF8SRTCPIV(RtcpHeader, uint, uint)
Calculates the Initialization Vector (IV) for the F8 AES encryption algorithm for a RTCP packet given the RTCP packet and the SRTCP packet index. See Section 4.1.2.3 of RFC 3711.
Declaration
public static byte[] CalcF8SRTCPIV(RtcpHeader RtcpHdr, uint SrtcpIndex, uint SSRC)
Parameters
Type | Name | Description |
---|---|---|
RtcpHeader | RtcpHdr | RTCP packet header to compute the IV for. |
uint | SrtcpIndex | SRTCP packet index as read from the the SRTCP packet. Includes the "E" bit. See Figure 2 of RFC 3711. |
uint | SSRC | SSRC for the sender of the RTCP packet. |
Returns
Type | Description |
---|---|
byte[] | Returns the 16-byte long IV to use for the IV for an RTCP packet. |
CalcF8SRTPIV(RtpPacket, uint)
Calculates the Initialization Vector (IV) for the F8 AES encryption algorithm for a RTP packet given the RTP packet header and the Roll Over Counter (ROC). See Section 4.1.2.2 of RFC 3711.
Declaration
public static byte[] CalcF8SRTPIV(RtpPacket RtpPckt, uint ROC)
Parameters
Type | Name | Description |
---|---|---|
RtpPacket | RtpPckt | RTP packet header. |
uint | ROC | Current Roll Over Counter value. |
Returns
Type | Description |
---|---|
byte[] | Returns the 16-byte long IV to use for the IV for an RTP packet. |
CalcRtpPacketAuthTag(byte[], byte[], uint, byte[], int)
Calculates the authentication tag for an RTP or an RTCP packet. See Section 4.2 of RFC 3711.
Declaration
public static byte[] CalcRtpPacketAuthTag(byte[] HdrBytes, byte[] Payload, uint ROCorSRTCPIndex, byte[] k_a, int TagLength)
Parameters
Type | Name | Description |
---|---|---|
byte[] | HdrBytes | Byte array containing the RTP packet header./// |
byte[] | Payload | Byte array containing the payload of the RTP or RTCP packet. This is the encrypted portion of the packet. |
uint | ROCorSRTCPIndex | Roll Over Counter (ROC) value. |
byte[] | k_a | Byte array containing the session authentication key. |
int | TagLength | Length in bytes of the authentication tag to return. This must be either 10 (for 80 bits) or 4 (for 32 bits) depending upon the encryption profile being used. |
Returns
Type | Description |
---|---|
byte[] | The authentication tag |
DeriveRtcpSessionKeys(ulong, MasterKeys, CryptoContext)
Derives the RTCP session keys for a CryptoContext. See Section 4.3.2 of RFC 3711.
Declaration
public static void DeriveRtcpSessionKeys(ulong PI, MasterKeys Mks, CryptoContext Context)
Parameters
Type | Name | Description |
---|---|---|
ulong | PI | Packet Index |
MasterKeys | Mks | Master keys to use to derive the session keya |
CryptoContext | Context | CryptoContext to write the session keys to |
DeriveRtpSessionKeys(ulong, MasterKeys, CryptoContext)
Derives the RTP session keys for a CryptoContext. See Section 4.3.1 of RFC 3711
Declaration
public static void DeriveRtpSessionKeys(ulong PI, MasterKeys Mks, CryptoContext Context)
Parameters
Type | Name | Description |
---|---|---|
ulong | PI | Packet Index |
MasterKeys | Mks | Master keys to use to derive the session keya |
CryptoContext | Context | CryptoContext to write the session keys to |
DeriveSrtpSessionKey(ulong, ulong, SrtpLabelItem, byte[], byte[], byte[])
Derives a session key given the master key and the master salt for SRTP. See Section 4.3.1 Key Derivation Algorithm and Section 4.3.2 SRTCP Key Derivation of RFC 3711.
Declaration
public static byte[] DeriveSrtpSessionKey(ulong PI, ulong kdr, SrtpLabelItem Label, byte[] MasterSalt, byte[] MasterKey, byte[] InputZeroArray)
Parameters
Type | Name | Description |
---|---|---|
ulong | PI | Packet index for the SRTP packet as calculated by the PacketIndex() function is for SRTP. Pass in 32-bit value 0 || SRTCP Index from the SRTCP packet as described in Section 4.3.2 of RFC 3711. |
ulong | kdr | Key Derivation Rate (KDR) |
SrtpLabelItem | Label | Identifies the type of key to derive. |
byte[] | MasterSalt | Master salt array. |
byte[] | MasterKey | Master Key array. |
byte[] | InputZeroArray | Array of zero values to use as the input for the key derivation. The length of this array determines the length of the array returned by this function. |
Returns
Type | Description |
---|---|
byte[] | Returns a byte array containing the derived key, salting key or the authentication key. |
ExtractDelimStr(char, char, string)
Extracts a string that is delimited by two characters. The delimiter characters may be different.
Declaration
public static string? ExtractDelimStr(char D1, char D2, string strInput)
Parameters
Type | Name | Description |
---|---|---|
char | D1 | First delimiter character. |
char | D2 | Second delimiter character. |
string | strInput | Input string. |
Returns
Type | Description |
---|---|
string | Returns the delimited string. Returns null if the delimiters are not present or the extracted string length is zero. |
GetValueOfNameValuePair(string, char)
Gets the value portion of a name/value pair from a string that is formatted as a name followed by a 1 character separator followed by a value. For example Param=Value or Param:Value
Declaration
public static string? GetValueOfNameValuePair(string Input, char Sep)
Parameters
Type | Name | Description |
---|---|---|
string | Input | Input string containing the name/value. |
char | Sep | Separator character such as '=' or ':' |
Returns
Type | Description |
---|---|
string | Returns the value portion or null if the input string is not in the proper format. |
PacketIndex(ushort, ushort, RocVals)
Calculates the packet index for an RTP packet. See Section 3.3.1 and Appendix A of RFC 3711. This algorithm accounds for rollover of the sequence number and the impact of packet loss.
Declaration
public static ulong PacketIndex(ushort SEQ, ushort s_l, RocVals Rv)
Parameters
Type | Name | Description |
---|---|---|
ushort | SEQ | Sequence number (SEQ) read from the RTP packet header. |
ushort | s_l | Highest received SEQ number so far. |
RocVals | Rv | Stored ROC values. |
Returns
Type | Description |
---|---|
ulong | Returns the packet index as a 48-bit number right justified in the lower 48 bits of a 64-bit unsigned integer. |