From 59759fdde9f03a6c565df50472da5079f6ba745b Mon Sep 17 00:00:00 2001 From: Determinant Date: Fri, 23 Aug 2024 17:52:45 -0700 Subject: remove pysha3 from the dependency --- README.rst | 3 +-- .../_pysha3.cpython-310-x86_64-linux-gnu.so | Bin 358248 -> 0 bytes frozen_deps/sha3.py | 24 --------------------- keytree.py | 11 +++++----- 4 files changed, 7 insertions(+), 31 deletions(-) delete mode 100755 frozen_deps/_pysha3.cpython-310-x86_64-linux-gnu.so delete mode 100644 frozen_deps/sha3.py diff --git a/README.rst b/README.rst index b695ab9..737dc8b 100644 --- a/README.rst +++ b/README.rst @@ -36,10 +36,9 @@ Security - The dependencies should be safe (but do your own check!) because the part under ``frozen_deps/`` only contains: - - Some standard AES provided by ``Cryptodome`` + - Some standard AES encryption and Keccak-256 hashing provided by ``Cryptodome`` - Curve manipulation provided by ``ecdsa`` - Base58 encoding provided by ``base58`` - - SHA3 calcuation provided by ``pysha3`` Whereas web3-specific modules are pretty short: diff --git a/frozen_deps/_pysha3.cpython-310-x86_64-linux-gnu.so b/frozen_deps/_pysha3.cpython-310-x86_64-linux-gnu.so deleted file mode 100755 index b075af6..0000000 Binary files a/frozen_deps/_pysha3.cpython-310-x86_64-linux-gnu.so and /dev/null differ diff --git a/frozen_deps/sha3.py b/frozen_deps/sha3.py deleted file mode 100644 index 5657f66..0000000 --- a/frozen_deps/sha3.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (C) 2012-2016 Christian Heimes (christian@python.org) -# Licensed to PSF under a Contributor Agreement. -# - -# monkey patch _hashlib -import hashlib as _hashlib - -from _pysha3 import keccak_224, keccak_256, keccak_384, keccak_512 -from _pysha3 import sha3_224, sha3_256, sha3_384, sha3_512 -from _pysha3 import shake_128, shake_256 - - -__all__ = ("sha3_224", "sha3_256", "sha3_384", "sha3_512", - "keccak_224", "keccak_256", "keccak_384", "keccak_512", - "shake_128", "shake_256") - - -if not hasattr(_hashlib, "sha3_512"): - _hashlib.sha3_224 = sha3_224 - _hashlib.sha3_256 = sha3_256 - _hashlib.sha3_384 = sha3_384 - _hashlib.sha3_512 = sha3_512 - _hashlib.shake_128 = shake_128 - _hashlib.shake_256 = shake_256 diff --git a/keytree.py b/keytree.py index 58f5cf5..b49ed22 100755 --- a/keytree.py +++ b/keytree.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3.10 +#!/usr/bin/env python3 # MIT License # # Copyright (c) 2020 Ted Yin @@ -55,10 +55,10 @@ from ecdsa import SigningKey, VerifyingKey, SECP256k1 from ecdsa.ecdsa import generator_secp256k1 from ecdsa.ellipticcurve import INFINITY from base58 import b58encode, b58decode -from sha3 import keccak_256 from uuid import uuid4 from Cryptodome.Cipher import AES from Cryptodome.Util import Counter +from Cryptodome.Hash import keccak import shamir @@ -206,7 +206,7 @@ class BIP32: def get_eth_addr(pk): pub_key = pk.to_string() - m = keccak_256() + m = keccak.new(digest_bits = 256) m.update(pub_key) return m.hexdigest()[24:] @@ -504,7 +504,7 @@ if __name__ == '__main__': recovered = mgen.to_mnemonic(shamir256_combine(verify)) if words != recovered: raise KeytreeError('Shamir sanity check failed: {} = {}'.format(case, recovered)) - print("checked {}".format(case)) + print("checked {}".format(','.join([str(i + 1) for i in case]))) else: shares = shamir256_split(seed, args.shamir_threshold, args.shamir_num) shares = [mgen.to_mnemonic(share[:32]) + ' ' + mgen.to_mnemonic(share[32:]) for share in shares] @@ -518,7 +518,8 @@ if __name__ == '__main__': recovered = shamir256_combine(verify) if seed != recovered: raise KeytreeError('Shamir sanity check failed: {} = {}'.format(case, recovered.hex())) - print("checked {}".format(case)) + print("checked {}".format(','.join([str(i + 1) for i in case]))) + for idx, share in enumerate(shares): print("KEEP THIS PRIVATE (share) #{} {}".format(idx + 1, share)) -- cgit v1.2.3-70-g09d2