Exemple #1
0
/*
 * generates all the rainbow table chains: it performs (10 * num_of_password / chain_length)
 * iterations, within each it calculates a rainbow table chain (first-password 
 * and last-digest) and stores them in the DEHT.
 */
static int generate_all_chains(const config_t * config, const rule_info_t * rule,
							   DEHT * deht)
{
	const uint64_t iterations = 10 * (rule->num_of_passwords / config->chain_length);
	uint64_t i;
	uint64_t k = config->seed_table[0]; /* some "random" k to start with */
	char first_password[MAX_INPUT_BUFFER];
	unsigned char last_digest[MAX_DIGEST_LENGTH_IN_BYTES];
#ifdef SHOW_GENERATED_CHAINS
	char hexdigest[MAX_DIGEST_LENGTH_IN_BYTES * 2 + 1];
#endif

	/* fill DEHT with chain heads and tails */
	for (i = 0; i < iterations; i++) {
		/* get the next k "randomly" */
		k = (k * 47 + 1) % rule->num_of_passwords;
		if (rainbow_generate_single_chain(config, rule, k, first_password,
				sizeof(first_password), last_digest) != 0) {
			/* error message printed by generate_chain */
			return 1;
		}
		if (add_DEHT(deht, last_digest, config->digest_size, (unsigned char*)first_password,
				strlen(first_password)) == DEHT_STATUS_FAIL) {
			/* error message printed by add_DEHT */
			return 1;
		}
#if SHOW_GENERATED_CHAINS
		binary2hexa(last_digest, config->digest_size, hexdigest, sizeof(hexdigest));
		printf("%05lu (%05lu): added %s = '%s'\n", i, k, hexdigest, first_password);
#endif
	}

	/* great success */
	return 0;
}
Exemple #2
0
int insert_uniquely_DEHT ( DEHT *ht, const unsigned char *key, int keyLength, 
				 const unsigned char *data, int dataLength)
{
	int ret = DEHT_STATUS_FAIL;

	byte_t * tempKeyBlock = NULL;
	DEHT_DISK_PTR keyBlockDiskOffset = 0;
	ulong_t keyIndex = 0;
	
	KeyFilePair_t * targetRecord = NULL;
	DEHT_DISK_PTR newDataOffset = 0;
	
	byte_t tempData[DEHT_MAX_DATA_LEN] = {0};

	TRACE_FUNC_ENTRY();

	CHECK(NULL != ht);
	CHECK(NULL != key);
	CHECK(NULL != data);

	/* allocate a buffer for DEHT_queryEx */
	tempKeyBlock = malloc(KEY_FILE_BLOCK_SIZE(ht));
	CHECK_MSG("malloc", (NULL != tempKeyBlock));
	
	ret = DEHT_queryEx(ht, key, keyLength, tempData, sizeof(tempData), tempKeyBlock, KEY_FILE_BLOCK_SIZE(ht), 
				  &keyBlockDiskOffset, &keyIndex);

	switch(ret) {
	case DEHT_STATUS_NOT_NEEDED:
		TRACE("simple insert");
		/* not found - just insert */
		CHECK(DEHT_STATUS_SUCCESS == add_DEHT (ht, key, keyLength, data, dataLength));

		ret = DEHT_STATUS_SUCCESS;

		break;

	case DEHT_STATUS_FAIL:
	default:
		if (0 >= ret) {
			/* internal error */
			goto LBL_ERROR;
		}


		/* if we got here, the key was found */
		TRACE_FPRINTF((stderr, "TRACE: %s:%d (%s): key already in DEHT. Updating record at %#x\n", __FILE__, __LINE__, __FUNCTION__, (uint_t) keyBlockDiskOffset));

		/* update data in the data file */
		CHECK(DEHT_addData(ht, data, dataLength, &newDataOffset)); 

		/* get the key record */
		targetRecord = GET_N_REC_PTR_IN_BLOCK(ht, tempKeyBlock, keyIndex);
		/* update key record */
		targetRecord->dataOffset = newDataOffset;

		/* update block on disk */
		CHECK_MSG(ht->sKeyfileName, (pfwrite(ht->keyFP, keyBlockDiskOffset, tempKeyBlock, KEY_FILE_BLOCK_SIZE(ht))));

		ret = DEHT_STATUS_NOT_NEEDED;
		
		break;
	}

	goto LBL_CLEANUP;	

LBL_ERROR:
	ret = DEHT_STATUS_FAIL;
	TRACE_FUNC_ERROR();

LBL_CLEANUP:
	FREE(tempKeyBlock);

	TRACE_FUNC_EXIT();
	return ret;
}