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
Share the implementation of hashlib across ports #8749
Conversation
.. many platforms can use mbedtls to implement hashlib. Compile-tested with pico-w. Tested on feather rp2040 dvi.
due to mbedtls version skew, some macros need to be provided. The espressif common-hal implementation is no longer needed. The copyright of hashlib/__init__.h comes from micropython extmod/modhashlib.c where I found the macro definitions.
I don't know how to test it, however CI doesn't seem to build images for WIZnet boards. |
@anecdata how are you on this? |
I'm an observer (no relevant expertise), certainly no objections, seems a much more thorough solution than what I originally tried. This originally arose due to someone noticing that websockets in HTTPServer didn't have access to native |
Due to the way the CI optimizes building fewer boards when possible, the rp2040 builds are on a previous Actions run. I think you can get the artifact you'd want for testing from here: https://github.com/adafruit/circuitpython/actions/runs/7305598483?pr=8749 |
Performs a similar calculation as in HTTPServer websockets: EXPAND...import time
GUID = b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
ITERATIONS = 10_000
def hashme():
key = "dGhlIHNhbXBsZSBub25jZQ=="
start = time.monotonic_ns()
for _ in range(0, ITERATIONS):
response_key = hashlib.new("sha1", key.encode())
response_key.update(GUID)
return time.monotonic_ns() - start
import hashlib
duration = hashme()
print(f"{ITERATIONS} iterations in {duration} ns - hashlib")
#import adafruit_hashlib as hashlib
#duration = hashme()
#print(f"{ITERATIONS} iterations in {duration} ns - adafruit_hashlib")
Native hashlib is now present and executes (an order of magnitude faster than the library)... LGTM! Thanks, @jepler ! |
Thank you @jepler ! I tested with W5500-EVB-Pico. I no longer get the hashlib error when I run the code used in the following Issue URL. LGTM. |
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.
reviewed but did not test, however nothing looks amiss to me :)
.. many platforms can use mbedtls to implement hashlib.
Compile-tested with pico-w. Tested on feather rp2040 dvi. Enabled on rp2040 for now. Could hypothetically be enabled on other ports.
Alternative to #8719 (ping @anecdata)