Developers.Hash.Refactor.Interface
A design for an easy to use hashing interface, demonstrated in pseudocode. You could have the Shareaza code use this interface, or put this interface over the one in Shareaza.
The types of hashing are: Md4, Md5, Sha1, TigerLeaf, TigerInternal The types of tree hashing are: Tiger, Donkey The hash value sizes are: 16 bytes, 20 bytes, 24 bytes
Hash
<source lang="c"> value = Hash(data);
value = h.Hash(data);
h.Begin(); h.Add(data); h.Finish(); value = h.GetHash(); </source>
You have some data, and want to compute its hash. Just use the Hash function. Or, make a hashing object and call the Hash method on it. If the data is flowing in piece by piece from the disk or wire, use Begin, Add, Finish, and GetHash instead. Call Add many times in the middle. If you mess up an add and want to start over, just call Begin again.
Tree Hash
<source lang="c"> value = Hash(data, maxtreeheight, &tree, &blocksize);
value = h.Hash(data, maxtreeheight, &tree, &blocksize);
blocksize = h.Begin(filesize, maxtreeheight); h.Add(data); h.Finish(); value = h.GetHash(); blocksize = h.GetTree(&tree); </source>
You have a file, and want to hash it with a tree hashing algorithm. You need the root hash, and the entire tree. You need to specify the maximum tree height, and would like to know what block size the tree you are getting is using.
Call the Hash function, or make an object and call the Hash method. Give either all the data of the file and your tree height limit. They will return the root hash value, and write the whole tree and the block size. Pass NULL instead of pointers to not request those.
If the file is flowing in, use Begin, Add, Finish, GetHash, and GetTree instead. Start over by calling Begin again.
Tree Verify
<source lang="c"> blocksize = h.LoadTree(tree, filesize);
result = h.Verify(location, data);
h.VerifyBegin(location); h.VerifyAdd(data); result = h.VerifyFinish(); </source>
You have an entire tree, and are downloading file fragments. You want to know if a file fragment is good. Create an object, and call LoadTree. Give it the tree, and the size of the file the tree is about. It reports what size blocks you can now check, or returns 0 if the tree isn't valid. If you want to start over with a different tree but use the same object, call LoadTree again.
With a tree loaded, call Verify. Give it the location of a file fragment, and the data of the fragment. It will return a result that says the fragment is valid, invalid, or it can't tell because of some error.
If you're getting the data of the fragment piece by piece, call VerifyBegin, VerifyAdd several times, and VerifyFinish. To start over, just start with a call to VerifyBegin again.