Example #1
0
    if len(ahex) % 2: ahex = '0' + ahex
    abin = binascii.unhexlify(ahex)

    priv_key = OpenSSL.BN_bin2bn(abin, len(abin), 0)
    pub_key = OpenSSL.EC_POINT_new(group)
    assert OpenSSL.EC_POINT_mul(group, pub_key, priv_key, None, None,
                                None) == 1

    pubhex = OpenSSL.EC_POINT_point2hex(group, pub_key,
                                        POINT_CONVERSION_COMPRESSED, 0)
    if ctypes.cast(pubhex, ctypes.c_char_p).value == cp:
        print 'found it!', ahex
        key = ahex
        break

    OpenSSL.CRYPTO_free(pubhex)
    OpenSSL.EC_POINT_free(pub_key)
    OpenSSL.BN_free(priv_key)

    tried += 1
    if tried % 10000 == 0:
        sys.stdout.write('%d.. ' % tried)
        sys.stdout.flush()

OpenSSL.EC_KEY_free(k)
assert key

# decrypt
key = key.rjust(32, '0')
p = subprocess.Popen([
    'mdecrypt',