Skip to content

extmod/moduhashlib: allow multiple calls to digest() method #6850

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 1 commit into from

Conversation

doc-hex
Copy link
Contributor

@doc-hex doc-hex commented Feb 5, 2021

It's useful to be able to call digest() multiple times on a sha256 object, and no way to code around the previous limitation of the uhashlib module which did not support that.

Fix is to copy the context and do the finalize operation on the copy. Cost is minimal (stack depth, one copy), and IMO, required by the API imposed by PEP 452. As it was, the sha256() object was left in an invalid state after first digest call and subsequent calls were returning garbage.

In my opinion, the right API for embedded systems, is to keep this fully-featured object-oriented API for complex cases, but also provide a single-shot function that doesn't keep state, and simply returns the binary digest of its only argument. A simple functional API like that can also accommodate hardware acceleration, which would be very difficult with the OO API.

@Jongy
Copy link
Contributor

Jongy commented Feb 20, 2021

It was suggested in the past: #4488, but I guess we concluded not to do that

@dpgeorge dpgeorge added the extmod Relates to extmod/ directory in source label Nov 29, 2021
@dpgeorge
Copy link
Member

Closing for the same reason as #4488, see comment #4488 (comment)

Also see #7316 which prevents calling digest() more than once.

@dpgeorge dpgeorge closed this Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extmod Relates to extmod/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants