Post
Topic
Board Development & Technical Discussion
Re: Is it secure to use bitcoin private public key for message encryption?
by
bit22gen
on 15/11/2015, 09:58:30 UTC
It takes a while to go through all the code, I just had a quick look at the main encryption function.

You use ECIES with the curve sect283r1 for public key encryption and aes-256-cbc for the symmetric encryption.

It seems like you send iv directly over the network.
That should be ok, but giving an attacker as little information as possible is a good thing,
so another possibility is to compute the iv from the shared secret, as is done in the Electrum ECIES.
But that is probably not a problem.

Here is the encrypt function:

==============================
    @staticmethod
    def raw_encrypt(data, pubkey_x, pubkey_y, curve='sect283r1',
                    ephemcurve=None, ciphername='aes-256-cbc'):
        if ephemcurve is None:
            ephemcurve = curve
        ephem = ECC(curve=ephemcurve)
        key = sha512(ephem.raw_get_ecdh_key(pubkey_x, pubkey_y)).digest()
        key_e, key_m = key[:32], key[32:]
        pubkey = ephem.get_pubkey()
        iv = Cipher.gen_IV(ciphername)
        ctx = Cipher(key_e, iv, 1, ciphername)
        ciphertext = iv + pubkey + ctx.ciphering(data)
        mac = hmac_sha256(key_m, ciphertext)
        return ciphertext + mac
==============================