Exemplo n.º 1
0
// Initialize B object by placing all Raws into one Bi
// Called on B construction
void b_init(B *b) {
  unsigned int i, index;
  
  // Destruct existing clusters
  for(i=0; i<b->nclust; i++) {
    bi_free(b->bi[i]);
  }
  b->nclust=0;
  
  // Add the one cluster and initialize its "birth" information
  b_add_bi(b, bi_new(b->nraw));
  strcpy(b->bi[0]->birth_type, "I");
  b->bi[0]->birth_pval = 0.0;
  b->bi[0]->birth_fold = 1.0;
  b->bi[0]->birth_e = b->reads;
  b->nalign = 0;
  b->nshroud = 0;
  
  // Add all raws to that cluster
  for (index=0; index<b->nraw; index++) {
    bi_add_raw(b->bi[0], b->raw[index]);
  }
  
  bi_census(b->bi[0]);
  bi_assign_center(b->bi[0]); // Makes cluster center sequence
}
Exemplo n.º 2
0
/* from DAAUtil */
bi_ptr project_into_group_gamma( bi_ptr base, TSS_DAA_PK_internal *issuer_pk) {
	bi_t exponent; bi_new( exponent);
	bi_ptr capital_gamma  = issuer_pk->capitalGamma;
	bi_ptr rho = issuer_pk->rho;
	bi_ptr zeta = bi_new_ptr();

	if( capital_gamma == NULL ||
		rho == NULL ||
		zeta == NULL) return NULL;
	// exponent = capital_gamma - 1
	bi_sub( exponent, capital_gamma, bi_1);
	// exponent = exponent / rho
	bi_div( exponent, exponent, rho);
	// zeta = ( base ^ exponent) % capital_gamma
	LogDebug("project_into_group_gamma:           rho      [%ld]:%s",
			bi_nbin_size( rho), bi_2_hex_char( rho));
	LogDebug("project_into_group_gamma:               base[%ld]:%s",
			bi_nbin_size( base), bi_2_hex_char( base));
	LogDebug("project_into_group_gamma: exponent       [%ld]:%s",
			bi_nbin_size( exponent), bi_2_hex_char( exponent));
	LogDebug("project_into_group_gamma: capitalGamma[%ld]:%s",
		bi_nbin_size( capital_gamma),
		bi_2_hex_char( capital_gamma));
	bi_mod_exp( zeta, base, exponent, capital_gamma);
	LogDebug("project_into_group_gamma: result:%s", bi_2_hex_char( zeta));
	bi_free( exponent);
	return zeta;
}
Exemplo n.º 3
0
inline bi_ptr apply_challenge( bi_ptr value, bi_ptr delta, bi_ptr c, bi_ptr capital_gamma) {
	bi_ptr delta_tilde = bi_new_ptr();
	bi_t c_negate;

	if( delta_tilde == NULL) return NULL;
	bi_new( c_negate);
	bi_set( c_negate, c);
	bi_negate( c_negate);
	// delta_tilde = ( delta ^ (-c)) % capital_gamma
	bi_mod_exp( delta_tilde, delta, c_negate, capital_gamma);
	bi_free( c_negate);
	// delta_tilde = (delta_tilde * value) % capital_gamma
	return bi_mod( delta_tilde, bi_mul( delta_tilde, delta_tilde, value), capital_gamma);
}
Exemplo n.º 4
0
Arquivo: bitree.c Projeto: taysom/tau
int bi_insert (BiTree_s *tree, Rec_s r)
{
	BiNode_s **np = &tree->root;
	for (;;) {
		BiNode_s *node = *np;
		if (!node) break;
		if (cmplump(r.key, node->rec.key) < 0) {
			np = &node->left;
		} else {
			np = &node->right;
		}
	}
	*np = bi_new(r);
	return 0;
}
Exemplo n.º 5
0
static bool process_block(const struct bp_block *block, int64_t fpos)
{
	struct blkinfo *bi = bi_new();
	bu256_copy(&bi->hash, &block->sha256);
	bp_block_copy_hdr(&bi->hdr, block);
	bi->n_file = 0;
	bi->n_pos = fpos;

	struct blkdb_reorg reorg;

	if (!blkdb_add(&db, bi, &reorg)) {
		fprintf(plog, "brd: blkdb add fail\n");
		goto err_out;
	}

	/* FIXME: support reorg */
	assert(reorg.conn == 1);
	assert(reorg.disconn == 0);

	/* if best chain, mark TX's as spent */
	if (bu256_equal(&db.best_chain->hash, &bi->hdr.sha256)) {
		if (!spend_block(&uset, block, bi->height)) {
			char hexstr[BU256_STRSZ];
			bu256_hex(hexstr, &bi->hdr.sha256);
			fprintf(plog,
				"brd: block spend fail %u %s\n",
				bi->height, hexstr);
			/* FIXME: bad record is now in blkdb */
			goto err_out;
		}
	}

	return true;

err_out:
	bi_free(bi);
	return false;
}
Exemplo n.º 6
0
static void read_test_msg(struct blkdb *db, struct bp_utxo_set *uset,
			  const struct p2p_message *msg, int64_t fpos)
{
	assert(strncmp(msg->hdr.command, "block",
		       sizeof(msg->hdr.command)) == 0);

	struct bp_block block;
	bp_block_init(&block);

	struct const_buffer buf = { msg->data, msg->hdr.data_len };
	assert(deser_bp_block(&block, &buf) == true);
	bp_block_calc_sha256(&block);

	assert(bp_block_valid(&block) == true);

	struct blkinfo *bi = bi_new();
	bu256_copy(&bi->hash, &block.sha256);
	bp_block_copy_hdr(&bi->hdr, &block);
	bi->n_file = 0;
	bi->n_pos = fpos + P2P_HDR_SZ;

	assert(blkdb_add(db, bi) == true);

	/* if best chain, mark TX's as spent */
	if (bu256_equal(&db->hashBestChain, &bi->hdr.sha256)) {
		if (!spend_block(uset, &block, bi->height)) {
			char hexstr[BU256_STRSZ];
			bu256_hex(hexstr, &bi->hdr.sha256);
			fprintf(stderr, 
				"chain-verf: block fail %u %s\n",
				bi->height, hexstr);
			assert(!"spend_block");
		}
	}

	bp_block_free(&block);
}
Exemplo n.º 7
0
static bool blkdb_read_rec(struct blkdb *db, const struct p2p_message *msg)
{
	struct blkinfo *bi;
	struct const_buffer buf = { msg->data, msg->hdr.data_len };

	if (strncmp(msg->hdr.command, "rec", 12))
		return false;

	bi = bi_new();
	if (!bi)
		return false;

	/* deserialize record */
	if (!deser_u256(&bi->hash, &buf))
		goto err_out;
	if (!deser_bp_block(&bi->hdr, &buf))
		goto err_out;

	/* verify that provided hash matches block header, as an additional
	 * self-verification step
	 */
	bp_block_calc_sha256(&bi->hdr);
	if (!bu256_equal(&bi->hash, &bi->hdr.sha256))
		goto err_out;

	/* verify block may be added to chain, then add it */
	struct blkdb_reorg dummy;
	if (!blkdb_connect(db, bi, &dummy))
		goto err_out;

	return true;

err_out:
	bi_free(bi);
	return false;
}