My Project
Functions
Algorithm - SRTP KDF

Functions

int wc_SRTP_KDF (const byte *key, word32 keySz, const byte *salt, word32 saltSz, int kdrIdx, const byte *index, byte *key1, word32 key1Sz, byte *key2, word32 key2Sz, byte *key3, word32 key3Sz)
 This function derives keys using SRTP KDF algorithm. More...
 
int wc_SRTCP_KDF (const byte *key, word32 keySz, const byte *salt, word32 saltSz, int kdrIdx, const byte *index, byte *key1, word32 key1Sz, byte *key2, word32 key2Sz, byte *key3, word32 key3Sz)
 This function derives keys using SRTCP KDF algorithm. More...
 
int wc_SRTP_KDF_label (const byte *key, word32 keySz, const byte *salt, word32 saltSz, int kdrIdx, const byte *index, byte label, byte *outKey, word32 outKeySz)
 This function derives a key with label using SRTP KDF algorithm. More...
 
int wc_SRTP_KDF_kdr_to_idx (word32 kdr)
 This function converts a kdr value to an index to use in SRTP/SRTCP KDF API. More...
 

Detailed Description

Function Documentation

◆ wc_SRTCP_KDF()

int wc_SRTCP_KDF ( const byte *  key,
word32  keySz,
const byte *  salt,
word32  saltSz,
int  kdrIdx,
const byte *  index,
byte *  key1,
word32  key1Sz,
byte *  key2,
word32  key2Sz,
byte *  key3,
word32  key3Sz 
)

This function derives keys using SRTCP KDF algorithm.

Returns
0 Returned upon successful key derivation.
BAD_FUNC_ARG Returned when key or salt is NULL
BAD_FUNC_ARG Returned when key length is not 16, 24 or 32.
BAD_FUNC_ARG Returned when saltSz is larger than 14.
BAD_FUNC_ARG Returned when kdrIdx is less than -1 or larger than 24.
MEMORY_E on dynamic memory allocation failure.
Parameters
[in]keyKey to use with encryption.
[in]keySzSize of key in bytes.
[in]saltRandom non-secret value.
[in]saltSzSize of random in bytes.
[in]kdrIdxKey derivation rate. kdr = 0 when -1, otherwise kdr = 2^kdrIdx.
[in]indexIndex value to XOR in.
[out]key1First key. Label value of 0x00.
[in]key1SzSize of first key in bytes.
[out]key2Second key. Label value of 0x01.
[in]key2SzSize of second key in bytes.
[out]key3Third key. Label value of 0x02.
[in]key3SzSize of third key in bytes.

Example

unsigned char key[16] = { ... };
unsigned char salt[14] = { ... };
unsigned char index[4] = { ... };
unsigned char keyE[16];
unsigned char keyA[20];
unsigned char keyS[14];
int kdrIdx = 0; // Use all of index
int ret;
ret = wc_SRTCP_KDF(key, sizeof(key), salt, sizeof(salt), kdrIdx, index,
keyE, sizeof(keyE), keyA, sizeof(keyA), keyS, sizeof(keyS));
if (ret != 0) {
WOLFSSL_MSG("wc_SRTP_KDF failed");
}
int wc_SRTCP_KDF(const byte *key, word32 keySz, const byte *salt, word32 saltSz, int kdrIdx, const byte *index, byte *key1, word32 key1Sz, byte *key2, word32 key2Sz, byte *key3, word32 key3Sz)
This function derives keys using SRTCP KDF algorithm.
See also
wc_SRTP_KDF
wc_SRTP_KDF_label
wc_SRTCP_KDF_label
wc_SRTP_KDF_kdr_to_idx

◆ wc_SRTP_KDF()

int wc_SRTP_KDF ( const byte *  key,
word32  keySz,
const byte *  salt,
word32  saltSz,
int  kdrIdx,
const byte *  index,
byte *  key1,
word32  key1Sz,
byte *  key2,
word32  key2Sz,
byte *  key3,
word32  key3Sz 
)

This function derives keys using SRTP KDF algorithm.

Returns
0 Returned upon successful key derivation.
BAD_FUNC_ARG Returned when key or salt is NULL
BAD_FUNC_ARG Returned when key length is not 16, 24 or 32.
BAD_FUNC_ARG Returned when saltSz is larger than 14.
BAD_FUNC_ARG Returned when kdrIdx is less than -1 or larger than 24.
MEMORY_E on dynamic memory allocation failure.
Parameters
[in]keyKey to use with encryption.
[in]keySzSize of key in bytes.
[in]saltRandom non-secret value.
[in]saltSzSize of random in bytes.
[in]kdrIdxKey derivation rate. kdr = 0 when -1, otherwise kdr = 2^kdrIdx.
[in]indexIndex value to XOR in.
[out]key1First key. Label value of 0x00.
[in]key1SzSize of first key in bytes.
[out]key2Second key. Label value of 0x01.
[in]key2SzSize of second key in bytes.
[out]key3Third key. Label value of 0x02.
[in]key3SzSize of third key in bytes.

Example

unsigned char key[16] = { ... };
unsigned char salt[14] = { ... };
unsigned char index[6] = { ... };
unsigned char keyE[16];
unsigned char keyA[20];
unsigned char keyS[14];
int kdrIdx = 0; // Use all of index
int ret;
ret = wc_SRTP_KDF(key, sizeof(key), salt, sizeof(salt), kdrIdx, index,
keyE, sizeof(keyE), keyA, sizeof(keyA), keyS, sizeof(keyS));
if (ret != 0) {
WOLFSSL_MSG("wc_SRTP_KDF failed");
}
int wc_SRTP_KDF(const byte *key, word32 keySz, const byte *salt, word32 saltSz, int kdrIdx, const byte *index, byte *key1, word32 key1Sz, byte *key2, word32 key2Sz, byte *key3, word32 key3Sz)
This function derives keys using SRTP KDF algorithm.
See also
wc_SRTCP_KDF
wc_SRTP_KDF_label
wc_SRTCP_KDF_label
wc_SRTP_KDF_kdr_to_idx

◆ wc_SRTP_KDF_kdr_to_idx()

int wc_SRTP_KDF_kdr_to_idx ( word32  kdr)

This function converts a kdr value to an index to use in SRTP/SRTCP KDF API.

Returns
Key derivation rate as an index.
Parameters
[in]kdrKey derivation rate to convert.

Example

word32 kdr = 0x00000010;
int kdrIdx;
int ret;
kdrIdx = wc_SRTP_KDF_kdr_to_idx(kdr);
int wc_SRTP_KDF_kdr_to_idx(word32 kdr)
This function converts a kdr value to an index to use in SRTP/SRTCP KDF API.
See also
wc_SRTP_KDF
wc_SRTCP_KDF
wc_SRTP_KDF_label
wc_SRTCP_KDF_label

◆ wc_SRTP_KDF_label()

int wc_SRTP_KDF_label ( const byte *  key,
word32  keySz,
const byte *  salt,
word32  saltSz,
int  kdrIdx,
const byte *  index,
byte  label,
byte *  outKey,
word32  outKeySz 
)

This function derives a key with label using SRTP KDF algorithm.

This function derives key with label using SRTCP KDF algorithm.

Returns
0 Returned upon successful key derivation.
BAD_FUNC_ARG Returned when key, salt or outKey is NULL
BAD_FUNC_ARG Returned when key length is not 16, 24 or 32.
BAD_FUNC_ARG Returned when saltSz is larger than 14.
BAD_FUNC_ARG Returned when kdrIdx is less than -1 or larger than 24.
MEMORY_E on dynamic memory allocation failure.
Parameters
[in]keyKey to use with encryption.
[in]keySzSize of key in bytes.
[in]saltRandom non-secret value.
[in]saltSzSize of random in bytes.
[in]kdrIdxKey derivation rate. kdr = 0 when -1, otherwise kdr = 2^kdrIdx.
[in]indexIndex value to XOR in.
[in]labelLabel to use when deriving key.
[out]outKeyDerived key.
[in]outKeySzSize of derived key in bytes.

Example

unsigned char key[16] = { ... };
unsigned char salt[14] = { ... };
unsigned char index[6] = { ... };
unsigned char keyE[16];
int kdrIdx = 0; // Use all of index
int ret;
ret = wc_SRTP_KDF_label(key, sizeof(key), salt, sizeof(salt), kdrIdx, index,
WC_SRTP_LABEL_ENCRYPTION, keyE, sizeof(keyE));
if (ret != 0) {
WOLFSSL_MSG("wc_SRTP_KDF failed");
}
int wc_SRTP_KDF_label(const byte *key, word32 keySz, const byte *salt, word32 saltSz, int kdrIdx, const byte *index, byte label, byte *outKey, word32 outKeySz)
This function derives a key with label using SRTP KDF algorithm.
See also
wc_SRTP_KDF
wc_SRTCP_KDF
wc_SRTCP_KDF_label
wc_SRTP_KDF_kdr_to_idx
Returns
0 Returned upon successful key derivation.
BAD_FUNC_ARG Returned when key, salt or outKey is NULL
BAD_FUNC_ARG Returned when key length is not 16, 24 or 32.
BAD_FUNC_ARG Returned when saltSz is larger than 14.
BAD_FUNC_ARG Returned when kdrIdx is less than -1 or larger than 24.
MEMORY_E on dynamic memory allocation failure.
Parameters
[in]keyKey to use with encryption.
[in]keySzSize of key in bytes.
[in]saltRandom non-secret value.
[in]saltSzSize of random in bytes.
[in]kdrIdxKey derivation rate. kdr = 0 when -1, otherwise kdr = 2^kdrIdx.
[in]indexIndex value to XOR in.
[in]labelLabel to use when deriving key.
[out]outKeyDerived key.
[in]outKeySzSize of derived key in bytes.

Example

unsigned char key[16] = { ... };
unsigned char salt[14] = { ... };
unsigned char index[4] = { ... };
unsigned char keyE[16];
int kdrIdx = 0; // Use all of index
int ret;
ret = wc_SRTCP_KDF_label(key, sizeof(key), salt, sizeof(salt), kdrIdx,
index, WC_SRTCP_LABEL_ENCRYPTION, keyE, sizeof(keyE));
if (ret != 0) {
WOLFSSL_MSG("wc_SRTP_KDF failed");
}
See also
wc_SRTP_KDF
wc_SRTCP_KDF
wc_SRTP_KDF_label
wc_SRTP_KDF_kdr_to_idx