Ejemplo n.º 1
0
/*-----------------------------------------------------------------------------------*/
static struct pbuf *
low_level_input(struct udpif *udpif)
{
  struct pbuf *p, *q;
  u16_t len;
  char buf[1514];
  char *bufptr;
  struct sockaddr_in cliaddr;
  socklen_t cli_len;
  struct s_compress_header * sh;

  /* Obtain the size of the packet and put it into the "len"
     variable. */
  cli_len = sizeof(cliaddr);
  bzero(&cliaddr, sizeof(cliaddr));
  len = recvfrom(udpif->fd, buf, sizeof(buf), 0, (struct sockaddr *)&cliaddr, &cli_len);
  if(len < sizeof(struct eth_hdr)) 
      return NULL;

  s_decrypt(udpif->enc_handle, (byte_t*)(buf + sizeof(struct eth_hdr)), len - sizeof(struct eth_hdr));

  sh = (struct s_compress_header * ) (buf+ sizeof(struct eth_hdr));
  if(s_uncompress(sh) != 0)
      return NULL;

#if 0
    if(((double)rand()/(double)RAND_MAX) < 0.2) {
    printf("drop\n");
    return NULL;
    }
#endif

  /* We allocate a pbuf chain of pbufs from the pool. */
  p = pbuf_alloc(PBUF_RAW, sh->real_size, PBUF_POOL);

  if(p != NULL) {
    /* We iterate over the pbuf chain until we have read the entire
       packet into the pbuf. */
    bufptr = buf + sizeof(struct eth_hdr) + sizeof(struct s_compress_header);
    for(q = p; q != NULL; q = q->next) {
      /* Read enough bytes to fill this pbuf in the chain. The
         available data in the pbuf is given by the q->len
         variable. */
      /* read data into(q->payload, q->len); */
      memcpy(q->payload, bufptr, q->len);
      bufptr += q->len;
    }
    /* acknowledge that packet has been read(); */
  } else {
    /* drop packet(); */
  }

  return p;
}
Ejemplo n.º 2
0
char* bee_s_decrypt(void *b, char *cipher, long len, long key, long *res_len)
{
    CK_RV r;
    char *res;

    if ((r = s_decrypt(*((bee*) b), (CK_BYTE_PTR) cipher, (CK_ULONG) len, (CK_OBJECT_HANDLE) key,
		    (CK_BYTE_PTR*) &res, (CK_ULONG_PTR) res_len)) != CKR_OK)
    {
	last_error = r;
	return NULL;
    }

    return res;
}