예제 #1
0
파일: vars.c 프로젝트: srijan/ncdc
static char *i_cid_pid() {
  if(db_vars_get(0, "cid") && db_vars_get(0, "pid"))
    return NULL;

  guint64 r = rand_64();

  struct tiger_ctx t;
  char pid[24];
  tiger_init(&t);
  tiger_update(&t, (char *)&r, 8);
  tiger_final(&t, pid);

  // now hash the PID so we have our CID
  char cid[24];
  tiger_init(&t);
  tiger_update(&t, pid, 24);
  tiger_final(&t, cid);

  // encode and save
  char enc[40] = {};
  base32_encode(pid, enc);
  db_vars_set(0, "pid", enc);
  base32_encode(cid, enc);
  db_vars_set(0, "cid", enc);

  return NULL;
}
예제 #2
0
/* get tth root hash */
void tth_final(tth_ctx *ctx, unsigned char result[24]) {
  uint64_t it = 1;
  unsigned pos = 0;
  unsigned char msg[24];
  unsigned char* last_message;

  /* process bytes left in the context buffer */
  if(ctx->tiger.length>1 || ctx->block_count==0) {
    tth_process_block_hash(ctx);
  }
  
  for(; it < ctx->block_count && (it&ctx->block_count)==0; it <<= 1) pos += 3;
  last_message = (unsigned char*)(ctx->stack + pos);

  for(it <<= 1; it <= ctx->block_count; it <<= 1) {
    /* merge tth sums in the tree */
    pos += 3;
    if(it&ctx->block_count) {
      tiger_init(&ctx->tiger);
      ctx->tiger.message[ ctx->tiger.length++ ] = 1;
      tiger_update(&ctx->tiger, (unsigned char*)(ctx->stack + pos), 24);
      tiger_update(&ctx->tiger, last_message, 24);

      tiger_final(&ctx->tiger, msg);
      bswap_3x64(msg);
      last_message = msg;
    }
  }
  
  memcpy(result, last_message, 24);
  return;
}
예제 #3
0
	bool run()
	{
		tiger_ctx ctx;
		tiger_init(&ctx, 1);
		tiger_update(&ctx, buf.get(), sz);
		tiger_end(&ctx, res0, TIGER_SZ_DIGEST);
		return std::equal(res, res + TIGER_SZ_DIGEST, res0);
	}
예제 #4
0
		int TigerHash::ProcessBlock(const void * _data, size_t _length)
		{
			CoreAssert(this != NULL);

			if (!_data) return -1;

			tiger_update(&m_state, (unsigned char *)_data, _length);
			return 0;
		}
예제 #5
0
static void tth_process_block_hash(tth_ctx *ctx) {
  uint64_t it;
  unsigned pos = 0;
  unsigned char msg[24];
  for(it=1; it & ctx->block_count; it <<= 1) {
    tiger_final(&ctx->tiger, msg);
    bswap_3x64(msg);
    tiger_init(&ctx->tiger);
    ctx->tiger.message[ ctx->tiger.length++ ] = 1;
    tiger_update(&ctx->tiger, (unsigned char*)(ctx->stack + pos), 24);
    /* note: we can cut this step, if the previous tiger_final saves directly to ctx->tiger.message+25; */
    tiger_update(&ctx->tiger, msg, 24);
    pos += 3;
  }
  tiger_final(&ctx->tiger, (unsigned char*)(ctx->stack + pos));
  bswap_3x64( ctx->stack + pos );
  ctx->block_count++;
}
예제 #6
0
		int TigerHash::Process(const void * _data, size_t _length)
		{
			CoreAssert(this != NULL);

			Reset();
			if (!_data) return -1;

			tiger_update(&m_state, (unsigned char *)_data, _length);
			m_hash = new unsigned char[TIGER_DIGEST_SIZE];
			tiger_final(m_hash, &m_state);
			return 0;
		}
예제 #7
0
void tiger_finalize(struct tiger_ctx *ctx, uint8_t *out)
{
	static uint8_t padding[64] = { 0x01, };
	uint64_t bits;
	uint32_t index, padlen;
	uint64_t *p = (uint64_t *) out;

	/* add padding and update data with it */
	bits = cpu_to_le64(ctx->sz << 3);

	/* pad out to 56 */
	index = (uint32_t) (ctx->sz & 0x3f);
	padlen = (index < 56) ? (56 - index) : ((64 + 56) - index);
	tiger_update(ctx, padding, padlen);

	/* append length */
	tiger_update(ctx, (uint8_t *) &bits, sizeof(bits));

	/* output hash */
	p[0] = cpu_to_le64(ctx->h[0]);
	p[1] = cpu_to_le64(ctx->h[1]);
	p[2] = cpu_to_le64(ctx->h[2]);
}
예제 #8
0
void tth_update(tth_ctx *ctx, const unsigned char* msg, unsigned size) {
  unsigned rest = 1025 - (unsigned)ctx->tiger.length;
  for(;;) {
    if(size<rest) rest = size;
    tiger_update(&ctx->tiger, msg, rest);
    msg += rest;
    size -= rest;
    if(ctx->tiger.length<1025) {
      return;
    }
    
    /* process block hash */
    tth_process_block_hash(ctx);
    
    /* init block hash */
    tiger_init(&ctx->tiger);
    ctx->tiger.message[ ctx->tiger.length++ ] = 0;
    rest = 1024;
  }
}
예제 #9
0
파일: tth.c 프로젝트: Tilka/ncdc
void tth_update(tth_ctx_t *ctx, const char *msg, size_t len) {
  char leaf[24];
  int left;
  if(len > 0)
    ctx->gotfirst = 1;
  while(len > 0) {
    left = MIN(tth_base_block - (ctx->tiger.length-1), len);
    tiger_update(&ctx->tiger, msg, left);
    len -= left;
    msg += left;
    g_assert(ctx->tiger.length-1 <= tth_base_block);
    // we've got a new base leaf
    if(ctx->tiger.length-1 == tth_base_block) {
      tiger_final(&ctx->tiger, leaf);
      tth_update_leaf(ctx, leaf);
      tth_new_leaf(ctx);
    }
  }
  g_assert(len == 0);
}