Define __all__ in highlevelcrypto and make all literals bytes

This commit is contained in:
Dmitri Bogomolov 2021-07-21 18:32:33 +03:00
parent ddb366b477
commit c1ea75c7a3
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

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