Replace old pysha3 with cryptodomex, test on Python 3.10

pysha3 is pretty old and doesn't seem to have any modern Python
wheels, so it requires being compiled on Python 3.7 or newer.

Cryptodome is more modern and maintained, though larger.
pull/103/head
/dev/null 3 years ago
parent 14c96dfb7f
commit f2df61585b

@ -6,6 +6,7 @@ python:
- "3.7" - "3.7"
- "3.8" - "3.8"
- "3.9" - "3.9"
- "3.10"
matrix: matrix:
allow_failures: allow_failures:
python: "nightly" python: "nightly"

@ -1,6 +1,5 @@
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
import re import re
from sha3 import keccak_256
import six import six
import struct import struct
import warnings import warnings
@ -9,6 +8,7 @@ from . import base58
from . import const from . import const
from . import ed25519 from . import ed25519
from . import numbers from . import numbers
from .keccak import keccak_256
_ADDR_REGEX = re.compile(r'^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{95}$') _ADDR_REGEX = re.compile(r'^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{95}$')
_IADDR_REGEX = re.compile(r'^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{106}$') _IADDR_REGEX = re.compile(r'^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{106}$')

@ -0,0 +1,10 @@
from Cryptodome.Hash import keccak
def keccak_256(data):
"""
Return a hashlib-compatible Keccak 256 object for the given data.
"""
hash = keccak.new(digest_bits=256)
hash.update(data)
return hash

@ -37,10 +37,10 @@
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from os import urandom from os import urandom
from sha3 import keccak_256
import warnings import warnings
from . import base58, const, ed25519, wordlists from . import base58, const, ed25519, wordlists
from .address import address from .address import address
from .keccak import keccak_256
class Seed(object): class Seed(object):
"""Creates a seed object either from local system randomness or an imported phrase. """Creates a seed object either from local system randomness or an imported phrase.
@ -124,9 +124,7 @@ class Seed(object):
return self.hex return self.hex
def _hex_seed_keccak(self): def _hex_seed_keccak(self):
h = keccak_256() return keccak_256(unhexlify(self.hex)).digest()
h.update(unhexlify(self.hex))
return h.digest()
def secret_spend_key(self): def secret_spend_key(self):
a = self._hex_seed_keccak() if self.is_mymonero() else unhexlify(self.hex) a = self._hex_seed_keccak() if self.is_mymonero() else unhexlify(self.hex)
@ -134,9 +132,7 @@ class Seed(object):
def secret_view_key(self): def secret_view_key(self):
b = self._hex_seed_keccak() if self.is_mymonero() else unhexlify(self.secret_spend_key()) b = self._hex_seed_keccak() if self.is_mymonero() else unhexlify(self.secret_spend_key())
h = keccak_256() return self.sc_reduce(keccak_256(b).digest())
h.update(b)
return self.sc_reduce(h.digest())
def public_spend_key(self): def public_spend_key(self):
if self._ed_pub_spend_key: if self._ed_pub_spend_key:
@ -164,9 +160,7 @@ class Seed(object):
"Invalid net argument '{:s}'. Must be one of monero.const.NET_*".format(net)) "Invalid net argument '{:s}'. Must be one of monero.const.NET_*".format(net))
netbyte = (18, 53, 24)[const.NETS.index(net)] netbyte = (18, 53, 24)[const.NETS.index(net)]
data = "{:x}{:s}{:s}".format(netbyte, self.public_spend_key(), self.public_view_key()) data = "{:x}{:s}{:s}".format(netbyte, self.public_spend_key(), self.public_view_key())
h = keccak_256() checksum = keccak_256(unhexlify(data)).hexdigest()
h.update(unhexlify(data))
checksum = h.hexdigest()
return address(base58.encode(data + checksum[0:8])) return address(base58.encode(data + checksum[0:8]))

@ -2,7 +2,6 @@ import binascii
import itertools import itertools
import operator import operator
import re import re
import sha3
import six import six
import struct import struct
import varint import varint
@ -12,6 +11,7 @@ from ..numbers import from_atomic, PaymentID
from .. import ed25519 from .. import ed25519
from .. import exceptions from .. import exceptions
from .extra import ExtraParser from .extra import ExtraParser
from ..keccak import keccak_256
class Payment(object): class Payment(object):
""" """
@ -138,7 +138,7 @@ class Transaction(object):
varint.encode(idx), varint.encode(idx),
] ]
) )
Hs_ur = sha3.keccak_256(hsdata).digest() Hs_ur = keccak_256(hsdata).digest()
# sc_reduce32: # sc_reduce32:
Hsint_ur = ed25519.decodeint(Hs_ur) Hsint_ur = ed25519.decodeint(Hs_ur)
@ -159,7 +159,7 @@ class Transaction(object):
timestamp=self.timestamp, timestamp=self.timestamp,
transaction=self, transaction=self,
local_address=addr) local_address=addr)
amount_hs = sha3.keccak_256(b"amount" + Hs).digest() amount_hs = keccak_256(b"amount" + Hs).digest()
xormask = amount_hs[:len(encamount)] xormask = amount_hs[:len(encamount)]
dec_amount = bytearray(a ^ b for a, b in zip(*map(bytearray, (encamount, xormask)))) dec_amount = bytearray(a ^ b for a, b in zip(*map(bytearray, (encamount, xormask))))
int_amount = struct.unpack("<Q", dec_amount)[0] int_amount = struct.unpack("<Q", dec_amount)[0]

@ -1,5 +1,4 @@
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from sha3 import keccak_256
import struct import struct
from . import address from . import address
@ -9,6 +8,7 @@ from . import const
from . import ed25519 from . import ed25519
from . import numbers from . import numbers
from .transaction import Payment, PaymentManager from .transaction import Payment, PaymentManager
from .keccak import keccak_256
class Wallet(object): class Wallet(object):
""" """

@ -1,4 +1,4 @@
pysha3 pycryptodomex
requests requests
six>=1.12.0 six>=1.12.0
ipaddress ipaddress

Loading…
Cancel
Save