RFC: hashlib
: allow getting digest without finalizing the hash object
#14362
vshymanskyy
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
During the implementation of OTA update, we came across a practical need to compute several (cumulative) digests of parts of a stream. The problem that we face is that the native implementation of the
hashlib
finalizes the hash object duringdigest()
call.We found 2 plausible ways to achieve what we need:
copy()
method. This would allow us to usehash.copy().digest()
, where only the copy of the hash is finalized, leaving the original hash intact.digest()
operate on the copy of the state. With this approach, the originalhash
object does not need to be finalized.Or, do both and make native hashlib implementations compatible with
CPython
. We have developed the PoC of (2) for SHA256 and it works like a charm. I would appreciate feedback on these approaches to determine if the uPy maintainers and community are open to accepting pull requests for these changes.Note:
micropython-lib/hashlib
does supportcopy()
and alsodigest()
operates on a copy of the state. However, pure python implementation is resource-hungry.@dpgeorge @pfalcon @jimmo
Beta Was this translation helpful? Give feedback.
All reactions