2018-05-06 13:23:21 -04:00
|
|
|
:mod:`hashlib` -- hashing algorithms
|
2017-02-25 16:55:33 -05:00
|
|
|
=====================================
|
2014-12-01 17:52:41 -05:00
|
|
|
|
2018-02-20 20:34:59 -05:00
|
|
|
.. include:: ../templates/unsupported_in_circuitpython.inc
|
|
|
|
|
2018-05-06 13:23:21 -04:00
|
|
|
.. module:: hashlib
|
2017-02-25 16:55:33 -05:00
|
|
|
:synopsis: hashing algorithms
|
2022-07-12 14:13:17 -04:00
|
|
|
:noindex:
|
2014-12-01 17:52:41 -05:00
|
|
|
|
2018-02-20 20:34:59 -05:00
|
|
|
|see_cpython_module| :mod:`cpython:hashlib`.
|
2017-07-02 08:37:31 -04:00
|
|
|
|
2017-02-25 16:55:33 -05: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:
|
2015-06-10 17:29:56 -04:00
|
|
|
|
2017-02-25 16:55:33 -05:00
|
|
|
* 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.
|
2015-06-10 17:29:56 -04:00
|
|
|
|
2017-02-25 16:55:33 -05:00
|
|
|
* 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 03:08:14 -04:00
|
|
|
applications, so boards targeting network connectivity and
|
2020-12-09 10:52:18 -05:00
|
|
|
interoperability will try to provide this.
|
2015-06-10 17:29:56 -04:00
|
|
|
|
2017-02-25 16:55:33 -05:00
|
|
|
* MD5 - A legacy algorithm, not considered cryptographically secure. Only
|
2020-12-09 10:52:18 -05:00
|
|
|
selected boards, targeting interoperability with legacy applications,
|
2017-02-25 16:55:33 -05:00
|
|
|
will offer this.
|
2014-12-01 17:52:41 -05:00
|
|
|
|
|
|
|
Constructors
|
|
|
|
------------
|
|
|
|
|
2018-05-06 13:23:21 -04:00
|
|
|
.. class:: hashlib.sha256([data])
|
2014-12-01 17:52:41 -05:00
|
|
|
|
2017-02-25 16:55:33 -05:00
|
|
|
Create an SHA256 hasher object and optionally feed ``data`` into it.
|
|
|
|
|
2018-05-06 13:23:21 -04:00
|
|
|
.. class:: hashlib.sha1([data])
|
2017-02-25 16:55:33 -05:00
|
|
|
|
|
|
|
Create an SHA1 hasher object and optionally feed ``data`` into it.
|
|
|
|
|
2018-05-06 13:23:21 -04:00
|
|
|
.. class:: hashlib.md5([data])
|
2017-02-25 16:55:33 -05:00
|
|
|
|
|
|
|
Create an MD5 hasher object and optionally feed ``data`` into it.
|
2014-12-01 17:52:41 -05:00
|
|
|
|
|
|
|
Methods
|
|
|
|
-------
|
|
|
|
|
2015-06-10 17:29:56 -04:00
|
|
|
.. method:: hash.update(data)
|
2014-12-01 17:52:41 -05:00
|
|
|
|
|
|
|
Feed more binary data into hash.
|
|
|
|
|
2015-06-10 17:29:56 -04:00
|
|
|
.. method:: hash.digest()
|
2014-12-01 17:52:41 -05:00
|
|
|
|
2016-07-31 19:52:00 -04:00
|
|
|
Return hash for all data passed through hash, as a bytes object. After this
|
2017-02-25 16:55:33 -05:00
|
|
|
method is called, more data cannot be fed into the hash any longer.
|
2015-06-10 17:29:56 -04:00
|
|
|
|
|
|
|
.. method:: hash.hexdigest()
|
2014-12-01 17:52:41 -05:00
|
|
|
|
2018-05-03 10:34:43 -04:00
|
|
|
This method is NOT implemented. Use ``binascii.hexlify(hash.digest())``
|
2015-06-10 17:29:56 -04:00
|
|
|
to achieve a similar effect.
|