-/* Decrypts the channel message payload. */
-
-int silc_channel_payload_decrypt(unsigned char *data,
- size_t data_len,
- SilcCipher cipher,
- SilcHmac hmac)
-{
- unsigned int iv_len, mac_len;
- unsigned char *end, *mac, mac2[32];
-
- /* Decrypt the channel message. First push the IV out of the packet.
- The IV is used in the decryption process. Then decrypt the message.
- After decyprtion, take the MAC from the decrypted packet, compute MAC
- and compare the MACs. If they match, the decryption was successfull
- and we have the channel message ready to be displayed. */
- end = data + data_len;
-
- /* Push the IV out of the packet */
- iv_len = silc_cipher_get_block_len(cipher);
-
- /* Decrypt the channel message */
- silc_cipher_decrypt(cipher, data, data, data_len - iv_len, (end - iv_len));
-
- /* Take the MAC */
- if (hmac) {
- mac_len = silc_hmac_len(hmac);
- mac = (end - iv_len - mac_len);
-
- /* Check the MAC of the message */
- SILC_LOG_DEBUG(("Checking channel message MACs"));
- silc_hmac_make(hmac, data, (data_len - iv_len - mac_len), mac2, &mac_len);
- if (memcmp(mac, mac2, mac_len)) {
- SILC_LOG_DEBUG(("Channel message MACs does not match"));
- return FALSE;
- }
- SILC_LOG_DEBUG(("MAC is Ok"));
- }
-
- return TRUE;
-}
-
-/* Parses channel payload returning new channel payload structure. This
- also decrypts it and checks the MAC. */