-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add public/private key encryption and decryption #110
base: master
Are you sure you want to change the base?
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks great! Thank you.
It should probably include a section for it in the docs, but I can take care of writing this :)
I might have someone else to review this before merging, as I am not knowledgeable when it comes to cryptography.
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 |
@@ -20,3 +23,110 @@ def ripemd160_sha256(bytestr): | |||
|
|||
|
|||
hash160 = ripemd160_sha256 | |||
|
|||
|
|||
def sha512(bytestr): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -48,7 +48,7 @@ | |||
'Programming Language :: Python :: Implementation :: PyPy' | |||
], | |||
|
|||
install_requires=['coincurve>=4.3.0', 'requests'], | |||
install_requires=['coincurve>=4.3.0', 'requests', 'pyaes'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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