示例#1
0
void validateRules() {
    assert(countRules() >= 0);
    for (const auto& rule : rules->subexpressions) {
        validateRule(rule);
    }
}
bool_t createRainbowTable(const char * hashName,
			  const char * prefix,
			  const char * rule,
			  const char * dictionaryFilename,
			  const char * chainLengthStr,
			  const char * entiresInHashTableStr,
			  const char * bucketBlockLengthStr) {
	bool_t ret = FALSE;
	BasicHashFunctionPtr hashFunc;
	ulong_t chainLength;
	ulong_t entiresInHashTable;
	ulong_t bucketBlockLength;
	dictionary_t dictionary;
	passwordGenerator_t passwordGenerator;
	ulong_t maxPasswordLength;
	char * enumeratorPassword = NULL;
	char * generatorPassword = NULL;
	randomPasswordEnumerator_t randomPasswordEnumerator;

	CHECK(parseHashFunName(&hashFunc, hashName));
	CHECK(verifyDEHTNotExist(prefix));
	CHECK(validateRule(rule));
	CHECK(parseIniNum(chainLengthStr, &chainLength));
	CHECK(parseIniNum(entiresInHashTableStr, &entiresInHashTable));
	CHECK(parseIniNum(bucketBlockLengthStr, &bucketBlockLength));
	CHECK(readDictionaryFromFile(&dictionary, dictionaryFilename));

	if (!passwordGeneratorInitialize(&passwordGenerator, rule, &dictionary)) {
		goto LBL_CLEANUP_DICTIONARY;
	}

	maxPasswordLength = passwordGeneratorGetMaxLength(&passwordGenerator);

	generatorPassword = (char *) malloc((maxPasswordLength + 1) * sizeof(char));
	if (NULL == generatorPassword) {
		PERROR();
		goto LBL_CLEANUP_GENERATOR;
	}

	enumeratorPassword = (char *) malloc((maxPasswordLength + 1) * sizeof(char));
	if (NULL == enumeratorPassword) {
		PERROR();
		goto LBL_CLEANUP_GENERATOR;
	}
	
	randomPasswordEnumeratorInitialize(&randomPasswordEnumerator,
					   &passwordGenerator,
					   enumeratorPassword,
					   RANDOM_PASSWORD_NUM_FACTOR * passwordGeneratorGetSize(&passwordGenerator));
	ret = RT_generate((passwordEnumerator_t *) &randomPasswordEnumerator,
			  &passwordGenerator,
			  enumeratorPassword,
			  generatorPassword,
			  hashFunc,
			  chainLength,
			  prefix,
			  entiresInHashTable,
			  bucketBlockLength);

LBL_CLEANUP_GENERATOR:
	passwordGeneratorFinalize(&passwordGenerator);
LBL_CLEANUP_DICTIONARY:
	dictionaryFinalize(&dictionary);
LBL_ERROR:
	FREE(generatorPassword);
	FREE(enumeratorPassword);
	return ret;;
}