blob: c780dcb00b4d4d37ddb92adcad72816bc61ad92e [file] [log] [blame]
Alex Gaynoraf82d5e2013-10-29 17:07:24 -07001.. hazmat::
Donald Stufftd8f01182013-10-27 16:59:56 -04002
Donald Stuffte51fb932013-10-27 17:26:17 -04003Message Digests
4===============
5
Donald Stufftf04317a2013-10-27 16:44:30 -04006.. currentmodule:: cryptography.hazmat.primitives.hashes
David Reid1f3d7182013-10-22 16:55:18 -07007
8.. class:: BaseHash(data=None)
Matthew Iversen505491b2013-10-19 15:56:17 +11009
Alex Gaynor23d01a22013-10-28 10:14:46 -070010 Abstract base class that implements a common interface for all hash
11 algorithms that follow here.
Matthew Iversen505491b2013-10-19 15:56:17 +110012
Alex Gaynor23d01a22013-10-28 10:14:46 -070013 If ``data`` is provided ``update(data)`` is called upon construction.
14
15 .. doctest::
16
17 >>> from cryptography.hazmat.primitives import hashes
18 >>> digest = hashes.SHA256()
19 >>> digest.update(b"abc")
20 >>> digest.update(b"123")
21 >>> digest.hexdigest()
22 '6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090'
Alex Gaynorf3b06cd2013-10-21 21:49:50 -070023
Paul Kehrer6b9ddeb2013-10-19 12:28:15 -050024 .. method:: update(data)
Matthew Iversen505491b2013-10-19 15:56:17 +110025
Alex Gaynorddc62f02013-10-20 06:14:24 -070026 :param bytes data: The bytes you wish to hash.
Matthew Iversen505491b2013-10-19 15:56:17 +110027
28 .. method:: copy()
29
Paul Kehrer6b9ddeb2013-10-19 12:28:15 -050030 :return: a new instance of this object with a copied internal state.
Matthew Iversen505491b2013-10-19 15:56:17 +110031
32 .. method:: digest()
33
34 :return bytes: The message digest as bytes.
35
36 .. method:: hexdigest()
37
38 :return str: The message digest as hex.
39
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050040SHA-1
Matthew Iversen505491b2013-10-19 15:56:17 +110041~~~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050042
43.. attention::
44
45 NIST has deprecated SHA-1 in favor of the SHA-2 variants. New applications
46 are strongly suggested to use SHA-2 over SHA-1.
47
David Reid1f3d7182013-10-22 16:55:18 -070048.. class:: SHA1()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050049
50 SHA-1 is a cryptographic hash function standardized by NIST. It has a
51 160-bit message digest.
52
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050053SHA-2 Family
Matthew Iversen505491b2013-10-19 15:56:17 +110054~~~~~~~~~~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050055
David Reid1f3d7182013-10-22 16:55:18 -070056.. class:: SHA224()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050057
58 SHA-224 is a cryptographic hash function from the SHA-2 family and
59 standardized by NIST. It has a 224-bit message digest.
60
David Reid1f3d7182013-10-22 16:55:18 -070061.. class:: SHA256()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050062
63 SHA-256 is a cryptographic hash function from the SHA-2 family and
64 standardized by NIST. It has a 256-bit message digest.
65
David Reid1f3d7182013-10-22 16:55:18 -070066.. class:: SHA384()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050067
68 SHA-384 is a cryptographic hash function from the SHA-2 family and
69 standardized by NIST. It has a 384-bit message digest.
70
David Reid1f3d7182013-10-22 16:55:18 -070071.. class:: SHA512()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050072
73 SHA-512 is a cryptographic hash function from the SHA-2 family and
74 standardized by NIST. It has a 512-bit message digest.
75
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050076RIPEMD160
Matthew Iversen505491b2013-10-19 15:56:17 +110077~~~~~~~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050078
David Reid1f3d7182013-10-22 16:55:18 -070079.. class:: RIPEMD160()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050080
81 RIPEMD160 is a cryptographic hash function that is part of ISO/IEC
82 10118-3:2004. It has a 160-bit message digest.
83
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050084Whirlpool
Matthew Iversen505491b2013-10-19 15:56:17 +110085~~~~~~~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050086
David Reid1f3d7182013-10-22 16:55:18 -070087.. class:: Whirlpool()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050088
89 Whirlpool is a cryptographic hash function that is part of ISO/IEC
90 10118-3:2004. It has a 512-bit message digest.
91
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050092MD5
Matthew Iversen505491b2013-10-19 15:56:17 +110093~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050094
95.. warning::
96
97 MD5 is a deprecated hash algorithm that has practical known collision
98 attacks. You are strongly discouraged from using it.
99
David Reid1f3d7182013-10-22 16:55:18 -0700100.. class:: MD5()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -0500101
Paul Kehrer2b9b3012013-10-22 17:09:38 -0500102 MD5 is a deprecated cryptographic hash function. It has a 128-bit message
Paul Kehrer36e7d0d2013-10-18 18:54:40 -0500103 digest and has practical known collision attacks.