Skip to content

hashlib: import pure python hash first to unbreak the hmac module #435

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

Closed
wants to merge 2 commits into from

Conversation

mvo5
Copy link

@mvo5 mvo5 commented Jul 21, 2021

With the current import strategy that favours the uhashlib
implementation before using the "internal" hashlib version external
modules like "hmac" break because the uhashlib versions lack properties
like {digest,block}_size, copy().

This commit changes the import so that the internal version of the
hash is tried to be imported first and only if there is no internal
version then the uhashlib version is used.

This should fix #384

I guess as an alternative we could try to make uhashlib compatible with hmac.
This should be relatively straightforward and was done in micropython/micropython#4539 but wasn't received favorable there.

mvo5 added 2 commits July 21, 2021 19:03
With the current import strategy that favours the uhashlib
implementation before using the "internal" hashlib version external
modules like "hmac" break because the uhashlib versions lack properties
like `{digest,block}_size, copy()`.

This commit changes the import so that the internal version of the
hash is tried to be imported first and only if there is no internal
version then the uhashlib version is used.
@mvo5
Copy link
Author

mvo5 commented Jul 27, 2021

I love micropython and would love to see this issue fixed. Is there anything I can do/should do to move this forward? I'm happy to write test cases or anything else that might help :)

@tfindlay-au
Copy link

@jimmo Can you provide some feedback on this PR ?
I know a few people that are held up by the issue that this would resolve if its accepted.

@jimmo
Copy link
Member

jimmo commented Aug 8, 2022

Thanks @mvo5 and sorry this has taken so long.

It's preferable to use the built-in one where possible -- e.g. an app that only needs to do sha256 hmacs shouldn't need to install hashlib from micropython-lib if the device already has it.

I agree it would be good to update uhashlib's ones to support hmac (as per micropython/micropython#4539) but hmac strictly doesn't need these extensions to function. So instead I think it's better to solve this by making the hmac module able to use the built-in ones as they are. See #515

@jimmo jimmo closed this Aug 8, 2022
@mvo5
Copy link
Author

mvo5 commented Aug 10, 2022

Thanks @jimmo - using the buildin hashes by default of course makes a ton of sense - thank so much for fixing hmac with the buildin hashes too, really appreicated!

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.

HMAC AttributeError
3 participants