Use pointMult instead of arithmetic.privtopub

pointMult is faster than the pure python arithmetic.privtopub

Additionally in makeCryptor the call to a.privtopub could have just simply be changed to call the local privToPub but then privkey would have been dehexified twice (once in makeCryptor, then again in privToPub) and privToPub would have hexified its result only for makeCryptor to immediately dehexify it. This sort of unnecessary hexifying/dehexifying seems to occur throughout PyBitmessage.
This commit is contained in:
bmng-dev 2014-05-21 11:08:15 +00:00
parent b1261a6c0e
commit 9b40838f25
1 changed files with 7 additions and 4 deletions

View File

@ -1,9 +1,10 @@
import pyelliptic
from pyelliptic import arithmetic as a, OpenSSL
def makeCryptor(privkey):
privkey_bin = '\x02\xca\x00 '+a.changebase(privkey,16,256,minlen=32)
pubkey = a.changebase(a.privtopub(privkey),16,256,minlen=65)[1:]
pubkey_bin = '\x02\xca\x00 '+pubkey[:32]+'\x00 '+pubkey[32:]
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' + pubkey[-32:]
cryptor = pyelliptic.ECC(curve='secp256k1',privkey=privkey_bin,pubkey=pubkey_bin)
return cryptor
def hexToPubkey(pubkey):
@ -15,7 +16,9 @@ def makePubCryptor(pubkey):
return pyelliptic.ECC(curve='secp256k1',pubkey=pubkey_bin)
# Converts hex private key into hex public key
def privToPub(privkey):
return a.privtopub(privkey)
private_key = a.changebase(privkey, 16, 256, minlen=32)
public_key = pointMult(private_key)
return public_key.encode('hex')
# Encrypts message with hex public key
def encrypt(msg,hexPubkey):
return pyelliptic.ECC(curve='secp256k1').encrypt(msg,hexToPubkey(hexPubkey))