Skip to content

Commit c51b287

Browse files
g1itchLee Miller
authored andcommitted
Tests for keys generation
this implementation for deterministic keys requires a passphrase of type bytes
1 parent 5c1dcc5 commit c51b287

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/tests/samples.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@
4343
)
4444

4545
sample_seed = b'TIGER, tiger, burning bright. In the forests of the night'
46-
# Deterministic addresses with stream 1 and versions 3, 4
46+
# RIPE hash on step 22 with signing key nonce 42
4747
sample_deterministic_ripe = b'00cfb69416ae76f68a81c459de4e13460c7d17eb'
48+
# Deterministic addresses with stream 1 and versions 3, 4
4849
sample_deterministic_addr3 = 'BM-2DBPTgeSawWYZceFD69AbDT5q4iUWtj1ZN'
4950
sample_deterministic_addr4 = 'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK'
5051
sample_daddr3_512 = 18875720106589866286514488037355423395410802084648916523381

src/tests/test_crypto.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
RIPEMD160 = None
1818

1919
from .samples import (
20-
sample_double_sha512, sample_hash_data,
20+
sample_deterministic_ripe, sample_double_sha512, sample_hash_data,
2121
sample_msg, sample_pubsigningkey, sample_pubencryptionkey,
2222
sample_privsigningkey, sample_privencryptionkey, sample_ripe,
23-
sample_sig, sample_sig_sha1
23+
sample_seed, sample_sig, sample_sig_sha1
2424
)
2525

2626

@@ -81,6 +81,22 @@ def test_randomBytes(self):
8181
self.assertNotEqual(len(set(data)), 1)
8282
self.assertNotEqual(data, highlevelcrypto.randomBytes(n))
8383

84+
def test_random_keys(self):
85+
"""Dummy checks for random keys"""
86+
priv, pub = highlevelcrypto.random_keys()
87+
self.assertEqual(len(priv), 32)
88+
self.assertEqual(highlevelcrypto.pointMult(priv), pub)
89+
90+
def test_deterministic_keys(self):
91+
"""Generate deterministic keys, make ripe and compare it to sample"""
92+
# encodeVarint(42) = b'*'
93+
sigkey = highlevelcrypto.deterministic_keys(sample_seed, b'*')[1]
94+
enkey = highlevelcrypto.deterministic_keys(sample_seed, b'+')[1]
95+
self.assertEqual(
96+
sample_deterministic_ripe,
97+
hexlify(TestHashlib._hashdigest(
98+
hashlib.sha512(sigkey + enkey).digest())))
99+
84100
def test_signatures(self):
85101
"""Verify sample signatures and newly generated ones"""
86102
pubkey_hex = hexlify(sample_pubsigningkey)

0 commit comments

Comments
 (0)