other process of HMAC computing and encryption is needed this function
cannot be used. */
-void silc_packet_encrypt(SilcCipher cipher, SilcHmac hmac, uint32 sequence,
- SilcBuffer buffer, uint32 len)
+void silc_packet_encrypt(SilcCipher cipher, SilcHmac hmac, SilcUInt32 sequence,
+ SilcBuffer buffer, SilcUInt32 len)
{
unsigned char mac[32];
- uint32 mac_len;
+ SilcUInt32 mac_len;
/* Compute HMAC. This assumes that HMAC is created from the entire
data area thus this uses the length found in buffer, not the length
/* Get the true length of the packet. This is saved as payload length
into the packet header. This does not include the length of the
padding. */
- if (!ctx->truelen)
+ if (!ctx->truelen) {
ctx->truelen = ctx->buffer->len + SILC_PACKET_HEADER_LEN +
ctx->src_id_len + ctx->dst_id_len;
+ if (ctx->truelen > SILC_PACKET_MAX_LEN) {
+ ctx->truelen -= (SILC_PACKET_MAX_LEN - ctx->truelen);
+ silc_buffer_push_tail(ctx->buffer, (SILC_PACKET_MAX_LEN - ctx->truelen));
+ }
+ }
/* Calculate the length of the padding. The padding is calculated from
the data that will be encrypted. */
outgoing buffer in SilcSocketConnection object. */
void silc_packet_send_prepare(SilcSocketConnection sock,
- uint32 header_len,
- uint32 padlen,
- uint32 data_len)
+ SilcUInt32 header_len,
+ SilcUInt32 padlen,
+ SilcUInt32 data_len)
{
int totlen, oldlen;
******************************************************************************/
static int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac,
- uint32 sequence, SilcBuffer buffer,
+ SilcUInt32 sequence, SilcBuffer buffer,
bool normal);
/* Receives packet from network and reads the data into connection's
bool silc_packet_receive_process(SilcSocketConnection sock,
bool local_is_router,
SilcCipher cipher, SilcHmac hmac,
- uint32 sequence,
+ SilcUInt32 sequence,
SilcPacketParserCallback parser,
void *parser_context)
{
SILC_UNSET_INBUF_PENDING(sock);
parse_ctx = silc_calloc(1, sizeof(*parse_ctx));
+ if (!parse_ctx)
+ return FALSE;
parse_ctx->packet = silc_packet_context_alloc();
parse_ctx->packet->buffer = silc_buffer_alloc(paddedlen + mac_len);
parse_ctx->packet->type = sock->inbuf->data[3];
after packet has been totally decrypted and parsed. */
static int silc_packet_check_mac(SilcHmac hmac, SilcBuffer buffer,
- uint32 sequence)
+ SilcUInt32 sequence)
{
/* Check MAC */
if (hmac) {
unsigned char mac[32], psn[4];
- uint32 mac_len;
+ SilcUInt32 mac_len;
SILC_LOG_DEBUG(("Verifying MAC"));
{
/* Decrypt rest of the header plus padding */
if (cipher) {
- uint16 len;
+ SilcUInt16 len;
/* Pull MAC from packet before decryption */
if (hmac) {
/* padding length + src id len + dst id len + header length - 16
bytes already decrypted, gives the rest of the encrypted packet */
- len = (((uint8)buffer->data[4] + (uint8)buffer->data[6] +
- (uint8)buffer->data[7] + SILC_PACKET_HEADER_LEN) -
+ len = (((SilcUInt8)buffer->data[4] + (SilcUInt8)buffer->data[6] +
+ (SilcUInt8)buffer->data[7] + SILC_PACKET_HEADER_LEN) -
SILC_PACKET_MIN_HEADER_LEN);
silc_buffer_pull(buffer, SILC_PACKET_MIN_HEADER_LEN);
is special and requires special procesing. */
static int silc_packet_decrypt(SilcCipher cipher, SilcHmac hmac,
- uint32 sequence, SilcBuffer buffer,
+ SilcUInt32 sequence, SilcBuffer buffer,
bool normal)
{
/* If the packet type is not any special type lets decrypt rest
SilcPacketType silc_packet_parse(SilcPacketContext *ctx, SilcCipher cipher)
{
SilcBuffer buffer = ctx->buffer;
- uint8 tmp;
+ SilcUInt8 tmp;
int len, ret;
SILC_LOG_DEBUG(("Parsing incoming packet"));
SilcCipher cipher)
{
SilcBuffer buffer = ctx->buffer;
- uint8 tmp;
+ SilcUInt8 tmp;
int len, ret;
SILC_LOG_DEBUG(("Parsing incoming packet"));
SilcPacketContext *silc_packet_context_alloc(void)
{
SilcPacketContext *ctx = silc_calloc(1, sizeof(*ctx));
+ if (!ctx)
+ return NULL;
ctx->users++;
return ctx;
}