updates.
[crypto.git] / lib / silcclient / client.c
index b4f46104e8e13cac0048d511aac65aa3c5cb469b..08b643ea33c3d1c2d72053e811c59590fa0d57a3 100644 (file)
@@ -970,7 +970,6 @@ void silc_client_packet_send_to_channel(SilcClient client,
   SilcCipher cipher;
   SilcHmac hmac;
   unsigned char *id_string;
-  unsigned int block_len;
 
   SILC_LOG_DEBUG(("Sending packet to channel"));
 
@@ -981,15 +980,14 @@ void silc_client_packet_send_to_channel(SilcClient client,
   }
 
   /* Generate IV */
-  block_len = silc_cipher_get_block_len(channel->channel_key);
   if (channel->iv[0] == '\0')
-    for (i = 0; i < block_len; i++) channel->iv[i] = silc_rng_get_byte(client->rng);
+    for (i = 0; i < 16; i++) channel->iv[i] = silc_rng_get_byte(client->rng);
   else
-    silc_hash_make(client->md5hash, channel->iv, block_len, channel->iv);
+    silc_hash_make(client->md5hash, channel->iv, 16, channel->iv);
 
   /* Encode the channel payload */
-  payload = silc_channel_payload_encode(data_len, data, block_len
-                                       channel->iv, client->rng);
+  payload = silc_channel_payload_encode(data_len, data, 16, channel->iv
+                                       client->rng);
   if (!payload) {
     client->ops->say(client, conn, 
                     "Error: Could not create packet to be sent to channel");
@@ -1030,10 +1028,13 @@ void silc_client_packet_send_to_channel(SilcClient client,
 
   packetdata.buffer = sock->outbuf;
 
+  SILC_LOG_HEXDUMP(("IV"), channel->iv, 16);
+  SILC_LOG_HEXDUMP(("channel key"), channel->key, channel->key_len/8);
+
   /* Encrypt payload of the packet. This is encrypted with the channel key. */
   channel->channel_key->cipher->encrypt(channel->channel_key->context,
                                        payload->data, payload->data,
-                                       payload->len - block_len, /* -IV_LEN */
+                                       payload->len - 16, /* -IV_LEN */
                                        channel->iv);
 
   /* Put the actual encrypted payload data into the buffer. */
@@ -2068,7 +2069,6 @@ void silc_client_channel_message(SilcClient client,
   SilcIDCacheEntry id_cache = NULL;
   SilcClientID *client_id = NULL;
   int found = FALSE;
-  unsigned int block_len;
 
   /* Sanity checks */
   if (packet->dst_id_type != SILC_ID_CHANNEL)
@@ -2089,14 +2089,20 @@ void silc_client_channel_message(SilcClient client,
 
   channel = (SilcChannelEntry)id_cache->context;
 
+  SILC_LOG_HEXDUMP(("channel key"), channel->key, channel->key_len);
+
   /* Decrypt the channel message payload. Push the IV out of the way,
      since it is not encrypted (after pushing buffer->tail has the IV). */
-  block_len = silc_cipher_get_block_len(channel->channel_key);
-  silc_buffer_push_tail(buffer, block_len);
+  SILC_LOG_HEXDUMP(("Packet"), buffer->data, buffer->len);
+  silc_buffer_push_tail(buffer, channel->channel_key->cipher->block_len);
+  SILC_LOG_HEXDUMP(("Packet"), buffer->data, buffer->len);
+  SILC_LOG_HEXDUMP(("IV"), buffer->tail, 16);
   channel->channel_key->cipher->decrypt(channel->channel_key->context,
                                        buffer->data, buffer->data,
                                        buffer->len, buffer->tail);
-  silc_buffer_pull_tail(buffer, block_len);
+  SILC_LOG_HEXDUMP(("Packet"), buffer->data, buffer->len);
+  silc_buffer_pull_tail(buffer, channel->channel_key->cipher->block_len);
+  SILC_LOG_HEXDUMP(("Packet"), buffer->data, buffer->len);
 
   /* Parse the channel message payload */
   payload = silc_channel_payload_parse(buffer);