X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=lib%2Fsilccore%2Fsilcpacket.c;h=7bac3681106e2d8282b224cda531b985a7b9d7d8;hp=0c3bcb9118c4581c9086db9e139e25e0b21ead0c;hb=382d15d447b7a95390decfa783836ae4fe255b3d;hpb=3cf38201f9ffaad2da53757ed48a5546e1d03636 diff --git a/lib/silccore/silcpacket.c b/lib/silccore/silcpacket.c index 0c3bcb91..7bac3681 100644 --- a/lib/silccore/silcpacket.c +++ b/lib/silccore/silcpacket.c @@ -83,8 +83,8 @@ void silc_packet_encrypt(SilcCipher cipher, SilcHmac hmac, SilcUInt32 sequence, /* 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); } @@ -116,7 +116,7 @@ bool silc_packet_assemble(SilcPacketContext *packet, SilcRng rng, 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")); @@ -202,9 +202,9 @@ bool silc_packet_send_prepare(SilcSocketConnection sock, 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; @@ -305,7 +305,9 @@ bool silc_packet_receive_process(SilcSocketConnection sock, 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]; @@ -361,9 +363,11 @@ bool silc_packet_receive_process(SilcSocketConnection sock, /* 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" : @@ -379,8 +383,8 @@ bool silc_packet_receive_process(SilcSocketConnection sock, 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; @@ -501,8 +505,11 @@ static int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac, 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; @@ -510,7 +517,7 @@ static int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac, /* 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")); @@ -527,7 +534,11 @@ static int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac, 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;