00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __ZRTP_TYPES_H__
00012 #define __ZRTP_TYPES_H__
00013
00014 #include "zrtp_config.h"
00015 #include "bn.h"
00016 #include "zrtp_base.h"
00017 #include "zrtp_iface.h"
00018 #include "zrtp_list.h"
00019 #include "zrtp_legal.h"
00020 #include "zrtp_string.h"
00021 #include "zrtp_protocol.h"
00022
00023
00034 typedef enum zrtp_state_t
00035 {
00036 ZRTP_STATE_NONE = 0,
00037 ZRTP_STATE_ACTIVE,
00038 ZRTP_STATE_START,
00039 ZRTP_STATE_WAIT_HELLOACK,
00040 ZRTP_STATE_WAIT_HELLO,
00041 ZRTP_STATE_CLEAR,
00042 ZRTP_STATE_START_INITIATINGSECURE,
00043 ZRTP_STATE_INITIATINGSECURE,
00044 ZRTP_STATE_WAIT_CONFIRM1,
00045 ZRTP_STATE_WAIT_CONFIRMACK,
00046 ZRTP_STATE_PENDINGSECURE,
00047 ZRTP_STATE_WAIT_CONFIRM2,
00048 ZRTP_STATE_SECURE,
00049 ZRTP_STATE_SASRELAYING,
00050 ZRTP_STATE_INITIATINGCLEAR,
00051 ZRTP_STATE_PENDINGCLEAR,
00052 ZRTP_STATE_INITIATINGERROR,
00053 ZRTP_STATE_PENDINGERROR,
00054 ZRTP_STATE_ERROR,
00055 #if (defined(ZRTP_BUILD_FOR_CSD) && (ZRTP_BUILD_FOR_CSD == 1))
00056 ZRTP_STATE_DRIVEN_INITIATOR,
00057 ZRTP_STATE_DRIVEN_RESPONDER,
00058 ZRTP_STATE_DRIVEN_PENDING,
00059 #endif
00060 ZRTP_STATE_NO_ZRTP,
00061 ZRTP_STATE_COUNT
00062 } zrtp_state_t;
00063
00068 typedef enum zrtp_stream_mode_t
00069 {
00070 ZRTP_STREAM_MODE_UNKN = 0,
00071 ZRTP_STREAM_MODE_CLEAR = 1,
00072 ZRTP_STREAM_MODE_DH = 2,
00073 ZRTP_STREAM_MODE_PRESHARED = 3,
00074 ZRTP_STREAM_MODE_MULT = 4,
00075 ZRTP_STREAM_MODE_COUNT = 5
00076 } zrtp_stream_mode_t;
00077
00104 struct zrtp_profile_t
00105 {
00117 uint8_t allowclear;
00118
00126 uint8_t autosecure;
00127
00133 uint8_t disclose_bit;
00134
00151 uint8_t discovery_optimization;
00152
00162 uint32_t cache_ttl;
00163
00165 uint8_t sas_schemes[ZRTP_MAX_COMP_COUNT+1];
00166
00168 uint8_t cipher_types[ZRTP_MAX_COMP_COUNT+1];
00169
00171 uint8_t pk_schemes[ZRTP_MAX_COMP_COUNT+1];
00172
00174 uint8_t auth_tag_lens[ZRTP_MAX_COMP_COUNT+1];
00175
00180 uint8_t hash_schemes[ZRTP_MAX_COMP_COUNT+1];
00181 };
00182
00189 struct zrtp_shared_secret_t
00190 {
00192 zrtp_string64_t value;
00193
00199 uint32_t lastused_at;
00200
00206 uint32_t ttl;
00207
00215 uint8_t _cachedflag;
00216 };
00217
00223 typedef enum zrtp_mitm_mode_t
00224 {
00226 ZRTP_MITM_MODE_UNKN = 0,
00227
00234 ZRTP_MITM_MODE_CLIENT,
00235
00241 ZRTP_MITM_MODE_RECONFIRM_SERVER,
00247 ZRTP_MITM_MODE_RECONFIRM_CLIENT,
00254 ZRTP_MITM_MODE_REG_SERVER,
00261 ZRTP_MITM_MODE_REG_CLIENT
00262 } zrtp_mitm_mode_t;
00263
00264
00268
00269
00270
00271
00285 typedef enum
00286 {
00287 ZRTP_UNPARSED = -1,
00288 ZRTP_NONE = 0,
00289 ZRTP_HELLO = 1,
00290 ZRTP_HELLOACK = 2,
00291 ZRTP_COMMIT = 3,
00292 ZRTP_DHPART1 = 4,
00293 ZRTP_DHPART2 = 5,
00294 ZRTP_CONFIRM1 = 6,
00295 ZRTP_CONFIRM2 = 7,
00296 ZRTP_CONFIRM2ACK = 8,
00297 ZRTP_GOCLEAR = 9,
00298 ZRTP_GOCLEARACK = 10,
00299 ZRTP_ERROR = 11,
00300 ZRTP_ERRORACK = 12,
00301 ZRTP_PROCESS = 13,
00302 ZRTP_SASRELAY = 14,
00303 ZRTP_RELAYACK = 15,
00304 ZRTP_ZFONEPING = 16,
00305 ZRTP_ZFONEPINGACK = 17,
00306 ZRTP_MSG_TYPE_COUNT = 18
00307 } zrtp_msg_type_t;
00308
00309
00315 typedef enum zrtp_statemachine_type_t
00316 {
00317 ZRTP_STATEMACHINE_NONE = 0,
00318 ZRTP_STATEMACHINE_INITIATOR = 1,
00319 ZRTP_STATEMACHINE_RESPONDER = 2
00320 } zrtp_statemachine_type_t;
00321
00322 #define ZRTP_BIT_RS1 0x02
00323 #define ZRTP_BIT_RS2 0x04
00324 #define ZRTP_BIT_AUX 0x10
00325 #define ZRTP_BIT_PBX 0x20
00326
00345 struct zrtp_global_t
00346 {
00348 uint32_t lic_mode;
00349
00351 zrtp_string16_t client_id;
00352
00354 uint8_t is_mitm;
00355
00357 MD_CTX rand_ctx;
00358
00360 uint8_t rand_initialized;
00361
00362 zrtp_string128_t def_cache_path;
00363
00365 zrtp_mutex_t* rng_protector;
00366
00368 struct BigNum one;
00369 struct BigNum G;
00370 struct BigNum P_2048;
00371 struct BigNum P_2048_1;
00372 struct BigNum P_3072;
00373 struct BigNum P_3072_1;
00374 uint8_t P_2048_data[256];
00375 uint8_t P_3072_data[384];
00376
00378 mlist_t hash_head;
00379
00381 mlist_t cipher_head;
00382
00384 mlist_t atl_head;
00385
00387 mlist_t pktype_head;
00388
00390 mlist_t sas_head;
00391
00393 void* srtp_global;
00394
00396 mlist_t sessions_head;
00397
00399 uint32_t sessions_count;
00400
00402 uint32_t streams_count;
00403
00405 zrtp_mutex_t* sessions_protector;
00406
00408 zrtp_callback_t cb;
00409 };
00410
00411
00418 typedef struct zrtp_rtp_info_t
00419 {
00421 uint32_t *length;
00422
00424 char *packet;
00425
00427 void *message;
00428
00430 zrtp_msg_type_t type;
00431
00433 uint32_t seq;
00434
00436 uint32_t ssrc;
00437 } zrtp_rtp_info_t;
00438
00439
00448 typedef struct zrtp_secrets_t
00449 {
00451 zrtp_shared_secret_t *rs1;
00452
00454 zrtp_shared_secret_t *rs2;
00455
00457 zrtp_shared_secret_t *auxs;
00458
00460 zrtp_shared_secret_t *pbxs;
00461
00463 uint32_t cached;
00464 uint32_t cached_curr;
00465
00467 uint32_t matches;
00468 uint32_t matches_curr;
00469
00471 uint32_t wrongs;
00472 uint32_t wrongs_curr;
00473
00475 uint8_t is_ready;
00476 } zrtp_secrets_t;
00477
00478
00484 typedef struct zrtp_proto_secret_t
00485 {
00487 zrtp_string8_t id;
00488
00490 zrtp_string8_t peer_id;
00491
00493 zrtp_shared_secret_t *secret;
00494 } zrtp_proto_secret_t;
00495
00496
00504 typedef struct zrtp_stream_mescache_t
00505 {
00506 zrtp_packet_Hello_t peer_hello;
00507 zrtp_packet_Hello_t hello;
00508 zrtp_packet_GoClear_t goclear;
00509 zrtp_packet_Commit_t peer_commit;
00510 zrtp_packet_Commit_t commit;
00511 zrtp_packet_DHPart_t peer_dhpart;
00512 zrtp_packet_DHPart_t dhpart;
00513 zrtp_packet_Confirm_t confirm;
00514 zrtp_string32_t h0;
00515 zrtp_packet_Confirm_t peer_confirm;
00516 zrtp_packet_Error_t error;
00517 zrtp_packet_SASRelay_t sasrelay;
00518
00519 zrtp_retry_task_t hello_task;
00520 zrtp_retry_task_t goclear_task;
00521 zrtp_retry_task_t dh_task;
00522 zrtp_retry_task_t commit_task;
00523 zrtp_retry_task_t dhpart_task;
00524 zrtp_retry_task_t confirm_task;
00525 zrtp_retry_task_t error_task;
00526 zrtp_retry_task_t errorack_task;
00527 zrtp_retry_task_t sasrelay_task;
00528
00529 zrtp_string16_t signaling_hash;
00530 } zrtp_stream_mescache_t;
00531
00532
00538 typedef struct zrtp_dh_crypto_context_t
00539 {
00541 struct BigNum sv;
00542
00544 struct BigNum pv;
00545
00547 struct BigNum peer_pv;
00548
00550 zrtp_string64_t dhss;
00551
00552 unsigned int initialized_with;
00553 } zrtp_dh_crypto_context_t;
00554
00555
00561 typedef struct zrtp_dsa_crypto_context_t
00562 {
00563 struct BigNum sv;
00564 struct BigNum pv;
00565 struct BigNum peer_pv;
00566 } zrtp_dsa_crypto_context_t;
00567
00568
00575 typedef struct zrtp_proto_crypto_t
00576 {
00578 zrtp_string128_t kdf_context;
00579
00581 zrtp_string64_t s0;
00582
00584 zrtp_string64_t hv;
00585
00587 zrtp_string64_t peer_hv;
00588
00590 zrtp_string64_t mes_hash;
00591
00593 zrtp_proto_secret_t rs1;
00594
00596 zrtp_proto_secret_t rs2;
00597
00599 zrtp_proto_secret_t auxs;
00600
00602 zrtp_proto_secret_t pbxs;
00603 } zrtp_proto_crypto_t;
00604
00611 struct zrtp_protocol_t
00612 {
00614 zrtp_statemachine_type_t type;
00615
00617 zrtp_proto_crypto_t* cc;
00618
00620 zrtp_srtp_ctx_t* _srtp;
00621
00623 zrtp_stream_t *context;
00624 };
00625
00631 typedef struct zrtp_stream_crypto_t
00632 {
00634 zrtp_string64_t hmackey;
00635
00637 zrtp_string64_t peer_hmackey;
00638
00640 zrtp_string64_t zrtp_key;
00641
00643 zrtp_string64_t peer_zrtp_key;
00644 } zrtp_stream_crypto_t;
00645
00646
00650 typedef struct zrtp_media_context_t
00651 {
00653 uint32_t high_in_zrtp_seq;
00654
00656 uint32_t high_out_zrtp_seq;
00657
00659 uint32_t high_in_media_seq;
00660
00662 uint32_t high_out_media_seq;
00663
00665 uint32_t ssrc;
00666 } zrtp_media_context_t;
00667
00672 struct zrtp_stream_t
00673 {
00675 zrtp_id_t id;
00676
00684 zrtp_stream_mode_t mode;
00685
00692 zrtp_mitm_mode_t mitm_mode;
00693
00699 zrtp_state_t prev_state;
00700
00702 zrtp_state_t state;
00703
00709 zrtp_stream_crypto_t cc;
00710
00712 zrtp_dh_crypto_context_t dh_cc;
00713
00720 zrtp_protocol_t *protocol;
00721
00727 zrtp_string128_t signaling_hash;
00728
00730 zrtp_media_context_t media_ctx;
00731
00733 zrtp_stream_mescache_t messages;
00734
00739 uint8_t allowclear;
00740
00745 uint8_t peer_passive;
00746
00756 uint32_t cache_ttl;
00757
00764 uint8_t peer_disclose_bit;
00765
00773 zrtp_protocol_error_t last_error;
00774
00778 uint8_t peer_mitm_flag;
00779
00791 zrtp_stream_t *concurrent;
00792
00794 zrtp_global_t *zrtp;
00795
00797 zrtp_session_t *session;
00798
00800 zrtp_pk_scheme_t *pubkeyscheme;
00801
00806 void *usr_data;
00807
00814 zrtp_mutex_t* stream_protector;
00815 };
00816
00817
00823 struct zrtp_session_t
00824 {
00826 zrtp_id_t id;
00827
00835 zrtp_string16_t zid;
00836
00844 zrtp_string16_t peer_zid;
00845
00847 zrtp_profile_t profile;
00848
00850 uint8_t is_initiator;
00851
00857 zrtp_secrets_t secrets;
00858
00860 zrtp_string64_t zrtpsess;
00861
00863 zrtp_string16_t sas1;
00864
00866 zrtp_string16_t sas2;
00867
00869 zrtp_string32_t sasbin;
00870
00872 zrtp_global_t *zrtp;
00873
00875 void *usr_data;
00876
00878 zrtp_hash_t *hash;
00879
00881 zrtp_cipher_t *blockcipher;
00882
00884 zrtp_auth_tag_length_t *authtaglength;
00885
00887 zrtp_sas_scheme_t *sasscheme;
00888
00890 zrtp_stream_t streams[ZRTP_MAX_STREAMS_PER_SESSION];
00891
00893 zrtp_mutex_t* streams_protector;
00894
00896 zrtp_mutex_t* init_protector;
00897
00901 uint8_t mitm_alert_detected;
00902
00903 mlist_t _mlist;
00904 };
00905
00909
00910
00911
00912
00913 #if ZRTP_BYTE_ORDER == ZBO_LITTLE_ENDIAN
00914
00919 typedef struct
00920 {
00921 uint16_t cc:4;
00922 uint16_t x:1;
00923 uint16_t p:1;
00924 uint16_t version:2;
00925 uint16_t pt:7;
00926 uint16_t m:1;
00927 uint16_t seq;
00928 uint32_t ts;
00929 uint32_t ssrc;
00930 } zrtp_rtp_hdr_t;
00931
00936 typedef struct
00937 {
00938 unsigned char rc:5;
00939 unsigned char p:1;
00940 unsigned char version:2;
00941 unsigned char pt:8;
00942 uint16_t len;
00943 uint32_t ssrc;
00944 } zrtp_rtcp_hdr_t;
00945
00946 typedef struct
00947 {
00948 unsigned int index:31;
00949 unsigned int e:1;
00952 } zrtp_rtcp_trailer_t;
00953
00954 #else
00955
00960 typedef struct
00961 {
00962 uint16_t version:2;
00963 uint16_t p:1;
00964 uint16_t x:1;
00965 uint16_t cc:4;
00966 uint16_t m:1;
00967 uint16_t pt:7;
00968 uint16_t seq;
00969 uint32_t ts;
00970 uint32_t ssrc;
00971 } zrtp_rtp_hdr_t;
00972
00977 typedef struct
00978 {
00979 unsigned char version:2;
00980 unsigned char p:1;
00981 unsigned char rc:5;
00982 unsigned char pt:8;
00983 uint16_t len;
00984 uint32_t ssrc;
00985 } zrtp_rtcp_hdr_t;
00986
00987 typedef struct
00988 {
00989 unsigned int e:1;
00990 unsigned int index:31;
00991 } zrtp_rtcp_trailer_t;
00992
00993 #endif
00994
00999 typedef struct
01000 {
01001 uint16_t profile_specific;
01002 uint16_t length;
01003 } zrtp_rtp_hdr_xtnd_t;
01004
01005
01008 #endif