diff options
author | mannol <eniz_vukovic@hotmail.com> | 2014-05-20 00:10:40 +0200 |
---|---|---|
committer | mannol <eniz_vukovic@hotmail.com> | 2014-05-20 00:10:40 +0200 |
commit | a1f2a18ae4146ebea11fbd3f83df803b715813da (patch) | |
tree | 63b29cf3770a65e94e3e5d0fcd53b33f2a654585 /toxav/rtp.c | |
parent | ea96c1758ae42c59978c450f9e11496a55d49ee5 (diff) |
Merge upstream and other stuff
Diffstat (limited to 'toxav/rtp.c')
-rwxr-xr-x | toxav/rtp.c | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/toxav/rtp.c b/toxav/rtp.c index 8b2768f1..cdaabd3a 100755 --- a/toxav/rtp.c +++ b/toxav/rtp.c | |||
@@ -170,8 +170,8 @@ inline__ void increase_nonce(uint8_t *nonce, uint16_t target) | |||
170 | uint16_t _nonce_counter; | 170 | uint16_t _nonce_counter; |
171 | 171 | ||
172 | uint8_t _reverse_bytes[2]; | 172 | uint8_t _reverse_bytes[2]; |
173 | _reverse_bytes[0] = nonce[crypto_secretbox_NONCEBYTES - 1]; | 173 | _reverse_bytes[0] = nonce[crypto_box_NONCEBYTES - 1]; |
174 | _reverse_bytes[1] = nonce[crypto_secretbox_NONCEBYTES - 2]; | 174 | _reverse_bytes[1] = nonce[crypto_box_NONCEBYTES - 2]; |
175 | 175 | ||
176 | bytes_to_U16(&_nonce_counter, _reverse_bytes ); | 176 | bytes_to_U16(&_nonce_counter, _reverse_bytes ); |
177 | 177 | ||
@@ -179,8 +179,8 @@ inline__ void increase_nonce(uint8_t *nonce, uint16_t target) | |||
179 | if (_nonce_counter > UINT16_MAX - target ) { /* 2 bytes are not long enough */ | 179 | if (_nonce_counter > UINT16_MAX - target ) { /* 2 bytes are not long enough */ |
180 | uint8_t _it = 3; | 180 | uint8_t _it = 3; |
181 | 181 | ||
182 | while ( _it <= crypto_secretbox_NONCEBYTES ) _it += ++nonce[crypto_secretbox_NONCEBYTES - _it] ? | 182 | while ( _it <= crypto_box_NONCEBYTES ) _it += ++nonce[crypto_box_NONCEBYTES - _it] ? |
183 | crypto_secretbox_NONCEBYTES : 1; | 183 | crypto_box_NONCEBYTES : 1; |
184 | 184 | ||
185 | _nonce_counter = _nonce_counter - (UINT16_MAX - target ); /* Assign the rest of it */ | 185 | _nonce_counter = _nonce_counter - (UINT16_MAX - target ); /* Assign the rest of it */ |
186 | } else { /* Increase nonce */ | 186 | } else { /* Increase nonce */ |
@@ -191,8 +191,8 @@ inline__ void increase_nonce(uint8_t *nonce, uint16_t target) | |||
191 | /* Assign the last bytes */ | 191 | /* Assign the last bytes */ |
192 | 192 | ||
193 | U16_to_bytes( _reverse_bytes, _nonce_counter); | 193 | U16_to_bytes( _reverse_bytes, _nonce_counter); |
194 | nonce [crypto_secretbox_NONCEBYTES - 1] = _reverse_bytes[0]; | 194 | nonce [crypto_box_NONCEBYTES - 1] = _reverse_bytes[0]; |
195 | nonce [crypto_secretbox_NONCEBYTES - 2] = _reverse_bytes[1]; | 195 | nonce [crypto_box_NONCEBYTES - 2] = _reverse_bytes[1]; |
196 | 196 | ||
197 | } | 197 | } |
198 | 198 | ||
@@ -416,7 +416,7 @@ RTPHeader *build_header ( RTPSession *session ) | |||
416 | ADD_SETTING_PAYLOAD ( _retu, session->payload_type ); | 416 | ADD_SETTING_PAYLOAD ( _retu, session->payload_type ); |
417 | 417 | ||
418 | _retu->sequnum = session->sequnum; | 418 | _retu->sequnum = session->sequnum; |
419 | _retu->timestamp = ((uint32_t)(current_time() / 1000)); /* micro to milli */ | 419 | _retu->timestamp = current_time_monotonic(); /* milliseconds */ |
420 | _retu->ssrc = session->ssrc; | 420 | _retu->ssrc = session->ssrc; |
421 | 421 | ||
422 | int i; | 422 | int i; |
@@ -505,7 +505,7 @@ int rtp_handle_packet ( void *object, IP_Port ip_port, uint8_t *data, uint32_t l | |||
505 | RTPSession *_session = object; | 505 | RTPSession *_session = object; |
506 | RTPMessage *_msg; | 506 | RTPMessage *_msg; |
507 | 507 | ||
508 | if ( !_session || length < 13 + crypto_secretbox_MACBYTES) { /* 12 is the minimum length for rtp + desc. byte */ | 508 | if ( !_session || length < 13 + crypto_box_MACBYTES) { /* 12 is the minimum length for rtp + desc. byte */ |
509 | LOGGER_WARNING("No session or invalid length of received buffer!"); | 509 | LOGGER_WARNING("No session or invalid length of received buffer!"); |
510 | return -1; | 510 | return -1; |
511 | } | 511 | } |
@@ -521,12 +521,13 @@ int rtp_handle_packet ( void *object, IP_Port ip_port, uint8_t *data, uint32_t l | |||
521 | bytes_to_U16(&_sequnum, data + 1); | 521 | bytes_to_U16(&_sequnum, data + 1); |
522 | 522 | ||
523 | /* Clculate the right nonce */ | 523 | /* Clculate the right nonce */ |
524 | uint8_t _calculated[crypto_secretbox_NONCEBYTES]; | 524 | uint8_t _calculated[crypto_box_NONCEBYTES]; |
525 | memcpy(_calculated, _session->decrypt_nonce, crypto_secretbox_NONCEBYTES); | 525 | memcpy(_calculated, _session->decrypt_nonce, crypto_box_NONCEBYTES); |
526 | increase_nonce ( _calculated, _sequnum ); | 526 | increase_nonce ( _calculated, _sequnum ); |
527 | 527 | ||
528 | /* Decrypt message */ | 528 | /* Decrypt message */ |
529 | int _decrypted_length = decrypt_data_symmetric((uint8_t *)_session->decrypt_key, _calculated, data + 3, length - 3, _plain ); | 529 | int _decrypted_length = decrypt_data_symmetric( |
530 | (uint8_t *)_session->decrypt_key, _calculated, data + 3, length - 3, _plain ); | ||
530 | 531 | ||
531 | /* This packet is either not encrypted properly or late | 532 | /* This packet is either not encrypted properly or late |
532 | */ | 533 | */ |
@@ -557,8 +558,8 @@ int rtp_handle_packet ( void *object, IP_Port ip_port, uint8_t *data, uint32_t l | |||
557 | } | 558 | } |
558 | 559 | ||
559 | /* A new cycle setting. */ | 560 | /* A new cycle setting. */ |
560 | memcpy(_session->nonce_cycle, _session->decrypt_nonce, crypto_secretbox_NONCEBYTES); | 561 | memcpy(_session->nonce_cycle, _session->decrypt_nonce, crypto_box_NONCEBYTES); |
561 | memcpy(_session->decrypt_nonce, _calculated, crypto_secretbox_NONCEBYTES); | 562 | memcpy(_session->decrypt_nonce, _calculated, crypto_box_NONCEBYTES); |
562 | } | 563 | } |
563 | } | 564 | } |
564 | 565 | ||
@@ -774,8 +775,8 @@ int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *dat | |||
774 | _send_data[0] = session->prefix; | 775 | _send_data[0] = session->prefix; |
775 | 776 | ||
776 | /* Generate the right nonce */ | 777 | /* Generate the right nonce */ |
777 | uint8_t _calculated[crypto_secretbox_NONCEBYTES]; | 778 | uint8_t _calculated[crypto_box_NONCEBYTES]; |
778 | memcpy(_calculated, session->encrypt_nonce, crypto_secretbox_NONCEBYTES); | 779 | memcpy(_calculated, session->encrypt_nonce, crypto_box_NONCEBYTES); |
779 | increase_nonce ( _calculated, msg->header->sequnum ); | 780 | increase_nonce ( _calculated, msg->header->sequnum ); |
780 | 781 | ||
781 | /* Need to skip 2 bytes that are for sequnum */ | 782 | /* Need to skip 2 bytes that are for sequnum */ |
@@ -798,7 +799,7 @@ int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *dat | |||
798 | /* Set sequ number */ | 799 | /* Set sequ number */ |
799 | if ( session->sequnum >= MAX_SEQU_NUM ) { | 800 | if ( session->sequnum >= MAX_SEQU_NUM ) { |
800 | session->sequnum = 0; | 801 | session->sequnum = 0; |
801 | memcpy(session->encrypt_nonce, _calculated, crypto_secretbox_NONCEBYTES); | 802 | memcpy(session->encrypt_nonce, _calculated, crypto_box_NONCEBYTES); |
802 | } else { | 803 | } else { |
803 | session->sequnum++; | 804 | session->sequnum++; |
804 | } | 805 | } |
@@ -888,16 +889,16 @@ RTPSession *rtp_init_session ( int payload_type, | |||
888 | _retu->decrypt_key = decrypt_key; | 889 | _retu->decrypt_key = decrypt_key; |
889 | 890 | ||
890 | /* Need to allocate new memory */ | 891 | /* Need to allocate new memory */ |
891 | _retu->encrypt_nonce = calloc ( crypto_secretbox_NONCEBYTES, sizeof (uint8_t) ); | 892 | _retu->encrypt_nonce = calloc ( crypto_box_NONCEBYTES, sizeof (uint8_t) ); |
892 | assert(_retu->encrypt_nonce); | 893 | assert(_retu->encrypt_nonce); |
893 | _retu->decrypt_nonce = calloc ( crypto_secretbox_NONCEBYTES, sizeof (uint8_t) ); | 894 | _retu->decrypt_nonce = calloc ( crypto_box_NONCEBYTES, sizeof (uint8_t) ); |
894 | assert(_retu->decrypt_nonce); | 895 | assert(_retu->decrypt_nonce); |
895 | _retu->nonce_cycle = calloc ( crypto_secretbox_NONCEBYTES, sizeof (uint8_t) ); | 896 | _retu->nonce_cycle = calloc ( crypto_box_NONCEBYTES, sizeof (uint8_t) ); |
896 | assert(_retu->nonce_cycle); | 897 | assert(_retu->nonce_cycle); |
897 | 898 | ||
898 | memcpy(_retu->encrypt_nonce, encrypt_nonce, crypto_secretbox_NONCEBYTES); | 899 | memcpy(_retu->encrypt_nonce, encrypt_nonce, crypto_box_NONCEBYTES); |
899 | memcpy(_retu->decrypt_nonce, decrypt_nonce, crypto_secretbox_NONCEBYTES); | 900 | memcpy(_retu->decrypt_nonce, decrypt_nonce, crypto_box_NONCEBYTES); |
900 | memcpy(_retu->nonce_cycle , decrypt_nonce, crypto_secretbox_NONCEBYTES); | 901 | memcpy(_retu->nonce_cycle , decrypt_nonce, crypto_box_NONCEBYTES); |
901 | 902 | ||
902 | _retu->csrc = calloc(1, sizeof (uint32_t)); | 903 | _retu->csrc = calloc(1, sizeof (uint32_t)); |
903 | assert(_retu->csrc); | 904 | assert(_retu->csrc); |