micropython/docs/library/uhashlib.rst

56 lines
1.7 KiB
ReStructuredText
Raw Normal View History

:mod:`uhashlib` -- hashing algorithms
=====================================
2014-12-01 22:52:41 +00:00
.. module:: uhashlib
:synopsis: hashing algorithms
2014-12-01 22:52:41 +00:00
This module implements binary data hashing algorithms. The exact inventory
of available algorithms depends on a board. Among the algorithms which may
be implemented:
* SHA256 - The current generation, modern hashing algorithm (of SHA2 series).
It is suitable for cryptographically-secure purposes. Included in the
MicroPython core and any board is recommended to provide this, unless
it has particular code size constraints.
* SHA1 - A previous generation algorithm. Not recommended for new usages,
but SHA1 is a part of number of Internet standards and existing
2017-05-29 08:08:14 +01:00
applications, so boards targeting network connectivity and
interoperatiability will try to provide this.
* MD5 - A legacy algorithm, not considered cryptographically secure. Only
2017-05-29 08:08:14 +01:00
selected boards, targeting interoperatibility with legacy applications,
will offer this.
2014-12-01 22:52:41 +00:00
Constructors
------------
.. class:: uhashlib.sha256([data])
2014-12-01 22:52:41 +00:00
Create an SHA256 hasher object and optionally feed ``data`` into it.
.. class:: uhashlib.sha1([data])
Create an SHA1 hasher object and optionally feed ``data`` into it.
.. class:: uhashlib.md5([data])
Create an MD5 hasher object and optionally feed ``data`` into it.
2014-12-01 22:52:41 +00:00
Methods
-------
.. method:: hash.update(data)
2014-12-01 22:52:41 +00:00
Feed more binary data into hash.
.. method:: hash.digest()
2014-12-01 22:52:41 +00:00
2016-08-01 00:52:00 +01:00
Return hash for all data passed through hash, as a bytes object. After this
method is called, more data cannot be fed into the hash any longer.
.. method:: hash.hexdigest()
2014-12-01 22:52:41 +00:00
This method is NOT implemented. Use ``ubinascii.hexlify(hash.digest())``
to achieve a similar effect.