Reverse padding for ctsrp and prevent overflow in tests

This commit is contained in:
Aron Wussler 2021-08-23 22:38:20 +02:00 committed by Alexandru Cheltuitor
parent 81c6614722
commit 7c10492ae4
No known key found for this signature in database
GPG key ID: 66B58C938EBBFA07
2 changed files with 7 additions and 3 deletions

View file

@ -111,6 +111,10 @@ def new_bn():
return bn
def bn_num_bytes(a):
return ((BN_num_bits(a) + 7) // 8) # noqa
def bn_mod(rem, m, d, ctx):
return BN_div(None, rem, m, d, ctx) # noqa
@ -120,9 +124,9 @@ def bn_is_zero(n):
def bn_to_bytes(n, num_bytes):
b = ctypes.create_string_buffer(num_bytes)
b = ctypes.create_string_buffer(bn_num_bytes(n))
BN_bn2bin(n, b) # noqa
return b.raw[::-1]
return b.raw[::-1].ljust(num_bytes, b'\0')
def bytes_to_bn(dest_bn, bytes):

View file

@ -18,7 +18,7 @@ class TestServer:
self.calculate_k() * self.verifier + pow(
self.generator, self.b, self.modulus
)
)
) % self.modulus
self.secret = None
self.A = None