Merged from silc_1_0_branch.
[silc.git] / lib / silcclient / client_prvmsg.c
index d447e0af24f2abd8c51888a549fd721b884c27df..36d7bbe43a7eaffd76fe308eb7980b50da6a9867 100644 (file)
@@ -53,11 +53,13 @@ void silc_client_send_private_message(SilcClient client,
   SILC_LOG_DEBUG(("Sending private message"));
 
   /* Encode private message payload */
-  buffer = silc_private_message_payload_encode(flags,
-                                              data_len, data,
-                                              client_entry->send_key,
-                                              client_entry->hmac_send,
-                                              client->rng);
+  buffer = silc_message_payload_encode(flags, data, data_len,
+                                      !client_entry->send_key ? FALSE :
+                                      !client_entry->generated,
+                                      TRUE, client_entry->send_key,
+                                      client_entry->hmac_send,
+                                      client->rng, NULL, client->private_key,
+                                      client->sha1hash);
 
   /* If we don't have private message specific key then private messages
      are just as any normal packet thus call normal packet sending.  If
@@ -153,7 +155,7 @@ void silc_client_private_message(SilcClient client,
                                 SilcPacketContext *packet)
 {
   SilcClientConnection conn = (SilcClientConnection)sock->user_data;
-  SilcPrivateMessagePayload payload = NULL;
+  SilcMessagePayload payload = NULL;
   SilcClientID *remote_id = NULL;
   SilcClientEntry remote_client;
   SilcMessageFlags flags;
@@ -197,20 +199,21 @@ void silc_client_private_message(SilcClient client,
   }
 
   /* Parse the payload and decrypt it also if private message key is set */
-  payload = silc_private_message_payload_parse(packet->buffer->data,
-                                              packet->buffer->len,
-                                              cipher, hmac);
+  payload = silc_message_payload_parse(packet->buffer->data,
+                                      packet->buffer->len, TRUE,
+                                      !remote_client->generated,
+                                      cipher, hmac);
   if (!payload) {
     silc_free(remote_id);
     return;
   }
 
-  flags = silc_private_message_get_flags(payload);
+  flags = silc_message_get_flags(payload);
 
   /* Pass the private message to application */
-  message = silc_private_message_get_message(payload, &message_len);
-  client->internal->ops->private_message(client, conn, remote_client, flags,
-                                        message, message_len);
+  message = silc_message_get_data(payload, &message_len);
+  client->internal->ops->private_message(client, conn, remote_client, payload,
+                                        flags, message, message_len);
 
   /* See if we are away (gone). If we are away we will reply to the
      sender with the set away message. */
@@ -230,7 +233,7 @@ void silc_client_private_message(SilcClient client,
 
  out:
   if (payload)
-    silc_private_message_payload_free(payload);
+    silc_message_payload_free(payload);
   silc_free(remote_id);
 }
 
@@ -380,7 +383,7 @@ bool silc_client_add_private_message_key(SilcClient client,
   /* Produce the key material as the protocol defines */
   keymat = silc_calloc(1, sizeof(*keymat));
   if (silc_ske_process_key_material_data(key, key_len, 16, 256, 16, 
-                                        client->md5hash, keymat) 
+                                        client->sha1hash, keymat) 
       != SILC_SKE_STATUS_OK)
     return FALSE;
 
@@ -452,6 +455,8 @@ bool silc_client_add_private_message_key_ske(SilcClient client,
   if (!silc_hmac_is_supported(hmac))
     return FALSE;
 
+  client_entry->generated = TRUE;
+
   /* Allocate the cipher and HMAC */
   silc_cipher_alloc(cipher, &client_entry->send_key);
   silc_cipher_alloc(cipher, &client_entry->receive_key);