没有通用哈希的良好哈希函数。取决于上下文,不同的标准确定哈希的质量。要使用从您希望使用相同分布的数据中获取的数据来测试您的哈希函数。当查看64位long上的哈希函数时,如果从所有可能的long值中统一提取输入值,则默认哈希函数非常出色。
有多种方法可以测试非加密哈希函数的分布,冲突和性能属性。当涉及哈希冲突或分布时,概率不是一个好主意。为此,一些库利用线性密码分析或其他方法。
SMHasher是一个测试套件,旨在测试非加密哈希函数的分布,冲突和性能属性。它的目标是成为哈希测试的DieHarder,汉武帝药枕并很好地发现了几种流行的哈希值中的缺陷。
template < typename hashtype >
void test ( hashfunc<hashtype> hash, HashInfo * info )
{
const int hashbits = sizeof(hashtype) * 8;
printf("-------------------------------------------------------------------------------n");
printf("--- Testing %s (%s)nn",info->name,info->desc);
//-----------------------------------------------------------------------------
// Sanity tests
if(g_testSanity || g_testAll)
{
printf("[[[ Sanity Tests ]]]nn");
VerificationTest(hash,hashbits,info->verification,true);
SanityTest(hash,hashbits);
AppendedZeroesTest(hash,hashbits);
printf("n");
}
//-----------------------------------------------------------------------------
// Speed tests
if(g_testSpeed || g_testAll)
{
printf("[[[ Speed Tests ]]]nn");
BulkSpeedTest(info->hash,info->verification);
printf("n");
for(int i = 1; i < 32; i++)
{
double cycles;
TinySpeedTest(hashfunc<hashtype>(info->hash),sizeof(hashtype),i,info->verification,true,cycles);
}
printf("n");
}
//-----------------------------------------------------------------------------
// Differential tests
if(g_testDiff || g_testAll)
{
printf("[[[ Differential Tests ]]]nn");
bool result = true;
bool dumpCollisions = false;
result &= DiffTest< Blob<64>, hashtype >(hash,5,1000,dumpCollisions);
result &= DiffTest< Blob<128>, hashtype >(hash,4,1000,dumpCollisions);
result &= DiffTest< Blob<256>, hashtype >(hash,3,1000,dumpCollisions);
if(!result) printf("*********FAIL*********n");
printf("n");
}
//-----------------------------------------------------------------------------
// Differential-distribution tests
if(g_testDiffDist /*|| g_testAll*/)
{
printf("[[[ Differential Distribution Tests ]]]nn");
bool result = true;
result &= DiffDistTest2<uint64_t,hashtype>(hash);
printf("n");
}
请确保直接在GetIt门户上查看SMHasher测试套件,并在IDE中下载它!
使用RAD Studio,Delphi或C ++ Builder减少开发时间并更快地推向市场。设计。编码。编译。部署。