31 lines
1.1 KiB
D
31 lines
1.1 KiB
D
|
import std.stdio;
|
||
|
|
||
|
extern(C) void tiger (char* parMessage, ulong parLength, out ulong[3] parOut, char parPadding);
|
||
|
|
||
|
ulong[3] getTiger (in string parData, bool parV2) {
|
||
|
char[] unaligned = new char[parData.length + ulong.alignof - 1];
|
||
|
size_t offset = ((cast(size_t)unaligned.ptr + (ulong.alignof - 1)) & ~cast(size_t)(ulong.alignof - 1)) - cast(size_t)unaligned.ptr;
|
||
|
assert(offset >= 0 && offset < ulong.alignof);
|
||
|
assert(offset + parData.length <= unaligned.length);
|
||
|
|
||
|
char padding = (parV2 ? 0x80 : 0x01);
|
||
|
char[] aligned = unaligned[offset .. offset + parData.length];
|
||
|
aligned[] = parData[];
|
||
|
assert((cast(size_t)aligned.ptr & cast(size_t)(ulong.alignof - 1)) == 0);
|
||
|
ulong[3] retval;
|
||
|
tiger(aligned.ptr, aligned.length, retval, padding);
|
||
|
return retval;
|
||
|
}
|
||
|
|
||
|
void printHash(in string parData) {
|
||
|
ulong[3] hash1 = getTiger(parData, false);
|
||
|
ulong[3] hash2 = getTiger(parData, true);
|
||
|
writefln("Tiger hash for \"%s\" is %X %X %X", parData, hash1[0], hash1[1], hash1[2]);
|
||
|
writefln("Tiger2 hash for \"%s\" is %X %X %X", parData, hash2[0], hash2[1], hash2[2]);
|
||
|
}
|
||
|
|
||
|
void main (string[] parArgs) {
|
||
|
printHash("abc");
|
||
|
printHash("Tiger");
|
||
|
}
|