Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
- Copyright (C) 1997 - 2000 Pekka Riikonen
+ Copyright (C) 1997 - 2001 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/* Channel Message Payload structure. Contents of this structure is parsed
from SILC packets. */
struct SilcChannelMessagePayloadStruct {
+ unsigned short flags;
unsigned short data_len;
unsigned char *data;
unsigned char *mac;
/* Parse the Channel Message Payload. Ignore the padding. */
ret = silc_buffer_unformat(buffer,
+ SILC_STR_UI_SHORT(&new->flags),
SILC_STR_UI16_NSTRING_ALLOC(&new->data,
&new->data_len),
SILC_STR_UI16_NSTRING(NULL, NULL),
encrypted separately from other parts of the packet padding must
be applied to the payload. */
-SilcBuffer silc_channel_message_payload_encode(unsigned short data_len,
+SilcBuffer silc_channel_message_payload_encode(unsigned short flags,
+ unsigned short data_len,
unsigned char *data,
unsigned short iv_len,
unsigned char *iv,
SilcCipher cipher,
- SilcHmac hmac,
- SilcRng rng)
+ SilcHmac hmac)
{
int i;
SilcBuffer buffer;
/* Calculate length of padding. IV is not included into the calculation
since it is not encrypted. */
mac_len = silc_hmac_len(hmac);
- len = 4 + data_len + mac_len;
+ len = 6 + data_len + mac_len;
pad_len = SILC_PACKET_PADLEN((len + 2));
/* Allocate channel payload buffer */
buffer = silc_buffer_alloc(len);
/* Generate padding */
- for (i = 0; i < pad_len; i++) pad[i] = silc_rng_get_byte(rng);
+ for (i = 0; i < pad_len; i++) pad[i] = silc_rng_global_get_byte();
/* Encode the Channel Message Payload */
- silc_buffer_pull_tail(buffer, 4 + data_len + pad_len);
+ silc_buffer_pull_tail(buffer, 6 + data_len + pad_len);
silc_buffer_format(buffer,
+ SILC_STR_UI_SHORT(flags),
SILC_STR_UI_SHORT(data_len),
SILC_STR_UI_XNSTRING(data, data_len),
SILC_STR_UI_SHORT(pad_len),
/* Put rest of the data to the payload */
silc_buffer_pull_tail(buffer, mac_len + iv_len);
- silc_buffer_pull(buffer, 4 + data_len + pad_len);
+ silc_buffer_pull(buffer, 6 + data_len + pad_len);
silc_buffer_format(buffer,
SILC_STR_UI_XNSTRING(mac, mac_len),
SILC_STR_UI_XNSTRING(iv, iv_len),
SILC_STR_END);
- silc_buffer_push(buffer, 4 + data_len + pad_len);
+ silc_buffer_push(buffer, 6 + data_len + pad_len);
/* Encrypt payload of the packet. This is encrypted with the channel key. */
silc_cipher_encrypt(cipher, buffer->data, buffer->data,
silc_free(payload);
}
+/* Return flags */
+
+unsigned short
+silc_channel_message_get_flags(SilcChannelMessagePayload payload)
+{
+ return payload->flags;
+}
+
/* Return data */
unsigned char *silc_channel_message_get_data(SilcChannelMessagePayload payload,