diff options
Diffstat (limited to 'toxav/rtp.c')
-rw-r--r-- | toxav/rtp.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/toxav/rtp.c b/toxav/rtp.c index dbaecbb6..8eca46d4 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c | |||
@@ -168,8 +168,8 @@ inline__ void increase_nonce(uint8_t *nonce, uint16_t target) | |||
168 | uint16_t _nonce_counter; | 168 | uint16_t _nonce_counter; |
169 | 169 | ||
170 | uint8_t _reverse_bytes[2]; | 170 | uint8_t _reverse_bytes[2]; |
171 | _reverse_bytes[0] = nonce[crypto_box_NONCEBYTES - 1]; | 171 | _reverse_bytes[0] = nonce[crypto_secretbox_NONCEBYTES - 1]; |
172 | _reverse_bytes[1] = nonce[crypto_box_NONCEBYTES - 2]; | 172 | _reverse_bytes[1] = nonce[crypto_secretbox_NONCEBYTES - 2]; |
173 | 173 | ||
174 | bytes_to_U16(&_nonce_counter, _reverse_bytes ); | 174 | bytes_to_U16(&_nonce_counter, _reverse_bytes ); |
175 | 175 | ||
@@ -177,7 +177,8 @@ inline__ void increase_nonce(uint8_t *nonce, uint16_t target) | |||
177 | if (_nonce_counter > UINT16_MAX - target ) { /* 2 bytes are not long enough */ | 177 | if (_nonce_counter > UINT16_MAX - target ) { /* 2 bytes are not long enough */ |
178 | uint8_t _it = 3; | 178 | uint8_t _it = 3; |
179 | 179 | ||
180 | while ( _it <= crypto_box_NONCEBYTES ) _it += ++nonce[crypto_box_NONCEBYTES - _it] ? crypto_box_NONCEBYTES : 1; | 180 | while ( _it <= crypto_secretbox_NONCEBYTES ) _it += ++nonce[crypto_secretbox_NONCEBYTES - _it] ? |
181 | crypto_secretbox_NONCEBYTES : 1; | ||
181 | 182 | ||
182 | _nonce_counter = _nonce_counter - (UINT16_MAX - target ); /* Assign the rest of it */ | 183 | _nonce_counter = _nonce_counter - (UINT16_MAX - target ); /* Assign the rest of it */ |
183 | } else { /* Increase nonce */ | 184 | } else { /* Increase nonce */ |
@@ -188,8 +189,8 @@ inline__ void increase_nonce(uint8_t *nonce, uint16_t target) | |||
188 | /* Assign the last bytes */ | 189 | /* Assign the last bytes */ |
189 | 190 | ||
190 | U16_to_bytes( _reverse_bytes, _nonce_counter); | 191 | U16_to_bytes( _reverse_bytes, _nonce_counter); |
191 | nonce [crypto_box_NONCEBYTES - 1] = _reverse_bytes[0]; | 192 | nonce [crypto_secretbox_NONCEBYTES - 1] = _reverse_bytes[0]; |
192 | nonce [crypto_box_NONCEBYTES - 2] = _reverse_bytes[1]; | 193 | nonce [crypto_secretbox_NONCEBYTES - 2] = _reverse_bytes[1]; |
193 | 194 | ||
194 | } | 195 | } |
195 | 196 | ||
@@ -516,7 +517,7 @@ int rtp_handle_packet ( void *object, IP_Port ip_port, uint8_t *data, uint32_t l | |||
516 | RTPSession *_session = object; | 517 | RTPSession *_session = object; |
517 | RTPMessage *_msg; | 518 | RTPMessage *_msg; |
518 | 519 | ||
519 | if ( !_session || length < 13 ) /* 12 is the minimum length for rtp + desc. byte */ | 520 | if ( !_session || length < 13 + crypto_secretbox_MACBYTES) /* 12 is the minimum length for rtp + desc. byte */ |
520 | return -1; | 521 | return -1; |
521 | 522 | ||
522 | uint8_t _plain[MAX_UDP_PACKET_SIZE]; | 523 | uint8_t _plain[MAX_UDP_PACKET_SIZE]; |
@@ -525,8 +526,8 @@ int rtp_handle_packet ( void *object, IP_Port ip_port, uint8_t *data, uint32_t l | |||
525 | bytes_to_U16(&_sequnum, data + 1); | 526 | bytes_to_U16(&_sequnum, data + 1); |
526 | 527 | ||
527 | /* Clculate the right nonce */ | 528 | /* Clculate the right nonce */ |
528 | uint8_t _calculated[crypto_box_NONCEBYTES]; | 529 | uint8_t _calculated[crypto_secretbox_NONCEBYTES]; |
529 | memcpy(_calculated, _session->decrypt_nonce, crypto_box_NONCEBYTES); | 530 | memcpy(_calculated, _session->decrypt_nonce, crypto_secretbox_NONCEBYTES); |
530 | increase_nonce ( _calculated, _sequnum ); | 531 | increase_nonce ( _calculated, _sequnum ); |
531 | 532 | ||
532 | /* Decrypt message */ | 533 | /* Decrypt message */ |
@@ -556,8 +557,8 @@ int rtp_handle_packet ( void *object, IP_Port ip_port, uint8_t *data, uint32_t l | |||
556 | if ( !_decrypted_length ) return -1; /* This is just an error */ | 557 | if ( !_decrypted_length ) return -1; /* This is just an error */ |
557 | 558 | ||
558 | /* A new cycle setting. */ | 559 | /* A new cycle setting. */ |
559 | memcpy(_session->nonce_cycle, _session->decrypt_nonce, crypto_box_NONCEBYTES); | 560 | memcpy(_session->nonce_cycle, _session->decrypt_nonce, crypto_secretbox_NONCEBYTES); |
560 | memcpy(_session->decrypt_nonce, _calculated, crypto_box_NONCEBYTES); | 561 | memcpy(_session->decrypt_nonce, _calculated, crypto_secretbox_NONCEBYTES); |
561 | } | 562 | } |
562 | } | 563 | } |
563 | 564 | ||
@@ -755,8 +756,8 @@ int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *dat | |||
755 | _send_data[0] = session->prefix; | 756 | _send_data[0] = session->prefix; |
756 | 757 | ||
757 | /* Generate the right nonce */ | 758 | /* Generate the right nonce */ |
758 | uint8_t _calculated[crypto_box_NONCEBYTES]; | 759 | uint8_t _calculated[crypto_secretbox_NONCEBYTES]; |
759 | memcpy(_calculated, session->encrypt_nonce, crypto_box_NONCEBYTES); | 760 | memcpy(_calculated, session->encrypt_nonce, crypto_secretbox_NONCEBYTES); |
760 | increase_nonce ( _calculated, msg->header->sequnum ); | 761 | increase_nonce ( _calculated, msg->header->sequnum ); |
761 | 762 | ||
762 | /* Need to skip 2 bytes that are for sequnum */ | 763 | /* Need to skip 2 bytes that are for sequnum */ |
@@ -779,7 +780,7 @@ int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *dat | |||
779 | /* Set sequ number */ | 780 | /* Set sequ number */ |
780 | if ( session->sequnum >= MAX_SEQU_NUM ) { | 781 | if ( session->sequnum >= MAX_SEQU_NUM ) { |
781 | session->sequnum = 0; | 782 | session->sequnum = 0; |
782 | memcpy(session->encrypt_nonce, _calculated, crypto_box_NONCEBYTES); | 783 | memcpy(session->encrypt_nonce, _calculated, crypto_secretbox_NONCEBYTES); |
783 | } else { | 784 | } else { |
784 | session->sequnum++; | 785 | session->sequnum++; |
785 | } | 786 | } |
@@ -874,16 +875,16 @@ RTPSession *rtp_init_session ( int payload_type, | |||
874 | _retu->decrypt_key = decrypt_key; | 875 | _retu->decrypt_key = decrypt_key; |
875 | 876 | ||
876 | /* Need to allocate new memory */ | 877 | /* Need to allocate new memory */ |
877 | _retu->encrypt_nonce = calloc ( crypto_box_NONCEBYTES, sizeof (uint8_t) ); | 878 | _retu->encrypt_nonce = calloc ( crypto_secretbox_NONCEBYTES, sizeof (uint8_t) ); |
878 | assert(_retu->encrypt_nonce); | 879 | assert(_retu->encrypt_nonce); |
879 | _retu->decrypt_nonce = calloc ( crypto_box_NONCEBYTES, sizeof (uint8_t) ); | 880 | _retu->decrypt_nonce = calloc ( crypto_secretbox_NONCEBYTES, sizeof (uint8_t) ); |
880 | assert(_retu->decrypt_nonce); | 881 | assert(_retu->decrypt_nonce); |
881 | _retu->nonce_cycle = calloc ( crypto_box_NONCEBYTES, sizeof (uint8_t) ); | 882 | _retu->nonce_cycle = calloc ( crypto_secretbox_NONCEBYTES, sizeof (uint8_t) ); |
882 | assert(_retu->nonce_cycle); | 883 | assert(_retu->nonce_cycle); |
883 | 884 | ||
884 | memcpy(_retu->encrypt_nonce, encrypt_nonce, crypto_box_NONCEBYTES); | 885 | memcpy(_retu->encrypt_nonce, encrypt_nonce, crypto_secretbox_NONCEBYTES); |
885 | memcpy(_retu->decrypt_nonce, decrypt_nonce, crypto_box_NONCEBYTES); | 886 | memcpy(_retu->decrypt_nonce, decrypt_nonce, crypto_secretbox_NONCEBYTES); |
886 | memcpy(_retu->nonce_cycle , decrypt_nonce, crypto_box_NONCEBYTES); | 887 | memcpy(_retu->nonce_cycle , decrypt_nonce, crypto_secretbox_NONCEBYTES); |
887 | 888 | ||
888 | _retu->csrc = calloc(1, sizeof (uint32_t)); | 889 | _retu->csrc = calloc(1, sizeof (uint32_t)); |
889 | assert(_retu->csrc); | 890 | assert(_retu->csrc); |