I need a Python/C/C++/Java implementation which can pause hashing progress and store that progress in a file in such a way that the progress is recoverable from that file at a later stage.
No matter in what language it is written from above listed, it should work properly in Python. It is recommended that you may provide that to work well with "hashlib" however it is not necessary. Also, if such a thing already exist, a link to that is sufficient.
For an idea, what your implementation should achieve.
import hashlib
import hashpersist #THIS IS NEEDED.
sha256 = hashlib.sha256("Hello ")
hashpersist.save_state(sha256, open('test_file', 'w'))
sha256_recovered = hashpersist.load_state(open('test_file', 'r'))
sha256_recovered.update("World")
print sha256_recovered.hexdigest()
This should give the same output as we had done simple hashing of "Hello World" with standard sha256 function.
a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e
It turned out to be easier than I thought to rewrite hashlib to be resumable, at least, the SHA-256 portion. I spent some time playing with C code that uses the OpenSSL crypto library, but then I realised that I don't need all that stuff, I can just use ctypes.
rehash.py
resumable_SHA-256.py
demo
output
edit
I've just made a minor edit to allow
rehash
to work on Windows, too, although I've only tested it on WinXP. Thelibeay32.dll
can be in the current directory, or somewhere in the system library search path, egWINDOWS\system32
. My rather ancient (and mostly unused) XP installation couldn't find the .dll, even though it's used by OpenOffice and Avira. So I just copied it from the Avira folder to system32. And now it works perfectly. :)