I am realized that default hashlib.sha3_256
hasher does not calculates hashes like other solution, for instance, other python's modules. Below, for instance, I comparing hashlib
and sha3
implementation of sha2_256
algorithm on Python 3.6.3.
Implemetation from sha3
gaves correct result (according to other internet resources) while hashlib.sha3_256
result is completely different. How it could be? Am I missed something?
import sha3
import hashlib
def test(s):
k = sha3.keccak_256()
k.update(s.encode())
print('test string="{s}", sha3.keccak_256()="{h}"'.format(s=s, h=k.hexdigest()))
h = hashlib.sha3_256()
h.update(s.encode())
print('test string="{s}", hashlib.keccak_256()="{h}"'.format(s=s, h=h.hexdigest()))
test('')
test('eth')
test('foo.bar')
Results:
test string="", sha3.keccak_256()="c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
test string="", hashlib.keccak_256()="a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a"
test string="eth", sha3.keccak_256()="4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0"
test string="eth", hashlib.keccak_256()="4b3cdfda85c576e43c848d43fdf8e901d8d02553fec8ee56289d10b8dc47d997"
test string="foo.bar", sha3.keccak_256()="461e2b648c9a6c0c3e2cab45884ae0fcab21c655fcf588f2a45e6596e3e0e9a7"
test string="foo.bar", hashlib.keccak_256()="e55dea66e750540f599874a18596745b0c5705bc6873ca3ef1ccd2acbba88670"