/* Encrypt the data area of the packet. */
if (cipher) {
SILC_LOG_DEBUG(("Encrypting packet, cipher %s, len %d",
- cipher->cipher->name, len));
- silc_cipher_encrypt(cipher, buffer->data, buffer->data, len, cipher->iv);
+ silc_cipher_get_name(cipher), len));
+ silc_cipher_encrypt(cipher, buffer->data, buffer->data, len,
+ silc_cipher_get_iv(cipher));
}
/* Pull the HMAC into the visible data area in the buffer */
/* Calculate the length of the padding. The padding is calculated from
the data that will be encrypted. */
if (!packet->padlen) {
- packet->padlen = (packet->long_pad ?
- SILC_PACKET_PADLEN_MAX(packet->truelen) :
- SILC_PACKET_PADLEN(packet->truelen, block_len));
+ if (packet->long_pad)
+ SILC_PACKET_PADLEN_MAX(packet->truelen, block_len, packet->padlen);
+ else
+ SILC_PACKET_PADLEN(packet->truelen, block_len, packet->padlen);
}
/* Now prepare the outgoing data buffer for packet sending and start
/* Decrypt first 16 bytes of the packet */
if (!SILC_IS_INBUF_PENDING(sock) && cipher)
silc_cipher_decrypt(cipher, sock->inbuf->data, sock->inbuf->data,
- SILC_PACKET_MIN_HEADER_LEN, cipher->iv);
+ SILC_PACKET_MIN_HEADER_LEN,
+ silc_cipher_get_iv(cipher));
/* Get packet lenght and full packet length with padding */
SILC_PACKET_LENGTH(sock->inbuf, packetlen, paddedlen);
if (silc_packet_decrypt(cipher, hmac, parse_ctx->packet->sequence,
parse_ctx->packet->buffer,
parse_ctx->normal) == -1) {
- SILC_LOG_WARNING(("Packet decryption failed %s:%d [%s]",
+ SILC_LOG_WARNING(("Packet decryption failed %s:%d [%s] [%s]",
sock->hostname, sock->port,
+ silc_get_packet_name(parse_ctx->packet->type),
(sock->type == SILC_SOCKET_TYPE_UNKNOWN ? "Unknown" :
sock->type == SILC_SOCKET_TYPE_CLIENT ? "Client" :
sock->type == SILC_SOCKET_TYPE_SERVER ? "Server" :
"Router")));
+ silc_packet_context_free(parse_ctx->packet);
+ silc_free(parse_ctx);
return FALSE;
}
/* Decrypt rest of the packet */
silc_buffer_pull(buffer, SILC_PACKET_MIN_HEADER_LEN);
silc_cipher_decrypt(cipher, buffer->data, buffer->data, buffer->len,
- cipher->iv);
+ silc_cipher_get_iv(cipher));
silc_buffer_push(buffer, SILC_PACKET_MIN_HEADER_LEN);
SILC_LOG_HEXDUMP(("Fully decrypted packet, len %d", buffer->len),
"packet dropped"));
return FALSE;
}
- silc_cipher_decrypt(cipher, buffer->data, buffer->data, len, cipher->iv);
+ silc_cipher_decrypt(cipher, buffer->data, buffer->data, len,
+ silc_cipher_get_iv(cipher));
silc_buffer_push(buffer, SILC_PACKET_MIN_HEADER_LEN);
SILC_LOG_HEXDUMP(("packet, len %d", buffer->len),
buffer->data, buffer->len);