bZRTP
bZRTP is an opensource implementation of ZRTP keys exchange protocol
Loading...
Searching...
No Matches
Macros | Functions
packetParser.c File Reference

Macros

#define ZRTP_MIN_PACKET_LENGTH   28
 
#define ZRTP_MAX_PACKET_LENGTH   3072
 
#define ZRTP_MESSAGE_HEADER_LENGTH   12
 
#define ZRTP_HELLOMESSAGE_FIXED_LENGTH   88
 
#define ZRTP_HELLOACKMESSAGE_FIXED_LENGTH   12
 
#define ZRTP_COMMITMESSAGE_FIXED_LENGTH   84
 
#define ZRTP_DHPARTMESSAGE_FIXED_LENGTH   84
 
#define ZRTP_CONFIRMMESSAGE_FIXED_LENGTH   76
 
#define ZRTP_CONF2ACKMESSAGE_FIXED_LENGTH   12
 
#define ZRTP_ERRORMESSAGE_FIXED_LENGTH   16
 
#define ZRTP_ERRORACKMESSAGE_FIXED_LENGTH   12
 
#define ZRTP_GOCLEARMESSAGE_FIXED_LENGTH   20
 
#define ZRTP_CLEARACKMESSAGE_FIXED_LENGTH   12
 
#define ZRTP_SASRELAYMESSAGE_FIXED_LENGTH   76
 
#define ZRTP_RELAYACKMESSAGE_FIXED_LENGTH   12
 
#define ZRTP_PINGMESSAGE_FIXED_LENGTH   24
 
#define ZRTP_PINGACKMESSAGE_FIXED_LENGTH   36
 

Functions

static uint8_tmessageTypeInttoString (uint32_t messageType)
 Retrieve the 8 char string value message type from the int32_t code.
 
static int32_t messageTypeStringtoInt (uint8_t messageTypeString[8])
 Map the 8 char string value message type to an int32_t.
 
static void zrtpMessageSetHeader (uint8_t *outputBuffer, uint16_t messageLength, uint8_t messageType[9])
 Write the message header(preambule, length, message type) into the given output buffer.
 
static void zrtpPacketSetHeader (bzrtpPacket_t *zrtpPacket)
 Write the packet header(preambule, MagicCookie, SSRC) in the zrtpPacket string.
 
bzrtpPacket_tbzrtp_packetCheck (uint8_t **inputPtr, uint16_t *inputLength, bzrtpChannelContext_t *zrtpChannelContext, int *exitCode)
 Parse a string which shall be a valid ZRTP packet Check validity and allocate the bzrtpPacket structure but do not parse the message except for type and length. messageData structure field is not allocated by this function (use then bzrtp_packetParse for that). The packet check and actual message parsing are split in two functions to avoid useless parsing when message is to be discarded as the check will give message type (in case of message repetition for example)
 
int bzrtp_packetParser (BCTBX_UNUSED(bzrtpContext_t *zrtpContext), bzrtpChannelContext_t *zrtpChannelContext, const uint8_t *input, uint16_t inputLength, bzrtpPacket_t *zrtpPacket)
 
int bzrtp_packetBuild (bzrtpContext_t *zrtpContext, bzrtpChannelContext_t *zrtpChannelContext, bzrtpPacket_t *zrtpPacket)
 Create a ZRTP packet string from the ZRTP packet values present in the structure messageType, messageData and sourceIdentifier in zrtpPacket must have been correctly set before calling this function The packet is not ready to be sent at that stage, sequenceNumber and CRC must be set using bzrtp_packetSetSequenceNumber.
 
bzrtpPacket_tbzrtp_createZrtpPacket (bzrtpContext_t *zrtpContext, bzrtpChannelContext_t *zrtpChannelContext, uint32_t messageType, int *exitCode)
 Create an empty packet and allocate the messageData according to requested packetType.
 
void bzrtp_freeZrtpPacket (bzrtpPacket_t *zrtpPacket)
 Deallocate zrtp Packet.
 
int bzrtp_packetSetSequenceNumber (bzrtpPacket_t *zrtpPacket, uint16_t sequenceNumber)
 Modify the current sequence number of the packet in the packetString and sequenceNumber fields The CRC at the end of packetString is also computed.
 

Macro Definition Documentation

◆ ZRTP_CLEARACKMESSAGE_FIXED_LENGTH

#define ZRTP_CLEARACKMESSAGE_FIXED_LENGTH   12

◆ ZRTP_COMMITMESSAGE_FIXED_LENGTH

#define ZRTP_COMMITMESSAGE_FIXED_LENGTH   84

◆ ZRTP_CONF2ACKMESSAGE_FIXED_LENGTH

#define ZRTP_CONF2ACKMESSAGE_FIXED_LENGTH   12

◆ ZRTP_CONFIRMMESSAGE_FIXED_LENGTH

#define ZRTP_CONFIRMMESSAGE_FIXED_LENGTH   76

◆ ZRTP_DHPARTMESSAGE_FIXED_LENGTH

#define ZRTP_DHPARTMESSAGE_FIXED_LENGTH   84

◆ ZRTP_ERRORACKMESSAGE_FIXED_LENGTH

#define ZRTP_ERRORACKMESSAGE_FIXED_LENGTH   12

◆ ZRTP_ERRORMESSAGE_FIXED_LENGTH

#define ZRTP_ERRORMESSAGE_FIXED_LENGTH   16

◆ ZRTP_GOCLEARMESSAGE_FIXED_LENGTH

#define ZRTP_GOCLEARMESSAGE_FIXED_LENGTH   20

◆ ZRTP_HELLOACKMESSAGE_FIXED_LENGTH

#define ZRTP_HELLOACKMESSAGE_FIXED_LENGTH   12

◆ ZRTP_HELLOMESSAGE_FIXED_LENGTH

#define ZRTP_HELLOMESSAGE_FIXED_LENGTH   88

◆ ZRTP_MAX_PACKET_LENGTH

#define ZRTP_MAX_PACKET_LENGTH   3072

◆ ZRTP_MESSAGE_HEADER_LENGTH

#define ZRTP_MESSAGE_HEADER_LENGTH   12

◆ ZRTP_MIN_PACKET_LENGTH

#define ZRTP_MIN_PACKET_LENGTH   28

◆ ZRTP_PINGACKMESSAGE_FIXED_LENGTH

#define ZRTP_PINGACKMESSAGE_FIXED_LENGTH   36

◆ ZRTP_PINGMESSAGE_FIXED_LENGTH

#define ZRTP_PINGMESSAGE_FIXED_LENGTH   24

◆ ZRTP_RELAYACKMESSAGE_FIXED_LENGTH

#define ZRTP_RELAYACKMESSAGE_FIXED_LENGTH   12

◆ ZRTP_SASRELAYMESSAGE_FIXED_LENGTH

#define ZRTP_SASRELAYMESSAGE_FIXED_LENGTH   76

Function Documentation

◆ bzrtp_createZrtpPacket()

bzrtpPacket_t * bzrtp_createZrtpPacket ( bzrtpContext_t zrtpContext,
bzrtpChannelContext_t zrtpChannelContext,
uint32_t  messageType,
int *  exitCode 
)

Create an empty packet and allocate the messageData according to requested packetType.

Parameters
[in]zrtpContextThe current ZRTP context, some data (H chain or others, may be needed to create messages)
[in]zrtpChannelContextThe channel context this packet is intended to
[in]messageTypeThe 32bit integer mapped to the message type to be created
[out]exitCode0 on success, error code otherwise
Returns
An empty packet initialised to get data for the requested paquet tyep. NULL on error

◆ bzrtp_freeZrtpPacket()

void bzrtp_freeZrtpPacket ( bzrtpPacket_t zrtpPacket)

Deallocate zrtp Packet.

Parameters
[in]zrtpPacketThe packet to be freed

◆ bzrtp_packetBuild()

int bzrtp_packetBuild ( bzrtpContext_t zrtpContext,
bzrtpChannelContext_t zrtpChannelContext,
bzrtpPacket_t zrtpPacket 
)

Create a ZRTP packet string from the ZRTP packet values present in the structure messageType, messageData and sourceIdentifier in zrtpPacket must have been correctly set before calling this function The packet is not ready to be sent at that stage, sequenceNumber and CRC must be set using bzrtp_packetSetSequenceNumber.

Parameters
[in]zrtpContextA zrtp context where to find H0-H3 to compute MAC requested by some paquets or encryption's key for commit/SASRelay packet
[in]zrtpChannelContextThe channel context this packet is intended to
[in,out]zrtpPacketThe zrtpPacket structure containing the message Data structure, output is stored in ->packetString
Returns
0 on success, error code otherwise

◆ bzrtp_packetCheck()

bzrtpPacket_t * bzrtp_packetCheck ( uint8_t **  inputPtr,
uint16_t inputLength,
bzrtpChannelContext_t zrtpChannelContext,
int *  exitCode 
)

Parse a string which shall be a valid ZRTP packet Check validity and allocate the bzrtpPacket structure but do not parse the message except for type and length. messageData structure field is not allocated by this function (use then bzrtp_packetParse for that). The packet check and actual message parsing are split in two functions to avoid useless parsing when message is to be discarded as the check will give message type (in case of message repetition for example)

Parameters
[in/out]inputPtr The string buffer storing the complete ZRTP packet. Modified if we complete a fragmented packet
[in/out]inputLength Input length in bytes. Modified if we complete a fragmented packet
[in/out]zrtpChannelContext The channel context this packet is intended to(channel context and packet must match peer SSRC).
[out]exitCode0 on success, BZRTP_PARSER_INFO_PACKETFRAGMENT when a fragment of incomplete packet is received, error code otherwise
Returns
The create bzrtpPacket structure(to be freed using bzrtp_freeZrtpPacket). NULL on error

◆ bzrtp_packetParser()

int bzrtp_packetParser ( BCTBX_UNUSED(bzrtpContext_t *zrtpContext)  ,
bzrtpChannelContext_t zrtpChannelContext,
const uint8_t input,
uint16_t  inputLength,
bzrtpPacket_t zrtpPacket 
)

◆ bzrtp_packetSetSequenceNumber()

int bzrtp_packetSetSequenceNumber ( bzrtpPacket_t zrtpPacket,
uint16_t  sequenceNumber 
)

Modify the current sequence number of the packet in the packetString and sequenceNumber fields The CRC at the end of packetString is also computed.

Set the current sequence number of the packet in the packetString and sequenceNumber fields The CRC at the end of packetString is also computed.

param[in,out] zrtpPacket The zrtpPacket to modify, the packetString must have been generated by a call to bzrtp_packetBuild on this packet param[in] sequenceNumber The sequence number to insert in the packetString

return 0 on succes, error code otherwise

◆ messageTypeInttoString()

static uint8_t * messageTypeInttoString ( uint32_t  messageType)
static

Retrieve the 8 char string value message type from the int32_t code.

Parameters
[in]messageTypeThe messageType code
Returns
an 9 char string : 8 chars message type as specified in rfc section 5.1.1 + string terminating char

◆ messageTypeStringtoInt()

static int32_t messageTypeStringtoInt ( uint8_t  messageTypeString[8])
static

Map the 8 char string value message type to an int32_t.

Parameters
[in]messageTypeStringan 8 bytes string matching a zrtp message type
Returns
a 32-bits unsigned integer mapping the message type

◆ zrtpMessageSetHeader()

static void zrtpMessageSetHeader ( uint8_t outputBuffer,
uint16_t  messageLength,
uint8_t  messageType[9] 
)
static

Write the message header(preambule, length, message type) into the given output buffer.

Parameters
[out]outputBufferMessage starts at the begining of this buffer
[in]messageLengthMessage length in bytes! To be converted into 32bits words before being inserted in the message header
[in]messageTypeAn 8 chars string for the message type (validity is not checked by this function)

◆ zrtpPacketSetHeader()

static void zrtpPacketSetHeader ( bzrtpPacket_t zrtpPacket)
static

Write the packet header(preambule, MagicCookie, SSRC) in the zrtpPacket string.

Parameters
[in/out]zrtpPacket the zrtp packet holding the stringBuffer