Collaboration diagram for libZRTP main functions:
Functions | |
| void | zrtp_config_defaults (zrtp_config_t *config) |
| Initializes libzrtp global config zrtp_config_defaults prepares all fields of zrtp_config_t for further usage. If the developer uses "enterprise" version of the libzrtp - zrtp_config_t::cb will be initialized with built-in realizations. | |
| zrtp_global_ctx_t * | zrtp_init (zrtp_config_t *config) |
Initializing libzrtp This function initializes the library and all its components. libzrtp will upload all available crypto-components implementations:
| |
| zrtp_status_t | zrtp_down (zrtp_global_ctx_t *zrtp_global) |
| Shutting down the ZRTP library Frees all allocated structures and resources. This function must be called at the end of use to stop libzrtp correctly. zrtp_down() doesn't stop in-progress ZRTP streams. To avoid mistakes, close all sessions before library deinitialization. | |
| zrtp_status_t | zrtp_init_session_ctx (zrtp_conn_ctx_t *session_ctx, zrtp_global_ctx_t *zrtp_global, zrtp_profile_t *profile, zrtp_zid_t zid, uint8_t is_initiator) |
| ZRTP Session context initialization. As explained in 3. Data structures, the session context is created in two steps: memory allocation for the external structure and internal data initialization. This function allocates and initializes the internal session context data. The given context is associated with the specified ZRTP identifier. Only after initialization does the session contain ZRTP_MAX_STREAMS_PER_SESSION streams ready to be used. After successfully initialization, configuration will be done according to the relevant profile profile. Profile will be applyed to every stream allocated within this session. Profile must contain lists of the crypto-components and other required information. Applying the profile entails:
| |
| void | zrtp_done_session_ctx (zrtp_conn_ctx_t *ctx) |
| ZRTP Session context deinitialization Session context deinitialization also requires two steps: deinitializing internal context data and releasing upper-level structure memory. This function releases all resources allocated for internal context operations. The upper-level structure can be destroyed only after calling this function. | |
| zrtp_stream_ctx_t * | zrtp_attach_stream (zrtp_conn_ctx_t *session_ctx, uint32_t rtp_ssrc) |
| Attaching a new stream to the session This function call initializes a ZRTP stream and prepares it for use within the specified session. The maximum number of streams for one session is defined by the types::ZRTP_MAX_STREAMS_PER_SESSION variable. All newly created streams are equivalent and have ZRTP_STREAM_MODE_CLEAR type mode. Only after attaching a stream can the ZRTP protocol be initiated. | |
| zrtp_status_t | zrtp_set_signaling_hash (zrtp_stream_ctx_t *stream_ctx, const char *hash_buff, uint32_t hash_buff_length) |
| Specifies the hash of the peer Hello message for verification. In accordance with the ZRTP ID sec. 9.1, this protocol can prevent DOS attacks by verification of the Hello message hash sent through the signaling protocol. This function allows the user to specify the Hello hash for verification. If after the discovering phase the Hello hashes don't match, libzrtp raises the zrtp_event_t::ZRTP_EVENT_WRONG_SIGNALING_HASH event. This function should only be called before starting the protocol from the ZRTP_STATE_ACTIVE state. | |
| zrtp_status_t | zrtp_get_signaling_hash (zrtp_stream_ctx_t *stream_ctx, char *hash_buff, uint32_t hash_buff_length) |
| Returns the hash of the Hello message to be transferred in signaling. To prevent DOS attacks, the hash of the Hello message may be sent through signaling. zrtp_get_signaling_hash() may be called after attaching the stream to receive the value of this hash. | |
| void | zrtp_start_stream (zrtp_stream_ctx_t *stream_ctx) |
| Starting a ZRTP stream ZRTP stream setup is initiated by calling this function. Exchange of command packets begins immediately according to protocol. If the option "autosecure" is on, calling this function is the only requirement for setting up the first ZRTP connection within a stream. If "autosecure" mode is not available, calling this function activates only ZRTP stream. A connection can be activated manually by calling zrtp_secure_stream(). Within one stream several ZRTP connections can be setup and interrupted consecutively by calling zrtp_secure_stream() and zrtp_clear_stream(). Setup of the stream/connection takes a certain interval of time. This function just initiates this process. The system of callbacks informs the user about the progress of libzrtp protocol. Stream and connection initialization are described in section 7 Connection life-cycle and management in detail. | |
| void | zrtp_stop_stream (zrtp_stream_ctx_t *stream_ctx) |
| ZRTP protocol stopping This function stops all protocol operations for the specified stream, releases resources allocated on the zrtp_start_stream() and prepares the stream structure for the next use. This function will stop the protocol at any stage: all delayed tasks are canceled, and the protocol packet exchange and encryption is stopped. After this function call it is necessary to stop processing traffic using the zrtp_process_xxx() function. | |
| zrtp_status_t | zrtp_clear_stream (zrtp_stream_ctx_t *stream_ctx) |
| Initiating an interruption of the secure connection This function initiates the shutting down of the ZRTP connection within a stream. In other words, after successfully switching to secure mode (SECURE state, fig. 1.5), calling this function begins the exchange of packets switching to insecure (CLEAR) mode. This function can only be implemented from the SECURE state. Attempt to call this function from any other state will end in failure. The client application is informed about protocol progress through a system of callbacks. | |
| zrtp_status_t | zrtp_secure_stream (zrtp_stream_ctx_t *stream_ctx) |
| Initiating a secure connection setup The function initiates a ZRTP connection setup within a stream. In other words, after the protocol has started and HELLO packets are successfully exchanged, calling this function will begin the exchange of packets for switching to SECURE mode. This function can be successfully performed only from the CLEAR state (Figure 1.6). Attempting to call this function from any other state will result in failure. The client application is informed about protocol progress through a system of callbacks. | |
| zrtp_status_t | zrtp_process_rtp (zrtp_stream_ctx_t *stream_ctx, char *packet, unsigned int *length) |
Processing outgoing RTP packets This is the main function for processing outgoing RTP packets. As soon as the protocol is started, each outgoing RTP packet (not encrypted) has to go through this function. It performs different actions depending on the connection state and packet type:
| |
| zrtp_status_t | zrtp_process_srtp (zrtp_stream_ctx_t *stream_ctx, char *packet, unsigned int *length) |
Processing incoming RTP packets This is the main function for incoming RTP packets processing. It is an analogue of zrtp_process_rtp() but for an incoming stream. After the protocol is started, each (encrypted) incoming RTP packet has to go through this function. It performs different actions depending on the connection state and packet type:
| |
| zrtp_status_t | zrtp_process_rtcp (zrtp_stream_ctx_t *stream_ctx, char *packet, unsigned int *length) |
Processing outgoing RTCP packets This is the main function for processing outgoing RTCP packets. The function behavior is similar to that of zrtp_process_rtp():
| |
| zrtp_status_t | zrtp_process_srtcp (zrtp_stream_ctx_t *stream_ctx, char *packet, unsigned int *length) |
Processing incoming RTCP packets This is the main function for processing incoming RTCP packets. The function behavior is similar to that of zrtp_process_srtp():
| |
| zrtp_status_t | zrtp_set_verified (zrtp_global_ctx_t *zrtp, zrtp_string16_t *zid1, zrtp_string16_t *zid2, uint8_t verified) |
| Changing the value of the secret's verification flag This function is used to change (set, unset) the secret's verification flag. zrtp_set_verified() changes the relevant internal data and stores a flag in the cache. Special synchronization mechanisms are provided to protect the cache from race conditions. Don't change the verified flag directly in the cache - use this function. | |
| zrtp_status_t | zrtp_check_profile (const zrtp_profile_t *profile, zrtp_global_ctx_t *zrtp_global) |
| Verifying the ZRTP profile zrtp_check_profile() checks the correctness of the values in the profile. This function is called automatically when zrtp_apply_profile() is called. The following checks are performed:
| |
| void | zrtp_profile_autoload (zrtp_profile_t *profile, zrtp_global_ctx_t *zrtp_global) |
| Configure the default ZRTP profile These options are used:. | |
| int | zrtp_find_in_profile (const zrtp_profile_t *profile, zrtp_crypto_comp_t type, uint8_t id) |
| Search for a component in the profile by ID The utility function returning the position of an element of the specified type in the profile. Used by libZRTP kernel and for external use. | |
| int | zrtp_add_entropy (zrtp_global_ctx_t *zrtp_global, const unsigned char *buffer, uint32_t length) |
Entropy accumulation The random number generation scheme is described in detail in chapter 5 Random number generation. This function gets length bytes of entropy from buffer and hashes it into the special storage. This function should be called periodically from the user's space to increase entropy quality. | |
| int | zrtp_randstr (zrtp_global_ctx_t *zrtp_global, unsigned char *buffer, uint32_t length) |
Random string generation zrtp_randstr() generates length bytes of "random" data. We say "random" because the "randomness" of the generated sequence depends on the quality of the entropy passed to zrtp_add_entropy(). If the user provides "good" entropy, zrtp_randstr() generates sufficiently "random" data. | |
| int zrtp_add_entropy | ( | zrtp_global_ctx_t * | zrtp_global, | |
| const unsigned char * | buffer, | |||
| uint32_t | length | |||
| ) |
Entropy accumulation The random number generation scheme is described in detail in chapter 5 Random number generation. This function gets length bytes of entropy from buffer and hashes it into the special storage. This function should be called periodically from the user's space to increase entropy quality.
| zrtp_global | - libzrtp global context; | |
| buffer | - pointer to the buffer with entropy for accumulating; | |
| length | - entropy size in bytes. |
| zrtp_stream_ctx_t* zrtp_attach_stream | ( | zrtp_conn_ctx_t * | session_ctx, | |
| uint32_t | rtp_ssrc | |||
| ) |
Attaching a new stream to the session This function call initializes a ZRTP stream and prepares it for use within the specified session. The maximum number of streams for one session is defined by the types::ZRTP_MAX_STREAMS_PER_SESSION variable. All newly created streams are equivalent and have ZRTP_STREAM_MODE_CLEAR type mode. Only after attaching a stream can the ZRTP protocol be initiated.
| session_ctx | - the ZRTP session within which a new stream is to be allocated. | |
| rtp_ssrc | - the SSRC number of the RTP media stream that this ZRTP stream corresponds to. ( In host byte order ) |
| zrtp_status_t zrtp_check_profile | ( | const zrtp_profile_t * | profile, | |
| zrtp_global_ctx_t * | zrtp_global | |||
| ) |
Verifying the ZRTP profile zrtp_check_profile() checks the correctness of the values in the profile. This function is called automatically when zrtp_apply_profile() is called.
The following checks are performed:
| profile | - ZRTP profile for validation; | |
| zrtp_global | - global ZRTP context. |
| zrtp_status_t zrtp_clear_stream | ( | zrtp_stream_ctx_t * | stream_ctx | ) |
Initiating an interruption of the secure connection This function initiates the shutting down of the ZRTP connection within a stream. In other words, after successfully switching to secure mode (SECURE state, fig. 1.5), calling this function begins the exchange of packets switching to insecure (CLEAR) mode. This function can only be implemented from the SECURE state. Attempt to call this function from any other state will end in failure. The client application is informed about protocol progress through a system of callbacks.
| stream_ctx | - context defining the ZRTP stream |
| void zrtp_config_defaults | ( | zrtp_config_t * | config | ) |
Initializes libzrtp global config zrtp_config_defaults prepares all fields of zrtp_config_t for further usage. If the developer uses "enterprise" version of the libzrtp - zrtp_config_t::cb will be initialized with built-in realizations.
| void zrtp_done_session_ctx | ( | zrtp_conn_ctx_t * | ctx | ) |
ZRTP Session context deinitialization Session context deinitialization also requires two steps: deinitializing internal context data and releasing upper-level structure memory. This function releases all resources allocated for internal context operations. The upper-level structure can be destroyed only after calling this function.
| ctx | - context for deinitialization. |
| zrtp_status_t zrtp_down | ( | zrtp_global_ctx_t * | zrtp_global | ) |
Shutting down the ZRTP library Frees all allocated structures and resources. This function must be called at the end of use to stop libzrtp correctly. zrtp_down() doesn't stop in-progress ZRTP streams. To avoid mistakes, close all sessions before library deinitialization.
| zrtp_global | - global ZRTP context; |
| int zrtp_find_in_profile | ( | const zrtp_profile_t * | profile, | |
| zrtp_crypto_comp_t | type, | |||
| uint8_t | id | |||
| ) |
Search for a component in the profile by ID The utility function returning the position of an element of the specified type in the profile. Used by libZRTP kernel and for external use.
| profile | - ZRTP profile; | |
| type | - sought component type; | |
| id | - sought component ID. |
| zrtp_status_t zrtp_get_signaling_hash | ( | zrtp_stream_ctx_t * | stream_ctx, | |
| char * | hash_buff, | |||
| uint32_t | hash_buff_length | |||
| ) |
Returns the hash of the Hello message to be transferred in signaling. To prevent DOS attacks, the hash of the Hello message may be sent through signaling. zrtp_get_signaling_hash() may be called after attaching the stream to receive the value of this hash.
| stream_ctx | - stream for operating with | |
| hash_buff | - buffer for storing signaling hash. Function returns already parsed hex string, not a binary value! | |
| hash_buff_length | - buffer length in bytes (not shorter than 34 bytes) |
| zrtp_global_ctx_t* zrtp_init | ( | zrtp_config_t * | config | ) |
Initializing libzrtp This function initializes the library and all its components. libzrtp will upload all available crypto-components implementations:
| config | - libzrtp inital parameters |
| zrtp_status_t zrtp_init_session_ctx | ( | zrtp_conn_ctx_t * | session_ctx, | |
| zrtp_global_ctx_t * | zrtp_global, | |||
| zrtp_profile_t * | profile, | |||
| zrtp_zid_t | zid, | |||
| uint8_t | is_initiator | |||
| ) |
ZRTP Session context initialization. As explained in 3. Data structures, the session context is created in two steps: memory allocation for the external structure and internal data initialization. This function allocates and initializes the internal session context data. The given context is associated with the specified ZRTP identifier. Only after initialization does the session contain ZRTP_MAX_STREAMS_PER_SESSION streams ready to be used.
After successfully initialization, configuration will be done according to the relevant profile profile. Profile will be applyed to every stream allocated within this session. Profile must contain lists of the crypto-components and other required information. Applying the profile entails:
| zrtp_global | - global ZRTP context; | |
| session_ctx | - session context for initialization; | |
| profile | - the stream configuration profile. If value of this parameter is NULL, default profile will be used. NULL profile usage is equivalent to calling zrtp_profile_autoload() | |
| zid | - ZRTP peer identification. | |
| is_initiator | - identifies if the endpoint was the signaling initator of the call. Used to provide Passive Mode options to the developer. If you'r application doesn't control signaling or you don't want to support Passive Mode features - set this flag to 1. |
| zrtp_status_t zrtp_process_rtcp | ( | zrtp_stream_ctx_t * | stream_ctx, | |
| char * | packet, | |||
| unsigned int * | length | |||
| ) |
Processing outgoing RTCP packets This is the main function for processing outgoing RTCP packets. The function behavior is similar to that of zrtp_process_rtp():
length variable;
| stream_ctx | - context associated with the current ZRTP session; | |
| packet | - buffer storing RTCP packet; | |
| length | - length of the buffered packet. |
| zrtp_status_t zrtp_process_rtp | ( | zrtp_stream_ctx_t * | stream_ctx, | |
| char * | packet, | |||
| unsigned int * | length | |||
| ) |
Processing outgoing RTP packets This is the main function for processing outgoing RTP packets. As soon as the protocol is started, each outgoing RTP packet (not encrypted) has to go through this function. It performs different actions depending on the connection state and packet type:
| stream_ctx | - context associated with the current ZRTP stream; | |
| packet | - buffer storing the RTP packet for encryption. After processing, the encrypted packet is stored in the same buffer. | |
| length | - the length of the buffered packet. After processing, the length of encrypted packet is stored here. |
| zrtp_status_t zrtp_process_srtcp | ( | zrtp_stream_ctx_t * | stream_ctx, | |
| char * | packet, | |||
| unsigned int * | length | |||
| ) |
Processing incoming RTCP packets This is the main function for processing incoming RTCP packets. The function behavior is similar to that of zrtp_process_srtp():
length variable;
| stream_ctx | - context associated with the current ZRTP stream; | |
| packet | - buffer storing the RTCP packet; | |
| length | - length of the buffered packet. |
| zrtp_status_t zrtp_process_srtp | ( | zrtp_stream_ctx_t * | stream_ctx, | |
| char * | packet, | |||
| unsigned int * | length | |||
| ) |
Processing incoming RTP packets This is the main function for incoming RTP packets processing. It is an analogue of zrtp_process_rtp() but for an incoming stream. After the protocol is started, each (encrypted) incoming RTP packet has to go through this function. It performs different actions depending on the connection state and packet type:
| stream_ctx | - context associated with the current ZRTP stream | |
| packet | - buffer storing the packet for decrypting. After processing, the decrypted packet is stored in the same buffer; | |
| length | - the length of the buffered packet. After processing, the length of decrypted packet is stored here; |
| void zrtp_profile_autoload | ( | zrtp_profile_t * | profile, | |
| zrtp_global_ctx_t * | zrtp_global | |||
| ) |
Configure the default ZRTP profile These options are used:.
"active" is enabled; "allowclear" is disabled by default and enabled for ZFone only; "autosecure" is enabled; "disclose_bit" is disabled; cache_ttl = ZRTP_CACHE_DEFAULT_TTL defined by ZRTP Internet draft; [sas_schemes] = ZRTP_SAS_BASE256, ZRTP_SAS_BASE32; [cipher_types] = ZRTP_CIPHER_AES128; [pk_schemes] = ZRTP_PKTYPE_DH3072; [auth_tag_lens] = ZRTP_ATL_HS32; [hash_schemes] = ZRTP_HASH_SHA256;
| profile | - ZRTP stream profile for filling; | |
| zrtp_global | - libzrtp global context. |
| int zrtp_randstr | ( | zrtp_global_ctx_t * | zrtp_global, | |
| unsigned char * | buffer, | |||
| uint32_t | length | |||
| ) |
Random string generation zrtp_randstr() generates length bytes of "random" data. We say "random" because the "randomness" of the generated sequence depends on the quality of the entropy passed to zrtp_add_entropy(). If the user provides "good" entropy, zrtp_randstr() generates sufficiently "random" data.
Random bits in libzrtp are produced as follows: First stir new entropy into the random state (zrtp_global->rand_ctx). Then make a copy of the random context and finalize it. Use the digest to seed an AES-256 context and, if space remains, to initialize a counter. Then encrypt the counter with the AES-256 context, incrementing it per block, until the desired quantity of data is produced.
| zrtp_global | - libzrtp global context; | |
| buffer | - buffer into which random data will be generated; | |
| length | - length of required sequence in bytes. |
| zrtp_status_t zrtp_secure_stream | ( | zrtp_stream_ctx_t * | stream_ctx | ) |
Initiating a secure connection setup The function initiates a ZRTP connection setup within a stream. In other words, after the protocol has started and HELLO packets are successfully exchanged, calling this function will begin the exchange of packets for switching to SECURE mode. This function can be successfully performed only from the CLEAR state (Figure 1.6). Attempting to call this function from any other state will result in failure. The client application is informed about protocol progress through a system of callbacks.
| stream_ctx | - context defining the ZRTP stream |
| zrtp_status_t zrtp_set_signaling_hash | ( | zrtp_stream_ctx_t * | stream_ctx, | |
| const char * | hash_buff, | |||
| uint32_t | hash_buff_length | |||
| ) |
Specifies the hash of the peer Hello message for verification. In accordance with the ZRTP ID sec. 9.1, this protocol can prevent DOS attacks by verification of the Hello message hash sent through the signaling protocol. This function allows the user to specify the Hello hash for verification. If after the discovering phase the Hello hashes don't match, libzrtp raises the zrtp_event_t::ZRTP_EVENT_WRONG_SIGNALING_HASH event. This function should only be called before starting the protocol from the ZRTP_STATE_ACTIVE state.
| stream_ctx | - stream for operating with; | |
| hash_buff | - signaling hash buffer. Function accpt string, not a binary value!; | |
| hash_buff_length | - signaling hash length in bytes (should be 34 bytes); |
| zrtp_status_t zrtp_set_verified | ( | zrtp_global_ctx_t * | zrtp, | |
| zrtp_string16_t * | zid1, | |||
| zrtp_string16_t * | zid2, | |||
| uint8_t | verified | |||
| ) |
Changing the value of the secret's verification flag This function is used to change (set, unset) the secret's verification flag. zrtp_set_verified() changes the relevant internal data and stores a flag in the cache. Special synchronization mechanisms are provided to protect the cache from race conditions. Don't change the verified flag directly in the cache - use this function.
| zrtp | - zrtp global data; | |
| zid1 | - ZID of the first party; | |
| zid2 | - ZID of the second party; | |
| verified | - Boolean value of the verified flag. |
| void zrtp_start_stream | ( | zrtp_stream_ctx_t * | stream_ctx | ) |
Starting a ZRTP stream ZRTP stream setup is initiated by calling this function. Exchange of command packets begins immediately according to protocol. If the option "autosecure" is on, calling this function is the only requirement for setting up the first ZRTP connection within a stream. If "autosecure" mode is not available, calling this function activates only ZRTP stream. A connection can be activated manually by calling zrtp_secure_stream(). Within one stream several ZRTP connections can be setup and interrupted consecutively by calling zrtp_secure_stream() and zrtp_clear_stream(). Setup of the stream/connection takes a certain interval of time. This function just initiates this process. The system of callbacks informs the user about the progress of libzrtp protocol. Stream and connection initialization are described in section 7 Connection life-cycle and management in detail.
| stream_ctx | - context within which the ZRTP stream/connection is setup. |
| void zrtp_stop_stream | ( | zrtp_stream_ctx_t * | stream_ctx | ) |
ZRTP protocol stopping This function stops all protocol operations for the specified stream, releases resources allocated on the zrtp_start_stream() and prepares the stream structure for the next use. This function will stop the protocol at any stage: all delayed tasks are canceled, and the protocol packet exchange and encryption is stopped. After this function call it is necessary to stop processing traffic using the zrtp_process_xxx() function.
| stream_ctx | - context, associated with the stream being shutdown. |