2024-01-26 11:16:55 +00:00
|
|
|
from common import * # isort:skip
|
2020-05-14 15:09:06 +00:00
|
|
|
|
2019-04-05 09:23:06 +00:00
|
|
|
from trezor import wire
|
2019-06-27 09:32:45 +00:00
|
|
|
from trezor.crypto import bip39
|
2019-04-05 09:23:06 +00:00
|
|
|
|
2023-06-28 10:58:54 +00:00
|
|
|
from apps.common.keychain import Keychain
|
|
|
|
from apps.common.seed import Slip21Node
|
|
|
|
|
2023-06-28 10:46:29 +00:00
|
|
|
|
2020-07-23 14:23:24 +00:00
|
|
|
class TestSeed(unittest.TestCase):
|
2019-06-27 09:32:45 +00:00
|
|
|
def test_slip21(self):
|
2023-06-28 10:46:29 +00:00
|
|
|
seed = bip39.seed(" ".join(["all"] * 12), "")
|
2019-06-27 09:32:45 +00:00
|
|
|
node1 = Slip21Node(seed)
|
|
|
|
node2 = node1.clone()
|
2020-07-23 14:23:24 +00:00
|
|
|
keychain = Keychain(seed, "", [], slip21_namespaces=[[b"SLIP-0021"]])
|
2019-06-27 09:32:45 +00:00
|
|
|
|
|
|
|
# Key(m)
|
2023-06-28 10:46:29 +00:00
|
|
|
KEY_M = unhexlify(
|
|
|
|
b"dbf12b44133eaab506a740f6565cc117228cbf1dd70635cfa8ddfdc9af734756"
|
|
|
|
)
|
2019-06-27 09:32:45 +00:00
|
|
|
self.assertEqual(node1.key(), KEY_M)
|
|
|
|
|
|
|
|
# Key(m/"SLIP-0021")
|
2023-06-28 10:46:29 +00:00
|
|
|
KEY_M_SLIP0021 = unhexlify(
|
|
|
|
b"1d065e3ac1bbe5c7fad32cf2305f7d709dc070d672044a19e610c77cdf33de0d"
|
|
|
|
)
|
2019-06-27 09:32:45 +00:00
|
|
|
node1.derive_path([b"SLIP-0021"])
|
|
|
|
self.assertEqual(node1.key(), KEY_M_SLIP0021)
|
2020-07-23 14:23:24 +00:00
|
|
|
self.assertEqual(keychain.derive_slip21([b"SLIP-0021"]).key(), KEY_M_SLIP0021)
|
2019-06-27 09:32:45 +00:00
|
|
|
|
|
|
|
# Key(m/"SLIP-0021"/"Master encryption key")
|
2023-06-28 10:46:29 +00:00
|
|
|
KEY_M_SLIP0021_MEK = unhexlify(
|
|
|
|
b"ea163130e35bbafdf5ddee97a17b39cef2be4b4f390180d65b54cf05c6a82fde"
|
|
|
|
)
|
2019-06-27 09:32:45 +00:00
|
|
|
node1.derive_path([b"Master encryption key"])
|
|
|
|
self.assertEqual(node1.key(), KEY_M_SLIP0021_MEK)
|
2023-06-28 10:46:29 +00:00
|
|
|
self.assertEqual(
|
|
|
|
keychain.derive_slip21([b"SLIP-0021", b"Master encryption key"]).key(),
|
|
|
|
KEY_M_SLIP0021_MEK,
|
|
|
|
)
|
2019-06-27 09:32:45 +00:00
|
|
|
|
|
|
|
# Key(m/"SLIP-0021"/"Authentication key")
|
2023-06-28 10:46:29 +00:00
|
|
|
KEY_M_SLIP0021_AK = unhexlify(
|
|
|
|
b"47194e938ab24cc82bfa25f6486ed54bebe79c40ae2a5a32ea6db294d81861a6"
|
|
|
|
)
|
2019-06-27 09:32:45 +00:00
|
|
|
node2.derive_path([b"SLIP-0021", b"Authentication key"])
|
|
|
|
self.assertEqual(node2.key(), KEY_M_SLIP0021_AK)
|
2023-06-28 10:46:29 +00:00
|
|
|
self.assertEqual(
|
|
|
|
keychain.derive_slip21([b"SLIP-0021", b"Authentication key"]).key(),
|
|
|
|
KEY_M_SLIP0021_AK,
|
|
|
|
)
|
2019-06-27 09:32:45 +00:00
|
|
|
|
|
|
|
# Forbidden paths.
|
|
|
|
with self.assertRaises(wire.DataError):
|
2020-07-23 14:23:24 +00:00
|
|
|
keychain.derive_slip21([])
|
2020-05-14 15:09:06 +00:00
|
|
|
with self.assertRaises(wire.DataError):
|
2020-07-23 14:23:24 +00:00
|
|
|
keychain.derive_slip21([b"SLIP-9999", b"Authentication key"])
|
2020-05-14 15:09:06 +00:00
|
|
|
|
2019-06-27 09:32:45 +00:00
|
|
|
|
2023-06-28 10:46:29 +00:00
|
|
|
if __name__ == "__main__":
|
2019-04-05 09:23:06 +00:00
|
|
|
unittest.main()
|