Could anybody post the necessary code changes to allow oclvanitygen to generate compressed and uncompressed keys simultaneously? I suspect the speed increase must be substantial
Thanks!
Your "suspicion" is misplaced. The only calculation in common that would be saved is the calculation of the x coordinate of the public key, which is just a few multiplications. Everything else, from creating the compressed public key parity, creating an address from a compressed public key and checking for the vanity match would be a completely different process.
Given that there are two bitcoin addresses per private key, that if you are iterating through private keys pseudo-randomly (i assume this is what vanitygen does, at the end of the day), it does seem that you may as well look at both the addresses each time you calculate a point on the curve for a given private key. I recently implemented this using some code from ken sherrif's bitcoins-the-hard-way blog along with some library routines from ecdsa module in python and I could basically as step one create a seed; step 2, get a point on the curve; and from there the process forks and you'd have two methods of generating a pubkey (one with and one without the y part). Anyway, it seems to me like there could be some value in looking at both addresses once you have a point on the curve.
def pubKeyToAddr(s):
ripemd160 = hashlib.new('ripemd160')
ripemd160.update(hashlib.sha256(s.decode('hex')).digest())
return base58CheckEncode(0, ripemd160.digest())
def privateKeyToPublicKey(s, compressed=False):
sk = ecdsa.SigningKey.from_string(s.decode('hex'), curve=ecdsa.SECP256k1)
vk = sk.verifying_key
if compressed:
from ecdsa.util import number_to_string
order = vk.pubkey.order
x_str = number_to_string(vk.pubkey.point.x(), order).encode('hex')
sign = '02' if vk.pubkey.point.y() % 2 == 0 else '03'
return (sign+x_str)
else:
return ('\04' + vk.to_string()).encode('hex')
private_key = ''.join(['%x' % random.randrange(16) for x in range(0,64)])
print "A private key: ", private_key
public_key = privateKeyToPublicKey(private_key)
cpublic_key = privateKeyToPublicKey(private_key,compressed=True)
print "The uncompressed bitcoin address: ", pubKeyToAddr(public_key)
print "The bitcoin address: ", pubKeyToAddr(cpublic_key)