1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-08-08 19:02:06 +03:00

packet: Improve readablity of packet decrypt.

After discussion with Aris and it was not obvious enough to understand
the issue we decided to refactor it.

Reviewd-by: Aris Adamantiadis <aris@0xbadc0de.be>
This commit is contained in:
Andreas Schneider
2014-02-06 20:30:29 +01:00
parent abe4ed0e75
commit 1cccfdf8a0

View File

@@ -152,7 +152,7 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
const uint8_t *packet;
int to_be_read;
int rc;
uint32_t len, compsize, payloadsize, buffer_len;
uint32_t len, compsize, payloadsize;
uint8_t padding;
size_t processed = 0; /* number of byte processed from the callback */
@@ -251,13 +251,14 @@ int ssh_packet_socket_callback(const void *data, size_t receivedlen, void *user)
* Decrypt the rest of the packet (blocksize bytes already
* have been decrypted)
*/
uint32_t buffer_len = buffer_get_rest_len(session->in_buffer);
/* The following check avoids decrypting zero bytes */
buffer_len = buffer_get_rest_len(session->in_buffer);
if (buffer_len != blocksize) {
rc = packet_decrypt(session,
((uint8_t*)buffer_get_rest(session->in_buffer) + blocksize),
buffer_len - blocksize);
if (buffer_len > blocksize) {
uint8_t *payload = ((uint8_t*)buffer_get_rest(session->in_buffer) + blocksize);
uint32_t plen = buffer_len - blocksize;
rc = packet_decrypt(session, payload, plen);
if (rc < 0) {
ssh_set_error(session, SSH_FATAL, "Decrypt error");
goto error;