+ /* Check SID, and get correct decryption key */
+ if (sid != stream->sid) {
+ /* If SID is recent get the previous key and use it */
+ if (sid > 0 && stream->sid > 0 && stream->sid - 1 == sid &&
+ stream->receive_key[1] && !stream->receive_hmac[1]) {
+ cipher = stream->receive_key[1];
+ hmac = stream->receive_hmac[1];
+ } else {
+ /* The SID is unknown, drop rest of the data in buffer */
+ SILC_LOG_DEBUG(("Unknown Security ID %d in packet, expected %d",
+ sid, stream->sid));
+ silc_mutex_unlock(stream->lock);
+ SILC_PACKET_CALLBACK_ERROR(stream, SILC_PACKET_ERR_UNKNOWN_SID);
+ silc_mutex_lock(stream->lock);
+ silc_buffer_reset(&stream->inbuf);
+ return;
+ }
+ }
+ } else {
+ memcpy(iv, silc_cipher_get_iv(cipher), block_len);
+ }
+
+ silc_cipher_decrypt(cipher, stream->inbuf.data + ivlen, tmp,
+ block_len, iv);