Add public/private key encryption and decryption#110
Conversation
Uses ECIES encryption decryption method; AES-128-CBC with PKCS7 is used as the cipher; hmac-sha256 is used as the mac
|
I don't think that this is BitCash specific and might make the most sense to have it in its own repository and Python package. If I'm not mistaken, would this code work for Bitcoin, Bitcoin Cash, and Bitcoin SV? |
|
@sometato However, it adds feature parity with the Electron-Cash app. Users of BitCash get the simplicity of public/private key based encryption/decryption. Such encryption/decryption methods are very common, and have allied applications. @merc1er |
| hash160 = ripemd160_sha256 | ||
|
|
||
|
|
||
| def sha512(bytestr): |
There was a problem hiding this comment.
I think that only the minimum should contain public methods. This could be _sha512().
| return base64.b64encode(encrypted + mac) | ||
|
|
||
|
|
||
| def ecies_decrypt(encrypted, secret): |
There was a problem hiding this comment.
Might consider making all functions except ecies_* private, or do bitcash/_crypto.py and only expose the wallet methods. Either way is good with me.
There was a problem hiding this comment.
Made aes_* functions private, since they're only used by ecies_* functions -- which should be public. But the other functions should be left public, since they expose hashlib functions in a simpler way, as used by Bitcash in other functions/classes.
| ], | ||
|
|
||
| install_requires=['coincurve>=4.3.0', 'requests'], | ||
| install_requires=['coincurve>=4.3.0', 'requests', 'pyaes'], |
There was a problem hiding this comment.
It's very cool that pyaes has no dependencies, but it's a bit dated and possibly prone to timing attacks. I'd just like to point that out.
Is this what Electron Cash uses?
There was a problem hiding this comment.
Electron cash uses cryptodome; however, falls back to pyaes if cryptodome import fails.
Pyaes is simply a pythonic implementation of AES-128. I think, mitigating attack such as timing attack would be more relevant on how bitcash -- and apps/implementation that use bitcash -- uses pyaes.
So mostly, any implementation that uses bitcash's ECIES would need to mitigate timing attacks by choosing when it declares the message to be invalid, right when bitcash tells it that AES key/iv is bad, or when it further verifies the content of the "successfully" decrypted data to be bad.
Uses ECIES encryption decryption method; AES-128-CBC with PKCS7 is used as the cipher; hmac-sha256 is used as the mac