libzrtp  1.2.0
ZRTP VoIP security
zrtp_types.h
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 
11 #ifndef __ZRTP_TYPES_H__
12 #define __ZRTP_TYPES_H__
13 
14 #include "zrtp_config.h"
15 #include "bn.h"
16 #include "zrtp_base.h"
17 #include "zrtp_iface.h"
18 #include "zrtp_list.h"
19 #include "zrtp_legal.h"
20 #include "zrtp_string.h"
21 #include "zrtp_protocol.h"
22 #include "zrtp_cache.h"
23 
24 
35 typedef enum zrtp_state_t
36 {
37  ZRTP_STATE_NONE = 0,
38  ZRTP_STATE_ACTIVE,
56 #if (defined(ZRTP_BUILD_FOR_CSD) && (ZRTP_BUILD_FOR_CSD == 1))
57  ZRTP_STATE_DRIVEN_INITIATOR,
58  ZRTP_STATE_DRIVEN_RESPONDER,
59  ZRTP_STATE_DRIVEN_PENDING,
60 #endif
63 } zrtp_state_t;
64 
69 typedef enum zrtp_stream_mode_t
70 {
71  ZRTP_STREAM_MODE_UNKN = 0,
78 
106 {
118  uint8_t allowclear;
119 
127  uint8_t autosecure;
128 
134  uint8_t disclose_bit;
135 
153 
163  uint32_t cache_ttl;
164 
166  uint8_t sas_schemes[ZRTP_MAX_COMP_COUNT+1];
167 
169  uint8_t cipher_types[ZRTP_MAX_COMP_COUNT+1];
170 
172  uint8_t pk_schemes[ZRTP_MAX_COMP_COUNT+1];
173 
175  uint8_t auth_tag_lens[ZRTP_MAX_COMP_COUNT+1];
176 
181  uint8_t hash_schemes[ZRTP_MAX_COMP_COUNT+1];
182 };
183 
184 
190 typedef enum zrtp_mitm_mode_t
191 {
193  ZRTP_MITM_MODE_UNKN = 0,
194 
201  ZRTP_MITM_MODE_CLIENT,
202 
208  ZRTP_MITM_MODE_RECONFIRM_SERVER,
214  ZRTP_MITM_MODE_RECONFIRM_CLIENT,
221  ZRTP_MITM_MODE_REG_SERVER,
228  ZRTP_MITM_MODE_REG_CLIENT
229 } zrtp_mitm_mode_t;
230 
231 
235 /*======================================================================*/
236 /* Internal ZRTP libzrtp datatypes */
237 /*======================================================================*/
238 
252 typedef enum
253 {
254  ZRTP_UNPARSED = -1,
255  ZRTP_NONE = 0,
256  ZRTP_HELLO = 1,
257  ZRTP_HELLOACK = 2,
258  ZRTP_COMMIT = 3,
259  ZRTP_DHPART1 = 4,
260  ZRTP_DHPART2 = 5,
261  ZRTP_CONFIRM1 = 6,
262  ZRTP_CONFIRM2 = 7,
263  ZRTP_CONFIRM2ACK = 8,
264  ZRTP_GOCLEAR = 9,
265  ZRTP_GOCLEARACK = 10,
266  ZRTP_ERROR = 11,
267  ZRTP_ERRORACK = 12,
268  ZRTP_PROCESS = 13,
269  ZRTP_SASRELAY = 14,
270  ZRTP_RELAYACK = 15,
271  ZRTP_ZFONEPING = 16,
272  ZRTP_ZFONEPINGACK = 17,
273  ZRTP_MSG_TYPE_COUNT = 18
274 } zrtp_msg_type_t;
275 
276 
282 typedef enum zrtp_statemachine_type_t
283 {
284  ZRTP_STATEMACHINE_NONE = 0,
285  ZRTP_STATEMACHINE_INITIATOR = 1,
286  ZRTP_STATEMACHINE_RESPONDER = 2
287 } zrtp_statemachine_type_t;
288 
289 #define ZRTP_BIT_RS1 0x02
290 #define ZRTP_BIT_RS2 0x04
291 #define ZRTP_BIT_AUX 0x10
292 #define ZRTP_BIT_PBX 0x20
293 
312 struct zrtp_global_t
313 {
314  zrtp_string16_t zid;
315  uint32_t lic_mode;
316  zrtp_string16_t client_id;
317  uint8_t is_mitm;
318  MD_CTX rand_ctx;
319  uint8_t rand_initialized;
320  zrtp_cache_t *cache;
321  zrtp_mutex_t* rng_protector;
322  struct BigNum one;
323  struct BigNum G;
324  struct BigNum P_2048;
325  struct BigNum P_2048_1;
326  struct BigNum P_3072;
327  struct BigNum P_3072_1;
328  uint8_t P_2048_data[256];
329  uint8_t P_3072_data[384];
330  mlist_t hash_head;
331  mlist_t cipher_head;
332  mlist_t atl_head;
333  mlist_t pktype_head;
334  mlist_t sas_head;
335  void* srtp_global;
336  mlist_t sessions_head;
337  uint32_t sessions_count;
338  uint32_t streams_count;
339  zrtp_mutex_t* sessions_protector;
340  zrtp_callback_t cb;
341 };
342 
343 
350 typedef struct zrtp_rtp_info_t
351 {
353  uint32_t *length;
354 
356  char *packet;
357 
359  void *message;
360 
362  zrtp_msg_type_t type;
363 
365  uint32_t seq;
366 
368  uint32_t ssrc;
369 } zrtp_rtp_info_t;
370 
371 
380 typedef struct zrtp_secrets_t
381 {
383  zrtp_shared_secret_t *rs1;
384 
386  zrtp_shared_secret_t *rs2;
387 
389  zrtp_shared_secret_t *auxs;
390 
392  zrtp_shared_secret_t *pbxs;
393 
395  uint32_t cached;
396  uint32_t cached_curr;
397 
399  uint32_t matches;
400  uint32_t matches_curr;
401 
403  uint32_t wrongs;
404  uint32_t wrongs_curr;
405 
407  uint8_t is_ready;
408 } zrtp_secrets_t;
409 
410 
416 typedef struct zrtp_proto_secret_t
417 {
419  zrtp_string8_t id;
420 
422  zrtp_string8_t peer_id;
423 
425  zrtp_shared_secret_t *secret;
426 } zrtp_proto_secret_t;
427 
428 
436 typedef struct zrtp_stream_mescache_t
437 {
438  zrtp_packet_Hello_t peer_hello;
439  zrtp_packet_Hello_t hello;
440  zrtp_packet_GoClear_t goclear;
441  zrtp_packet_Commit_t peer_commit;
442  zrtp_packet_Commit_t commit;
443  zrtp_packet_DHPart_t peer_dhpart;
444  zrtp_packet_DHPart_t dhpart;
445  zrtp_packet_Confirm_t confirm;
446  zrtp_string32_t h0;
447  zrtp_packet_Confirm_t peer_confirm;
448  zrtp_packet_Error_t error;
449  zrtp_packet_SASRelay_t sasrelay;
450 
451  zrtp_retry_task_t hello_task;
452  zrtp_retry_task_t goclear_task;
453  zrtp_retry_task_t dh_task;
454  zrtp_retry_task_t commit_task;
455  zrtp_retry_task_t dhpart_task;
456  zrtp_retry_task_t confirm_task;
457  zrtp_retry_task_t error_task;
458  zrtp_retry_task_t errorack_task;
459  zrtp_retry_task_t sasrelay_task;
460 
466  zrtp_string64_t signaling_hash;
467 } zrtp_stream_mescache_t;
468 
469 
475 typedef struct zrtp_dh_crypto_context_t
476 {
478  struct BigNum sv;
479 
481  struct BigNum pv;
482 
484  struct BigNum peer_pv;
485 
487  zrtp_string64_t dhss;
488 
489  unsigned int initialized_with;
490 } zrtp_dh_crypto_context_t;
491 
492 
498 typedef struct zrtp_dsa_crypto_context_t
499 {
500  struct BigNum sv;
501  struct BigNum pv;
502  struct BigNum peer_pv;
503 } zrtp_dsa_crypto_context_t;
504 
505 
512 typedef struct zrtp_proto_crypto_t
513 {
515  zrtp_string128_t kdf_context;
516 
518  zrtp_string64_t s0;
519 
521  zrtp_string64_t hv;
522 
524  zrtp_string64_t peer_hv;
525 
527  zrtp_string64_t mes_hash;
528 
530  zrtp_proto_secret_t rs1;
531 
533  zrtp_proto_secret_t rs2;
534 
536  zrtp_proto_secret_t auxs;
537 
539  zrtp_proto_secret_t pbxs;
540 } zrtp_proto_crypto_t;
541 
548 struct zrtp_protocol_t
549 {
551  zrtp_statemachine_type_t type;
552 
554  zrtp_proto_crypto_t* cc;
555 
557  zrtp_srtp_ctx_t* _srtp;
558 
560  zrtp_stream_t *context;
561 };
562 
568 typedef struct zrtp_stream_crypto_t
569 {
571  zrtp_string64_t hmackey;
572 
574  zrtp_string64_t peer_hmackey;
575 
577  zrtp_string64_t zrtp_key;
578 
580  zrtp_string64_t peer_zrtp_key;
581 } zrtp_stream_crypto_t;
582 
583 
587 typedef struct zrtp_media_context_t
588 {
590  uint32_t high_in_zrtp_seq;
591 
593  uint32_t high_out_zrtp_seq;
594 
596  uint32_t high_in_media_seq;
597 
599  uint32_t high_out_media_seq;
600 
602  uint32_t ssrc;
603 } zrtp_media_context_t;
604 
609 struct zrtp_stream_t
610 {
612  zrtp_id_t id;
613 
621  zrtp_stream_mode_t mode;
622 
629  zrtp_mitm_mode_t mitm_mode;
630 
636  zrtp_state_t prev_state;
637 
639  uint8_t is_hello_received;
640 
642  zrtp_state_t state;
643 
649  zrtp_stream_crypto_t cc;
650 
652  zrtp_dh_crypto_context_t dh_cc;
653 
660  zrtp_protocol_t *protocol;
661 
663  zrtp_media_context_t media_ctx;
664 
666  zrtp_stream_mescache_t messages;
667 
672  uint8_t allowclear;
673 
678  uint8_t peer_passive;
679 
689  uint32_t cache_ttl;
690 
697  uint8_t peer_disclose_bit;
698 
706  zrtp_protocol_error_t last_error;
707 
711  uint8_t peer_mitm_flag;
712 
716  uint8_t peer_super_flag;
717 
729  zrtp_stream_t *concurrent;
730 
732  zrtp_global_t *zrtp;
733 
735  zrtp_session_t *session;
736 
738  zrtp_pk_scheme_t *pubkeyscheme;
739 
744  void *usr_data;
745 
750  zrtp_stream_t *linked_mitm;
751 
758  zrtp_mutex_t* stream_protector;
759 };
760 
761 
767 struct zrtp_session_t
768 {
770  zrtp_id_t id;
771 
779  zrtp_string16_t peer_zid;
780 
782  zrtp_profile_t profile;
783 
784  /*
785  * Signaling Role which protocol was started with, one of zrtp_signaling_role_t values.
786  */
787  unsigned signaling_role;
788 
794  zrtp_secrets_t secrets;
795 
797  zrtp_string64_t zrtpsess;
798 
800  zrtp_string16_t sas1;
801 
803  zrtp_string16_t sas2;
804 
806  zrtp_string32_t sasbin;
807 
809  zrtp_global_t *zrtp;
810 
812  void *usr_data;
813 
815  zrtp_hash_t *hash;
816 
818  zrtp_cipher_t *blockcipher;
819 
821  zrtp_auth_tag_length_t *authtaglength;
822 
824  zrtp_sas_scheme_t *sasscheme;
825 
827  zrtp_stream_t streams[ZRTP_MAX_STREAMS_PER_SESSION];
828 
830  zrtp_mutex_t* streams_protector;
831 
833  zrtp_mutex_t* init_protector;
834 
838  uint8_t mitm_alert_detected;
839 
840  mlist_t _mlist;
841 };
842 
846 /*===========================================================================*/
847 /* Data types and definitions for SRTP */
848 /*===========================================================================*/
849 
850 #if ZRTP_BYTE_ORDER == ZBO_LITTLE_ENDIAN
851 
856 typedef struct
857 {
858  uint16_t cc:4;
859  uint16_t x:1;
860  uint16_t p:1;
861  uint16_t version:2;
862  uint16_t pt:7;
863  uint16_t m:1;
864  uint16_t seq;
865  uint32_t ts;
866  uint32_t ssrc;
867 } zrtp_rtp_hdr_t;
868 
873 typedef struct
874 {
875  unsigned char rc:5;
876  unsigned char p:1;
877  unsigned char version:2;
878  unsigned char pt:8;
879  uint16_t len;
880  uint32_t ssrc;
881 } zrtp_rtcp_hdr_t;
882 
883 typedef struct
884 {
885  unsigned int index:31;
886  unsigned int e:1;
889 } zrtp_rtcp_trailer_t;
890 
891 #else
892 
897 typedef struct
898 {
899  uint16_t version:2;
900  uint16_t p:1;
901  uint16_t x:1;
902  uint16_t cc:4;
903  uint16_t m:1;
904  uint16_t pt:7;
905  uint16_t seq;
906  uint32_t ts;
907  uint32_t ssrc;
908 } zrtp_rtp_hdr_t;
909 
914 typedef struct
915 {
916  unsigned char version:2;
917  unsigned char p:1;
918  unsigned char rc:5;
919  unsigned char pt:8;
920  uint16_t len;
921  uint32_t ssrc;
922 } zrtp_rtcp_hdr_t;
923 
924 typedef struct
925 {
926  unsigned int e:1;
927  unsigned int index:31;
928 } zrtp_rtcp_trailer_t;
929 
930 #endif
931 
936 typedef struct
937 {
938  uint16_t profile_specific;
939  uint16_t length;
940 } zrtp_rtp_hdr_xtnd_t;
941 
942 
945 #endif /* __ZRTP_TYPES_H__ */
Delay Call wrapper.
Definition: zrtp_iface.h:54
Definition: zrtp_string.h:73
Definition: zrtp_types.h:74
Definition: zrtp_string.h:52
Definition: zrtp_types.h:43
Definition: zrtp_types.h:72
Definition: zrtp_string.h:66
uint8_t auth_tag_lens[ZRTP_MAX_COMP_COUNT+1]
Auth tag length preferences.
Definition: zrtp_types.h:175
Definition: zrtp_types.h:44
Definition: zrtp_types.h:62
Definition: zrtp_types.h:46
Definition: zrtp_types.h:53
Definition: zrtp_types.h:49
uint32_t cache_ttl
Cache time-to-live.
Definition: zrtp_types.h:163
uint8_t hash_schemes[ZRTP_MAX_COMP_COUNT+1]
Hash calculation scheme preferences.
Definition: zrtp_types.h:181
Definition: zrtp_types.h:75
Definition: zrtp_types.h:50
uint8_t sas_schemes[ZRTP_MAX_COMP_COUNT+1]
SAS calculation scheme preferences.
Definition: zrtp_types.h:166
zrtp_stream_mode_t
Enumeration for ZRTP stream mode definition.
Definition: zrtp_types.h:69
Definition: zrtp_types.h:73
Definition: zrtp_types.h:42
#define ZRTP_MAX_STREAMS_PER_SESSION
Defines maximum number of ZRTP streams within one session.
Definition: zrtp_config_user.h:78
zrtp_state_t
Defines ZRTP state-machine statesThe conditions for switching from one state to another, and libzrtp behavior in every state is described in detail in XXX and depicted in diagram XXX and XXX.
Definition: zrtp_types.h:35
Definition: zrtp_types.h:47
uint8_t allowclear
Allowclear mode flag.
Definition: zrtp_types.h:118
uint8_t pk_schemes[ZRTP_MAX_COMP_COUNT+1]
Public key exchange scheme preferences.
Definition: zrtp_types.h:172
uint8_t autosecure
ZRTP "autosecure" mode flag.
Definition: zrtp_types.h:127
Definition: zrtp_string.h:59
Definition: zrtp_types.h:52
Definition: zrtp_types.h:54
Definition: zrtp_string.h:44
Definition: zrtp_types.h:45
Definition: zrtp_types.h:51
uint8_t cipher_types[ZRTP_MAX_COMP_COUNT+1]
Cipher type preferences.
Definition: zrtp_types.h:169
Definition: zrtp_types.h:76
Definition: zrtp_types.h:55
Definition: zrtp_types.h:40
Definition: zrtp_types.h:39
Definition: zrtp_types.h:61
uint8_t discovery_optimization
Enabled Discovery Optimization.
Definition: zrtp_types.h:152
ZRTP feedback interface and application dependent routine.
Definition: zrtp_iface.h:468
libzrtp product-dependent functions
zrtp_protocol_error_t
Define protocol error codes according to ZRTP RFC sec. 5.9.
Definition: zrtp_error.h:34
Definition: zrtp_types.h:48
ZRTP session profileZRTP Sessions are configured with a profile scheme. Each profile is defined by a ...
Definition: zrtp_types.h:105
Definition: zrtp_types.h:41
uint8_t disclose_bit
Disclose bit.
Definition: zrtp_types.h:134