def decode_ack_plain(self, ciphertext): """ decode legacy pre-EIP-8 ack message format """ try: message = self.ecc.ecies_decrypt(ciphertext[:210]) except RuntimeError as e: raise AuthenticationError(e) assert len(message) == 64 + 32 + 1 eph_pubkey = message[:64] nonce = message[64:64 + 32] known = safe_ord(message[-1]) assert known == 0 return (210, eph_pubkey, nonce, 4)
def decode_auth_plain(self, ciphertext): """ decode legacy pre-EIP-8 auth message format """ try: message = self.ecc.ecies_decrypt(ciphertext[:307]) except RuntimeError as e: raise AuthenticationError(e) assert len(message) == 194 signature = message[:65] pubkey = message[65 + 32:65 + 32 + 64] if not self.ecc.is_valid_key(pubkey): raise InvalidKeyError('invalid initiator pubkey') nonce = message[65 + 32 + 64:65 + 32 + 64 + 32] known_flag = bool(safe_ord(message[65 + 32 + 64 + 32:])) assert known_flag == 0 return (307, signature, pubkey, nonce, 4)
def _decode_sig(sig): return safe_ord(sig[64]) + 27, bitcoin.decode(sig[0:32], 256), bitcoin.decode( sig[32:64], 256)
def sxor(s1, s2): "string xor" assert len(s1) == len(s2) return b''.join( ascii_chr(safe_ord(a) ^ safe_ord(b)) for a, b in zip(s1, s2))
def remove_chars(s, chars): if PY3: d = {safe_ord(c): None for c in chars} return s.translate(d) else: return s.translate(None, chars)