mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added data packet padding to toxcore.
Data sent as lossless or lossy is now padded with: ((MAX_CRYPTO_DATA_SIZE - data_length) % CRYPTO_MAX_PADDING) bytes in order to reduce the possibility of length related attacks. I set CRYPTO_MAX_PADDING to 8 but it can be changed anytime without breaking network compatibility between tox cores.
This commit is contained in:
parent
de5a33e852
commit
b44b58cae4
@ -752,12 +752,17 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, uint8_t *dat
|
||||
static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint32_t buffer_start, uint32_t num,
|
||||
uint8_t *data, uint32_t length)
|
||||
{
|
||||
if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
|
||||
return -1;
|
||||
|
||||
num = htonl(num);
|
||||
buffer_start = htonl(buffer_start);
|
||||
uint8_t packet[sizeof(uint32_t) + sizeof(uint32_t) + length];
|
||||
uint16_t padding_length = (MAX_CRYPTO_DATA_SIZE - length) % CRYPTO_MAX_PADDING;
|
||||
uint8_t packet[sizeof(uint32_t) + sizeof(uint32_t) + padding_length + length];
|
||||
memcpy(packet, &buffer_start, sizeof(uint32_t));
|
||||
memcpy(packet + sizeof(uint32_t), &num, sizeof(uint32_t));
|
||||
memcpy(packet + (sizeof(uint32_t) * 2), data, length);
|
||||
memset(packet + (sizeof(uint32_t) * 2), 0, padding_length);
|
||||
memcpy(packet + (sizeof(uint32_t) * 2) + padding_length, data, length);
|
||||
|
||||
return send_data_packet(c, crypt_connection_id, packet, sizeof(packet));
|
||||
}
|
||||
|
@ -76,6 +76,8 @@
|
||||
#define PACKET_ID_LOSSY_RANGE_START 192
|
||||
#define PACKET_ID_LOSSY_RANGE_SIZE 63
|
||||
|
||||
#define CRYPTO_MAX_PADDING 8 /* All packets will be padded a number of bytes based on this number. */
|
||||
|
||||
typedef struct {
|
||||
uint64_t time;
|
||||
uint16_t length;
|
||||
|
Loading…
x
Reference in New Issue
Block a user