Solved test_blind_sig issue
This commit is contained in:
parent
269ffbb275
commit
fbc33b1df6
|
@ -15,5 +15,5 @@ install:
|
||||||
- python setup.py install
|
- python setup.py install
|
||||||
script:
|
script:
|
||||||
- python checkdeps.py
|
- python checkdeps.py
|
||||||
- xvfb-run src/bitmessagemain.py -t
|
- xvfb-run pybitmessage -t
|
||||||
- python setup.py test
|
- python setup.py test
|
||||||
|
|
|
@ -52,7 +52,7 @@ helper_startup.loadConfig()
|
||||||
# logging.config.fileConfig interface
|
# logging.config.fileConfig interface
|
||||||
# examples are here:
|
# examples are here:
|
||||||
# https://bitmessage.org/forum/index.php/topic,4820.msg11163.html#msg11163
|
# https://bitmessage.org/forum/index.php/topic,4820.msg11163.html#msg11163
|
||||||
log_level = 'DEBUG'
|
log_level = 'WARNING'
|
||||||
|
|
||||||
def log_uncaught_exceptions(ex_cls, ex, tb):
|
def log_uncaught_exceptions(ex_cls, ex, tb):
|
||||||
"""The last resort logging function used for sys.excepthook"""
|
"""The last resort logging function used for sys.excepthook"""
|
||||||
|
|
|
@ -659,7 +659,7 @@ class _OpenSSL(object):
|
||||||
"""
|
"""
|
||||||
returns the length of a BN (OpenSSl API)
|
returns the length of a BN (OpenSSl API)
|
||||||
"""
|
"""
|
||||||
return int((self.BN_num_bits(x) + 7) / 8)
|
return int((self.BN_num_bits(x) + 7) // 8)
|
||||||
|
|
||||||
def BN_is_odd_compatible(self, x):
|
def BN_is_odd_compatible(self, x):
|
||||||
"""
|
"""
|
||||||
|
@ -721,16 +721,27 @@ class _OpenSSL(object):
|
||||||
"""
|
"""
|
||||||
returns a create_string_buffer (ctypes)
|
returns a create_string_buffer (ctypes)
|
||||||
"""
|
"""
|
||||||
buffer_ = None
|
return self.create_string_buffer_with_bytes(data, size)
|
||||||
if data != 0:
|
|
||||||
if sys.version_info.major == 3 and isinstance(data, type('')):
|
|
||||||
data = data.encode()
|
|
||||||
buffer_ = self.create_string_buffer(bytes(data), size)
|
|
||||||
else:
|
|
||||||
buffer_ = self.create_string_buffer(bytes(size))
|
|
||||||
return buffer_
|
|
||||||
|
|
||||||
|
|
||||||
|
def create_string_buffer_with_bytes(self, data, size):
|
||||||
|
buffer_ = None
|
||||||
|
try:
|
||||||
|
if data != 0:
|
||||||
|
if sys.version_info.major == 3 and isinstance(data, type('')):
|
||||||
|
data = data.encode()
|
||||||
|
buffer_ = self.create_string_buffer(data, size)
|
||||||
|
else:
|
||||||
|
buffer_ = self.create_string_buffer(size)
|
||||||
|
except:
|
||||||
|
if data != 0:
|
||||||
|
if sys.version_info.major == 3 and isinstance(data, type('')):
|
||||||
|
data = data.encode()
|
||||||
|
buffer_ = self.create_string_buffer(bytes(data), size)
|
||||||
|
else:
|
||||||
|
buffer_ = self.create_string_buffer(bytes(size))
|
||||||
|
return buffer_
|
||||||
|
|
||||||
def loadOpenSSL():
|
def loadOpenSSL():
|
||||||
"""Method find and load the OpenSSL library"""
|
"""Method find and load the OpenSSL library"""
|
||||||
# pylint: disable=global-statement, protected-access, too-many-branches
|
# pylint: disable=global-statement, protected-access, too-many-branches
|
||||||
|
|
|
@ -31,7 +31,7 @@ class TestBlindSig(unittest.TestCase):
|
||||||
# only 64 byte messages are planned to be used in Bitmessage
|
# only 64 byte messages are planned to be used in Bitmessage
|
||||||
msg = os.urandom(64)
|
msg = os.urandom(64)
|
||||||
msg_blinded = requester_obj.create_signing_request(point_r, msg)
|
msg_blinded = requester_obj.create_signing_request(point_r, msg)
|
||||||
self.assertEqual(len(msg_blinded), 33)
|
self.assertEqual(len(msg_blinded), 32)
|
||||||
|
|
||||||
# check
|
# check
|
||||||
self.assertNotEqual(sha256(msg).digest(), msg_blinded)
|
self.assertNotEqual(sha256(msg).digest(), msg_blinded)
|
||||||
|
@ -39,18 +39,18 @@ class TestBlindSig(unittest.TestCase):
|
||||||
# (3) Signature Generation
|
# (3) Signature Generation
|
||||||
signature_blinded = signer_obj.blind_sign(msg_blinded)
|
signature_blinded = signer_obj.blind_sign(msg_blinded)
|
||||||
assert isinstance(signature_blinded, bytes)
|
assert isinstance(signature_blinded, bytes)
|
||||||
self.assertEqual(len(signature_blinded), 33)
|
self.assertEqual(len(signature_blinded), 32)
|
||||||
|
|
||||||
# (4) Extraction
|
# (4) Extraction
|
||||||
signature = requester_obj.unblind(signature_blinded)
|
signature = requester_obj.unblind(signature_blinded)
|
||||||
assert isinstance(signature, bytes)
|
assert isinstance(signature, bytes)
|
||||||
self.assertEqual(len(signature), 66)
|
self.assertEqual(len(signature), 65)
|
||||||
|
|
||||||
self.assertNotEqual(signature, signature_blinded)
|
self.assertNotEqual(signature, signature_blinded)
|
||||||
|
|
||||||
# (5) Verification
|
# (5) Verification
|
||||||
verifier_obj = ECCBlind(pubkey=signer_obj.pubkey())
|
verifier_obj = ECCBlind(pubkey=signer_obj.pubkey())
|
||||||
self.assertTrue(verifier_obj.verify(msg, signature[1:]))
|
self.assertTrue(verifier_obj.verify(msg, signature))
|
||||||
|
|
||||||
def test_is_odd(self):
|
def test_is_odd(self):
|
||||||
"""Test our implementation of BN_is_odd"""
|
"""Test our implementation of BN_is_odd"""
|
||||||
|
|
Reference in New Issue
Block a user