-
- SILC_LOG_DEBUG(("Decrypting rest of the header"));
-
- SILC_GET16_MSB(len1, &buffer->data[4]);
- SILC_GET16_MSB(len2, &buffer->data[6]);
-
- truelen = SILC_PACKET_HEADER_LEN + len1 + len2;
- padlen = SILC_PACKET_PADLEN(truelen);
- len1 = (truelen + padlen) - (SILC_PACKET_MIN_HEADER_LEN - 2);
-
- silc_buffer_pull(buffer, SILC_PACKET_MIN_HEADER_LEN - 2);
- cipher->cipher->decrypt(cipher->context, buffer->data + 2,
- buffer->data + 2, len1 - 2,
- cipher->iv);
- silc_buffer_push(buffer, SILC_PACKET_MIN_HEADER_LEN - 2);
- }
-
- return TRUE;
-}
-
-/* Decrypts a packet. This assumes that typical SILC packet is the
- packet to be decrypted and thus checks for normal and special SILC
- packets and can handle both of them. This also computes and checks
- the HMAC of the packet. If any other special or customized decryption
- processing is required this function cannot be used. This returns
- -1 on error, 0 when packet is normal packet and 1 when the packet
- is special and requires special processing. */
-
-int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac,
- SilcBuffer buffer, SilcPacketContext *packet)
-{
-#if 0
- SILC_LOG_DEBUG(("Decrypting packet, cipher %s, len %d (%d)",
- cipher->cipher->name, len, len - 2));
-#endif
-
- /* Decrypt start of the packet header */
- if (cipher)
- cipher->cipher->decrypt(cipher->context, buffer->data + 2,
- buffer->data + 2, SILC_PACKET_MIN_HEADER_LEN - 2,
- cipher->iv);
-
- /* If the packet type is not any special type lets decrypt rest
- of the packet here. */
- if ((buffer->data[3] == SILC_PACKET_PRIVATE_MESSAGE &&
- !(buffer->data[2] & SILC_PACKET_FLAG_PRIVMSG_KEY)) ||
- buffer->data[3] != SILC_PACKET_CHANNEL_MESSAGE) {
-
- /* Normal packet, decrypt rest of the packet */
- if (!silc_packet_decrypt_rest(cipher, hmac, buffer))
- return -1;
-
- /* Check MAC */
- if (!silc_packet_check_mac(hmac, buffer))
- return FALSE;
-
- return 0;
- } else {
- /* Packet requires special handling, decrypt rest of the header.
- This only decrypts. */
- silc_packet_decrypt_rest_special(cipher, hmac, buffer);
-
- /* Check MAC */
- if (!silc_packet_check_mac(hmac, buffer))
- return FALSE;