1 /*
2  * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
3  * Copyright (c) 2006-2009 Philip R. Zimmermann.  All rights reserved.
4  * Contact: http://philzimmermann.com
5  * For licensing and other legal details, see the file zrtp_legal.c.
6  *
7  * Viktor Krykun <v.krikun at zfoneproject.com>
8  */
9 
10 #ifndef __ZRTP_CRYPTO_H__
11 #define __ZRTP_CRYPTO_H__
12 
13 #include "bn.h"
14 #include "zrtp_types.h"
15 #include "zrtp_error.h"
16 #include "zrtp_engine.h"
17 #include "zrtp_config_user.h"
18 #include "zrtp_ec.h"
19 
20 
21 
22 /*!
23  * \defgroup crypto Library crypto-components
24  * \ingroup zrtp_dev
25  *
26  * This section describes functions and data types for managing crypto-components.
27  * All these functions and structures are used by the libZRTP kernel for the
28  * built-in crypt-components management. The developer has the option of
29  * implementing and integrating her own components into the library. This is not
30  * a full manual on creating crypto-components. Its purpose is only to elucidate
31  * the library functionality.
32  *
33  * The concept behind crypto components is similar to that of classes in object
34  * oriented programming.  The components are defined as structures and
35  * manipulated by functions. Component attributes are stored in 'contexts', and
36  * are defined during initialization. Resources allocated at initialization are
37  * freed with the 'free' function.
38  *
39  * Components are divided into 5 functional groups (component types):
40  *  - ciphers;
41  *  - hash/hmac components;
42  *  - public key exchange schemes;
43  *  - components defined SRTP authentication scheme;
44  *  - SAS calculation schemes.
45  * Within a group, components are distinguished by integer identifiers and by
46  * their defined functionality. So to fully identify a component, you need to
47  * know its type and its identifier. (For example an AES cipher with a 128 bit
48  * key is defined as: ZRTP_CC_CIPHER, zrtp_cipher_id_t::ZRTP_CIPHER_AES128).
49  * The high number of components means that every component must have a minimal
50  * set of attributes and functions: type identifier, and function initialization
51  * and deinitialization. The base type of all components is zrtp_comp_t. Every
52  * new component MUST start with definitions of this structure strictly in the
53  * given order.
54  * \warning
55  * Every crypto-component included in libZRTP was developed and tested by
56  * professionals. Its presence is functionally based. Using only the built-in
57  * components gives you 100% crypto-strength and the guarantee of the fully
58  * tested code. Never use your own components without strong reasons. If you
59  * have noticed the absence of any important component in the library, contact
60  * the developers. Reasonable offers will be considered for implementation in
61  * the following versions.
62  * \{
63  */
64 
65 
66 /*============================================================================*/
67 /* 	  Types  of libZRTP crypto-components definitions						  */
68 /*============================================================================*/
69 
70 /*!
71  * \brief Enumeration for crypto-components types definition
72  */
73 typedef enum zrtp_crypto_comp_t
74 {
75     ZRTP_CC_HASH		= 1,	/*!< hash calculation schemes */
76     ZRTP_CC_SAS			= 2,	/*!< short autentification scheme components */
77     ZRTP_CC_CIPHER		= 3,	/*!< ciphers */
78     ZRTP_CC_PKT			= 4,	/*!< public key exchange scheme */
79 	ZRTP_CC_ATL         = 5,
80 }zrtp_crypto_comp_t;
81 
82 
83 /*!
84  * This ID with code 0 is used as an error signal by all crypto-components
85  * groups to indicate a wrongly defined component identifier.
86  */
87 #define ZRTP_COMP_UNKN 0
88 
89 /*! Defines types of hash functions */
90 typedef enum zrtp_hash_id_t
91 {
92 	ZRTP_HASH_SHA256	= 1,
93 	ZRTP_HASH_SHA384	= 2
94 } zrtp_hash_id_t;
95 
96 /*! Defines types of ciphers */
97 typedef enum zrtp_cipher_id_t
98 {
99 	ZRTP_CIPHER_AES128	= 1,
100 	ZRTP_CIPHER_AES256	= 2
101 } zrtp_cipher_id_t;
102 
103 /*! Defines SRTP authentication schemes */
104 typedef enum zrtp_atl_id_t
105 {
106 	ZRTP_ATL_HS32		= 1,
107 	ZRTP_ATL_HS80		= 2
108 } zrtp_atl_id_t;
109 
110 /*! Defines public key exchange schemes */
111 /* WARNING! don't change order of the PK components definitions! */
112 typedef enum zrtp_pktype_id_t
113 {
114 	ZRTP_PKTYPE_PRESH	= 1,
115 	ZRTP_PKTYPE_MULT	= 2,
116 	ZRTP_PKTYPE_DH2048	= 3,
117 	ZRTP_PKTYPE_EC256P  = 4,
118 	ZRTP_PKTYPE_DH3072	= 5,
119     ZRTP_PKTYPE_EC384P  = 6,
120     ZRTP_PKTYPE_EC521P  = 7,
121 	ZRTP_PKTYPE_DH4096	= 8
122 } zrtp_pktype_id_t;
123 
124 /*! Defines modes of short authentication scheme calculation */
125 typedef enum zrtp_sas_id
126 {
127 	ZRTP_SAS_BASE32		= 1,
128 	ZRTP_SAS_BASE256	= 2
129 } zrtp_sas_id_t;
130 
131 
132 /*!
133  * \brief Global structure for all crypto-component types.
134  * \warning All developed components must have these 4 fields at the beginning.
135  */
136 typedef struct zrtp_comp_t
137 {
138     zrtp_uchar4_t		type;		/*!< 4-character symbolic name defined by ZRTP Draft */
139     uint8_t				id;			/*!< Integer component identifier */
140     zrtp_global_t*		zrtp;/*!< ZRTP global context */
141 
142 	/*!
143      * \brief Component initiation function.
144      * This function body is for holding component initialization code. libzrtp
145 	 * calls the function before using a component, at its registration. If the
146 	 * component does not require additional actions for initialization, the
147 	 * value of this field can be NULL.
148      * \param self - self-pointer for fast access to structure data.
149      * \return
150      *	- zrtp_status_ok - if initialized successfully;
151      *	- one of \ref zrtp_status_t errors - if initialization failed.
152      */
153 	zrtp_status_t		(*init)(void* self);
154 
155 	/*!
156      * \brief Component deinitializtion function.
157      * This function body is for holding component deinitialization code and
158      * all code for releasing allocated resources. libzrtp calls the function
159      * at the end of component use, at context deinitialization. If the component
160 	 * does not require additional actions for deinitialization, the value of
161 	 * this field can be NULL.
162      * \param self - pointer to component structure for deinitialization.
163      * \return
164      *	- zrtp_status_ok - if deinitialized successfully;
165      *	- one of \ref zrtp_status_t errors - if deinitialization failed.
166      */
167     zrtp_status_t (*free)(void* self);
168 } zrtp_comp_t;
169 
170 
171 /*!
172  * \brief Structure for defining the hash-value computing scheme
173  * The ZRTP context field zrtp_stream#_hash is initialized by the given type
174  * value and used for all hash calculations within the ZRTP sessions. Having
175  * implemented a structure of this type, it is possible to integrate new hash
176  * calculation schemes into libzrtp.
177  */
178 struct zrtp_hash_t
179 {
180 	zrtp_comp_t		base;
181 
182     /*!
183      * \brief Begin hash computation with update support.
184      * The following set of functions ( zrtp_hash#hash_begin, zrtp_hash#hash_update,
185 	 * zrtp_hash#hash_end) implements a standard hash calculation scheme with
186 	 * accumulation. The functions perform the required actions to start
187 	 * calculations and to allocate hash-contexts for preserving intermediate
188 	 * results and other required information. The allocated context will be
189 	 * passed-to by the subsequent calls zrtp_hash#hash_update and zrtp_hash#hash_end.
190      * \param self - self-pointer for fast access to structure data
191      * \return
192      * 	- pointer to allocated hash-context if successful;
193      * 	- NULL if error.
194      */
195     void*			(*hash_begin)(zrtp_hash_t *self);
196 
197     /*!
198      * \brief Process more input data for hash calculation
199      * This function is called in the hash-building chain to obtain additional
200 	 * data that it then processes and recalculates intermediate values.
201      * \param self - self-pointer for fast access to structure data;
202      * \param ctx - hash-context for current hash-value calculation;
203      * \param msg - additional source data for processing;
204      * \param length - length of additional data in bytes.
205      * \return
206      *	- zrtp_status_ok - if successfully processed;
207      * 	- one of \ref zrtp_status_t errors - if error.
208      */
209     zrtp_status_t	(*hash_update)( zrtp_hash_t *self,
210 									void *ctx,
211 									const int8_t*msg,
212 									uint32_t length );
213 
214     /*!
215      * \brief Completes the computation of the current hash-value
216      * This function completes the computation of the hash-value with accumul.
217 	 * After completion, the hash-context previously allocated by the call to
218 	 * zrtp_hash#hash_begin, must be destroyed. The size of the calculated
219 	 * value must be kept in the parameter digest field zrtp_string#length.
220      * \param self - self-pointer for fast access to structure data;
221      * \param ctx - hash-context for current hash-value calculation;
222      * \param digest - buffer for storing result.
223      * \return
224      *	- zrtp_status_ok - if computing finished successfully;
225      * 	- one of \ref zrtp_status_t errors - if error.
226      */
227     zrtp_status_t	(*hash_end)( zrtp_hash_t *self,
228 								 void *ctx,
229 								 zrtp_stringn_t *digest );
230 
231     /*!
232      * \brief Calculate hash-value for current message
233      * This function implicitly calls the previous 3 functions. The only
234 	 * difference is that initial data for hash value construction is gathered
235      * in a single buffer and is passed to the function in the \c msg argument.
236      * The calculated value size must be stored in the digest zrtp_string#length
237      * parameter
238      * \param self - self-pointer for fast access to structure data;
239      * \param msg - source data buffer for hash computing;
240      * \param digest - buffer for storing result.
241      * \return
242      *	- zrtp_status_ok - if computing finished successfully;
243      * 	- one of \ref zrtp_status_t errors - if error.
244      */
245     zrtp_status_t	(*hash)( zrtp_hash_t *self,
246 							 const zrtp_stringn_t *msg,
247 							 zrtp_stringn_t *digest );
248 
249 	/*! \brief Analogue of zrtp_hash::hash for C-string */
250 	zrtp_status_t	(*hash_c)( zrtp_hash_t *self,
251 							   const char* msg,
252 							   uint32_t	 msg_len,
253 							   zrtp_stringn_t *digest );
254 
255 	/*!
256 	 * \brief HASH self-test.
257 	 * This function implements hmac self-tests using pre-defined test vectors.
258 	 * \param self - self-pointer for fast access to structure data;
259 	 * \return
260 	 *	- zrtp_status_ok - if tests have been passed successfully;
261 	 *	- one of \ref zrtp_status_t errors - if one or more tests have
262 	 *	  failed.
263 	 */
264 	zrtp_status_t	(*hash_self_test)(zrtp_hash_t *self);
265 
266 
267     /*!
268      * \brief Begin HMAC computation with update support.
269      * The zrtp_hash#hmac_begin, zrtp_hash#hmac_update and zrtp_hash#hmac_end
270      * functions implement the HMAC calculation scheme with accumulation.  The
271      * function performs all actions required before beginning the calculation
272      * and allocates a hash-context to store intermediate values. The allocated
273      * hash-context will be passed to successive hash_update and hash_end calls
274      * \param self - self-pointer for fast access to structure data;
275      * \param key - secret key for hmac-value protection.
276      * \return
277      * 	- pointer to allocated hmac-context if successful;
278      * 	- NULL - if error.
279      */
280     void*			(*hmac_begin)(zrtp_hash_t *self, const zrtp_stringn_t *key);
281 
282 	/*! \brief Analogue of zrtp_hash::hmac_begin for C-string */
283 	void*			(*hmac_begin_c)(zrtp_hash_t *self, const char *key, uint32_t length);
284 
285     /*!
286      * \brief Process more input data for HMAC calculation
287      * This function is called to transfer additional data to the HMAC hash-
288 	 * calculation. Processes new data and recalculates intermediate values.
289      * \param self - self-pointer for fast access to structure data;
290      * \param ctx - hmac-context for current hmac-value calculation;
291      * \param msg - additional source data for processing;
292      * \param length - additional data length in bytes.
293      * \return
294      *	- zrtp_status_ok - if successfully processed;
295      * 	- one of \ref zrtp_status_t errors - if error.
296      */
297     zrtp_status_t	(*hmac_update)( zrtp_hash_t *self,
298 									void *ctx,
299 									const char *msg,
300 									uint32_t length );
301 
302     /*!
303      * \brief Complete current HMAC-value computation
304      * This function completes the hmac calculation. After the final iteration
305      * \a the hash_context allocated by zrtp_hash#hmac_begin is destroyed. The
306      * argument \c len holds the HMAC size. If the buffer contains more than \c
307      * length characters then only the first \c length are copied to \c digest.
308      * The calculated value size is stored in the digest parameter length.
309      * \param self - self-pointer for fast access to structure data;
310      * \param ctx - hmac-context for current hmac-value calculation;
311      * \param digest - buffer for storing result;
312      * \param len - required hmac-value size.
313      * \return
314      *	- zrtp_status_ok - if computing finished successfully;
315      * 	- one of \ref zrtp_status_t errors - if error.
316      */
317     zrtp_status_t	(*hmac_end)( zrtp_hash_t *self,
318 								 void *ctx,
319 								 zrtp_stringn_t *digest,
320 								 uint32_t len);
321 
322     /*!
323      * \brief Calculate hmac-value for current message
324      * The function implicitly calls the previous 3 functions
325      * (zrtp_hash#hmac_begin, zrtp_hash#hmac_update and zrtp_hash#hmac_end). The
326      * difference is that the initial data for hash value construction is
327      * gathered in a single buffer and is passed to the function in the \a msg
328      * argument.  The calculated value size must be stored in the \a digest
329      * zrtp_string#length  parameter
330      * \param self - self-pointer for fast access to structure data;
331      * \param key - key for protecting hmac;
332      * \param msg - source data buffer for hash computing;
333      * \param digest - buffer for storing result.
334      * \return
335      *	- zrtp_status_ok - if computing finished successfully;
336      * 	- one of \ref zrtp_status_t errors - if error.
337      */
338     zrtp_status_t	(*hmac)( zrtp_hash_t *self,
339 							 const zrtp_stringn_t *key,
340 							 const zrtp_stringn_t *msg,
341 							 zrtp_stringn_t *digest );
342 
343 	/*! \brief Analogue of zrtp_hash::hmac for C-string */
344 	zrtp_status_t	(*hmac_c)( zrtp_hash_t *self,
345 							   const char *key,
346 							   const uint32_t key_len,
347 							   const char *msg,
348 							   const uint32_t msg_len,
349 							   zrtp_stringn_t *digest );
350 
351     /*!
352      * \brief Truncated Hmac-calculation version
353      * This function acts just like the previous \a hmac except it returns the
354      * first \a length bytes of the calculated value in the digest.
355      * \param self - self-pointer for fast access to structure data;
356      * \param key - key for hmac protection;
357      * \param msg - source data buffer for hash computing;
358      * \param digest - buffer for storing result;
359      * \param len - required hmac-value size.
360      * \return
361      *	- zrtp_status_ok - if computed successfully;
362      * 	- one of \ref zrtp_status_t errors - if error.
363      */
364     zrtp_status_t	(*hmac_truncated)( zrtp_hash_t *self,
365 									   const zrtp_stringn_t *key,
366 									   const zrtp_stringn_t *msg,
367 									   uint32_t len,
368 									   zrtp_stringn_t *digest );
369 
370 	/*! \brief Analogue of zrtp_hash::hmac_truncated for C-string */
371 	zrtp_status_t	(*hmac_truncated_c)( zrtp_hash_t *self,
372 									     const char *key,
373 										 const uint32_t key_len,
374 										 const char *msg,
375 										 const uint32_t msg_len,
376 										 uint32_t necessary_len,
377 										 zrtp_stringn_t *digest );
378 
379 	/*!
380 	 * \brief HMAC self-test.
381 	 * This function implements the hmac self-tests using pre-defined test vectors.
382 	 * \param self - self-pointer for fast access to structure data;	.
383 	 * \return
384 	 *	- zrtp_status_ok - if tests have passed successfully;
385      *	- one of \ref zrtp_status_t errors - if one or more tests have failed.
386 	 */
387 	zrtp_status_t	(*hmac_self_test)( zrtp_hash_t *self);
388 
389 	uint32_t		digest_length;
390 	uint32_t		block_length;
391 	mlist_t	mlist;
392 };
393 
394 
395 /*!
396  * \brief Structure for defining the SRTP authentication scheme
397  * The ZRTP context field zrtp_stream#_authtaglength is initialized by the
398  * given type value and used for SRTP encryption configuration.
399  */
400 struct zrtp_auth_tag_length_t
401 {
402     zrtp_comp_t	  base;
403     uint32_t	  tag_length;
404     mlist_t		  mlist;
405 };
406 
407 
408 /**
409  * @brief Structure for describing the public key scheme
410  * The ZRTP context field zrtp_stream#_pubkeyscheme is initialized by the given
411  * type value and used by libzrtp in public key exchange.
412  */
413 struct zrtp_pk_scheme_t
414 {
415 	zrtp_comp_t		base;
416 
417     /** Generate Diffie-Hellman secret value and Calculate public value */
418     zrtp_status_t	(*initialize)( zrtp_pk_scheme_t *self,
419 								   zrtp_dh_crypto_context_t *dh_cc );
420 
421     /** Calculate Diffie-Hellman result (ZRTP Internet Draft) */
422     zrtp_status_t	(*compute)( zrtp_pk_scheme_t *self,
423 								zrtp_dh_crypto_context_t *dh_cc,
424 								struct BigNum *dhresult,
425 								struct BigNum *pv);
426 
427     /** Validate Diffie-Hellman public value */
428     zrtp_status_t	(*validate)(zrtp_pk_scheme_t *self, struct BigNum *pv);
429 
430 	/** Diffie-Hellman self-test routine. */
431 	zrtp_status_t	(*self_test)(zrtp_pk_scheme_t *self);
432 
433 	/** Diffie-Hellman secret value size in bytes */
434     uint32_t		sv_length;
435 
436 	/** Diffie-Hellman public value size in bytes */
437     uint32_t		pv_length;
438 
439     mlist_t			mlist;
440 };
441 
442 
443 /*!
444  * \brief Structure for defining SAS generation scheme
445  * The type of the ZRTP context's field zrtp_stream#_sasscheme. It is used
446  * to generate short authentication strings. LibZRTP functionality can be augmented
447  * with a new SAS scheme by supplying your own instance of zrtp_sas_scheme.
448  */
449 struct zrtp_sas_scheme_t
450 {
451 	zrtp_comp_t		base;
452 
453     /*!
454      * \brief Generate short authentication strings
455      * This function computes SAS values according to the specified scheme. It
456      * can use base32 or base256 algorithms. It stores the generated SAS values
457      * as a zrtp_sas_values_t structure (string and binary representation).
458      * \param self - self-pointer for fast access to structure data;
459      * \param session - ZRTP session context for additional data;
460 	 * \param hash - hmac component to be used for SAS calculation;
461 	 * \param is_transferred - if this flag is equal to 1 new SAS value should
462 	 *    not be computed. It is already in sas->bin buffer and rendering only
463 	 *    is required.
464      * \return
465      *	- zrtp_status_ok - if generation successful;
466      *	- one of zrtp_status_t errors - if generation failed.
467      */
468     zrtp_status_t	(*compute)( zrtp_sas_scheme_t *self,
469 								zrtp_stream_t *stream,
470 								zrtp_hash_t *hash,
471 								uint8_t is_transferred );
472 
473 	mlist_t	mlist;
474 };
475 
476 
477 #include "aes.h"
478 
479 /*! Defines block cipher modes. */
480 typedef enum zrtp_cipher_mode_values_t
481 {
482 	ZRTP_CIPHER_MODE_CTR = 1,
483 	ZRTP_CIPHER_MODE_CFB = 2
484 } zrtp_cipher_mode_values_t;
485 
486 typedef struct zrtp_cipher_mode_t
487 {
488 	uint8_t	mode;
489 } zrtp_cipher_mode_t;
490 
491 
492 /* \brief Structure for cipher definition */
493 struct zrtp_cipher_t
494 {
495 	zrtp_comp_t		base;
496 
497 	/*!
498 	 * \brief Start cipher.
499 	 * This function performs all actions necessary to allocate the cipher context
500 	 * for holding intermediate results and other required information. The allocated
501 	 * context should be related to the given key. It will be passed to the
502 	 * zrtp_cipher#set_iv, zrtp_cipher#encrypt and zrtp_cipher#decrypt functions.
503 	 * \param self - self-pointer for fast access to structure data;
504 	 * \param key - cipher key;
505 	 * \param extra_data - additional data necessary for cipher initialization;
506 	 * \param mode - cipher mode (one of \ref zrtp_cipher_mode_values_t values).
507      * \return
508      *	- pointer to allocated cipher context;
509      *	- NULL if error.
510 	*/
511 	void*			(*start)( zrtp_cipher_t *self,
512 							  void *key,
513 							  void *extra_data, uint8_t mode );
514 
515 	/*!
516 	 * \brief Set Initialization Vector.
517 	 * Function resets the previous state of the cipher context and sets the new IV.
518 	 * \param self - self-pointer for fast access to structure data;
519 	 * \param cipher_ctx - cipher context for current key value;
520 	 * \param iv - new initialization vector value.
521 	 * \return
522 	 *	- zrtp_status_ok - if vector has been set successfully;
523      *	- one of \ref zrtp_status_t errors - if operation failed.
524 	*/
525 	zrtp_status_t	(*set_iv)( zrtp_cipher_t *self,
526 							   void *cipher_ctx,
527 							   zrtp_v128_t *iv );
528 
529 	/*!
530 	 * \brief Encrypt data.
531 	 * Implements the encryption engine.
532 	 * \param self - self-pointer for fast access to structure data;
533 	 * \param cipher_ctx - cipher context for current key value;
534 	 * \param buf - buffer with data for encryption. If successful this
535 	 *              buffer contains the resulting encrypted text;
536 	 * \param len - length of plain/encrypted data.
537 	 * \return
538 	 *	- zrtp_status_ok - if data has been encrypted successfully;
539      *	- one of \ref zrtp_status_t errors - if encryption failed.
540 	*/
541 	zrtp_status_t	(*encrypt)( zrtp_cipher_t *self,
542 								void *cipher_ctx,
543 								unsigned char *buf,
544 								int len );
545 
546 	/*!
547 	 * \brief Decrypt data.
548 	 * Implements the decryption engine.
549 	 * \param self - self-pointer for fast access to structure data;
550 	 * \param cipher_ctx - cipher context for current key value;
551 	 * \param buf - buffer with data for decryption. If successful this buffer
552 	 *    contains the resulting plain text;
553 	 * \param len - length of encrypted/plain data.
554 	 * \return
555 	 *	- zrtp_status_ok - if data has been decrypted successfully;
556      *	- one of \ref zrtp_status_t errors - if decryption failed.
557 	*/
558 	zrtp_status_t	(*decrypt)( zrtp_cipher_t *self,
559 								void *cipher_ctx,
560 								unsigned char *buf,
561 								int len );
562 
563 	/*!
564 	 * \brief Cipher self-test.
565 	 * Implements cipher self-tests using pre-defined test vectors.
566 	 * \param self - self-pointer for fast access to structure data;
567 	 * \param mode - cipher mode (one of \ref zrtp_cipher_mode_values_t values).
568 	 * \return
569 	 *	- zrtp_status_ok - if tests have passed successfully;
570      *	- one of \ref zrtp_status_t errors - if one or more tests have failed.
571 	 */
572 	zrtp_status_t	(*self_test)(zrtp_cipher_t *self, uint8_t mode);
573 
574 	/*!
575 	 * \brief Destroy cipher context.
576 	 * Deallocs the cipher context previously allocated by a call to zrtp_cipher#start.
577 	 * \param self - self-pointer for fast access to structure data;
578 	 * \param cipher_ctx - cipher context for current key value.
579 	 * \return
580 	 *	- zrtp_status_ok - if the context has been deallocated
581 	 *	                   successfully;
582      *	- one of \ref zrtp_status_t errors - if deallocation failed.
583 	 */
584 	zrtp_status_t (*stop)(zrtp_cipher_t *self, void* cipher_ctx);
585 
586 	mlist_t mlist;
587 };
588 
589 #if defined(__cplusplus)
590 extern "C"
591 {
592 #endif
593 
594 
595 /*============================================================================*/
596 /* 	  Crypto-components management Private part		      					  */
597 /*============================================================================*/
598 
599 
600 /*!
601  * \brief Destroy components buffer
602  * This function clears the list of components of the specified type, destroys
603  * all components and releases all allocated resources. It is used on libzrtp
604  * down. zrtp_comp_done calls zrtp_comp_t#free() if it isn't NULL.
605  * \param zrtp - the ZRTP global context where components are stored;
606  * \param type - specifies the component pool type for destroying.
607  * \return
608  * 	- zrtp_status_ok - if clearing successful;
609  * 	- zrtp_status_fail - if error.
610  */
611 zrtp_status_t zrtp_comp_done(zrtp_crypto_comp_t type, zrtp_global_t* zrtp);
612 
613 /*!
614  * \brief Registering a new crypto-component
615  * Correctness of values in the necessary structure is the developer's
616  * responsibility. zrtp_comp_register calls zrtp_comp_t#init() if it isn't NULL.
617  * \param type - type of registred component;
618  * \param comp - registered crypto-component;
619  * \param zrtp - the ZRTP global context where components are stored.
620  * \return
621  *	- zrtp_status_ok if registration successful;
622  * 	-  zrtp_status_fail if error (conflicts with other components).
623  */
624 zrtp_status_t zrtp_comp_register( zrtp_crypto_comp_t type,
625 								  void *comp,
626 								  zrtp_global_t* zrtp);
627 
628 /*!
629  * \brief Search component by ID
630  * \param type - type of sought component;
631  * \param zrtp - the ZRTP global context where components are stored;
632  * \param id - integer identifier of the necessary element.
633  * \return
634  * 	- the found structure if successful;
635  * 	- NULL if the element with the specified ID can't be found or
636  *        other error.
637  */
638 void* zrtp_comp_find( zrtp_crypto_comp_t type,
639 					  uint8_t id,
640 					  zrtp_global_t* zrtp);
641 
642 
643 /*! Converts a component's integer ID to a symbolic ZRTP name */
644 char* zrtp_comp_id2type(zrtp_crypto_comp_t type, uint8_t id);
645 
646 /*! Converts a component's ZRTP symbolic name to an integer ID */
647 uint8_t zrtp_comp_type2id(zrtp_crypto_comp_t type, char* name);
648 
649 
650 /*! \} */
651 
652 #if defined(__cplusplus)
653 }
654 #endif
655 
656 #endif /*__ZRTP_CRYPTO_H__ */
657