Developers.Hash.TigerTree.Sample.Code.Server: Difference between revisions
(Importing page from Tikiwiki) |
m (1 revision) |
(No difference)
|
Latest revision as of 20:09, 20 June 2009
TigerTree server code
<source lang="c"> // Takes a file and our maximum tree height policy // Hashes the file with TigerTree // Writes the complete TigerTree of hashes void TigerServer(DWORD maxheight, CBuffer* file, CBuffer* tree) {
// Compute the TigerTree hash of the file CTigerTree tiger; // The object that will compute the hash tiger.BeginFile(maxheight, file->m_nLength); // Tell it the maximum tree height, and the file size tiger.AddToFile(file->m_pBuffer, file->m_nLength); // Give it the data to hash tiger.FinishFile(); // That's all
// Get the TigerTree root hash value TIGEROOT value; // The variable that will store the hash value DWORD size = sizeof(value); // 24 bytes tiger.GetRoot(&value); // Get the hash value from the object CString root = tobase16byte*)(&value), sizeof(value; // Write the root hash as text
// Ask the object about the details of the tree DWORD blocksize, blocks, height, treesize, hashes; blocksize = tiger.GetBlockLength(); blocks = tiger.GetBlockCount(); height = tiger.GetHeight();
// The CTigerTree object won't tell us how many hashes are in the tree, or how much space ToBytes needs size = blocks * height * sizeof TIGEROOT; // But it can't be more than this
// Copy the whole tree into the given buffer tree->EnsureBuffer(size); // Make enough room BOOL result = tiger.ToBytes(&(tree->m_pBuffer), &size, maxheight); // Writes how much it wrote in size tree->m_nLength += size; // Report how much it wrote
// Now we know the actual tree size, and can figure out how many hashes are in the tree treesize = size; hashes = size / sizeof TIGEROOT; } </source>