From 49a20a87d7c635687b00fc301968b07a52446592 Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Wed, 2 Feb 2022 02:25:52 +0000 Subject: [PATCH] Remove dependency on pyblake2. Signed-off-by: Daira Hopwood --- f4jumble_long.py | 2 +- poetry.lock | 21 +------------------ pyproject.toml | 1 - zcash_test_vectors/f4jumble.py | 3 +-- zcash_test_vectors/orchard/generators.py | 2 +- zcash_test_vectors/orchard/group_hash.py | 2 +- zcash_test_vectors/orchard/note_encryption.py | 6 +++--- zcash_test_vectors/sapling/generators.py | 2 +- zcash_test_vectors/sapling/key_components.py | 2 +- zcash_test_vectors/sapling/note_encryption.py | 2 +- zcash_test_vectors/sapling/notes.py | 2 +- zcash_test_vectors/sapling/redjubjub.py | 2 +- zcash_test_vectors/sapling/zip32.py | 21 ++++++++++++------- zcash_test_vectors/zip_0143.py | 2 +- zcash_test_vectors/zip_0243.py | 2 +- zcash_test_vectors/zip_0244.py | 2 +- 16 files changed, 29 insertions(+), 45 deletions(-) diff --git a/f4jumble_long.py b/f4jumble_long.py index d1cc0ca..417de29 100755 --- a/f4jumble_long.py +++ b/f4jumble_long.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from pyblake2 import blake2b +from hashlib import blake2b from zcash_test_vectors.output import render_args, render_tv from zcash_test_vectors.f4jumble import f4jumble, f4jumble_inv, MAX_l_M diff --git a/poetry.lock b/poetry.lock index 974089f..ad3f78d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -48,14 +48,6 @@ category = "main" optional = false python-versions = ">=3.7" -[[package]] -name = "pyblake2" -version = "1.1.2" -description = "BLAKE2 hash function extension module" -category = "main" -optional = false -python-versions = "*" - [[package]] name = "pycparser" version = "2.21" @@ -78,7 +70,7 @@ cffi = ">=1.3.0" [metadata] lock-version = "1.1" python-versions = "^3.7" -content-hash = "e010c1cdcddf9d8e5d49d7b1578d95e966b4271158567cebf4cca1c2ac0e5b89" +content-hash = "948efde6d090bec2749dc1b557f3147dc0e33a98d8b12ddc41c8a7ffb07ea8ba" [metadata.files] cffi = [ @@ -189,17 +181,6 @@ numpy = [ {file = "numpy-1.21.0-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:3c40e6b860220ed862e8097b8f81c9af6d7405b723f4a7af24a267b46f90e461"}, {file = "numpy-1.21.0.zip", hash = "sha256:e80fe25cba41c124d04c662f33f6364909b985f2eb5998aaa5ae4b9587242cce"}, ] -pyblake2 = [ - {file = "pyblake2-1.1.2-cp27-cp27m-win32.whl", hash = "sha256:3757f7ad709b0e1b2a6b3919fa79fe3261f166fc375cd521f2be480f8319dde9"}, - {file = "pyblake2-1.1.2-cp27-cp27m-win_amd64.whl", hash = "sha256:8043267fbc0b2f3748c6920591cd0b8b5609dcce60c504c32858aa36206386f2"}, - {file = "pyblake2-1.1.2-cp34-cp34m-win32.whl", hash = "sha256:4d47b4a2c1d292b1e460bde1dda4d13aa792ed2ed70fcc263b6bc24632c8e902"}, - {file = "pyblake2-1.1.2-cp34-cp34m-win_amd64.whl", hash = "sha256:982295a87907d50f4723db6bc724660da76b6547826d52160171d54f95b919ac"}, - {file = "pyblake2-1.1.2-cp35-cp35m-win32.whl", hash = "sha256:baa2190bfe549e36163aa44664d4ee3a9080b236fc5d42f50dc6fd36bbdc749e"}, - {file = "pyblake2-1.1.2-cp35-cp35m-win_amd64.whl", hash = "sha256:407e02c7f8f36fcec1b7aa114ddca0c1060c598142ea6f6759d03710b946a7e3"}, - {file = "pyblake2-1.1.2-cp36-cp36m-win32.whl", hash = "sha256:fbc9fcde75713930bc2a91b149e97be2401f7c9c56d735b46a109210f58d7358"}, - {file = "pyblake2-1.1.2-cp36-cp36m-win_amd64.whl", hash = "sha256:c53417ee0bbe77db852d5fd1036749f03696ebc2265de359fe17418d800196c4"}, - {file = "pyblake2-1.1.2.tar.gz", hash = "sha256:5ccc7eb02edb82fafb8adbb90746af71460fbc29aa0f822526fc976dff83e93f"}, -] pycparser = [ {file = "pycparser-2.21-py2.py3-none-any.whl", hash = "sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9"}, {file = "pycparser-2.21.tar.gz", hash = "sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206"}, diff --git a/pyproject.toml b/pyproject.toml index b2a03b4..14a0672 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,6 @@ python = "^3.7" numpy = "1.21.0" chacha20poly1305 = "0.0.3" cryptography = "36.0.0" -pyblake2 = "1.1.2" secp256k1 = "0.14.0" [tool.poetry.scripts] diff --git a/zcash_test_vectors/f4jumble.py b/zcash_test_vectors/f4jumble.py index 2a634e0..1d47dff 100755 --- a/zcash_test_vectors/f4jumble.py +++ b/zcash_test_vectors/f4jumble.py @@ -1,11 +1,10 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." +from hashlib import blake2b import math import struct -from pyblake2 import blake2b - from .output import render_args, render_tv from .rand import Rand from .utils import i2leosp diff --git a/zcash_test_vectors/orchard/generators.py b/zcash_test_vectors/orchard/generators.py index fdbf55e..a0e3c18 100755 --- a/zcash_test_vectors/orchard/generators.py +++ b/zcash_test_vectors/orchard/generators.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from pyblake2 import blake2s +from hashlib import blake2s from ..output import render_args, render_tv from .group_hash import group_hash diff --git a/zcash_test_vectors/orchard/group_hash.py b/zcash_test_vectors/orchard/group_hash.py index b153c80..30db8fd 100755 --- a/zcash_test_vectors/orchard/group_hash.py +++ b/zcash_test_vectors/orchard/group_hash.py @@ -1,11 +1,11 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." +from hashlib import blake2b import math from . import iso_pallas -from pyblake2 import blake2b from .pallas import Fp, p, q, PALLAS_B, Point from .iso_pallas import PALLAS_ISO_B, PALLAS_ISO_A from ..utils import i2beosp, cldiv, beos2ip, i2leosp, lebs2ip diff --git a/zcash_test_vectors/orchard/note_encryption.py b/zcash_test_vectors/orchard/note_encryption.py index 9414bc0..af49642 100755 --- a/zcash_test_vectors/orchard/note_encryption.py +++ b/zcash_test_vectors/orchard/note_encryption.py @@ -1,11 +1,11 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." +from chacha20poly1305 import ChaCha20Poly1305 +from hashlib import blake2b +import os import struct -from chacha20poly1305 import ChaCha20Poly1305 -import os -from pyblake2 import blake2b from ..transaction import MAX_MONEY from ..output import render_args, render_tv from ..rand import Rand diff --git a/zcash_test_vectors/sapling/generators.py b/zcash_test_vectors/sapling/generators.py index caed3b4..6f97873 100755 --- a/zcash_test_vectors/sapling/generators.py +++ b/zcash_test_vectors/sapling/generators.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from pyblake2 import blake2s +from hashlib import blake2s from .jubjub import Point, JUBJUB_COFACTOR from ..output import render_args, render_tv diff --git a/zcash_test_vectors/sapling/key_components.py b/zcash_test_vectors/sapling/key_components.py index 94ae667..d5e4f8a 100755 --- a/zcash_test_vectors/sapling/key_components.py +++ b/zcash_test_vectors/sapling/key_components.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from pyblake2 import blake2b, blake2s +from hashlib import blake2b, blake2s from .generators import PROVING_KEY_BASE, SPENDING_KEY_BASE, group_hash from .jubjub import Fr diff --git a/zcash_test_vectors/sapling/note_encryption.py b/zcash_test_vectors/sapling/note_encryption.py index 891aa4b..02317b0 100755 --- a/zcash_test_vectors/sapling/note_encryption.py +++ b/zcash_test_vectors/sapling/note_encryption.py @@ -2,8 +2,8 @@ import sys; assert sys.version_info[0] >= 3, "Python 3 required." from chacha20poly1305 import ChaCha20Poly1305 +from hashlib import blake2b import os -from pyblake2 import blake2b import struct from .generators import VALUE_COMMITMENT_VALUE_BASE, VALUE_COMMITMENT_RANDOMNESS_BASE diff --git a/zcash_test_vectors/sapling/notes.py b/zcash_test_vectors/sapling/notes.py index 9f6516f..841ebcc 100644 --- a/zcash_test_vectors/sapling/notes.py +++ b/zcash_test_vectors/sapling/notes.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from pyblake2 import blake2s +from hashlib import blake2s from .pedersen import ( mixing_pedersen_hash, diff --git a/zcash_test_vectors/sapling/redjubjub.py b/zcash_test_vectors/sapling/redjubjub.py index b3b140c..deb779c 100755 --- a/zcash_test_vectors/sapling/redjubjub.py +++ b/zcash_test_vectors/sapling/redjubjub.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." +from hashlib import blake2b import os -from pyblake2 import blake2b from .generators import SPENDING_KEY_BASE from .jubjub import Fr, Point, r_j diff --git a/zcash_test_vectors/sapling/zip32.py b/zcash_test_vectors/sapling/zip32.py index 5d2ec2f..bf22772 100755 --- a/zcash_test_vectors/sapling/zip32.py +++ b/zcash_test_vectors/sapling/zip32.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from pyblake2 import blake2b +from hashlib import blake2b from .key_components import to_scalar, prf_expand, diversify_hash, DerivedAkNk, DerivedIvk from .generators import SPENDING_KEY_BASE, PROVING_KEY_BASE @@ -42,8 +42,9 @@ class ExtendedBase(object): return d if diversify_hash(d) else None def fingerprint(self): - FVK = bytes(self.ak()) + bytes(self.nk()) + self.ovk() - return blake2b(person=b'ZcashSaplingFVFP', digest_size=32, data=FVK).digest() + digest = blake2b(person=b'ZcashSaplingFVFP', digest_size=32) + digest.update(bytes(self.ak()) + bytes(self.nk()) + self.ovk()) + return digest.digest() def tag(self): return self.fingerprint()[:4] @@ -72,7 +73,9 @@ class ExtendedSpendingKey(DerivedAkNk, DerivedIvk, ExtendedBase): @classmethod def master(cls, S): - I = blake2b(person=b'ZcashIP32Sapling', data=S).digest() + digest = blake2b(person=b'ZcashIP32Sapling') + digest.update(S) + I = digest.digest() I_L = I[:32] I_R = I[32:] sk_m = I_L @@ -122,8 +125,9 @@ class ExtendedSpendingKey(DerivedAkNk, DerivedIvk, ExtendedBase): return self.__class__(ask_i, nsk_i, ovk_i, dk_i, c_i, self.depth()+1, self.tag(), i) def internal(self): - FVK = encode_xfvk_parts(self.ak(), self.nk(), self.ovk(), self.dk()) - I = blake2b(person=b'Zcash_SaplingInt', digest_size=32, data=FVK).digest() + digest = blake2b(person=b'Zcash_SaplingInt', digest_size=32) + digest.update(encode_xfvk_parts(self.ak(), self.nk(), self.ovk(), self.dk())) + I = digest.digest() I_nsk = to_scalar(prf_expand(I, b'\x17')) R = prf_expand(I, b'\x18') nsk_internal = I_nsk + self.nsk() @@ -204,8 +208,9 @@ class ExtendedFullViewingKey(DerivedIvk, ExtendedBase): return self.__class__(ak_i, nk_i, ovk_i, dk_i, c_i, self.depth()+1, self.tag(), i) def internal(self): - FVK = encode_xfvk_parts(self.ak(), self.nk(), self.ovk(), self.dk()) - I = blake2b(person=b'Zcash_SaplingInt', digest_size=32, data=FVK).digest() + digest = blake2b(person=b'Zcash_SaplingInt', digest_size=32) + digest.update(encode_xfvk_parts(self.ak(), self.nk(), self.ovk(), self.dk())) + I = digest.digest() I_nsk = to_scalar(prf_expand(I, b'\x17')) R = prf_expand(I, b'\x18') nk_internal = PROVING_KEY_BASE * I_nsk + self.nk() diff --git a/zcash_test_vectors/zip_0143.py b/zcash_test_vectors/zip_0143.py index 77e6399..8af52eb 100755 --- a/zcash_test_vectors/zip_0143.py +++ b/zcash_test_vectors/zip_0143.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from pyblake2 import blake2b +from hashlib import blake2b import struct from .transaction import ( diff --git a/zcash_test_vectors/zip_0243.py b/zcash_test_vectors/zip_0243.py index b860db8..36549fd 100755 --- a/zcash_test_vectors/zip_0243.py +++ b/zcash_test_vectors/zip_0243.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from pyblake2 import blake2b +from hashlib import blake2b import struct from .transaction import ( diff --git a/zcash_test_vectors/zip_0244.py b/zcash_test_vectors/zip_0244.py index 2b08071..be2684f 100755 --- a/zcash_test_vectors/zip_0244.py +++ b/zcash_test_vectors/zip_0244.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys; assert sys.version_info[0] >= 3, "Python 3 required." -from pyblake2 import blake2b +from hashlib import blake2b import struct from .transaction import (