Vb.net 第3个测试向量
我正在尝试将a移植到VB.Net 它运行。。。但是有人能给我提供一些已知的测试向量来验证正确性吗Vb.net 第3个测试向量,vb.net,murmurhash,Vb.net,Murmurhash,我正在尝试将a移植到VB.Net 它运行。。。但是有人能给我提供一些已知的测试向量来验证正确性吗 已知字符串文本 种子价值 第3部分的结果 提前谢谢 编辑:我将实现限制为仅32位哈希3,但如果您还可以为64位实现提供向量,也会很好。SMHasher使用a,基本上它计算以下值的哈希,使用每个值的递减种子值(从256开始): ' The comment in the SMHasher code is a little wrong - ' it's missing the first case.
- 已知字符串文本
- 种子价值
- 第3部分的结果
' The comment in the SMHasher code is a little wrong -
' it's missing the first case.
{}, {0}, {0, 1}, {0, 1, 2} ... {0, 1, 2, ... 254}
并将其附加到HASHLENGTH*256
length数组,换句话说:
' Where & is a byte array concatenation.
HashOf({}, 256) &
HashOf({0}, 255) &
HashOf({0, 1}, 254) &
...
HashOf({0, 1, ... 254), 1)
然后它获取该大数组的散列。最终散列的前4个字节被解释为无符号32位整数,并根据验证码进行检查:
0xB0F57EE3
0xB3ECE62A
0x6384BA69
static void VerificationTest(uint expected)
{
using (var hash = new Murmur3())
// Also test that Merkle incremental hashing works.
using (var cs = new CryptoStream(Stream.Null, hash, CryptoStreamMode.Write))
{
var key = new byte[256];
for (var i = 0; i < 256; i++)
{
key[i] = (byte)i;
using (var m = new Murmur3(256 - i))
{
var computed = m.ComputeHash(key, 0, i);
// Also check that your implementation deals with incomplete
// blocks.
cs.Write(computed, 0, 5);
cs.Write(computed, 5, computed.Length - 5);
}
}
cs.FlushFinalBlock();
var final = hash.Hash;
var verification = ((uint)final[0]) | ((uint)final[1] << 8) | ((uint)final[2] << 16) | ((uint)final[3] << 24);
if (verification == expected)
Console.WriteLine("Verification passed.");
else
Console.WriteLine("Verification failed, got {0:x8}, expected {1:x8}", verification, expected);
}
}
静态无效验证测试(预期为uint)
{
使用(var hash=new3())
//还要测试Merkle增量哈希是否有效。
使用(var cs=newcryptostream(Stream.Null、hash、CryptoStreamMode.Write))
{
var key=新字节[256];
对于(变量i=0;i<256;i++)
{
键[i]=(字节)i;
使用(var m=新的3(256-i))
{
var computed=m.ComputeHash(键,0,i);
//还要检查您的实现是否处理不完整的数据
//街区。
cs.写入(计算,0,5);
cs.Write(computed,5,computed.Length-5);
}
}
cs.FlushFinalBlock();
var final=hash.hash;
var verification=((uint)final[0])|((uint)final[1]我终于开始创建一个Murruld3实现,并成功地翻译了SMHasher测试代码。我的实现给出了与SMHasher测试相同的结果。这意味着我最终可以给出一些有用的、假设正确的测试向量
这仅适用于3_x86_32
| Input | Seed | Expected |
|--------------|------------|------------|
| (no bytes) | 0 | 0 | with zero data and zero seed, everything becomes zero
| (no bytes) | 1 | 0x514E28B7 | ignores nearly all the math
| (no bytes) | 0xffffffff | 0x81F16F39 | make sure your seed uses unsigned 32-bit math
| FF FF FF FF | 0 | 0x76293B50 | make sure 4-byte chunks use unsigned math
| 21 43 65 87 | 0 | 0xF55B516B | Endian order. UInt32 should end up as 0x87654321
| 21 43 65 87 | 0x5082EDEE | 0x2362F9DE | Special seed value eliminates initial key with xor
| 21 43 65 | 0 | 0x7E4A8634 | Only three bytes. Should end up as 0x654321
| 21 43 | 0 | 0xA0F7B07A | Only two bytes. Should end up as 0x4321
| 21 | 0 | 0x72661CF4 | Only one byte. Should end up as 0x21
| 00 00 00 00 | 0 | 0x2362F9DE | Make sure compiler doesn't see zero and convert to null
| 00 00 00 | 0 | 0x85F0B427 |
| 00 00 | 0 | 0x30F4C306 |
| 00 | 0 | 0x514E28B7 |
对于那些将要移植到没有实际数组的语言的人,我还提供了一些基于字符串的测试。对于这些测试:
- 假设所有字符串都是UTF-8编码的
- 并且不包括任何空终止符
我将以代码形式保留这些内容:
TestString("", 0, 0); //empty string with zero seed should give zero
TestString("", 1, 0x514E28B7);
TestString("", 0xffffffff, 0x81F16F39); //make sure seed value is handled unsigned
TestString("\0\0\0\0", 0, 0x2362F9DE); //make sure we handle embedded nulls
TestString("aaaa", 0x9747b28c, 0x5A97808A); //one full chunk
TestString("aaa", 0x9747b28c, 0x283E0130); //three characters
TestString("aa", 0x9747b28c, 0x5D211726); //two characters
TestString("a", 0x9747b28c, 0x7FA09EA6); //one character
//Endian order within the chunks
TestString("abcd", 0x9747b28c, 0xF0478627); //one full chunk
TestString("abc", 0x9747b28c, 0xC84A62DD);
TestString("ab", 0x9747b28c, 0x74875592);
TestString("a", 0x9747b28c, 0x7FA09EA6);
TestString("Hello, world!", 0x9747b28c, 0x24884CBA);
//Make sure you handle UTF-8 high characters. A bcrypt implementation messed this up
TestString("ππππππππ", 0x9747b28c, 0xD58063C1); //U+03C0: Greek Small Letter Pi
//String of 256 characters.
//Make sure you don't store string lengths in a char, and overflow at 255 bytes (as OpenBSD's canonical BCrypt implementation did)
TestString(StringOfChar("a", 256), 0x9747b28c, 0x37405BDC);
我将发布我转换为SHA-3的11个SHA-2测试向量中的两个
TestString("abc", 0, 0xB3DD93FA);
TestString("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 0, 0xEE925B90);
最后,大问题是:
- 键:
“敏捷的棕色狐狸跳过了懒狗”
- 种子:0x9747b28c
- 散列:0x2FA826CD
如果其他任何人可以从他们的实现中确认任何/所有这些向量
同样,这些测试向量来自通过SMHasher 256迭代循环测试的实现
这些测试来自我在Delphi中的实现,我还在Lua中创建了一个实现(它在支持数组方面不是很大)
注意:任何发布到公共域的代码。无需属性
我已经改进了Jonathan提供的救生代码。您的计算机3必须实现ICryptoTransform
,此方法才能工作。您可以在
实现此接口的
public static void VerificationTest(uint expected)
{
using (var hash = new Murmur32ManagedX86())
{
using (var cs = new CryptoStream(Stream.Null, hash, CryptoStreamMode.Write))
{
var key = new byte[256];
for (var i = 0; i < 256; i++)
{
key[i] = (byte)i;
using (var mur = new Murmur32ManagedX86((uint)(256 - i)))
{
var computed = mur.ComputeHash(key, 0,i);
cs.Write(computed, 0, 4);
}
}
cs.FlushFinalBlock();
var testBoy = hash.Seed;
var final = hash.Hash;
var verification = ((uint)final[0]) | ((uint)final[1] << 8) | ((uint)final[2] << 16) | ((uint)final[3] << 24);
if (verification == expected)
Console.WriteLine("Verification passed.");
else
Console.WriteLine("Verification failed, got {0:x8}, expected {1:x8}", verification, expected);
}
}
}
我编写了自己的实现,并注意到这些值与我得到的值相同:@kaiselgren我根据自己的实现验证了x86 32位测试
。如果javascript测试还检查javascript字符串是否是utf-8编码的(例如“π”),以及它是否支持嵌入式空值,这将非常有用(例如“\0\0\0\0”)@IanBoyd为了它的价值,下面是我在Rust中的实现,底部有几个单元测试:哦,我的天哪,我愿意为了一个测试向量而杀人。因为现在我需要一个测试来测试我的测试代码,这是一个感谢的副本!哇,这是一个相当大的努力。我将你的标记为“答案”。“如果其他任何人可以从他们的实现中确认任何/所有这些向量。”——确认,都将在我的C#实现中传递。谢谢!
public static void VerificationTest(uint expected)
{
using (var stream = new MemoryStream())
{
var key = new byte[256];
for (var i = 0; i < 256; i++)
{
key[i] = (byte)i;
var hasher = new MurMurHash3((uint)(256 - i));
int computed = hasher.ComputeBytesFast(key.Take(i).ToArray());
stream.Write(BitConverter.GetBytes(computed), 0, 4);
}
var finalHasher = new MurMurHash3(0); //initial seed = 0
int result = finalHasher.ComputeBytesFast2(stream.GetBuffer());
if (result == (int)expected)
Console.WriteLine("Verification passed.");
else
Console.WriteLine("Verification failed, got {0:x8}, expected {1:x8}", verification, expected);
}
}