Reformat and clean up

pycryptodomex
Michał Sałaban 2 years ago
parent 3263684dcb
commit 756b23db58

@ -2,9 +2,17 @@ cd_keccak = None
sha3_keccak = None
try:
from Cryptodome.Hash import cd_keccak
from Cryptodome.Hash import keccak as cd_keccak
except ImportError:
from sha3 import keccak_256 as sha3_keccak
pass
if not cd_keccak:
try:
from sha3 import keccak_256 as sha3_keccak
except ImportError:
raise ImportError(
"Could not import 'keccak' from 'Cryptodome.Hash' nor 'keccak_256' from 'sha3'. "
"Install one of those modules ('cryptodomex' is the recommended one)."
)
def keccak_256(data):
@ -16,6 +24,8 @@ def keccak_256(data):
h.update(data)
elif sha3_keccak is not None:
h = sha3_keccak(data)
else: # pragma: no cover
raise RuntimeError("SHA3 implementation is missing. Install either 'pycryptodomex' (recommended) or 'pysha3' package to provide it")
else: # pragma: no cover
raise RuntimeError(
"SHA3 implementation is missing. Install either 'pycryptodomex' (recommended) or 'pysha3' package to provide it"
)
return h

@ -134,7 +134,11 @@ class Seed(object):
return self.sc_reduce(a)
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())
)
return self.sc_reduce(keccak_256(b).digest())
def public_spend_key(self):
@ -165,7 +169,9 @@ class Seed(object):
)
)
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()
)
checksum = keccak_256(unhexlify(data)).hexdigest()
return address(base58.encode(data + checksum[0:8]))

@ -173,10 +173,13 @@ class Transaction(object):
amount=amount,
timestamp=self.timestamp,
transaction=self,
local_address=addr)
local_address=addr,
)
amount_hs = keccak_256(b"amount" + Hs).digest()
xormask = amount_hs[:len(encamount)]
dec_amount = bytearray(a ^ b for a, b in zip(*map(bytearray, (encamount, xormask))))
xormask = amount_hs[: len(encamount)]
dec_amount = bytearray(
a ^ b for a, b in zip(*map(bytearray, (encamount, xormask)))
)
int_amount = struct.unpack("<Q", dec_amount)[0]
amount = from_atomic(int_amount)
return Payment(

Loading…
Cancel
Save