Zend certified PHP/Magento developer

Building a hash chain

Hi everyone,

I want to build a hash chain, i.e. an immutable trail of log messages. Each log message is hashed together with a timestamp and the hash from the previous record. By announcing the most recent hash in public from time to time (e.g. daily submission to blockchain, or in a newspaper, or similar), the trail cannot be tampered with, as one small change to any record would change all subsequent hashes.

What I’m wondering now is what way to implement this. I’ve read a few scientific papers and they basically just used

SHA256("timestamp" . "new log data" . "old hash") = new hash 

However, I also found https://github.com/paragonie/blakechain and they use the new sodium_crypto_generichash function for a keyed BLAKE2b hash, where the key of the new hash is the hash of the previous entry:

BLAKE2b("timestamp" . "new log data", "old hash") = new hash 

Does anybody here maybe have experience with this and can say something about whether it is advised to use the second approach? Personally, I like the first approach better since I want a long-term solution and the whole libsodium stuff is so new to PHP that it is not even officially documented yet.

Any help / discussion is highly appreciated!

submitted by /u/2face2
[link] [comments]