5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2001 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
21 /****h* silccore/SilcChannelAPI
25 * Implementations of the Channel Payload, Channel Message Payload and
26 * Channel Key Payload. The Channel Payload represents new channel and
27 * is used to distribute the information of the new channel. The Channel
28 * Message Payload is used to deliver messages to the channel. The routines
29 * for Channel Message Payload also handles the encryption and decryption
30 * of the payload. Last, the Channel Key Payload is used to distribute
31 * a new key to the channel. It is done for example every time someone
32 * joins a channel or the old key expires.
39 #include "silcdlist.h"
41 /****s* silccore/SilcChannelAPI/SilcChannelPayload
45 * typedef struct SilcChannelPayloadStruct *SilcChannelPayload;
49 * This context is the actual Channel Payload and is allocated
50 * by silc_channel_payload_parse and given as argument usually to
51 * all silc_channel_payload_* functions. It is freed by the
52 * silc_channel_payload_free function.
55 typedef struct SilcChannelPayloadStruct *SilcChannelPayload;
57 /****s* silccore/SilcChannelAPI/SilcChannelMessagePayload
62 * SilcChannelMessagePayloadStruct *SilcChannelMessagePayload;
66 * This context is the actual Channel Message Payload and is allocated
67 * by silc_channel_message_payload_parse and given as argument usually to
68 * all silc_channel_message_payload_* functions. It is freed by the
69 * silc_channel_message_payload_free function.
72 typedef struct SilcChannelMessagePayloadStruct *SilcChannelMessagePayload;
74 /****s* silccore/SilcChannelAPI/SilcChannelKeyPayload
78 * typedef struct SilcChannelKeyPayloadStruct *SilcChannelKeyPayload;
82 * This context is the actual Channel Key Payload and is allocated
83 * by silc_channel_key_payload_parse and given as argument usually to
84 * all silc_channel_key_payload_* functions. It is freed by the
85 * silc_channel_key_payload_free function.
88 typedef struct SilcChannelKeyPayloadStruct *SilcChannelKeyPayload;
90 /****d* silccore/SilcChannelAPI/SilcMessageFlags
94 * typedef uint16 SilcMessageFlags;
98 * The message flags type definition and the message flags. The
99 * message flags are used to indicate some status of the message.
100 * These flags are also used by the private message interfaces.
104 typedef uint16 SilcMessageFlags;
106 /* The message flags (shared by both channel and private messages) */
107 #define SILC_MESSAGE_FLAG_NONE 0x0000
108 #define SILC_MESSAGE_FLAG_AUTOREPLY 0x0001
109 #define SILC_MESSAGE_FLAG_NOREPLY 0x0002
110 #define SILC_MESSAGE_FLAG_ACTION 0x0004
111 #define SILC_MESSAGE_FLAG_NOTICE 0x0008
112 #define SILC_MESSAGE_FLAG_REQUEST 0x0010
113 #define SILC_MESSAGE_FLAG_SIGNED 0x0020
114 #define SILC_MESSAGE_FLAG_RESERVED 0x0040 /* to 0x0200 */
115 #define SILC_MESSAGE_FLAG_PRIVATE 0x0400 /* to 0x8000 */
120 /****f* silccore/SilcChannelAPI/silc_channel_payload_parse
124 * SilcChannelPayload silc_channel_payload_parse(SilcBuffer buffer);
128 * Parses channel payload returning new channel payload structure. The
129 * `buffer' is the raw payload buffer.
132 SilcChannelPayload silc_channel_payload_parse(SilcBuffer buffer);
134 /****f* silccore/SilcChannelAPI/silc_channel_payload_parse_list
138 * SilcDList silc_channel_payload_parse_list(SilcBuffer buffer);
142 * Parses list of channel payloads returning list of payloads. This
143 * is equivalent to the silc_channel_payload_parse except that the `buffer'
144 * now includes multiple Channel Payloads one after the other.
147 SilcDList silc_channel_payload_parse_list(SilcBuffer buffer);
149 /****f* silccore/SilcChannelAPI/silc_channel_payload_encode
153 * SilcBuffer silc_channel_payload_encode(unsigned char *channel_name,
154 * uint16 channel_name_len,
155 * unsigned char *channel_id,
156 * uint32 channel_id_len,
161 * Encode new channel payload and returns it as buffer.
164 SilcBuffer silc_channel_payload_encode(unsigned char *channel_name,
165 uint16 channel_name_len,
166 unsigned char *channel_id,
167 uint32 channel_id_len,
170 /****f* silccore/SilcChannelAPI/silc_channel_payload_free
174 * void silc_channel_payload_free(SilcChannelPayload payload);
178 * Frees Channel Payload and all data in it.
181 void silc_channel_payload_free(SilcChannelPayload payload);
183 /****f* silccore/SilcChannelAPI/silc_channel_payload_list_free
187 * void silc_channel_payload_list_free(SilcDList list);
191 * Frees list of Channel Payloads and all data in them.
194 void silc_channel_payload_list_free(SilcDList list);
196 /****f* silccore/SilcChannelAPI/silc_channel_get_name
200 * unsigned char *silc_channel_get_name(SilcChannelPayload payload,
201 * uint32 *channel_name_len);
205 * Return the channel name from the payload. The caller must not free it.
208 unsigned char *silc_channel_get_name(SilcChannelPayload payload,
209 uint32 *channel_name_len);
211 /****f* silccore/SilcChannelAPI/silc_channel_get_id
215 * unsigned char *silc_channel_get_id(SilcChannelPayload payload,
216 * uint32 *channel_id_len);
220 * Return the Channel ID data from the payload. The caller must not free it.
223 unsigned char *silc_channel_get_id(SilcChannelPayload payload,
224 uint32 *channel_id_len);
226 /****f* silccore/SilcChannelAPI/silc_channel_get_id_parse
230 * SilcChannelID *silc_channel_get_id_parse(SilcChannelPayload payload);
234 * Return the Channel ID as parsed ID. This is equivalent to the
235 * silc_channel_get_id execpt that the ID is already parsed. The caller
236 * must free the parsed Channel ID.
239 SilcChannelID *silc_channel_get_id_parse(SilcChannelPayload payload);
241 /****f* silccore/SilcChannelAPI/silc_channel_get_mode
245 * uint32 silc_channel_get_mode(SilcChannelPayload payload);
249 * Return the mode. The mode is arbitrary. It can be the mode of the
250 * channel or perhaps the mode of the client on the channel. The protocol
251 * dictates what the usage of the mode is in different circumstances.
254 uint32 silc_channel_get_mode(SilcChannelPayload payload);
256 /****f* silccore/SilcChannelAPI/silc_channel_message_payload_decrypt
260 * int silc_channel_message_payload_decrypt(unsigned char *data,
267 * Decrypt the channel message. First push the IV out of the packet `data'.
268 * The IV is used in the decryption process. Then decrypt the message.
269 * After decryption, take the MAC from the decrypted packet, compute MAC
270 * and compare the MACs. If they match, the decryption was successful
271 * and we have the channel message ready to be displayed.
273 * This is usually used by the Channel Message interface itself but can
274 * be called by the appliation if separate decryption process is required.
275 * For example server might need to call this directly in some
276 * circumstances. The `cipher' is used to decrypt the payload.
278 * If the `hmac' is no provided then the MAC of the channel message is
282 int silc_channel_message_payload_decrypt(unsigned char *data,
287 /****f* silccore/SilcChannelAPI/silc_channel_message_payload_parse
291 * SilcChannelMessagePayload
292 * silc_channel_message_payload_parse(SilcBuffer buffer,
298 * Parses channel message payload returning new channel payload structure.
299 * This also decrypts it and checks the MAC. The `cipher's is used to
300 * decrypt the payload.
302 * If the `hmac' is no provided then the MAC of the channel message is
306 SilcChannelMessagePayload
307 silc_channel_message_payload_parse(SilcBuffer buffer,
311 /****f* silccore/SilcChannelAPI/silc_channel_message_payload_encode
315 * SilcBuffer silc_channel_message_payload_encode(uint16 flags,
317 * unsigned char *data,
325 * Encodes channel message payload into a buffer and returns it. This
326 * is used to add channel message payload into a packet. As the channel
327 * payload is encrypted separately from other parts of the packet padding
328 * must be applied to the payload. The function generates the padding
329 * automatically from random data. The `cipher' is the cipher used
330 * encrypt the payload and `hmac' is used to compute the MAC for the
334 SilcBuffer silc_channel_message_payload_encode(uint16 flags,
342 /****f* silccore/SilcChannelAPI/silc_channel_message_payload_free
347 * silc_channel_message_payload_free(SilcChannelMessagePayload payload);
351 * Free's Channel Message Payload and all data in it.
354 void silc_channel_message_payload_free(SilcChannelMessagePayload payload);
356 /****f* silccore/SilcChannelAPI/silc_channel_message_get_flags
361 * silc_channel_message_get_flags(SilcChannelMessagePayload payload);
365 * Returns the message flags from the payload.
369 silc_channel_message_get_flags(SilcChannelMessagePayload payload);
371 /****f* silccore/SilcChannelAPI/silc_channel_message_get_data
376 * silc_channel_message_get_data(SilcChannelMessagePayload payload,
381 * Return the data in the payload, that is, the actual channel message.
382 * The caller must not free it.
385 unsigned char *silc_channel_message_get_data(SilcChannelMessagePayload payload,
388 /****f* silccore/SilcChannelAPI/silc_channel_message_get_mac
393 * silc_channel_message_get_mac(SilcChannelMessagePayload payload);
397 * Return the MAC of the payload. The caller must already know the
398 * length of the MAC. The caller must not free the MAC.
401 unsigned char *silc_channel_message_get_mac(SilcChannelMessagePayload payload);
403 /****f* silccore/SilcChannelAPI/silc_channel_message_get_iv
408 * silc_channel_message_get_iv(SilcChannelMessagePayload payload);
412 * Return the IV of the payload. The caller must already know the
413 * length of the IV. The caller must not free the IV.
416 unsigned char *silc_channel_message_get_iv(SilcChannelMessagePayload payload);
418 /****f* silccore/SilcChannelAPI/silc_channel_key_payload_parse
422 * SilcChannelKeyPayload silc_channel_key_payload_parse(SilcBuffer buffer);
426 * Parses channel key payload returning new channel key payload
430 SilcChannelKeyPayload silc_channel_key_payload_parse(SilcBuffer buffer);
432 /****f* silccore/SilcChannelAPI/silc_channel_key_payload_encode
436 * SilcBuffer silc_channel_key_payload_encode(uint16 id_len,
439 * unsigned char *cipher,
441 * unsigned char *key);
445 * Encodes channel key payload into a buffer and returns it. This is used
446 * to add channel key payload into a packet.
449 SilcBuffer silc_channel_key_payload_encode(uint16 id_len,
452 unsigned char *cipher,
456 /****f* silccore/SilcChannelAPI/silc_channel_key_payload_free
460 * void silc_channel_key_payload_free(SilcChannelKeyPayload payload);
464 * Frees the Channel Key Payload and all data in it.
467 void silc_channel_key_payload_free(SilcChannelKeyPayload payload);
469 /****f* silccore/SilcChannelAPI/silc_channel_key_get_id
473 * unsigned char *silc_channel_key_get_id(SilcChannelKeyPayload payload,
478 * Return the Channel ID data from the payload. The caller must not
482 unsigned char *silc_channel_key_get_id(SilcChannelKeyPayload payload,
485 /****f* silccore/SilcChannelAPI/silc_channel_key_get_cipher
489 * unsigned char *silc_channel_key_get_cipher(SilcChannelKeyPayload payload,
490 * uint32 *cipher_len);
494 * Return the name of the cipher from the payload. The caller must not
498 unsigned char *silc_channel_key_get_cipher(SilcChannelKeyPayload payload,
501 /****f* silccore/SilcChannelAPI/silc_channel_key_get_key
505 * unsigned char *silc_channel_key_get_key(SilcChannelKeyPayload payload,
510 * Return the raw key material from the payload. The caller must not
514 unsigned char *silc_channel_key_get_key(SilcChannelKeyPayload payload,