blob: de66b7fe90e02dce14f3d3df90e0d498fbe9c647 [file] [log] [blame]
Donald Stufftd8f01182013-10-27 16:59:56 -04001.. danger::
2
3 This is a "Hazardous Materials" module. You should **ONLY** use it if
4 you're 100% absolutely sure that you know what you're doing because this
5 module is full of land mines, dragons, and dinosaurs with laser guns.
6
7
Donald Stuffte51fb932013-10-27 17:26:17 -04008Message Digests
9===============
10
Donald Stufftf04317a2013-10-27 16:44:30 -040011.. currentmodule:: cryptography.hazmat.primitives.hashes
David Reid1f3d7182013-10-22 16:55:18 -070012
13.. class:: BaseHash(data=None)
Matthew Iversen505491b2013-10-19 15:56:17 +110014
Paul Kehrer6b9ddeb2013-10-19 12:28:15 -050015 Abstract base class that implements a common interface for all hash
16 algorithms that follow here.
Matthew Iversen505491b2013-10-19 15:56:17 +110017
Alex Gaynorf3b06cd2013-10-21 21:49:50 -070018 If ``data`` is provided ``update(data)`` is called upon construction.
19
Paul Kehrer6b9ddeb2013-10-19 12:28:15 -050020 .. method:: update(data)
Matthew Iversen505491b2013-10-19 15:56:17 +110021
Alex Gaynorddc62f02013-10-20 06:14:24 -070022 :param bytes data: The bytes you wish to hash.
Matthew Iversen505491b2013-10-19 15:56:17 +110023
24 .. method:: copy()
25
Paul Kehrer6b9ddeb2013-10-19 12:28:15 -050026 :return: a new instance of this object with a copied internal state.
Matthew Iversen505491b2013-10-19 15:56:17 +110027
28 .. method:: digest()
29
30 :return bytes: The message digest as bytes.
31
32 .. method:: hexdigest()
33
34 :return str: The message digest as hex.
35
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050036SHA-1
Matthew Iversen505491b2013-10-19 15:56:17 +110037~~~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050038
39.. attention::
40
41 NIST has deprecated SHA-1 in favor of the SHA-2 variants. New applications
42 are strongly suggested to use SHA-2 over SHA-1.
43
David Reid1f3d7182013-10-22 16:55:18 -070044.. class:: SHA1()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050045
46 SHA-1 is a cryptographic hash function standardized by NIST. It has a
47 160-bit message digest.
48
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050049SHA-2 Family
Matthew Iversen505491b2013-10-19 15:56:17 +110050~~~~~~~~~~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050051
David Reid1f3d7182013-10-22 16:55:18 -070052.. class:: SHA224()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050053
54 SHA-224 is a cryptographic hash function from the SHA-2 family and
55 standardized by NIST. It has a 224-bit message digest.
56
David Reid1f3d7182013-10-22 16:55:18 -070057.. class:: SHA256()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050058
59 SHA-256 is a cryptographic hash function from the SHA-2 family and
60 standardized by NIST. It has a 256-bit message digest.
61
David Reid1f3d7182013-10-22 16:55:18 -070062.. class:: SHA384()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050063
64 SHA-384 is a cryptographic hash function from the SHA-2 family and
65 standardized by NIST. It has a 384-bit message digest.
66
David Reid1f3d7182013-10-22 16:55:18 -070067.. class:: SHA512()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050068
69 SHA-512 is a cryptographic hash function from the SHA-2 family and
70 standardized by NIST. It has a 512-bit message digest.
71
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050072RIPEMD160
Matthew Iversen505491b2013-10-19 15:56:17 +110073~~~~~~~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050074
David Reid1f3d7182013-10-22 16:55:18 -070075.. class:: RIPEMD160()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050076
77 RIPEMD160 is a cryptographic hash function that is part of ISO/IEC
78 10118-3:2004. It has a 160-bit message digest.
79
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050080Whirlpool
Matthew Iversen505491b2013-10-19 15:56:17 +110081~~~~~~~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050082
David Reid1f3d7182013-10-22 16:55:18 -070083.. class:: Whirlpool()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050084
85 Whirlpool is a cryptographic hash function that is part of ISO/IEC
86 10118-3:2004. It has a 512-bit message digest.
87
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050088MD5
Matthew Iversen505491b2013-10-19 15:56:17 +110089~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050090
91.. warning::
92
93 MD5 is a deprecated hash algorithm that has practical known collision
94 attacks. You are strongly discouraged from using it.
95
David Reid1f3d7182013-10-22 16:55:18 -070096.. class:: MD5()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050097
Paul Kehrer2b9b3012013-10-22 17:09:38 -050098 MD5 is a deprecated cryptographic hash function. It has a 128-bit message
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050099 digest and has practical known collision attacks.