def test_blind(): tests = [ ('02eec7245d6b7d2ccb30380bfbe2a3648cd7a942653f5aa340edcea1f283686619', '53eb63ea8a3fec3b3cd433b85cd62a4b145e1dda09391b348c4e1cd36a03ea66', '2ec2e5da605776054187180343287683aa6a51b4b1c04d6dd49c45d8cffb3c36'), ('028f9438bfbf7feac2e108d677e3a82da596be706cc1cf342b75c7b7e22bf4e6e2', 'a6519e98832a0b179f62123b3567c106db99ee37bef036e783263602f3488fae', 'bf66c28bc22e598cfd574a1931a2bafbca09163df2261e6d0056b2610dab938f'), ('03bfd8225241ea71cd0843db7709f4c222f62ff2d4516fd38b39914ab6b83e0da0', '3a6b412548762f0dbccce5c7ae7bb8147d1caf9b5471c34120b30bc9c04891cc', 'a1f2dadd184eb1627049673f18c6325814384facdee5bfd935d9cb031a1698a5'), ('031dde6926381289671300239ea8e57ffaf9bebd05b9a5b95beaf07af05cd43595', '21e13c2d7cfe7e18836df50872466117a295783ab8aab0e7ecc8c725503ad02d', '7cfe0b699f35525029ae0fa437c69d0f20f7ed4e3916133f9cacbb13c82ff262'), ('03a214ebd875aab6ddfd77f22c5e7311d7f77f17a169e599f157bbcdae8bf071f4', 'b5756b9b542727dbafc6765a49488b023a725d631af688fc031217e90770c328', 'c96e00dddaf57e7edcd4fb5954be5b65b09f17cb6d20651b4e90315be5779205'), ] for pubkey, sharedsecret, expected in tests: expected = onion.Secret(bytes.fromhex(expected)) pubkey = onion.PublicKey(bytes.fromhex(pubkey)) sharedsecret = onion.Secret(bytes.fromhex(sharedsecret)) res = onion.blind(pubkey, sharedsecret) assert (res == expected)
def test_generate_keyset(): secret = onion.Secret( bytes.fromhex( '53eb63ea8a3fec3b3cd433b85cd62a4b145e1dda09391b348c4e1cd36a03ea66') ) keys = onion.generate_keyset(secret) expected = onion.KeySet( rho=bytes.fromhex( 'ce496ec94def95aadd4bec15cdb41a740c9f2b62347c4917325fcc6fb0453986' ), mu=bytes.fromhex( 'b57061dc6d0a2b9f261ac410c8b26d64ac5506cbba30267a649c28c179400eba' ), um=bytes.fromhex( '3ca76e96fad1a0300928639d203b4369e81254032156c936179077b08091ca49' ), pad=bytes.fromhex( '3c348715f933c32b5571e2c9136b17c4da2e8fd13e35b7092deff56650eea958' ), gamma=bytes.fromhex( 'c5b96917bc536aff7c2d6584bd60cf3b99151ccac18f173133f1fd0bdcae08b5' ), pi=bytes.fromhex( '3a70333f46a4fd1b3f72acae87760b147b07fe4923131066906a4044d4f1ddd1' ), ammag=bytes.fromhex( '3761ba4d3e726d8abb16cba5950ee976b84937b61b7ad09e741724d7dee12eb5' ), ) assert (keys == expected)
def sphinx_path_from_test_vector( filename: str) -> Tuple[onion.SphinxPath, dict]: """Loads a sphinx test vector from the repo root. """ path = os.path.dirname(__file__) root = os.path.join(path, '..') filename = os.path.join(root, filename) v = json.load(open(filename, 'r')) session_key = onion.Secret(bytes.fromhex(v['generate']['session_key'])) associated_data = bytes.fromhex(v['generate']['associated_data']) hops = [] for h in v['generate']['hops']: payload = bytes.fromhex(h['payload']) if h['type'] == 'raw' or h['type'] == 'tlv': b = BytesIO() onion.varint_encode(len(payload), b) payload = b.getvalue() + payload elif h['type'] == 'legacy': padlen = 32 - len(payload) payload = b'\x00' + payload + (b'\x00' * padlen) assert (len(payload) == 33) pubkey = onion.PublicKey(bytes.fromhex(h['pubkey'])) hops.append(onion.SphinxHop( pubkey=pubkey, payload=payload, )) return onion.SphinxPath(hops=hops, session_key=session_key, assocdata=associated_data), v
def test_blind_group_element(): tests = [ ('031dde6926381289671300239ea8e57ffaf9bebd05b9a5b95beaf07af05cd43595', '7cfe0b699f35525029ae0fa437c69d0f20f7ed4e3916133f9cacbb13c82ff262', '03a214ebd875aab6ddfd77f22c5e7311d7f77f17a169e599f157bbcdae8bf071f4'), ('028f9438bfbf7feac2e108d677e3a82da596be706cc1cf342b75c7b7e22bf4e6e2', 'bf66c28bc22e598cfd574a1931a2bafbca09163df2261e6d0056b2610dab938f', '03bfd8225241ea71cd0843db7709f4c222f62ff2d4516fd38b39914ab6b83e0da0'), ('03bfd8225241ea71cd0843db7709f4c222f62ff2d4516fd38b39914ab6b83e0da0', 'a1f2dadd184eb1627049673f18c6325814384facdee5bfd935d9cb031a1698a5', '031dde6926381289671300239ea8e57ffaf9bebd05b9a5b95beaf07af05cd43595'), ('031dde6926381289671300239ea8e57ffaf9bebd05b9a5b95beaf07af05cd43595', '7cfe0b699f35525029ae0fa437c69d0f20f7ed4e3916133f9cacbb13c82ff262', '03a214ebd875aab6ddfd77f22c5e7311d7f77f17a169e599f157bbcdae8bf071f4'), ] for pubkey, blind, expected in tests: expected = onion.PublicKey(bytes.fromhex(expected)) pubkey = onion.PublicKey(bytes.fromhex(pubkey)) blind = onion.Secret(bytes.fromhex(blind)) res = onion.blind_group_element(pubkey, blind) assert(res.to_bytes() == expected.to_bytes())