Skip to content

Commit

Permalink
Merge pull request #1 from onyb/support-pycryptodome-backend
Browse files Browse the repository at this point in the history
Add pycryptodome backend to compute keccak256 hash
  • Loading branch information
carver committed Feb 7, 2018
2 parents dc4a8a4 + f87d507 commit e2e7c70
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions eth_hash/backends/pycryptodome.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
def keccak256(prehash):
return b''
from Crypto.Hash import (
keccak,
)


def keccak256(prehash: bytes) -> bytes:
hash = keccak.new(digest_bits=256)
hash.update(prehash)
return hash.digest()
3 changes: 2 additions & 1 deletion eth_hash/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Keccak256:
def __init__(self, backend):
self.hasher = backend.keccak256
# TODO run assertion to validate hash once on load, after first backend set up

assert self.hasher(b'') == b"\xc5\xd2F\x01\x86\xf7#<\x92~}\xb2\xdc\xc7\x03\xc0\xe5\x00\xb6S\xca\x82';{\xfa\xd8\x04]\x85\xa4p" # noqa: E501

def __call__(self, preimage):
if not isinstance(preimage, bytes):
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
url='https://github.com/ethereum/eth-hash',
include_package_data=True,
install_requires=[
"pycryptodome>=3.4.6",
],
setup_requires=['setuptools-markdown'],
extras_require=extras_require,
Expand Down

0 comments on commit e2e7c70

Please sign in to comment.