blob: 8f1d342f41b6297ccf7c219c8f05062cceffb6cf [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
Alex Gaynor23d01a22013-10-28 10:14:46 -070015 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 Gaynor23d01a22013-10-28 10:14:46 -070018 If ``data`` is provided ``update(data)`` is called upon construction.
19
20 .. doctest::
21
22 >>> from cryptography.hazmat.primitives import hashes
23 >>> digest = hashes.SHA256()
24 >>> digest.update(b"abc")
25 >>> digest.update(b"123")
26 >>> digest.hexdigest()
27 '6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090'
Alex Gaynorf3b06cd2013-10-21 21:49:50 -070028
Paul Kehrer6b9ddeb2013-10-19 12:28:15 -050029 .. method:: update(data)
Matthew Iversen505491b2013-10-19 15:56:17 +110030
Alex Gaynorddc62f02013-10-20 06:14:24 -070031 :param bytes data: The bytes you wish to hash.
Matthew Iversen505491b2013-10-19 15:56:17 +110032
33 .. method:: copy()
34
Paul Kehrer6b9ddeb2013-10-19 12:28:15 -050035 :return: a new instance of this object with a copied internal state.
Matthew Iversen505491b2013-10-19 15:56:17 +110036
37 .. method:: digest()
38
39 :return bytes: The message digest as bytes.
40
41 .. method:: hexdigest()
42
43 :return str: The message digest as hex.
44
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050045SHA-1
Matthew Iversen505491b2013-10-19 15:56:17 +110046~~~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050047
48.. attention::
49
50 NIST has deprecated SHA-1 in favor of the SHA-2 variants. New applications
51 are strongly suggested to use SHA-2 over SHA-1.
52
David Reid1f3d7182013-10-22 16:55:18 -070053.. class:: SHA1()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050054
55 SHA-1 is a cryptographic hash function standardized by NIST. It has a
56 160-bit message digest.
57
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050058SHA-2 Family
Matthew Iversen505491b2013-10-19 15:56:17 +110059~~~~~~~~~~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050060
David Reid1f3d7182013-10-22 16:55:18 -070061.. class:: SHA224()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050062
63 SHA-224 is a cryptographic hash function from the SHA-2 family and
64 standardized by NIST. It has a 224-bit message digest.
65
David Reid1f3d7182013-10-22 16:55:18 -070066.. class:: SHA256()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050067
68 SHA-256 is a cryptographic hash function from the SHA-2 family and
69 standardized by NIST. It has a 256-bit message digest.
70
David Reid1f3d7182013-10-22 16:55:18 -070071.. class:: SHA384()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050072
73 SHA-384 is a cryptographic hash function from the SHA-2 family and
74 standardized by NIST. It has a 384-bit message digest.
75
David Reid1f3d7182013-10-22 16:55:18 -070076.. class:: SHA512()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050077
78 SHA-512 is a cryptographic hash function from the SHA-2 family and
79 standardized by NIST. It has a 512-bit message digest.
80
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050081RIPEMD160
Matthew Iversen505491b2013-10-19 15:56:17 +110082~~~~~~~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050083
David Reid1f3d7182013-10-22 16:55:18 -070084.. class:: RIPEMD160()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050085
86 RIPEMD160 is a cryptographic hash function that is part of ISO/IEC
87 10118-3:2004. It has a 160-bit message digest.
88
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050089Whirlpool
Matthew Iversen505491b2013-10-19 15:56:17 +110090~~~~~~~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050091
David Reid1f3d7182013-10-22 16:55:18 -070092.. class:: Whirlpool()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050093
94 Whirlpool is a cryptographic hash function that is part of ISO/IEC
95 10118-3:2004. It has a 512-bit message digest.
96
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050097MD5
Matthew Iversen505491b2013-10-19 15:56:17 +110098~~~
Paul Kehrer36e7d0d2013-10-18 18:54:40 -050099
100.. warning::
101
102 MD5 is a deprecated hash algorithm that has practical known collision
103 attacks. You are strongly discouraged from using it.
104
David Reid1f3d7182013-10-22 16:55:18 -0700105.. class:: MD5()
Paul Kehrer36e7d0d2013-10-18 18:54:40 -0500106
Paul Kehrer2b9b3012013-10-22 17:09:38 -0500107 MD5 is a deprecated cryptographic hash function. It has a 128-bit message
Paul Kehrer36e7d0d2013-10-18 18:54:40 -0500108 digest and has practical known collision attacks.