/* Encrypt the data area of the packet. */
if (cipher) {
- SILC_LOG_DEBUG(("Encrypting packet, cipher %s, len %d",
- silc_cipher_get_name(cipher), len));
+ SILC_LOG_DEBUG(("Encrypting packet (%d), cipher %s, len %d",
+ sequence, silc_cipher_get_name(cipher), len));
silc_cipher_encrypt(cipher, buffer->data, buffer->data, len, NULL);
}
const SilcBuffer assembled_packet)
{
unsigned char tmppad[SILC_PACKET_MAX_PADLEN];
- int block_len = cipher ? silc_cipher_get_block_len(cipher) : 0;
+ unsigned int block_len = cipher ? silc_cipher_get_block_len(cipher) : 0;
int i, ret;
SILC_LOG_DEBUG(("Assembling outgoing packet"));
SilcHmac hmac,
const SilcBuffer packet)
{
- int totlen;
+ SilcUInt32 totlen;
unsigned char *oldptr;
- int mac_len = hmac ? silc_hmac_len(hmac) : 0;
+ unsigned int mac_len = hmac ? silc_hmac_len(hmac) : 0;
if (!packet)
return FALSE;
void *parser_context)
{
SilcPacketParserContext *parse_ctx;
- int packetlen, paddedlen, mac_len = 0, ret, block_len;
+ SilcUInt16 packetlen;
+ SilcUInt32 paddedlen, mac_len = 0, block_len;
+ int ret;
bool cont = TRUE;
unsigned char tmp[SILC_PACKET_MIN_HEADER_LEN], *header;
unsigned char iv[SILC_CIPHER_MAX_IV_SIZE];
/* Check MAC of the packet */
if (!silc_packet_check_mac(hmac, sock->inbuf->data, paddedlen,
sock->inbuf->data + paddedlen, sequence)) {
- SILC_LOG_WARNING(("Packet MAC check failed %s:%d [%s] [%s]",
+ SILC_LOG_WARNING(("Packet MAC check failed %s:%d "
+ "[%s type %d len %dB seq %d] [%s]",
sock->hostname, sock->port,
silc_get_packet_name(header[3]),
+ header[3], paddedlen, sequence,
(sock->type == SILC_SOCKET_TYPE_UNKNOWN ? "Unknown" :
sock->type == SILC_SOCKET_TYPE_CLIENT ? "Client" :
sock->type == SILC_SOCKET_TYPE_SERVER ? "Server" :
return FALSE;
parse_ctx->packet = silc_packet_context_alloc();
parse_ctx->packet->buffer = silc_buffer_alloc_size(paddedlen);
- parse_ctx->packet->type = header[3];
- parse_ctx->packet->padlen = header[4];
+ parse_ctx->packet->type = (SilcPacketType)header[3];
+ parse_ctx->packet->padlen = (SilcUInt8)header[4];
parse_ctx->packet->sequence = sequence++;
parse_ctx->sock = sock;
parse_ctx->context = parser_context;
if (cipher) {
/* Decrypt rest of the packet */
SILC_LOG_DEBUG(("Decrypting the packet"));
- silc_cipher_decrypt(cipher, buffer->data, buffer->data, buffer->len,
- NULL);
+ if (!silc_cipher_decrypt(cipher, buffer->data, buffer->data,
+ buffer->len, NULL)) {
+ SILC_LOG_ERROR(("silc_cipher_decrypt failed"));
+ return -1;
+ }
}
return 0;
/* Decrypt rest of the header plus padding */
if (cipher) {
SilcUInt16 len;
- int block_len = silc_cipher_get_block_len(cipher);
+ SilcUInt32 block_len = silc_cipher_get_block_len(cipher);
SILC_LOG_DEBUG(("Decrypting the header"));
return -1;
}
silc_buffer_pull(buffer, block_len);
- silc_cipher_decrypt(cipher, buffer->data, buffer->data, len, NULL);
+ if (!silc_cipher_decrypt(cipher, buffer->data, buffer->data,
+ len, NULL)) {
+ SILC_LOG_ERROR(("silc_cipher_decrypt failed"));
+ return -1;
+ }
}
return 1;