Example #1
0
void sha1append(const char *prefixhash, const char *append, size_t appendlen,
		size_t minlen, size_t maxlen) {

	SHA_CTX ctx;
	unsigned char md[SHA_DIGEST_LENGTH];
	size_t i;
	uint64_t datasize;


	/* Prepare (part of) the SHA context */
	SHA1_Init(&ctx);

	sscanf(prefixhash + 0, "%08x", &ctx.h0);
	sscanf(prefixhash + 8, "%08x", &ctx.h1);
	sscanf(prefixhash + 16, "%08x", &ctx.h2);
	sscanf(prefixhash + 24, "%08x", &ctx.h3);
	sscanf(prefixhash + 32, "%08x", &ctx.h4);

	for (datasize = minlen; datasize <= maxlen; datasize++) {
		SHA_CTX c = ctx;
		uint64_t nblock = (datasize + 8 + 1 + SHA_CBLOCK - 1) / SHA_CBLOCK;
		uint64_t datasizebits = datasize * 8;
		uint64_t datapadsize = nblock * SHA_CBLOCK;
		uint64_t datapadsizebits = datapadsize * 8;
		uint64_t padzerosize = datapadsize - datasize - 8 - 1;
		unsigned char *p;

		/* Compute the final hash if the prefix data is i bytes long */
		c.Nh = datapadsizebits >> 32;
		c.Nl = datapadsizebits & 0xffffffffUL;

		SHA1_Update(&c, append, appendlen);
		SHA1_Final(md, &c);


		printf("%llu: ", datasize);
		printhash(md);
		printf(" ");


		/* Print the padding */
		printf("\\x80");
		for (i = 0; i < padzerosize; i++)
			printf("\\x00");

		/* Big endian datasize */
		p = (unsigned char *)&datasizebits;
		for (i = 0; i < sizeof(datasizebits); i++)
			printf("\\x%02x", p[sizeof(datasizebits) - 1 - i]);

		for (i = 0; i < appendlen; i++)
			printf("\\x%02x", append[i]);
		printf("\n");
	}
}
Example #2
0
void get_or_set_dbu(DBT *hash)
{
   unsigned long long inuse;

   inuse=getInUse(hash->data);
   if ( 0 == inuse ) {
     printhash("Used hash without reference in blockusage data, reset to 1",hash->data);
     inuse++;
     update_inuse(hash->data,inuse);
   } 
}
Example #3
0
void hash(char *data, size_t len, char *buf)
{
	unsigned char hash[SHA256_DIGEST_LENGTH];

	SHA256_CTX ctx;
	SHA256_Init(&ctx);

	SHA256_Update(&ctx, data, len);
	SHA256_Final(hash, &ctx);

	printhash(hash, buf);
}
Example #4
0
static void printcfg( CamConfig *ccfg ){
  hscan_t hs;
  hnode_t *hn;

  hash_scan_begin(&hs, ccfg->mainhash);
  while ((hn = hash_scan_next(&hs))){
    CamConfigSection *sec;

    sec = hnode_get( hn );
    printf("-------%s--------\n", sec->section_name );
    printhash( sec->entryhash );
  }
}
Example #5
0
/**
 * 6.6 テーブル参照
 * 
 */
int main(int argc, char *argv[])
{
	int i;
	for( i = 0; i < HASHSIZE; i++ ){
		hashtab[i] = NULL;
	}

	install("HOGE","001");
	install("MOGE","002");
	
	printhash();	
	
	return 0;
}
Example #6
0
void file_get_or_set_dbu(DBT *hash)
{
   INUSE *inuse;

   if ( 0 == memcmp(config->nexthash, hash->data, config->hashlen)){
        printf("got it\n");
        return; // Skip the nextoffset hash
   }
   inuse=file_get_inuse(hash->data);
   if ( NULL == inuse ) {
     printhash("Used hash without reference in blockusage",hash->data);
   } else {
     if ( inuse->offset + inuse->size  > detected_size ) detected_size=inuse->offset + inuse->size;
   }
}
Example #7
0
void check_orphaned_data_blocks()
{
    char *key;

    /* traverse records */
    tchdbiterinit(dbdta);
    while ((key = tchdbiternext2(dbdta)) != NULL) {
        if ( 0 == check_inuse((unsigned char *)key)) {
           printhash("Deleting orphaned hash",(unsigned char *)key);
           if (!tchdbout(dbdta, key, config->hashlen)) {
              die_syserr();
           }
        }
        free(key);
    }
}
Example #8
0
void file_check_inode_structure(DDSTAT *ddstat)
{
   INOBNO inobno;
   bool found=0;
   DBT *data;
   DBT *blockdata;
   DBT *ddbuf;

   unsigned long long real_size;

   inobno.blocknr=0;
   inobno.inode=ddstat->stbuf.st_ino;

   while (1){
     data=fscheck_block_exists(inobno);
     if ( NULL != data ) {
        blockdata=file_tgr_read_data(data->data);
        if ( NULL == blockdata ) {
           printf("inode %llu-%llu\n",inobno.inode,inobno.blocknr);
           inobno.blocknr--;
           printhash ("hash not found, file is truncated",data->data);
           purge_dbb_beyond(&inobno);
           break;
        }
        file_get_or_set_dbu(data);
        DBTfree(blockdata);
        DBTfree(data);
        found=1;
     } else break;
     inobno.blocknr++;
   }
   real_size=BLKSIZE * inobno.blocknr;
   if ( found  && real_size>ddstat->stbuf.st_size+BLKSIZE ) {
     printf("inode %llu size %llu mismatch, restore size to %llu bytes\n",(unsigned long long)ddstat->stbuf.st_ino,(unsigned long long)ddstat->stbuf.st_size,real_size);
     ddstat->stbuf.st_size=real_size;
     ddbuf = create_ddbuf(ddstat->stbuf, ddstat->filename, real_size);
     bin_write_dbdata(dbp, &inobno.inode,
                      sizeof(unsigned long long), (void *) ddbuf->data,
                      ddbuf->size);
     DBTfree(ddbuf);
   }
   return;
}
Example #9
0
void printhashnl(unsigned char *md) {
	printhash(md);
	printf("\n");
}
Example #10
0
void filereader(FILE* in, int bflag, char* sym, int n){
	FILE* iq = fopen("iq.txt", "w");
	FILE* ob = fopen("ob.txt", "w");
	int count = 0;
	if(!bflag){
		char ch;
		int id;
		while(!feof(in)){
			fscanf(in,"%c",&ch);
			if(ch == 'A'){
				char side;
				char* symbol = (char*)malloc(sizeof(char*));
				int quantity;
				double price; 
				fscanf(in,"%d %c %s %d %lf\n",&id, &side, symbol, &quantity, &price);
				if(!strcmp(sym,symbol)){
					hashAdd(id, side, symbol, quantity, price);
					//printf("%ld %c %s %d %lf\n", id, side, symbol, quantity, price);
					//count++;
				}
			}else if(ch == 'X'){
				char* symbol = (char*)malloc(sizeof(char*));
				fscanf(in,"%d %s\n",&id, symbol);
				hashDel(id);
			}else if(ch == 'T'){
				int id;
				char* symbol = (char*)malloc(sizeof(char*));
				int quantity;
				fscanf(in, "%d %s %d\n", &id, symbol, & quantity);
				if(!strcmp(sym,symbol)){
					changeNode(id, quantity);
				}
			}else if(ch == 'R'){
				int id;
				char* symbol = (char*)malloc(sizeof(char*));
				int quantity;
				double price;
				fscanf(in, "%d %s %d %lf\n", &id, symbol, &quantity, &price);
				changePnode(id, quantity, price);
			}else if(ch == 'C'){
				int id;
				char* symbol = (char*)malloc(sizeof(char*));
				int quantity;
				fscanf(in, "%d %s %d\n", &id, symbol, & quantity);
				if(!strcmp(sym,symbol)){
					changeNode(id, quantity);
				}

			}
			count++;
			//printf("count %d\n", count);
			//printf("n in file %d\n", n);
			if(count == n){
				count = 0;
				double sellPrice = 0.0;
				double buyPrice = 0.0;
				if(sell != NULL)
					sellPrice = sell->price;
				if(buy != NULL)
					buyPrice = buy->price;
				fprintf(iq, "%lf %lf\n", sellPrice, buyPrice);
			}

		}

	}else{
		char c;
		  while(!feof(in)){
			fread(&c, sizeof(char), 1,in);
			if(c == 'A'){
				int id;
				char side;
				char *symbol = (char *) malloc(sizeof(char *));
				int quantity;
				double price;
				fread(&id,sizeof(int),1,in);
				fread(&side,sizeof(char),1,in);
				fread(symbol,sizeof(char),4,in);
				symbol[strlen(symbol)] = '\0';
				fread(&quantity,sizeof(int),1,in);
				fread(&price,sizeof(double),1,in);
				if(!strcmp(sym,symbol)){
					hashAdd(id, side, symbol, quantity, price);
					//printf("%ld %c %s %d %lf\n", id, side, symbol, quantity, price);
				}
			}
			if(c == 'X'){
				int id;
				char *symbol = (char *) malloc(sizeof(char *));
				fread(&id,sizeof(int),1,in);
				fread(symbol,sizeof(char),4,in);
				symbol[strlen(symbol)] = '\0';
				hashDel(id);
			}
			
			if(c == 'T'){
				int id;
				char *symbol = (char *) malloc(sizeof(char *));
				int quantity;
				fread(&id,sizeof(int),1,in);
				fread(symbol,sizeof(char),4,in);
				symbol[strlen(symbol)] = '\0';
				fread(&quantity,sizeof(int),1,in);
				changeNode(id, quantity);				
			}
			if(c == 'C'){
				int id;
				char *symbol = (char *) malloc(sizeof(char *));
				int quantity;
				fread(&id,sizeof(int),1,in);
				fread(symbol,sizeof(char),4,in);
				symbol[strlen(symbol)] = '\0';
				fread(&quantity,sizeof(int),1,in);
				changeNode(id,quantity);
			}
			if(c == 'R'){
				int id;
				char *symbol = (char *) malloc(sizeof(char *));
				int quantity;
				double price;
				fread(&id,sizeof(int),1,in);
				fread(symbol,sizeof(char),4,in);
				symbol[strlen(symbol)] = '\0';
				fread(&quantity,sizeof(int),1,in);
				fread(&price,sizeof(double),1,in);
				changePnode(id, quantity, price);
			}
		}
	
	}
	printhash(ob);
}