Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame^] | 1 | .. hazmat:: |
Donald Stufft | d8f0118 | 2013-10-27 16:59:56 -0400 | [diff] [blame] | 2 | |
Donald Stufft | e51fb93 | 2013-10-27 17:26:17 -0400 | [diff] [blame] | 3 | Message Digests |
| 4 | =============== |
| 5 | |
Donald Stufft | f04317a | 2013-10-27 16:44:30 -0400 | [diff] [blame] | 6 | .. currentmodule:: cryptography.hazmat.primitives.hashes |
David Reid | 1f3d718 | 2013-10-22 16:55:18 -0700 | [diff] [blame] | 7 | |
| 8 | .. class:: BaseHash(data=None) |
Matthew Iversen | 505491b | 2013-10-19 15:56:17 +1100 | [diff] [blame] | 9 | |
Alex Gaynor | 23d01a2 | 2013-10-28 10:14:46 -0700 | [diff] [blame] | 10 | Abstract base class that implements a common interface for all hash |
| 11 | algorithms that follow here. |
Matthew Iversen | 505491b | 2013-10-19 15:56:17 +1100 | [diff] [blame] | 12 | |
Alex Gaynor | 23d01a2 | 2013-10-28 10:14:46 -0700 | [diff] [blame] | 13 | 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 Gaynor | f3b06cd | 2013-10-21 21:49:50 -0700 | [diff] [blame] | 23 | |
Paul Kehrer | 6b9ddeb | 2013-10-19 12:28:15 -0500 | [diff] [blame] | 24 | .. method:: update(data) |
Matthew Iversen | 505491b | 2013-10-19 15:56:17 +1100 | [diff] [blame] | 25 | |
Alex Gaynor | ddc62f0 | 2013-10-20 06:14:24 -0700 | [diff] [blame] | 26 | :param bytes data: The bytes you wish to hash. |
Matthew Iversen | 505491b | 2013-10-19 15:56:17 +1100 | [diff] [blame] | 27 | |
| 28 | .. method:: copy() |
| 29 | |
Paul Kehrer | 6b9ddeb | 2013-10-19 12:28:15 -0500 | [diff] [blame] | 30 | :return: a new instance of this object with a copied internal state. |
Matthew Iversen | 505491b | 2013-10-19 15:56:17 +1100 | [diff] [blame] | 31 | |
| 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 Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 40 | SHA-1 |
Matthew Iversen | 505491b | 2013-10-19 15:56:17 +1100 | [diff] [blame] | 41 | ~~~~~ |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 42 | |
| 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 Reid | 1f3d718 | 2013-10-22 16:55:18 -0700 | [diff] [blame] | 48 | .. class:: SHA1() |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 49 | |
| 50 | SHA-1 is a cryptographic hash function standardized by NIST. It has a |
| 51 | 160-bit message digest. |
| 52 | |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 53 | SHA-2 Family |
Matthew Iversen | 505491b | 2013-10-19 15:56:17 +1100 | [diff] [blame] | 54 | ~~~~~~~~~~~~ |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 55 | |
David Reid | 1f3d718 | 2013-10-22 16:55:18 -0700 | [diff] [blame] | 56 | .. class:: SHA224() |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 57 | |
| 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 Reid | 1f3d718 | 2013-10-22 16:55:18 -0700 | [diff] [blame] | 61 | .. class:: SHA256() |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 62 | |
| 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 Reid | 1f3d718 | 2013-10-22 16:55:18 -0700 | [diff] [blame] | 66 | .. class:: SHA384() |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 67 | |
| 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 Reid | 1f3d718 | 2013-10-22 16:55:18 -0700 | [diff] [blame] | 71 | .. class:: SHA512() |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 72 | |
| 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 Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 76 | RIPEMD160 |
Matthew Iversen | 505491b | 2013-10-19 15:56:17 +1100 | [diff] [blame] | 77 | ~~~~~~~~~ |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 78 | |
David Reid | 1f3d718 | 2013-10-22 16:55:18 -0700 | [diff] [blame] | 79 | .. class:: RIPEMD160() |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 80 | |
| 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 Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 84 | Whirlpool |
Matthew Iversen | 505491b | 2013-10-19 15:56:17 +1100 | [diff] [blame] | 85 | ~~~~~~~~~ |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 86 | |
David Reid | 1f3d718 | 2013-10-22 16:55:18 -0700 | [diff] [blame] | 87 | .. class:: Whirlpool() |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 88 | |
| 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 Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 92 | MD5 |
Matthew Iversen | 505491b | 2013-10-19 15:56:17 +1100 | [diff] [blame] | 93 | ~~~ |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 94 | |
| 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 Reid | 1f3d718 | 2013-10-22 16:55:18 -0700 | [diff] [blame] | 100 | .. class:: MD5() |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 101 | |
Paul Kehrer | 2b9b301 | 2013-10-22 17:09:38 -0500 | [diff] [blame] | 102 | MD5 is a deprecated cryptographic hash function. It has a 128-bit message |
Paul Kehrer | 36e7d0d | 2013-10-18 18:54:40 -0500 | [diff] [blame] | 103 | digest and has practical known collision attacks. |