void*
paillier_plaintext_to_bytes( int len,
														 paillier_plaintext_t* pt )
{
	void* buf0;
	void* buf1;
	size_t written;

	buf0 = mpz_export(0, &written, 1, 1, 0, 0, pt->m);

 	if( written == len )
 		return buf0;

	buf1 = malloc(len);
	memset(buf1, 0, len);

	if( written == 0 )
		/* no need to copy anything, pt->m = 0 and buf0 was not allocated */
		return buf1;
	else if( written < len )
		/* pad with leading zeros */
		memcpy(buf1 + (len - written), buf0, written);
	else
		/* truncate leading garbage */
		memcpy(buf1, buf0 + (written - len), len);

	free(buf0);

	return buf1;
}
void generate_random_bytes(size_t n, void *result) {
#if !defined(NDEBUG)
  assert(curstate == 1);
  curstate = 2;
#endif
  if (n == 0) {
#if !defined(NDEBUG)
    assert(curstate == 2);
    curstate = 1;
#endif
    return;
  }
  for (;;) {
    hash_permutation(&state);
    if (n <= HASH_DATA_AREA) {
      memcpy(result, &state, n);
#if !defined(NDEBUG)
      assert(curstate == 2);
      curstate = 1;
#endif
      return;
    } else {
      memcpy(result, &state, HASH_DATA_AREA);
      result = padd(result, HASH_DATA_AREA);
      n -= HASH_DATA_AREA;
    }
  }
}
Example #3
0
static struct xfrm_state *ipcomp6_tunnel_create(struct xfrm_state *x)
{
	struct net *net = xs_net(x);
	struct xfrm_state *t = NULL;

	t = xfrm_state_alloc(net);
	if (!t)
		goto out;

	t->id.proto = IPPROTO_IPV6;
	t->id.spi = xfrm6_tunnel_alloc_spi(net, (xfrm_address_t *)&x->props.saddr);
	if (!t->id.spi)
		goto error;

	memcpy(t->id.daddr.a6, x->id.daddr.a6, sizeof(struct in6_addr));
	memcpy(&t->sel, &x->sel, sizeof(t->sel));
	t->props.family = AF_INET6;
	t->props.mode = x->props.mode;
	memcpy(t->props.saddr.a6, x->props.saddr.a6, sizeof(struct in6_addr));
	memcpy(&t->mark, &x->mark, sizeof(t->mark));

	if (xfrm_init_state(t))
		goto error;

	atomic_set(&t->tunnel_users, 1);

out:
	return t;

error:
	t->km.state = XFRM_STATE_DEAD;
	xfrm_state_put(t);
	t = NULL;
	goto out;
}
Example #4
0
inline void gemm_block_calc_A(
    float ALPHA, float BETA, 
    BlockedMatrix *A_blk, 
    BlockedMatrix *B_blk, 
    BlockedMatrix *C_blk, 
    float *A_buf, float *B_buf, float *T_buf, 
    float *C_buf, float *R_buf) 
{
  int num_blk_M=A_blk->H/BLK_M;
  int num_blk_N=B_blk->W/BLK_N;
  int num_blk_K=A_blk->W/BLK_K;

  int i, j, k, d, p, t;
  int num_depth, num_pipes;

  for (j = 0; j < num_blk_N; j ++) {
    for (i = 0; i < num_blk_M; i += NUM_DEPTH) {
      num_depth = ((i+NUM_DEPTH) <= num_blk_M) ? NUM_DEPTH : num_blk_M-i;
      // initialize C_buf
      for (d = 0; d < num_depth; d ++)
        memcpy(&C_buf[d*BLK_SIZE_MN], 
               &C_blk->mat[((i+d)*num_blk_N+j)*BLK_SIZE_MN],
               sizeof(float)*BLK_SIZE_MN);
      for (t = 0; t < NUM_DEPTH*BLK_SIZE_MN; t ++)
        C_buf[t] *= BETA;

      // Here NUM_DEPTH number of C blocks will be computed
      for (k = 0; k < num_blk_K; k += NUM_PIPES) {
        num_pipes = ((k+NUM_PIPES) <= num_blk_K) ? NUM_PIPES : num_blk_K-k;
        // initialize A_buf
        for (d = 0; d < num_depth; d ++)
          memcpy(&A_buf[d*PIPE_SIZE_MK],
                 &A_blk->mat[((i+d)*num_blk_K+k)*BLK_SIZE_MK],
                 sizeof(float)*PIPE_SIZE_MK);
        for (t = 0; t < NUM_DEPTH*PIPE_SIZE_MK; t ++)
          A_buf[t] *= ALPHA;
        
        // initialize B_buf
        for (p = 0; p < num_pipes; p ++) 
          for (d = 0; d < num_depth; d ++) 
            memcpy(&B_buf[d*PIPE_SIZE_KN+p*BLK_SIZE_KN], 
                   &B_blk->mat[((k+p)*num_blk_N+j)*BLK_SIZE_KN],
                   sizeof(float)*BLK_SIZE_KN);

        // compute
        gemm_block_units_mmult(A_buf,B_buf,T_buf);
        gemm_block_units_mplus(T_buf,C_buf,R_buf);

        // copy R_buf to C_buf
        memcpy(C_buf, R_buf, sizeof(float)*NUM_DEPTH*BLK_SIZE_MN);
      }

      // final write back
      for (d = 0; d < num_depth; d ++)
        memcpy(&C_blk->mat[((i+d)*num_blk_N+j)*BLK_SIZE_MN],
               &C_buf[d*BLK_SIZE_MN],
               sizeof(float)*BLK_SIZE_MN);
    }
  }
}
Example #5
0
unsigned char *EncryptXXTea::decode()
{
    UserData user_d = {10,20,30};
    unsigned char *t_data = (unsigned char *)&user_d;
    const  char *key_s = "YuanfeiTestXXTea";
    xxtea_long key_len = strlen(key_s);
    xxtea_long ret_len;
    unsigned char *bufs=xxtea_encrypt(t_data, sizeof(UserData), (unsigned char*)key_s, key_len, &ret_len);
    
    char t_buf[512];
    memset(&t_buf, 0, 512);
    memcpy(&t_buf, bufs, ret_len+1);
    
    key_s = "YuanfeiTestXXTea";
    key_len = strlen(key_s);
    xxtea_long de_len;
    unsigned char *de_data=xxtea_decrypt(bufs, ret_len, (unsigned char*)key_s, key_len, &de_len);
    memset(&t_buf, 0, 512);
    memcpy(&t_buf, de_data, ret_len+1);
    
    UserData decod;
    memset(&decod, 0, sizeof(UserData));
    memcpy(&decod, de_data, sizeof(UserData));
    return nullptr;

}
Example #6
0
/** As trn_cell_introduce1_parse(), but do not allocate the output
 * object.
 */
static ssize_t
trn_cell_introduce1_parse_into(trn_cell_introduce1_t *obj, const uint8_t *input, const size_t len_in)
{
  const uint8_t *ptr = input;
  size_t remaining = len_in;
  ssize_t result = 0;
  (void)result;

  /* Parse u8 legacy_key_id[TRUNNEL_SHA1_LEN] */
  CHECK_REMAINING(TRUNNEL_SHA1_LEN, truncated);
  memcpy(obj->legacy_key_id, ptr, TRUNNEL_SHA1_LEN);
  remaining -= TRUNNEL_SHA1_LEN; ptr += TRUNNEL_SHA1_LEN;

  /* Parse u8 auth_key_type IN [0, 1, 2] */
  CHECK_REMAINING(1, truncated);
  obj->auth_key_type = (trunnel_get_uint8(ptr));
  remaining -= 1; ptr += 1;
  if (! (obj->auth_key_type == 0 || obj->auth_key_type == 1 || obj->auth_key_type == 2))
    goto fail;

  /* Parse u16 auth_key_len */
  CHECK_REMAINING(2, truncated);
  obj->auth_key_len = trunnel_ntohs(trunnel_get_uint16(ptr));
  remaining -= 2; ptr += 2;

  /* Parse u8 auth_key[auth_key_len] */
  CHECK_REMAINING(obj->auth_key_len, truncated);
  TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->auth_key, obj->auth_key_len, {});
  obj->auth_key.n_ = obj->auth_key_len;
  if (obj->auth_key_len)
    memcpy(obj->auth_key.elts_, ptr, obj->auth_key_len);
  ptr += obj->auth_key_len; remaining -= obj->auth_key_len;

  /* Parse struct trn_cell_extension extensions */
  result = trn_cell_extension_parse(&obj->extensions, ptr, remaining);
  if (result < 0)
    goto relay_fail;
  trunnel_assert((size_t)result <= remaining);
  remaining -= result; ptr += result;

  /* Parse u8 encrypted[] */
  TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->encrypted, remaining, {});
  obj->encrypted.n_ = remaining;
  if (remaining)
    memcpy(obj->encrypted.elts_, ptr, remaining);
  ptr += remaining; remaining -= remaining;
  trunnel_assert(ptr + remaining == input + len_in);
  return len_in - remaining;

 truncated:
  return -2;
 relay_fail:
  trunnel_assert(result < 0);
  return result;
 trunnel_alloc_failed:
  return -1;
 fail:
  result = -1;
  return result;
}
Example #7
0
static int frame_to_frame_xlate(AVCodecContext * avctx, AVFrame * picture,
		int * outlen, char * out)
{
	int line;

	*outlen = avctx->width * avctx->height * 6 / 4;

	for ( line = 0; line < avctx->height / 2; ++line )
	{
		/* y even */
		memcpy(out + avctx->width * (2 * line + 0),
		       picture->data[0] + (2 * line + 0) * picture->linesize[0],
		       avctx->width);

		/* y odd */
		memcpy(out + avctx->width * (2 * line + 1),
		       picture->data[0] + (2 * line + 1) * picture->linesize[0],
		       avctx->width);

		/* u + v */
		memcpy(out + avctx->width * avctx->height
				+ line * avctx->width / 2,
		       picture->data[1] + line * picture->linesize[1],
		       avctx->width / 2);

		memcpy(out + avctx->width * avctx->height * 5 / 4
				+ line * avctx->width / 2,
		       picture->data[2] + line * picture->linesize[2],
		       avctx->width / 2);
	}

	return 0;
}
Example #8
0
oam_status cv_oam_vam_cfg_set(uint32_t mask, vam_config_t * cfg)
{
    uint8_t buf[CV_SDK_MSG_MAX_LEN] = {0};
    cv_sdk_msg_t *pMsg = (cv_sdk_msg_t *)buf;
    oam_status result = OAM_E_ERROR;
    cv_vam_cfg_set_msg_wrap_t * _wrap_cfg = (cv_vam_cfg_set_msg_wrap_t*)(pMsg->data);

    if( NULL == cfg){
        return OAM_E_PARAM;
    }

    memset(buf,0x00,sizeof(buf));

    pMsg->len = sizeof(cv_vam_cfg_set_msg_wrap_t);
    pMsg->sdk_id = CV_SDK_VAM_PARAM_CFG_SET;

    _wrap_cfg->mask = mask;
    memcpy(&_wrap_cfg->cfg, cfg, sizeof(vam_config_t));

    result = (oam_status)  cv_oam_sdk_api_request(pMsg);
    memcpy(cfg, &_wrap_cfg->cfg, sizeof(vam_config_t));

    if(result != OAM_E_OK){
        return result;
    }

    return OAM_E_OK;
}
Example #9
0
static int prp_read(const char* path, char* buf, size_t size, off_t offset,
                    fuse_file_info* fi)
{
    if (strcmp(path, "/" PAGEINFO) == 0) {
        // TODO
        return -1;
    }

    plString ext = plString(path).afterLast('.');
    FileCache* fc = s_openfiles[fi->fh - 1];
    if (ext == "prc") {
        if (offset >= fc->prcsize)
            return 0;
        if (offset + size > fc->prcsize)
            size = fc->prcsize - offset;
        memcpy(buf, fc->prcdata + offset, size);
        return size;
    } else if (ext == "po") {
        if (offset >= fc->objsize)
            return 0;
        if (offset + size > fc->objsize)
            size = fc->objsize - offset;
        memcpy(buf, fc->objdata + offset, size);
        return size;
    } else {
        return -ENOENT;
    }
}
Example #10
0
/*
 * Construct a key
 *
 */
int _sasldb_alloc_key(const sasl_utils_t *utils,
                      const char *auth_identity,
                      const char *realm,
                      const char *propName,
                      char **key,
                      size_t *key_len)
{
    size_t auth_id_len, realm_len, prop_len;

    if(!utils || !auth_identity || !realm || !propName || !key || !key_len)
        return SASL_BADPARAM;

    auth_id_len = strlen(auth_identity);
    realm_len = strlen(realm);
    prop_len = strlen(propName);

    *key_len = auth_id_len + realm_len + prop_len + 2;
    *key = utils->malloc(*key_len);
    if (! *key)
        return SASL_NOMEM;
    memcpy(*key, auth_identity, auth_id_len);
    (*key)[auth_id_len] = '\0';
    memcpy(*key + auth_id_len + 1, realm, realm_len);
    (*key)[auth_id_len + realm_len + 1] = '\0';
    memcpy(*key + auth_id_len + realm_len + 2, propName, prop_len);

    return SASL_OK;
}
Example #11
0
void DRV_AviSoundUpdate(void* soundData, int soundLen)
{
	if(!AVI_IsRecording() || !avi_file->sound_added)
		return;

	const int audioSegmentSize = avi_audiosegment_size(avi_file);
	const int samplesPerSegment = audioSegmentSize / avi_file->wave_format.nBlockAlign;
	const int soundSize = soundLen * avi_file->wave_format.nBlockAlign;
	int nBytes = soundSize;
	while (avi_file->audio_buffer_pos + nBytes > audioSegmentSize) {
		const int bytesToTransfer = audioSegmentSize - avi_file->audio_buffer_pos;
		memcpy(&avi_file->audio_buffer[avi_file->audio_buffer_pos], &((u8*)soundData)[soundSize - nBytes], bytesToTransfer);
		nBytes -= bytesToTransfer;

		if(FAILED(AVIStreamWrite(avi_file->compressed_streams[AUDIO_STREAM],
		                         avi_file->sound_samples, samplesPerSegment,
		                         avi_file->audio_buffer, audioSegmentSize, 0, NULL, &avi_file->ByteBuffer)))
		{
			avi_file->valid = 0;
			return;
		}
		avi_file->sound_samples += samplesPerSegment;
		avi_file->tBytes += avi_file->ByteBuffer;
		avi_file->audio_buffer_pos = 0;
	}
	memcpy(&avi_file->audio_buffer[avi_file->audio_buffer_pos], &((u8*)soundData)[soundSize - nBytes], nBytes);
	avi_file->audio_buffer_pos += nBytes;
}
Example #12
0
File: vector.c Project: 198767/cyy2
void* vect_delelmat(vector vector,int index)
{ 
	int real_index;
	int i;
	if(vector->size==0)
		return NULL;
	//确定下标
	if(index>=0)
	{
		if(index>=vector->size)
			real_index=vector->size-1;
		else
			real_index=index;
	}
	else
	{
		real_index=vector->size+index;
		if(real_index<0)
			real_index=0;
	}

	//把要删除的元素放在del_data
	memcpy(vector->del_data, vector->data+real_index*vector->element_size, vector->element_size); 
	//元素往前移动
	for(i=real_index;i<vector->size-1;i++)
		memcpy(vector->data+i*vector->element_size, vector->data+(i+1)*vector->element_size, vector->element_size); 

	vector->size--;
	return vector->del_data;
}
Example #13
0
static void
asc_write_string(struct conn *c, const char *str, size_t len)
{
    log_debug(LOG_VVERB, "write on c %d noreply %d str '%.*s'", c->sd,
              c->noreply, len, str);

    if (c->noreply) {
        c->noreply = 0;
        conn_set_state(c, CONN_NEW_CMD);
        return;
    }

    if ((len + CRLF_LEN) > c->wsize) {
        log_warn("server error on c %d for str '%.*s' because wbuf is not big "
                 "enough", c->sd, len, str);

        stats_thread_incr(server_error);
        str = "SERVER_ERROR";
        len = sizeof("SERVER_ERROR") - 1;
    }

    memcpy(c->wbuf, str, len);
    memcpy(c->wbuf + len, CRLF, CRLF_LEN);
    c->wbytes = len + CRLF_LEN;
    c->wcurr = c->wbuf;

    conn_set_state(c, CONN_WRITE);
    c->write_and_go = CONN_NEW_CMD;
}
Example #14
0
/* Send open command to device */
static int usb_8dev_cmd_open(struct usb_8dev_priv *priv)
{
	struct can_bittiming *bt = &priv->can.bittiming;
	struct usb_8dev_cmd_msg outmsg;
	struct usb_8dev_cmd_msg inmsg;
	u32 ctrlmode = priv->can.ctrlmode;
	u32 flags = USB_8DEV_STATUS_FRAME;
	__be32 beflags;
	__be16 bebrp;

	memset(&outmsg, 0, sizeof(outmsg));
	outmsg.command = USB_8DEV_OPEN;
	outmsg.opt1 = USB_8DEV_BAUD_MANUAL;
	outmsg.data[0] = bt->prop_seg + bt->phase_seg1;
	outmsg.data[1] = bt->phase_seg2;
	outmsg.data[2] = bt->sjw;

	/* BRP */
	bebrp = cpu_to_be16((u16)bt->brp);
	memcpy(&outmsg.data[3], &bebrp, sizeof(bebrp));

	/* flags */
	if (ctrlmode & CAN_CTRLMODE_LOOPBACK)
		flags |= USB_8DEV_LOOPBACK;
	if (ctrlmode & CAN_CTRLMODE_LISTENONLY)
		flags |= USB_8DEV_SILENT;
	if (ctrlmode & CAN_CTRLMODE_ONE_SHOT)
		flags |= USB_8DEV_DISABLE_AUTO_RESTRANS;

	beflags = cpu_to_be32(flags);
	memcpy(&outmsg.data[5], &beflags, sizeof(beflags));

	return usb_8dev_send_cmd(priv, &outmsg, &inmsg);
}
Example #15
0
/* FIXME: This function is currently not used anywhere */
int dccp_insert_option_elapsed_time(struct sk_buff *skb, u32 elapsed_time)
{
    const int elapsed_time_len = dccp_elapsed_time_len(elapsed_time);
    const int len = 2 + elapsed_time_len;
    unsigned char *to;

    if (elapsed_time_len == 0)
        return 0;

    if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
        return -1;

    DCCP_SKB_CB(skb)->dccpd_opt_len += len;

    to    = skb_push(skb, len);
    *to++ = DCCPO_ELAPSED_TIME;
    *to++ = len;

    if (elapsed_time_len == 2) {
        const __be16 var16 = htons((u16)elapsed_time);
        memcpy(to, &var16, 2);
    } else {
        const __be32 var32 = htonl(elapsed_time);
        memcpy(to, &var32, 4);
    }

    return 0;
}
Example #16
0
static void compat_input(struct dlm_write_request *kb,
			 struct dlm_write_request32 *kb32,
			 int namelen)
{
	kb->version[0] = kb32->version[0];
	kb->version[1] = kb32->version[1];
	kb->version[2] = kb32->version[2];

	kb->cmd = kb32->cmd;
	kb->is64bit = kb32->is64bit;
	if (kb->cmd == DLM_USER_CREATE_LOCKSPACE ||
	    kb->cmd == DLM_USER_REMOVE_LOCKSPACE) {
		kb->i.lspace.flags = kb32->i.lspace.flags;
		kb->i.lspace.minor = kb32->i.lspace.minor;
		memcpy(kb->i.lspace.name, kb32->i.lspace.name, namelen);
	} else if (kb->cmd == DLM_USER_PURGE) {
		kb->i.purge.nodeid = kb32->i.purge.nodeid;
		kb->i.purge.pid = kb32->i.purge.pid;
	} else {
		kb->i.lock.mode = kb32->i.lock.mode;
		kb->i.lock.namelen = kb32->i.lock.namelen;
		kb->i.lock.flags = kb32->i.lock.flags;
		kb->i.lock.lkid = kb32->i.lock.lkid;
		kb->i.lock.parent = kb32->i.lock.parent;
		kb->i.lock.xid = kb32->i.lock.xid;
		kb->i.lock.timeout = kb32->i.lock.timeout;
		kb->i.lock.castparam = (void *)(long)kb32->i.lock.castparam;
		kb->i.lock.castaddr = (void *)(long)kb32->i.lock.castaddr;
		kb->i.lock.bastparam = (void *)(long)kb32->i.lock.bastparam;
		kb->i.lock.bastaddr = (void *)(long)kb32->i.lock.bastaddr;
		kb->i.lock.lksb = (void *)(long)kb32->i.lock.lksb;
		memcpy(kb->i.lock.lvb, kb32->i.lock.lvb, DLM_USER_LVB_LEN);
		memcpy(kb->i.lock.name, kb32->i.lock.name, namelen);
	}
}
Example #17
0
bool SlottedPage::tryUpdateSlotWithIndirection(uint16_t slotID, char const *dataptr, uint16_t lenInBytes) {
    Slot* s = &slots[slotID];
    if(getFreeSpaceInBytes() >= lenInBytes){
        header.dataStart -= lenInBytes;
        memcpy( &data[header.dataStart], dataptr, lenInBytes);

        s->offset = header.dataStart;
        s->length = lenInBytes;

        setControlbitsToDefault(slotID);
        //here we have completely removed the TID, which was previously stored in this slot
        return true;
    }
    //4. (length is greater than before && space after defrag) -> defrag and insert anywhere on page -> update length & offset
    else if(getFreeSpaceInBytesAfterDefrag() >= lenInBytes){
        defrag();

        header.dataStart -= lenInBytes;
        memcpy( &data[header.dataStart], dataptr, lenInBytes);

        s->offset = header.dataStart;
        s->length = lenInBytes;

        setControlbitsToDefault(slotID);
        //here we have completely removed the TID, which was previously stored in this slot
        return true;
    }
    return false;
}
Example #18
0
static int tpm_emulator_ctrlcmd(TPMEmulator *tpm, unsigned long cmd, void *msg,
                                size_t msg_len_in, size_t msg_len_out)
{
    CharBackend *dev = &tpm->ctrl_chr;
    uint32_t cmd_no = cpu_to_be32(cmd);
    ssize_t n = sizeof(uint32_t) + msg_len_in;
    uint8_t *buf = NULL;
    int ret = -1;

    qemu_mutex_lock(&tpm->mutex);

    buf = g_alloca(n);
    memcpy(buf, &cmd_no, sizeof(cmd_no));
    memcpy(buf + sizeof(cmd_no), msg, msg_len_in);

    n = qemu_chr_fe_write_all(dev, buf, n);
    if (n <= 0) {
        goto end;
    }

    if (msg_len_out != 0) {
        n = qemu_chr_fe_read_all(dev, msg, msg_len_out);
        if (n <= 0) {
            goto end;
        }
    }

    ret = 0;

end:
    qemu_mutex_unlock(&tpm->mutex);
    return ret;
}
/*
 * INT64
 */
 int pmix_bfrop_pack_int64(pmix_buffer_t *buffer, const void *src,
                           int32_t num_vals, pmix_data_type_t type)
 {
    int32_t i;
    uint64_t tmp, tmp2;
    char *dst;
    size_t bytes_packed = num_vals * sizeof(tmp);

    pmix_output_verbose(20, pmix_globals.debug_output, "pmix_bfrop_pack_int64 * %d\n", num_vals);
    /* check to see if buffer needs extending */
    if (NULL == (dst = pmix_bfrop_buffer_extend(buffer, bytes_packed))) {
        return PMIX_ERR_OUT_OF_RESOURCE;
    }

    for (i = 0; i < num_vals; ++i) {
        memcpy(&tmp2, (char *)src+i*sizeof(uint64_t), sizeof(uint64_t));
        tmp = pmix_hton64(tmp2);
        memcpy(dst, &tmp, sizeof(tmp));
        dst += sizeof(tmp);
    }
    buffer->pack_ptr += bytes_packed;
    buffer->bytes_used += bytes_packed;

    return PMIX_SUCCESS;
}
Example #20
0
/*
 * encoder_output_gop_size:
 * @encoder_output: (in): the encoder output.
 * @rap_addr: (in): the rap addr
 *
 * get gop size.
 *
 * Returns: size of gop.
 *
 */
guint64 encoder_output_gop_size (EncoderOutput *encoder_output, guint64 rap_addr)
{
        gint gop_size;
        guint64 gop_size_addr;

        /* gop size address */
        if (rap_addr + 8 < encoder_output->cache_size) {
                gop_size_addr = rap_addr + 8;

        } else {
                gop_size_addr = rap_addr + 8 - encoder_output->cache_size;
        }

        /* gop size */
        if (gop_size_addr + 4 < encoder_output->cache_size) {
                memcpy (&gop_size, encoder_output->cache_addr + gop_size_addr, 4);

        } else {
                gint n;

                n = encoder_output->cache_size - gop_size_addr;
                memcpy (&gop_size, encoder_output->cache_addr + gop_size_addr, n);
                memcpy (&gop_size + n, encoder_output->cache_addr, 4 - n);
        }

        return gop_size;
}
Example #21
0
void gearman_universal_set_error(gearman_universal_st *universal, const char *function,
                                 const char *format, ...)
{
  size_t size;
  char *ptr;
  char log_buffer[GEARMAN_MAX_ERROR_SIZE];
  va_list args;

  size= strlen(function);
  ptr= memcpy(log_buffer, function, size);
  ptr+= size;
  ptr[0]= ':';
  size++;
  ptr++;

  va_start(args, format);
  size+= (size_t)vsnprintf(ptr, GEARMAN_MAX_ERROR_SIZE - size, format, args);
  va_end(args);

  if (universal->log_fn == NULL)
  {
    if (size >= GEARMAN_MAX_ERROR_SIZE)
      size= GEARMAN_MAX_ERROR_SIZE - 1;

    memcpy(universal->last_error, log_buffer, size + 1);
  }
  else
  {
    universal->log_fn(log_buffer, GEARMAN_VERBOSE_FATAL,
                      (void *)universal->log_context);
  }
}
Example #22
0
File: tty.c Project: Hooman3/minix
static void
do_new_kmess(void)
{
/* Kernel wants to print a new message */
	struct kmessages *kmess_ptr;	/* kmessages structure */
	char kernel_buf_copy[_KMESS_BUF_SIZE];
	static int prev_next = 0;
	int next, bytes, copy, restore = 0;
	tty_t *tp, rtp;

	assert(_minix_kerninfo);
	kmess_ptr = _minix_kerninfo->kmessages;

	/* The kernel buffer is circular; print only the new part. Determine
	 * how many new bytes there are with the help of current and
	 * previous 'next' index. This works fine if less than _KMESS_BUF_SIZE
	 * bytes is new data; else we miss % _KMESS_BUF_SIZE here. Obtain
	 * 'next' only once, since we are operating on shared memory here.
	 * Check for size being positive; the buffer might as well be emptied!
	 */
	next = kmess_ptr->km_next;
	bytes = ((next + _KMESS_BUF_SIZE) - prev_next) % _KMESS_BUF_SIZE;
	if (bytes > 0) {
		/* Copy from current position toward end of buffer */
		copy = MIN(_KMESS_BUF_SIZE - prev_next, bytes);
		memcpy(kernel_buf_copy, &kmess_ptr->km_buf[prev_next], copy);

		/* Copy remainder from start of buffer */
		if (copy < bytes) {
			memcpy(&kernel_buf_copy[copy], &kmess_ptr->km_buf[0],
				bytes - copy);
		}

		tp = line2tty(consoleline);
		if (tp == NULL)
			panic("Don't know where to send kernel messages");
		if (tp->tty_outleft > 0) {
			/* Terminal is already printing */
			rtp = *tp;	/* Make backup */
			tp->tty_outleft = 0; /* So do_write is happy */
			restore = 1;
		}

		if (kernel_msg_color != 0)
			set_color(tp, kernel_msg_color);
		do_write(tp->tty_minor, 0, KERNEL,
			(cp_grant_id_t) kernel_buf_copy, bytes,
			CDEV_NONBLOCK, 0);
		if (kernel_msg_color != 0)
			reset_color(tp);
		if (restore) {
			*tp = rtp;
		}
	}

	/* Store 'next' pointer so that we can determine what part of the
	 * kernel messages buffer to print next time a notification arrives.
	 */
	prev_next = next;
}
Example #23
0
uint8_t *av_packet_pack_dictionary(AVDictionary *dict, int *size)
{
    AVDictionaryEntry *t = NULL;
    uint8_t *data = NULL;
    *size = 0;

    if (!dict)
        return NULL;

    while ((t = av_dict_get(dict, "", t, AV_DICT_IGNORE_SUFFIX))) {
        const size_t keylen   = strlen(t->key);
        const size_t valuelen = strlen(t->value);
        const size_t new_size = *size + keylen + 1 + valuelen + 1;
        uint8_t *const new_data = av_realloc(data, new_size);

        if (!new_data)
            goto fail;
        data = new_data;
        if (new_size > INT_MAX)
            goto fail;

        memcpy(data + *size, t->key, keylen + 1);
        memcpy(data + *size + keylen + 1, t->value, valuelen + 1);

        *size = new_size;
    }

    return data;

fail:
    av_freep(&data);
    *size = 0;
    return NULL;
}
Example #24
0
CTag::CTag(const CTag& rTag)
{
	m_uType = rTag.m_uType;
	m_uName = rTag.m_uName;
	m_Name = rTag.m_Name;
	m_nSize = 0;
	if (rTag.IsStr()) {
		m_pstrVal = new wxString(rTag.GetStr());
	} else if (rTag.IsInt()) {
		m_uVal = rTag.GetInt();
	} else if (rTag.IsFloat()) {
		m_fVal = rTag.GetFloat();
	} else if (rTag.IsHash()) {
		m_hashVal = new CMD4Hash(rTag.GetHash());
	} else if (rTag.IsBlob()) {
		m_nSize = rTag.GetBlobSize();
		m_pData = new unsigned char[rTag.GetBlobSize()];
		memcpy(m_pData, rTag.GetBlob(), rTag.GetBlobSize());
	} else if (rTag.IsBsob()) {
		m_nSize = rTag.GetBsobSize();
		m_pData = new unsigned char[rTag.GetBsobSize()];
		memcpy(m_pData, rTag.GetBsob(), rTag.GetBsobSize());
	} else {
		wxFAIL;
		m_uVal = 0;
	}
}
Example #25
0
/**
 * MP Reach Link State NLRI parse
 *
 * \details Will handle parsing the link state NLRI
 *
 * \param [in]   nlri           Reference to parsed NLRI struct
 */
void MPLinkState::parseReachLinkState(MPReachAttr::mp_reach_nlri &nlri) {
    ls_data = &parsed_data->ls;

    // Process the next hop
    // Next-hop is an IPv6 address - Change/set the next-hop attribute in parsed data to use this next-hop
    u_char ip_raw[16];
    char ip_char[40];

    if (nlri.nh_len == 4) {
        memcpy(ip_raw, nlri.next_hop, nlri.nh_len);
        inet_ntop(AF_INET, ip_raw, ip_char, sizeof(ip_char));
    } else if (nlri.nh_len > 4) {
        memcpy(ip_raw, nlri.next_hop, nlri.nh_len);
        inet_ntop(AF_INET6, ip_raw, ip_char, sizeof(ip_char));
    }

    parsed_data->attrs[ATTR_TYPE_NEXT_HOP] = std::string(ip_char);

    /*
     * Decode based on SAFI
     */
    switch (nlri.safi) {
    case bgp::BGP_SAFI_BGPLS: // Unicast BGP-LS
        SELF_DEBUG("REACH: bgp-ls: len=%d", nlri.nlri_len);
        parseLinkStateNlriData(nlri.nlri_data, nlri.nlri_len);
        break;

    default :
        LOG_INFO("%s: MP_UNREACH AFI=bgp-ls SAFI=%d is not implemented yet, skipping for now",
                 peer_addr.c_str(), nlri.afi, nlri.safi);
        return;
    }
}
Example #26
0
static int poll_fd_resize(struct poll_fd_mgr *poll_mgr, int size)
{
	struct pollfd *new_poll_fds;
	struct poll_fd_info *new_poll_info;

	new_poll_fds = calloc(size, sizeof(*new_poll_fds));
	if (!new_poll_fds)
		return -FI_ENOMEM;

	new_poll_info = calloc(size, sizeof(*new_poll_info));
	if (!new_poll_info) {
		free(new_poll_fds);
		return -FI_ENOMEM;
	}

	if (poll_mgr->max_nfds) {
		memcpy(new_poll_fds, poll_mgr->poll_fds,
		       poll_mgr->max_nfds * sizeof(*new_poll_fds));
		free(poll_mgr->poll_fds);

		memcpy(new_poll_info, poll_mgr->poll_info,
		       poll_mgr->max_nfds * sizeof(*new_poll_info));
		free(poll_mgr->poll_info);
	}

	poll_mgr->poll_fds = new_poll_fds;
	poll_mgr->poll_info = new_poll_info;
	poll_mgr->max_nfds = size;

	return 0;
}
Example #27
0
static int __init acpi_read_sdt_at(void *sdt_va,
                                   struct acpi_sdt_hdr * tb,
                                   size_t size,
                                   const char * name)
{
    struct acpi_sdt_hdr hdr;

    /* if NULL is supplied, we only return the size of the table */
    if (tb == NULL) {
        memcpy(&hdr, sdt_va, sizeof(struct acpi_sdt_hdr));
        return hdr.len;
    }

    memcpy(tb, sdt_va, sizeof(struct acpi_sdt_hdr));

    if (acpi_check_signature((const char *)tb->signature,
                             (const char *)name)) {
        vmm_printf("ACPI ERROR: acpi %s signature does not match\n", name);
        return VMM_EFAIL;
    }

    if (size < tb->len) {
        vmm_printf("ACPI ERROR: acpi buffer too small for %s\n", name);
        return VMM_EFAIL;
    }

    memcpy(tb, sdt_va, size);

    if (acpi_check_csum(tb, tb->len)) {
        vmm_printf("ACPI ERROR: acpi %s checksum does not match\n", name);
        return VMM_EFAIL;
    }

    return tb->len;
}
Example #28
0
void DiscardDeint::filter(QQueue< FrameBuffer > &framesQueue)
{
    int insertAt = addFramesToDeinterlace(framesQueue);
    while (!internalQueue.isEmpty())
    {
        FrameBuffer dequeued = internalQueue.dequeue();
        VideoFrame *videoFrame = VideoFrame::fromData(dequeued.data);
        const bool TFF = isTopFieldFirst(videoFrame);
        videoFrame->setNoInterlaced();
        for (int p = 0; p < 3; ++p)
        {
            const int linesize = videoFrame->linesize[p];
            quint8 *src = videoFrame->data[p];
            quint8 *dst = videoFrame->data[p];
            const int lines = (p ? h >> 2 : h >> 1) - 1;
            if (!TFF)
            {
                memcpy(dst, src + linesize, linesize);
                src += linesize;
                dst += linesize;
            }
            dst += linesize;
            src += linesize;
            for (int i = 0; i < lines; ++i)
            {
                VideoFilters::averageTwoLines(dst, src - linesize, src + linesize, linesize);
                src += linesize << 1;
                dst += linesize << 1;
            }
            if (TFF)
                memcpy(dst, src - linesize, linesize);
        }
        framesQueue.insert(insertAt++, dequeued);
    }
}
Example #29
0
size_t CRYPTO_cts128_encrypt_block(const unsigned char *in,
                                   unsigned char *out, size_t len,
                                   const void *key, unsigned char ivec[16],
                                   block128_f block)
{
    size_t residue, n;

    assert(in && out && key && ivec);

    if (len <= 16)
        return 0;

    if ((residue = len % 16) == 0)
        residue = 16;

    len -= residue;

    CRYPTO_cbc128_encrypt(in, out, len, key, ivec, block);

    in += len;
    out += len;

    for (n = 0; n < residue; ++n)
        ivec[n] ^= in[n];
    (*block) (ivec, ivec, key);
    memcpy(out, out - 16, residue);
    memcpy(out - 16, ivec, 16);

    return len + residue;
}
Example #30
0
static unsigned char *
sc_gp_get_session_key(struct sc_context *ctx, struct sm_gp_session *gp_session,
		unsigned char *key)
{
	int out_len;
	unsigned char *out;
	unsigned char deriv[16];

	memcpy(deriv,		gp_session->card_challenge + 4,	4);
	memcpy(deriv + 4,	gp_session->host_challenge,	4);
	memcpy(deriv + 8,	gp_session->card_challenge,	4);
	memcpy(deriv + 12,	gp_session->host_challenge + 4,	4);

	if (sm_encrypt_des_ecb3(key, deriv, 16, &out, &out_len))   {
		if (ctx)
			sc_debug(ctx, SC_LOG_DEBUG_VERBOSE, "SM GP get session key: des_ecb3 encryption error");
		free(out);
		return NULL;
	}
	else if (out==NULL  || out_len!=16)   {
		if (ctx)
			sc_debug(ctx, SC_LOG_DEBUG_VERBOSE, "SM GP get session key: des_ecb3 encryption error: out(%p,len:%i)", out, out_len);
		if (out)
			free(out);
		return NULL;
	}

	return out;
}