Hash algorithm for dynamic growing/streaming data?

后端 未结 3 565
南笙
南笙 2020-12-10 16:38

Are there any algorithms that you can continue hashing from a known hash digest? For example, the client upload a chunk of file to ServerA, I can get a

3条回答
  •  执念已碎
    2020-12-10 16:49

    I was facing this problem too, and found no existing solution, so I wrote a library that uses ctypes to deconstruct the OpenSSL data structure holding the hasher state: https://github.com/kislyuk/rehash. Example:

    import pickle, rehash
    hasher = rehash.sha256(b"foo")
    state = pickle.dumps(hasher)
    
    hasher2 = pickle.loads(state)
    hasher2.update(b"bar")
    
    assert hasher2.hexdigest() == rehash.sha256(b"foobar").hexdigest()
    

提交回复
热议问题