Skip to content
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

Added pure-python fallback implementation for ripemd160 #33

Merged
merged 1 commit into from
Sep 8, 2022

Conversation

bigspider
Copy link
Contributor

Closes: #32

Copy link
Owner

@darosior darosior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you for reporting and fixing this issue.

I agree it's fine to use a non-constant time implementation, since it's only used for the fingerprint. Being constant time is not a goal of this library at the moment. I wouldn't be surprised if there were non-constant timeness on actual secret data.

nit: Could you add the tests from the original implementation (https://github.com/bitcoin/bitcoin/blob/124e75a41ea0f3f0e90b63b0c41813184ddce2ab/test/functional/test_framework/ripemd160.py#L112-L130) as a sanity check of the custom implementation?

@darosior
Copy link
Owner

darosior commented Sep 7, 2022

Also, linter is failing. We use Black. A small black path/to/file.py should do the trick.

@bigspider
Copy link
Contributor Author

black path/to/file.py

Should I use the linter on ripemd160.py, or disable it there to keep the source in line with the upstream implementation from core?

I'll lint the other file.

@bigspider
Copy link
Contributor Author

Rebased.
Added tests and linted.

I added # fmt: off to ripemd160.py to disable linting, as it unrolls the big data arrays 1 element per line, which is pointless and ugly.

Copy link
Owner

@darosior darosior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, but i think you forgot to commit the test?

rip = hashlib.new("ripemd160")
rip.update(data)
return rip.digest()
except BaseException:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it to catch exception even on non-CPython? Because it looks like CPython would always raise a ValueError if it couldn't find the requested hash function.

(Note: i'm not asking to change it, was just curious about the usage of BaseException)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw it elsewhere (I think electrum), and I didn't bother making sure that it's always a ValueError (anyway, if any error happened, it doesn't feel wrong to use the custom implementation).

darosior added a commit that referenced this pull request Sep 8, 2022
@bigspider
Copy link
Contributor Author

Oops, I did forget the test.
Added and rebased again.

@darosior
Copy link
Owner

darosior commented Sep 8, 2022

ACK 7654daf

@darosior darosior merged commit 0eddd4b into darosior:master Sep 8, 2022
@darosior
Copy link
Owner

darosior commented Sep 8, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing ripemd160 in hashlib
2 participants