Possible fix for test_random_keys() failure on short keys #2173

Merged
PeterSurda merged 4 commits from gitea-68 into v0.6 2024-02-20 02:23:12 +01:00
Showing only changes of commit 8e95279906 - Show all commits

View File

@ -107,12 +107,19 @@ class ECC(object):
High level function which returns :
curve(2) + len_of_pubkeyX(2) + pubkeyX + len_of_pubkeyY + pubkeyY
"""
ctx = OpenSSL.BN_CTX_new()
n = OpenSSL.BN_new()
group = OpenSSL.EC_GROUP_new_by_curve_name(self.curve)
OpenSSL.EC_GROUP_get_order(group, n, ctx)
key_len = OpenSSL.BN_num_bytes(n)
pubkey_x = self.pubkey_x.rjust(key_len, b'\x00')
pubkey_y = self.pubkey_y.rjust(key_len, b'\x00')
return b''.join((
pack('!H', self.curve),
pack('!H', len(self.pubkey_x)),
self.pubkey_x,
pack('!H', len(self.pubkey_y)),
self.pubkey_y,
pack('!H', len(pubkey_x)),
pubkey_x,
pack('!H', len(pubkey_y)),
pubkey_y,
))
def get_privkey(self):