Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/key.py
Property | Old Value | New Value |
---|---|---|
File Mode | 100644 | 100755 |
Show All 11 Lines | |||||
import hashlib | import hashlib | ||||
import sys | import sys | ||||
ssl = ctypes.cdll.LoadLibrary(ctypes.util.find_library('ssl') or 'libeay32') | ssl = ctypes.cdll.LoadLibrary(ctypes.util.find_library('ssl') or 'libeay32') | ||||
ssl.BN_new.restype = ctypes.c_void_p | ssl.BN_new.restype = ctypes.c_void_p | ||||
ssl.BN_new.argtypes = [] | ssl.BN_new.argtypes = [] | ||||
ssl.BN_free.restype = None | |||||
ssl.BN_free.argtypes = [ctypes.c_void_p] | |||||
ssl.BN_bin2bn.restype = ctypes.c_void_p | ssl.BN_bin2bn.restype = ctypes.c_void_p | ||||
ssl.BN_bin2bn.argtypes = [ctypes.c_char_p, ctypes.c_int, ctypes.c_void_p] | ssl.BN_bin2bn.argtypes = [ctypes.c_char_p, ctypes.c_int, ctypes.c_void_p] | ||||
ssl.BN_CTX_free.restype = None | ssl.BN_CTX_free.restype = None | ||||
ssl.BN_CTX_free.argtypes = [ctypes.c_void_p] | ssl.BN_CTX_free.argtypes = [ctypes.c_void_p] | ||||
ssl.BN_CTX_new.restype = ctypes.c_void_p | ssl.BN_CTX_new.restype = ctypes.c_void_p | ||||
ssl.BN_CTX_new.argtypes = [] | ssl.BN_CTX_new.argtypes = [] | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | def set_secretbytes(self, secret): | ||||
pub_key = ssl.EC_POINT_new(group) | pub_key = ssl.EC_POINT_new(group) | ||||
ctx = ssl.BN_CTX_new() | ctx = ssl.BN_CTX_new() | ||||
if not ssl.EC_POINT_mul(group, pub_key, priv_key, None, None, ctx): | if not ssl.EC_POINT_mul(group, pub_key, priv_key, None, None, ctx): | ||||
raise ValueError( | raise ValueError( | ||||
"Could not derive public key from the supplied secret.") | "Could not derive public key from the supplied secret.") | ||||
ssl.EC_POINT_mul(group, pub_key, priv_key, None, None, ctx) | ssl.EC_POINT_mul(group, pub_key, priv_key, None, None, ctx) | ||||
ssl.EC_KEY_set_private_key(self.k, priv_key) | ssl.EC_KEY_set_private_key(self.k, priv_key) | ||||
ssl.EC_KEY_set_public_key(self.k, pub_key) | ssl.EC_KEY_set_public_key(self.k, pub_key) | ||||
ssl.BN_free(priv_key) | |||||
ssl.EC_POINT_free(pub_key) | ssl.EC_POINT_free(pub_key) | ||||
ssl.BN_CTX_free(ctx) | ssl.BN_CTX_free(ctx) | ||||
return self.k | return self.k | ||||
def set_privkey(self, key): | def set_privkey(self, key): | ||||
self.mb = ctypes.create_string_buffer(key) | self.mb = ctypes.create_string_buffer(key) | ||||
return ssl.d2i_ECPrivateKey(ctypes.byref(self.k), ctypes.byref(ctypes.pointer(self.mb)), len(key)) | return ssl.d2i_ECPrivateKey(ctypes.byref(self.k), ctypes.byref(ctypes.pointer(self.mb)), len(key)) | ||||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |