Exemplo n.º 1
0
void test_basic_hashing() {
	SHA512 hasher;
	hasher.write("vossibaer");
	hasher.close();
	assert(hasher.gethash() == reference_hash("vossibaer"));

	SHA512 tigger;
	tigger.write("honey");
	tigger.close();
	assert(tigger.gethash() == reference_hash("honey"));

	SHA512 leo;
	leo.write("lifestyle");
	leo.close();
	const unsigned char should[64] = 
	{	0xc0, 0x25, 0xb1, 0x2c, 0x03, 0xa6, 0xea, 0x2d, 
		0xe6, 0x76, 0x00, 0xf5, 0x79, 0x25, 0xb0, 0x60, 
		0xdd, 0x70, 0xa5, 0xbd, 0x02, 0xb1, 0x4f, 0x39, 
		0x7f, 0x4e, 0x69, 0x95, 0xec, 0xaa, 0xd4, 0x4c, 
		0xfc, 0x66, 0xaf, 0xc8, 0xea, 0xcd, 0x61, 0x55, 
		0x1f, 0x00, 0x93, 0x7c, 0x03, 0x31, 0x83, 0xff, 
		0x30, 0xa8, 0xb3, 0xe5, 0xbd, 0x45, 0xaf, 0x2c, 
		0x1b, 0x56, 0xbd, 0xf0, 0x44, 0xf1, 0x58, 0x95,	};
	unsigned char current[64];
	leo.gethash(current);

	for(int i = 0; i < 64; ++i) {
		assert(should[i] == current[i]);
	}
}
Exemplo n.º 2
0
void test_hashing_errors() {
	bool caught_exception = false;
	SHA512 test;
	test << "hello";
	string hash;

	try {
		hash = test.gethash();
	} catch(std::runtime_error e) {
		caught_exception = true;
	}

	assert(caught_exception);

	test.close();
	caught_exception = false;

	try {
		test << "more";
	} catch(std::runtime_error e) {
		caught_exception = true;
	}

	assert(caught_exception);
}
Exemplo n.º 3
0
void test_hashing_comparisons() {
	SHA512 valid;
	valid.write("monk");
	valid.close();

	assert(valid == "83d558db35b474e2e930f6866583bb166fd497dc310d044edcffd8e2e656fce8f2f2564fafc202635e08a9504348fc4932e2e0d65de2c536922096eb82302032");
	assert(valid == reference_hash("monk"));
	SHA512 helper;
	helper.write("monk");
	helper.close();
	assert(valid == helper);

	SHA512 invalid;
	invalid.write("m0nk");
	invalid.close();
	assert(invalid != "83d558db35b474e2e930f6866583bb166fd497dc310d044edcffd8e2e656fce8f2f2564fafc202635e08a9504348fc4932e2e0d65de2c536922096eb82302032");
	assert(invalid != reference_hash("monk"));
	assert(invalid != helper);
}