Refactoring crypto base changes #1806
|
@ -10,17 +10,22 @@ High level cryptographic functions based on `.pyelliptic` OpenSSL bindings.
|
|||
from binascii import hexlify
|
||||
|
||||
import pyelliptic
|
||||
from bmconfigparser import BMConfigParser
|
||||
from pyelliptic import OpenSSL
|
||||
from pyelliptic import arithmetic as a
|
||||
|
||||
from bmconfigparser import BMConfigParser
|
||||
|
||||
__all__ = ['encrypt', 'makeCryptor', 'pointMult', 'privToPub', 'sign', 'verify']
|
||||
|
||||
|
||||
def makeCryptor(privkey):
|
||||
"""Return a private `.pyelliptic.ECC` instance"""
|
||||
private_key = a.changebase(privkey, 16, 256, minlen=32)
|
||||
public_key = pointMult(private_key)
|
||||
privkey_bin = '\x02\xca\x00\x20' + private_key
|
||||
pubkey_bin = '\x02\xca\x00\x20' + public_key[1:-32] + '\x00\x20' + public_key[-32:]
|
||||
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(
|
||||
curve='secp256k1', privkey=privkey_bin, pubkey=pubkey_bin)
|
||||
return cryptor
|
||||
|
@ -29,7 +34,7 @@ def makeCryptor(privkey):
|
|||
def hexToPubkey(pubkey):
|
||||
"""Convert a pubkey from hex to binary"""
|
||||
pubkey_raw = a.changebase(pubkey[2:], 16, 256, minlen=64)
|
||||
pubkey_bin = '\x02\xca\x00 ' + pubkey_raw[:32] + '\x00 ' + pubkey_raw[32:]
|
||||
pubkey_bin = b'\x02\xca\x00 ' + pubkey_raw[:32] + b'\x00 ' + pubkey_raw[32:]
|
||||
return pubkey_bin
|
||||
|
||||
|
||||
|
|
Reference in New Issue
Block a user