Description
First of all, thank you for your implementation of AICH
, which helped me to understand the algorithm.
I'm not a C/C++ language expert, but because the algorithm lacks good specifications, I have to refer to some code implementations.
I accidentally discovered something interesting while debugging, that is, the RHash
implementation appears to calculate the Block-Hash-Tree twice (as LEFT_BRANCH
and RIGHT_BRANCH
) in all parts except the first and last part.
I did not fully understand all the code logic, but I guess it might be as a streaming calculation, it is designed as is to pick the correct HASH value from it when calculate the FULL_TREE
in the end.
Reading the code seems to be true:
Lines 297 to 307 in e5b0cb6
The design here is probably save memory usage, that is, whenever the full 53 blocks are obtained, the Part-Hash is calculated immediately, I'm not sure whether the memory footprint of the 53 blocks of Hash is then released.
In any case, based on my own implementation, I find this seems like a trade-off that is not worth it.
Let's assume we want to hash a 100GB file, based on the fact that the result of SHA1 takes up 20 bytes and the size of each block is 184320 bytes, we can get that caching the full block hashes set requires about 11MB of memory. (100 * 1000 / 184320 * 20 ≈ 10.85MB)
This seems trivial for most modern devices. But performing twice Block-Hash-Tree calculations on almost all parts, where the result of one will not end up being used, seems like an unnecessary and considerable waste.
So I think delaying Block-Hash-Tree calculation until all blocks are hashed and only performing necessary calculations based on tree branches is a feasible optimization method. It would be beneficial for most devices and significantly reduce the carbon footprint.
Of course, perhaps on devices with, say, only 32MB of RAM, this might be an issue. Maybe make available memory determinations?
Finally, thank you again for developing the tool, in addition to helping me understand the algorithm, I found it useful in other ways. ❤️🙏