Rewrite highlevelcrypto.makeCryptor() to reuse pyelliptic.ECC._set_keys()
This commit is contained in:
parent
d751fb9081
commit
df235f6c20
|
@ -18,16 +18,13 @@ from bmconfigparser import config
|
||||||
__all__ = ['encrypt', 'makeCryptor', 'pointMult', 'privToPub', 'sign', 'verify']
|
__all__ = ['encrypt', 'makeCryptor', 'pointMult', 'privToPub', 'sign', 'verify']
|
||||||
|
|
||||||
|
|
||||||
def makeCryptor(privkey):
|
def makeCryptor(privkey, curve='secp256k1'):
|
||||||
"""Return a private `.pyelliptic.ECC` instance"""
|
"""Return a private `.pyelliptic.ECC` instance"""
|
||||||
private_key = a.changebase(privkey, 16, 256, minlen=32)
|
private_key = a.changebase(privkey, 16, 256, minlen=32)
|
||||||
public_key = pointMult(private_key)
|
public_key = pointMult(private_key)
|
||||||
privkey_bin = b'\x02\xca\x00\x20' + private_key
|
|
||||||
pubkey_bin = (
|
|
||||||
b'\x02\xca\x00\x20' + public_key[1:-32] + b'\x00\x20' + public_key[-32:]
|
|
||||||
)
|
|
||||||
cryptor = pyelliptic.ECC(
|
cryptor = pyelliptic.ECC(
|
||||||
curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin)
|
pubkey_x=public_key[1:-32], pubkey_y=public_key[-32:],
|
||||||
|
raw_privkey=private_key, curve=curve)
|
||||||
return cryptor
|
return cryptor
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user