Refactoring crypto base changes #1806

Merged
g1itch merged 14 commits from crypto-sort into v0.6 2021-08-17 15:07:33 +02:00
3 changed files with 35 additions and 26 deletions
Showing only changes of commit e76a47779e - Show all commits

26
src/tests/samples.py Normal file
View File

@ -0,0 +1,26 @@
"""Various sample data"""
from binascii import unhexlify
# These keys are from addresses test script
sample_pubsigningkey = unhexlify(
'044a367f049ec16cb6b6118eb734a9962d10b8db59c890cd08f210c43ff08bdf09d'
'16f502ca26cd0713f38988a1237f1fc8fa07b15653c996dc4013af6d15505ce')
sample_pubencryptionkey = unhexlify(
'044597d59177fc1d89555d38915f581b5ff2286b39d022ca0283d2bdd5c36be5d3c'
'e7b9b97792327851a562752e4b79475d1f51f5a71352482b241227f45ed36a9')
sample_privsigningkey = \
b'93d0b61371a54b53df143b954035d612f8efa8a3ed1cf842c2186bfd8f876665'
sample_privencryptionkey = \
b'4b0b73a54e19b059dc274ab69df095fe699f43b17397bca26fdf40f4d7400a3a'
sample_ripe = b'003cd097eb7f35c87b5dc8b4538c22cb55312a9f'
# stream: 1, version: 2
sample_address = 'BM-onkVu1KKL2UaUss5Upg9vXmqd3esTmV79'
sample_factor = 66858749573256452658262553961707680376751171096153613379801854825275240965733
# G * sample_factor
sample_point = (
33567437183004486938355437500683826356288335339807546987348409590129959362313,
94730058721143827257669456336351159718085716196507891067256111928318063085006
)

View File

@ -4,10 +4,7 @@ from binascii import unhexlify
from pybitmessage import addresses from pybitmessage import addresses
from .samples import sample_address, sample_ripe
sample_ripe = unhexlify('003cd097eb7f35c87b5dc8b4538c22cb55312a9f')
# stream: 1, version: 2
sample_address = 'BM-onkVu1KKL2UaUss5Upg9vXmqd3esTmV79'
class TestAddresses(unittest.TestCase): class TestAddresses(unittest.TestCase):
@ -17,7 +14,7 @@ class TestAddresses(unittest.TestCase):
"""Decode some well known addresses and check the result""" """Decode some well known addresses and check the result"""
self.assertEqual( self.assertEqual(
addresses.decodeAddress(sample_address), addresses.decodeAddress(sample_address),
('success', 2, 1, sample_ripe)) ('success', 2, 1, unhexlify(sample_ripe)))
status, version, stream, ripe1 = addresses.decodeAddress( status, version, stream, ripe1 = addresses.decodeAddress(
'2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK') '2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK')
self.assertEqual(status, 'success') self.assertEqual(status, 'success')
@ -33,4 +30,5 @@ class TestAddresses(unittest.TestCase):
def test_encode(self): def test_encode(self):
"""Encode sample ripe and compare the result to sample address""" """Encode sample ripe and compare the result to sample address"""
self.assertEqual( self.assertEqual(
addresses.encodeAddress(2, 1, sample_ripe), sample_address) sample_address,
addresses.encodeAddress(2, 1, unhexlify(sample_ripe)))

View File

@ -5,7 +5,7 @@ Test the alternatives for crypto primitives
import hashlib import hashlib
import unittest import unittest
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from binascii import hexlify, unhexlify from binascii import hexlify
from pybitmessage.pyelliptic import arithmetic from pybitmessage.pyelliptic import arithmetic
@ -15,27 +15,12 @@ try:
except ImportError: except ImportError:
RIPEMD = None RIPEMD = None
from .samples import (
# These keys are from addresses test script sample_factor, sample_point, sample_pubsigningkey, sample_pubencryptionkey,
sample_pubsigningkey = unhexlify( sample_privsigningkey, sample_privencryptionkey, sample_ripe
'044a367f049ec16cb6b6118eb734a9962d10b8db59c890cd08f210c43ff08bdf09d'
'16f502ca26cd0713f38988a1237f1fc8fa07b15653c996dc4013af6d15505ce')
sample_pubencryptionkey = unhexlify(
'044597d59177fc1d89555d38915f581b5ff2286b39d022ca0283d2bdd5c36be5d3c'
'e7b9b97792327851a562752e4b79475d1f51f5a71352482b241227f45ed36a9')
sample_privsigningkey = \
'93d0b61371a54b53df143b954035d612f8efa8a3ed1cf842c2186bfd8f876665'
sample_privencryptionkey = \
'4b0b73a54e19b059dc274ab69df095fe699f43b17397bca26fdf40f4d7400a3a'
sample_ripe = b'003cd097eb7f35c87b5dc8b4538c22cb55312a9f'
sample_factor = 66858749573256452658262553961707680376751171096153613379801854825275240965733
# G * sample_factor
sample_point = (
33567437183004486938355437500683826356288335339807546987348409590129959362313,
94730058721143827257669456336351159718085716196507891067256111928318063085006
) )
_sha = hashlib.new('sha512') _sha = hashlib.new('sha512')
_sha.update(sample_pubsigningkey + sample_pubencryptionkey) _sha.update(sample_pubsigningkey + sample_pubencryptionkey)