From a3904932bf56e1326b3b90061011a5030e5ce27d Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 19 Feb 2014 07:34:44 -0500 Subject: crypto_secretbox_NONCEBYTES is the one to use for the symmetric encryption. Not currently a big deal since they are the same size, but... --- toxav/rtp.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'toxav/rtp.c') 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) uint16_t _nonce_counter; uint8_t _reverse_bytes[2]; - _reverse_bytes[0] = nonce[crypto_box_NONCEBYTES - 1]; - _reverse_bytes[1] = nonce[crypto_box_NONCEBYTES - 2]; + _reverse_bytes[0] = nonce[crypto_secretbox_NONCEBYTES - 1]; + _reverse_bytes[1] = nonce[crypto_secretbox_NONCEBYTES - 2]; bytes_to_U16(&_nonce_counter, _reverse_bytes ); @@ -177,7 +177,8 @@ inline__ void increase_nonce(uint8_t *nonce, uint16_t target) if (_nonce_counter > UINT16_MAX - target ) { /* 2 bytes are not long enough */ uint8_t _it = 3; - while ( _it <= crypto_box_NONCEBYTES ) _it += ++nonce[crypto_box_NONCEBYTES - _it] ? crypto_box_NONCEBYTES : 1; + while ( _it <= crypto_secretbox_NONCEBYTES ) _it += ++nonce[crypto_secretbox_NONCEBYTES - _it] ? + crypto_secretbox_NONCEBYTES : 1; _nonce_counter = _nonce_counter - (UINT16_MAX - target ); /* Assign the rest of it */ } else { /* Increase nonce */ @@ -188,8 +189,8 @@ inline__ void increase_nonce(uint8_t *nonce, uint16_t target) /* Assign the last bytes */ U16_to_bytes( _reverse_bytes, _nonce_counter); - nonce [crypto_box_NONCEBYTES - 1] = _reverse_bytes[0]; - nonce [crypto_box_NONCEBYTES - 2] = _reverse_bytes[1]; + nonce [crypto_secretbox_NONCEBYTES - 1] = _reverse_bytes[0]; + nonce [crypto_secretbox_NONCEBYTES - 2] = _reverse_bytes[1]; } @@ -525,8 +526,8 @@ int rtp_handle_packet ( void *object, IP_Port ip_port, uint8_t *data, uint32_t l bytes_to_U16(&_sequnum, data + 1); /* Clculate the right nonce */ - uint8_t _calculated[crypto_box_NONCEBYTES]; - memcpy(_calculated, _session->decrypt_nonce, crypto_box_NONCEBYTES); + uint8_t _calculated[crypto_secretbox_NONCEBYTES]; + memcpy(_calculated, _session->decrypt_nonce, crypto_secretbox_NONCEBYTES); increase_nonce ( _calculated, _sequnum ); /* Decrypt message */ @@ -556,8 +557,8 @@ int rtp_handle_packet ( void *object, IP_Port ip_port, uint8_t *data, uint32_t l if ( !_decrypted_length ) return -1; /* This is just an error */ /* A new cycle setting. */ - memcpy(_session->nonce_cycle, _session->decrypt_nonce, crypto_box_NONCEBYTES); - memcpy(_session->decrypt_nonce, _calculated, crypto_box_NONCEBYTES); + memcpy(_session->nonce_cycle, _session->decrypt_nonce, crypto_secretbox_NONCEBYTES); + memcpy(_session->decrypt_nonce, _calculated, crypto_secretbox_NONCEBYTES); } } @@ -755,8 +756,8 @@ int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *dat _send_data[0] = session->prefix; /* Generate the right nonce */ - uint8_t _calculated[crypto_box_NONCEBYTES]; - memcpy(_calculated, session->encrypt_nonce, crypto_box_NONCEBYTES); + uint8_t _calculated[crypto_secretbox_NONCEBYTES]; + memcpy(_calculated, session->encrypt_nonce, crypto_secretbox_NONCEBYTES); increase_nonce ( _calculated, msg->header->sequnum ); /* 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 /* Set sequ number */ if ( session->sequnum >= MAX_SEQU_NUM ) { session->sequnum = 0; - memcpy(session->encrypt_nonce, _calculated, crypto_box_NONCEBYTES); + memcpy(session->encrypt_nonce, _calculated, crypto_secretbox_NONCEBYTES); } else { session->sequnum++; } @@ -874,16 +875,16 @@ RTPSession *rtp_init_session ( int payload_type, _retu->decrypt_key = decrypt_key; /* Need to allocate new memory */ - _retu->encrypt_nonce = calloc ( crypto_box_NONCEBYTES, sizeof (uint8_t) ); + _retu->encrypt_nonce = calloc ( crypto_secretbox_NONCEBYTES, sizeof (uint8_t) ); assert(_retu->encrypt_nonce); - _retu->decrypt_nonce = calloc ( crypto_box_NONCEBYTES, sizeof (uint8_t) ); + _retu->decrypt_nonce = calloc ( crypto_secretbox_NONCEBYTES, sizeof (uint8_t) ); assert(_retu->decrypt_nonce); - _retu->nonce_cycle = calloc ( crypto_box_NONCEBYTES, sizeof (uint8_t) ); + _retu->nonce_cycle = calloc ( crypto_secretbox_NONCEBYTES, sizeof (uint8_t) ); assert(_retu->nonce_cycle); - memcpy(_retu->encrypt_nonce, encrypt_nonce, crypto_box_NONCEBYTES); - memcpy(_retu->decrypt_nonce, decrypt_nonce, crypto_box_NONCEBYTES); - memcpy(_retu->nonce_cycle , decrypt_nonce, crypto_box_NONCEBYTES); + memcpy(_retu->encrypt_nonce, encrypt_nonce, crypto_secretbox_NONCEBYTES); + memcpy(_retu->decrypt_nonce, decrypt_nonce, crypto_secretbox_NONCEBYTES); + memcpy(_retu->nonce_cycle , decrypt_nonce, crypto_secretbox_NONCEBYTES); _retu->csrc = calloc(1, sizeof (uint32_t)); assert(_retu->csrc); -- cgit v1.2.3