summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-02-19 07:34:44 -0500
committerirungentoo <irungentoo@gmail.com>2014-02-19 07:34:44 -0500
commita3904932bf56e1326b3b90061011a5030e5ce27d (patch)
treee7de6be10b9f891a0352399ac30cb70c377b6cb9
parent80d5aaa98e49aa0245cd4681acbfae80c7a01dc2 (diff)
crypto_secretbox_NONCEBYTES is the one to use for the symmetric encryption.
Not currently a big deal since they are the same size, but...
-rw-r--r--toxav/msi.c16
-rw-r--r--toxav/rtp.c37
2 files changed, 27 insertions, 26 deletions
diff --git a/toxav/msi.c b/toxav/msi.c
index 8f69d942..6cc9cf12 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -893,8 +893,8 @@ int handle_recv_start ( MSISession *session, MSIMessage *msg )
893 session->call->key_peer = calloc ( sizeof ( uint8_t ), crypto_secretbox_KEYBYTES ); 893 session->call->key_peer = calloc ( sizeof ( uint8_t ), crypto_secretbox_KEYBYTES );
894 memcpy ( session->call->key_peer, msg->cryptokey.header_value, crypto_secretbox_KEYBYTES ); 894 memcpy ( session->call->key_peer, msg->cryptokey.header_value, crypto_secretbox_KEYBYTES );
895 895
896 session->call->nonce_peer = calloc ( sizeof ( uint8_t ), crypto_box_NONCEBYTES ); 896 session->call->nonce_peer = calloc ( sizeof ( uint8_t ), crypto_secretbox_NONCEBYTES );
897 memcpy ( session->call->nonce_peer, msg->nonce.header_value, crypto_box_NONCEBYTES ); 897 memcpy ( session->call->nonce_peer, msg->nonce.header_value, crypto_secretbox_NONCEBYTES );
898 898
899 flush_peer_type ( session, msg, 0 ); 899 flush_peer_type ( session, msg, 0 );
900 900
@@ -981,21 +981,21 @@ int handle_recv_starting ( MSISession *session, MSIMessage *msg )
981 session->call->key_local = calloc ( sizeof ( uint8_t ), crypto_secretbox_KEYBYTES ); 981 session->call->key_local = calloc ( sizeof ( uint8_t ), crypto_secretbox_KEYBYTES );
982 new_symmetric_key ( session->call->key_local ); 982 new_symmetric_key ( session->call->key_local );
983 983
984 session->call->nonce_local = calloc ( sizeof ( uint8_t ), crypto_box_NONCEBYTES ); 984 session->call->nonce_local = calloc ( sizeof ( uint8_t ), crypto_secretbox_NONCEBYTES );
985 new_nonce ( session->call->nonce_local ); 985 new_nonce ( session->call->nonce_local );
986 986
987 /* Save peer key/nonce */ 987 /* Save peer key/nonce */
988 session->call->key_peer = calloc ( sizeof ( uint8_t ), crypto_secretbox_KEYBYTES ); 988 session->call->key_peer = calloc ( sizeof ( uint8_t ), crypto_secretbox_KEYBYTES );
989 memcpy ( session->call->key_peer, msg->cryptokey.header_value, crypto_secretbox_KEYBYTES ); 989 memcpy ( session->call->key_peer, msg->cryptokey.header_value, crypto_secretbox_KEYBYTES );
990 990
991 session->call->nonce_peer = calloc ( sizeof ( uint8_t ), crypto_box_NONCEBYTES ); 991 session->call->nonce_peer = calloc ( sizeof ( uint8_t ), crypto_secretbox_NONCEBYTES );
992 memcpy ( session->call->nonce_peer, msg->nonce.header_value, crypto_box_NONCEBYTES ); 992 memcpy ( session->call->nonce_peer, msg->nonce.header_value, crypto_secretbox_NONCEBYTES );
993 993
994 session->call->state = call_active; 994 session->call->state = call_active;
995 995
996 MSIMessage *_msg_start = msi_new_message ( TYPE_REQUEST, stringify_request ( start ) ); 996 MSIMessage *_msg_start = msi_new_message ( TYPE_REQUEST, stringify_request ( start ) );
997 msi_msg_set_cryptokey ( _msg_start, session->call->key_local, crypto_secretbox_KEYBYTES ); 997 msi_msg_set_cryptokey ( _msg_start, session->call->key_local, crypto_secretbox_KEYBYTES );
998 msi_msg_set_nonce ( _msg_start, session->call->nonce_local, crypto_box_NONCEBYTES ); 998 msi_msg_set_nonce ( _msg_start, session->call->nonce_local, crypto_secretbox_NONCEBYTES );
999 send_message ( session, _msg_start, msg->friend_id ); 999 send_message ( session, _msg_start, msg->friend_id );
1000 free_message ( _msg_start ); 1000 free_message ( _msg_start );
1001 1001
@@ -1341,11 +1341,11 @@ int msi_answer ( MSISession *session, MSICallType call_type )
1341 session->call->key_local = calloc ( sizeof ( uint8_t ), crypto_secretbox_KEYBYTES ); 1341 session->call->key_local = calloc ( sizeof ( uint8_t ), crypto_secretbox_KEYBYTES );
1342 new_symmetric_key ( session->call->key_local ); 1342 new_symmetric_key ( session->call->key_local );
1343 1343
1344 session->call->nonce_local = calloc ( sizeof ( uint8_t ), crypto_box_NONCEBYTES ); 1344 session->call->nonce_local = calloc ( sizeof ( uint8_t ), crypto_secretbox_NONCEBYTES );
1345 new_nonce ( session->call->nonce_local ); 1345 new_nonce ( session->call->nonce_local );
1346 1346
1347 msi_msg_set_cryptokey ( _msg_starting, session->call->key_local, crypto_secretbox_KEYBYTES ); 1347 msi_msg_set_cryptokey ( _msg_starting, session->call->key_local, crypto_secretbox_KEYBYTES );
1348 msi_msg_set_nonce ( _msg_starting, session->call->nonce_local, crypto_box_NONCEBYTES ); 1348 msi_msg_set_nonce ( _msg_starting, session->call->nonce_local, crypto_secretbox_NONCEBYTES );
1349 1349
1350 send_message ( session, _msg_starting, session->call->peers[session->call->peer_count - 1] ); 1350 send_message ( session, _msg_starting, session->call->peers[session->call->peer_count - 1] );
1351 free_message ( _msg_starting ); 1351 free_message ( _msg_starting );
diff --git a/toxav/rtp.c b/toxav/rtp.c
index dbaecbb6..8f6f0be7 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
@@ -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);