Exemple #1
0
static void tiger_tree_fd(OS_FD fd, OFF_T len, OFF_T pos, OFF_T block_size, char *digest)
{
  static char tiger_buffer[BLOCK_SIZE+1];
  if(block_size == BLOCK_SIZE){
    OFF_T length = (len - pos > BLOCK_SIZE) ? BLOCK_SIZE : len - pos;
    char *s = tiger_buffer+1;
    size_t toread = length;
    char *curs = s;
      while (toread!=0){
      int max_nread = toread;
/* HASH_BUFFER_LEN > toread ? toread : HASH_BUFFER_LEN; */

      ssize_t nread = os_read (fd, curs, max_nread);

        if(nread <= 0) {
        unix_error(errno, "tiger_safe_fd: Read", Nothing);
      }
      curs += nread;
      toread -= nread;
    }

    tiger_hash(0, s, length, digest);
  } else {    
    if(pos+block_size/2 >=len){
      tiger_tree_fd(fd, len, pos, block_size/2, digest);
    } else {
      char digests_prefixed[1+DIGEST_LEN * 2];
      char *digests = digests_prefixed+1;
      tiger_tree_fd(fd, len, pos, block_size/2, digests);
      tiger_tree_fd(fd, len, pos+block_size/2, block_size/2, digests+DIGEST_LEN);
      tiger_hash(1,digests, 2*DIGEST_LEN, digest);
    }
  }
}
Exemple #2
0
char *cube2crypto_hashstring(char *string)
{
	char *result = (char *)malloc(49);
	union hashval hv;
	
	tiger_hash((uchar *)string, strlen(string), &hv);
	
	int i;
	for(i = 0; i < sizeof(hv.bytes); i++)
	{
		uchar c = hv.bytes[i];
		*(result+(i*2))   = "0123456789ABCDEF"[c&0xF];
		*(result+(i*2)+1) = "0123456789ABCDEF"[c>>4];
	}
	*(result+(i*2)+2) = '\0';
	
	return result;
}