diff --git a/src/apps/cardano/cbor.py b/src/apps/cardano/cbor.py index b8651338c..a2b592ca4 100644 --- a/src/apps/cardano/cbor.py +++ b/src/apps/cardano/cbor.py @@ -19,11 +19,11 @@ _CBOR_PRIMITIVE = const(0b111 << 5) _CBOR_UINT8_FOLLOWS = const(0x18) _CBOR_UINT16_FOLLOWS = const(0x19) -_CBOR_UINT32_FOLLOWS = const(0x1a) -_CBOR_UINT64_FOLLOWS = const(0x1b) -_CBOR_VAR_FOLLOWS = const(0x1f) +_CBOR_UINT32_FOLLOWS = const(0x1A) +_CBOR_UINT64_FOLLOWS = const(0x1B) +_CBOR_VAR_FOLLOWS = const(0x1F) -_CBOR_BREAK = const(0x1f) +_CBOR_BREAK = const(0x1F) _CBOR_RAW_TAG = const(0x18) diff --git a/src/apps/ethereum/get_address.py b/src/apps/ethereum/get_address.py index 2cfc90e7d..46938efc9 100644 --- a/src/apps/ethereum/get_address.py +++ b/src/apps/ethereum/get_address.py @@ -18,7 +18,7 @@ async def get_address(ctx, msg): if msg.show_display: if len(address_n) > 1: # path has slip44 network identifier - network = networks.by_slip44(address_n[1] & 0x7fffffff) + network = networks.by_slip44(address_n[1] & 0x7FFFFFFF) else: network = None hex_addr = _ethereum_address_hex(address, network) diff --git a/src/apps/fido_u2f/__init__.py b/src/apps/fido_u2f/__init__.py index 9ff4f0292..174c2a676 100644 --- a/src/apps/fido_u2f/__init__.py +++ b/src/apps/fido_u2f/__init__.py @@ -10,7 +10,7 @@ from trezor.crypto.curve import nist256p1 from apps.common import HARDENED, storage _HID_RPT_SIZE = const(64) -_CID_BROADCAST = const(0xffffffff) # broadcast channel id +_CID_BROADCAST = const(0xFFFFFFFF) # broadcast channel id # types of frame _TYPE_MASK = const(0x80) # frame type mask @@ -23,7 +23,7 @@ _CMD_MSG = const(0x83) # send U2F message frame _CMD_LOCK = const(0x84) # send lock channel command _CMD_INIT = const(0x86) # channel initialization _CMD_WINK = const(0x88) # send device identification wink -_CMD_ERROR = const(0xbf) # error response +_CMD_ERROR = const(0xBF) # error response # types for the msg cmd _MSG_REGISTER = const(0x01) # registration command @@ -38,18 +38,18 @@ _ERR_INVALID_LEN = const(0x03) # invalid message length _ERR_INVALID_SEQ = const(0x04) # invalid message sequencing _ERR_MSG_TIMEOUT = const(0x05) # message has timed out _ERR_CHANNEL_BUSY = const(0x06) # channel busy -_ERR_LOCK_REQUIRED = const(0x0a) # command requires channel lock -_ERR_INVALID_CID = const(0x0b) # command not allowed on this cid -_ERR_OTHER = const(0x7f) # other unspecified error +_ERR_LOCK_REQUIRED = const(0x0A) # command requires channel lock +_ERR_INVALID_CID = const(0x0B) # command not allowed on this cid +_ERR_OTHER = const(0x7F) # other unspecified error # command status responses _SW_NO_ERROR = const(0x9000) _SW_WRONG_LENGTH = const(0x6700) _SW_DATA_INVALID = const(0x6984) _SW_CONDITIONS_NOT_SATISFIED = const(0x6985) -_SW_WRONG_DATA = const(0x6a80) -_SW_INS_NOT_SUPPORTED = const(0x6d00) -_SW_CLA_NOT_SUPPORTED = const(0x6e00) +_SW_WRONG_DATA = const(0x6A80) +_SW_INS_NOT_SUPPORTED = const(0x6D00) +_SW_CLA_NOT_SUPPORTED = const(0x6E00) # init response _CAPFLAG_WINK = const(0x01) # device supports _CMD_WINK @@ -491,7 +491,7 @@ def cmd_init(req: Cmd) -> Cmd: return cmd_error(req.cid, _ERR_INVALID_CID) elif req.cid == _CID_BROADCAST: # uint32_t except 0 and 0xffffffff - resp_cid = random.uniform(0xfffffffe) + 1 + resp_cid = random.uniform(0xFFFFFFFE) + 1 else: resp_cid = req.cid @@ -552,7 +552,7 @@ def msg_register_sign(challenge: bytes, app_id: bytes) -> bytes: from apps.common import seed # derivation path is m/U2F'/r'/r'/r'/r'/r'/r'/r'/r' - keypath = [HARDENED | random.uniform(0xf0000000) for _ in range(0, 8)] + keypath = [HARDENED | random.uniform(0xF0000000) for _ in range(0, 8)] nodepath = [_U2F_KEY_PATH] + keypath # prepare signing key from random path, compute decompressed public key diff --git a/src/apps/nem/namespace/serialize.py b/src/apps/nem/namespace/serialize.py index cfba58014..cbcac273e 100644 --- a/src/apps/nem/namespace/serialize.py +++ b/src/apps/nem/namespace/serialize.py @@ -23,6 +23,6 @@ def serialize_provision_namespace( if namespace.parent: write_bytes_with_len(tx, namespace.parent.encode()) else: - write_uint32_le(tx, 0xffffffff) + write_uint32_le(tx, 0xFFFFFFFF) return tx diff --git a/src/apps/ripple/serialize.py b/src/apps/ripple/serialize.py index d7d54c4f7..7b4481afb 100644 --- a/src/apps/ripple/serialize.py +++ b/src/apps/ripple/serialize.py @@ -71,7 +71,7 @@ def write(w: bytearray, field: dict, value): def write_type(w: bytearray, field: dict): - if field["key"] <= 0xf: + if field["key"] <= 0xF: w.append((field["type"] << 4) | field["key"]) else: # this concerns two-bytes fields such as lastLedgerSequence @@ -88,7 +88,7 @@ def serialize_amount(value: int) -> bytearray: raise ValueError("Value is too large") b = bytearray(value.to_bytes(8, "big")) - b[0] &= 0x7f # clear first bit to indicate XRP + b[0] &= 0x7F # clear first bit to indicate XRP b[0] |= 0x40 # set second bit to indicate positive number return b @@ -111,12 +111,12 @@ def write_varint(w: bytearray, val: int): elif val <= 12480: val -= 193 w.append(193 + rshift(val, 8)) - w.append(val & 0xff) + w.append(val & 0xFF) elif val <= 918744: val -= 12481 w.append(241 + rshift(val, 16)) - w.append(rshift(val, 8) & 0xff) - w.append(val & 0xff) + w.append(rshift(val, 8) & 0xFF) + w.append(val & 0xFF) else: raise ValueError("Value is too large") diff --git a/src/apps/stellar/helpers.py b/src/apps/stellar/helpers.py index a433c7a7d..753ba1817 100644 --- a/src/apps/stellar/helpers.py +++ b/src/apps/stellar/helpers.py @@ -49,4 +49,4 @@ def _crc16_checksum(data: bytes) -> bytes: if c15 ^ bit: crc ^= polynomial - return ustruct.pack(" TxInputType: if txi.script_type is None: txi.script_type = InputScriptType.SPENDADDRESS if txi.sequence is None: - txi.sequence = 0xffffffff + txi.sequence = 0xFFFFFFFF return txi diff --git a/src/apps/wallet/sign_tx/tx_weight_calculator.py b/src/apps/wallet/sign_tx/tx_weight_calculator.py index 2a1bb75eb..ea0edf4bd 100644 --- a/src/apps/wallet/sign_tx/tx_weight_calculator.py +++ b/src/apps/wallet/sign_tx/tx_weight_calculator.py @@ -105,7 +105,7 @@ class TxWeightCalculator: @staticmethod def op_push_size(length: int): - if length < 0x4c: + if length < 0x4C: return 1 if length < 0x100: return 2 diff --git a/src/trezor/crypto/base32.py b/src/trezor/crypto/base32.py index 5fdf7afec..eab710b15 100644 --- a/src/trezor/crypto/base32.py +++ b/src/trezor/crypto/base32.py @@ -30,13 +30,13 @@ def encode(s: bytes) -> str: encoded += bytes( [ _b32tab[c1 >> 11], # bits 1 - 5 - _b32tab[(c1 >> 6) & 0x1f], # bits 6 - 10 - _b32tab[(c1 >> 1) & 0x1f], # bits 11 - 15 + _b32tab[(c1 >> 6) & 0x1F], # bits 6 - 10 + _b32tab[(c1 >> 1) & 0x1F], # bits 11 - 15 _b32tab[c2 >> 12], # bits 16 - 20 (1 - 5) - _b32tab[(c2 >> 7) & 0x1f], # bits 21 - 25 (6 - 10) - _b32tab[(c2 >> 2) & 0x1f], # bits 26 - 30 (11 - 15) + _b32tab[(c2 >> 7) & 0x1F], # bits 21 - 25 (6 - 10) + _b32tab[(c2 >> 2) & 0x1F], # bits 26 - 30 (11 - 15) _b32tab[c3 >> 5], # bits 31 - 35 (1 - 5) - _b32tab[c3 & 0x1f], # bits 36 - 40 (1 - 5) + _b32tab[c3 & 0x1F], # bits 36 - 40 (1 - 5) ] ) # Adjust for any leftover partial quanta diff --git a/src/trezor/crypto/bech32.py b/src/trezor/crypto/bech32.py index e2c3d21ca..212705d55 100644 --- a/src/trezor/crypto/bech32.py +++ b/src/trezor/crypto/bech32.py @@ -26,11 +26,11 @@ CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l" def bech32_polymod(values): """Internal function that computes the Bech32 checksum.""" - generator = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3] + generator = [0x3B6A57B2, 0x26508E6D, 0x1EA119FA, 0x3D4233DD, 0x2A1462B3] chk = 1 for value in values: top = chk >> 25 - chk = (chk & 0x1ffffff) << 5 ^ value + chk = (chk & 0x1FFFFFF) << 5 ^ value for i in range(5): chk ^= generator[i] if ((top >> i) & 1) else 0 return chk diff --git a/src/trezor/crypto/cashaddr.py b/src/trezor/crypto/cashaddr.py index c133fe2a7..c8c8b576b 100644 --- a/src/trezor/crypto/cashaddr.py +++ b/src/trezor/crypto/cashaddr.py @@ -26,25 +26,25 @@ ADDRESS_TYPE_P2SH = 8 def cashaddr_polymod(values): - generator = [0x98f2bc8e61, 0x79b76d99e2, 0xf33e5fb3c4, 0xae2eabe2a8, 0x1e4f43e470] + generator = [0x98F2BC8E61, 0x79B76D99E2, 0xF33E5FB3C4, 0xAE2EABE2A8, 0x1E4F43E470] chk = 1 for value in values: top = chk >> 35 - chk = ((chk & 0x07ffffffff) << 5) ^ value + chk = ((chk & 0x07FFFFFFFF) << 5) ^ value for i in range(5): chk ^= generator[i] if (top & (1 << i)) else 0 return chk ^ 1 def prefix_expand(prefix): - return [ord(x) & 0x1f for x in prefix] + [0] + return [ord(x) & 0x1F for x in prefix] + [0] def calculate_checksum(prefix, payload): poly = cashaddr_polymod(prefix_expand(prefix) + payload + [0, 0, 0, 0, 0, 0, 0, 0]) out = list() for i in range(8): - out.append((poly >> 5 * (7 - i)) & 0x1f) + out.append((poly >> 5 * (7 - i)) & 0x1F) return out diff --git a/src/trezor/crypto/rlp.py b/src/trezor/crypto/rlp.py index b052241a3..8b66ffeb3 100644 --- a/src/trezor/crypto/rlp.py +++ b/src/trezor/crypto/rlp.py @@ -42,12 +42,12 @@ def encode(data, include_length=True) -> bytes: def field_length(length: int, first_byte: bytearray) -> int: - if length == 1 and first_byte[0] <= 0x7f: + if length == 1 and first_byte[0] <= 0x7F: return 1 elif length <= 55: return 1 + length - elif length <= 0xff: + elif length <= 0xFF: return 2 + length - elif length <= 0xffff: + elif length <= 0xFFFF: return 3 + length return 4 + length