Change encrypted structure
This commit is contained in:
parent
82ee7785f7
commit
47fd0968cb
2 changed files with 3 additions and 6 deletions
|
@ -263,9 +263,7 @@ int encrypt_packet(int sockfd, key_pair *kp)
|
|||
/* Pad with null characters up to max length */
|
||||
memset(recipient + length, 0, MAX_NAME - length);
|
||||
}
|
||||
memcpy(raw_data, kp->pk.username, MAX_NAME);
|
||||
memcpy(raw_data + MAX_NAME, recipient, MAX_NAME);
|
||||
memcpy(raw_data + MAX_NAME * 2, line, length_line);
|
||||
memcpy(raw_data, line, length_line);
|
||||
size_t raw_data_size = MAX_NAME * 2 + strlen(line);
|
||||
|
||||
uint8_t *data = encrypt_data(kp->pk.username, recipient, raw_data, raw_data_size, &data_len);
|
||||
|
@ -331,7 +329,6 @@ uint8_t *encrypt_data(uint8_t *from, uint8_t *to, uint8_t *raw, uint32_t raw_len
|
|||
uint8_t encrypted[encrypted_len];
|
||||
|
||||
/* Generate random nonce(number used once) */
|
||||
printf("raw: %s\n", raw);
|
||||
randombytes_buf(nonce, sizeof(nonce));
|
||||
crypto_aead_xchacha20poly1305_ietf_encrypt(encrypted, NULL, raw,
|
||||
raw_length, NULL, 0, NULL, nonce, shared_key);
|
||||
|
@ -383,7 +380,7 @@ uint8_t *decrypt_data(packet *pkt)
|
|||
} else {
|
||||
/* Terminate decrypted message so we don't print random bytes */
|
||||
decrypted[data_len] = '\0';
|
||||
printf("<%s> to <%s>: %s\n", from, to, decrypted + MAX_NAME * 2);
|
||||
printf("<%s> to <%s>: %s\n", from, to, decrypted);
|
||||
return decrypted;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,7 +128,7 @@ void *thread_worker(void *arg)
|
|||
for (int j = 0; j < thread.num_clients; j++) {
|
||||
client_t client = thread.clients[j];
|
||||
if (strcmp(client.username, to) == 0) {
|
||||
error(0, "Relaying message to %s\n", client.username);
|
||||
error(0, "Relaying message to %s", client.username);
|
||||
send_packet(verified_pkt, client.fd);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue