MCPcopy Create free account
hub / github.com/Bitmessage/PyBitmessage / raw_check_key

Method raw_check_key

src/pyelliptic/ecc.py:261–303  ·  view source on GitHub ↗
(self, privkey, pubkey_x, pubkey_y, curve=None)

Source from the content-addressed store, hash-verified

259 return self.raw_check_key(raw_privkey, pubkey_x, pubkey_y, curve)
260
261 def raw_check_key(self, privkey, pubkey_x, pubkey_y, curve=None):
262 if curve is None:
263 curve = self.curve
264 elif type(curve) == str:
265 curve = OpenSSL.get_curve(curve)
266 else:
267 curve = curve
268 try:
269 key = OpenSSL.EC_KEY_new_by_curve_name(curve)
270 if key == 0:
271 raise Exception("[OpenSSL] EC_KEY_new_by_curve_name FAIL ...")
272 if privkey is not None:
273 priv_key = OpenSSL.BN_bin2bn(privkey, len(privkey), 0)
274 pub_key_x = OpenSSL.BN_bin2bn(pubkey_x, len(pubkey_x), 0)
275 pub_key_y = OpenSSL.BN_bin2bn(pubkey_y, len(pubkey_y), 0)
276
277 if privkey is not None:
278 if (OpenSSL.EC_KEY_set_private_key(key, priv_key)) == 0:
279 raise Exception(
280 "[OpenSSL] EC_KEY_set_private_key FAIL ...")
281
282 group = OpenSSL.EC_KEY_get0_group(key)
283 pub_key = OpenSSL.EC_POINT_new(group)
284
285 if (OpenSSL.EC_POINT_set_affine_coordinates_GFp(group, pub_key,
286 pub_key_x,
287 pub_key_y,
288 0)) == 0:
289 raise Exception(
290 "[OpenSSL] EC_POINT_set_affine_coordinates_GFp FAIL ...")
291 if (OpenSSL.EC_KEY_set_public_key(key, pub_key)) == 0:
292 raise Exception("[OpenSSL] EC_KEY_set_public_key FAIL ...")
293 if (OpenSSL.EC_KEY_check_key(key)) == 0:
294 raise Exception("[OpenSSL] EC_KEY_check_key FAIL ...")
295 return 0
296
297 finally:
298 OpenSSL.EC_KEY_free(key)
299 OpenSSL.BN_free(pub_key_x)
300 OpenSSL.BN_free(pub_key_y)
301 OpenSSL.EC_POINT_free(pub_key)
302 if privkey is not None:
303 OpenSSL.BN_free(priv_key)
304
305 def sign(self, inputb, digest_alg=OpenSSL.digest_ecdsa_sha1):
306 """

Callers 3

_set_keysMethod · 0.95
_generateMethod · 0.95
check_keyMethod · 0.95

Calls 1

get_curveMethod · 0.45

Tested by

no test coverage detected