SHA-1
In cryptography, SHA-1 (Secure Hash Algorithm 1) is a hash function. It takes an input and produces a 160-bit (20-byte) value called a message digest, which is usually written as 40 hexadecimal digits. The United States National Security Agency designed SHA-1, and it is a U.S. Federal Information Processing Standard. The algorithm has been cryptographically broken, but it is still widely used.
Since 2005, SHA-1 has not been considered secure against well-funded opponents, and as of 2010 many organizations have recommended replacing it. NIST formally deprecated SHA-1 in 2011, disallowed its use for digital signatures in 2013, and declared that it should be phased out by 2030. As of 2020, chosen-prefix attacks against SHA-1 are practical. For this reason, it is recommended to remove SHA-1 from products as soon as possible and use SHA-2 or SHA-3 instead. Replacing SHA-1 is urgent where it is used for digital signatures.
All major web browser makers stopped accepting SHA-1 SSL certificates in 2017. In February 2017, CWI Amsterdam and Google announced that they had carried out a collision attack against SHA-1. They published two different PDF files that produced the same SHA-1 hash. However, SHA-1 is still secure for HMAC.
Microsoft stopped SHA-1 code signing support for Windows Update on August 3, 2020. This also effectively ended the update servers for versions of Windows that had not been updated to SHA-2, such as Windows 2000 up to Vista, and Windows Server versions from Windows 2000 Server to Server 2003.
Development
SHA-1 uses ideas similar to those that Ronald L. Rivest of MIT used for the MD4 and MD5 methods. However, it creates a larger message digest, with 160 bits instead of 128. SHA-1 was developed as part of the U.S. Government's Capstone project. The first version was published in 1993 as the Secure Hash Standard, FIPS PUB 180, by the NIST standards agency. This first version is now often called SHA-0. The NSA withdrew it soon after it was published.
The revised version, published in 1995, is commonly called SHA-1. It differs from SHA-0 by only one small change. According to the NSA, this change fixed a flaw that had weakened the original method's security, but the NSA did not explain this further. Methods that were publicly available showed that SHA-0 was broken in 2004, and SHA-1 in 2017 (see §Attacks).
Applications
Further information: Cryptographic hash function § Applications
SHA-1 is part of several widely used security tools and internet protocols, including TLS and SSL, PGP, SSH, S/MIME, and IPsec. Some of these can also use MD5, and both MD5 and SHA-1 come from MD4. The U.S. government requires SHA-1 and the SHA-2 family for some sensitive, unclassified information. SHA-1 is being phased out of most government uses, though it can still be used to check old digital signatures and time stamps. The Secure Hash Algorithm was mainly published to support the Digital Signature Standard, which uses it. SHA hash functions have also been used as the basis for SHACAL block ciphers.
Version control systems such as Git, Mercurial, and Monotone use SHA-1 to label versions and to check that data has not been changed by accident, not to keep data secure. Linus Torvalds explained that Git's use of SHA-1 is a consistency check, not a security feature. He noted that one reason he cared was a break-in at a BitKeeper site, where people tried to damage kernel source code. Git also does not depend on the second preimage resistance of SHA-1 for security, because it keeps the earliest version of an object if two versions clash.
Cryptanalysis and validation
Finding a message that matches a given hash value can be done by trying many possibilities, about 2L tries, where L is the number of bits in the hash. This is called a preimage attack. Finding two different messages that produce the same hash, called a collision, takes far fewer tries using a birthday attack. SHA-1 was originally thought to have 80-bit strength. Some uses, such as password storage, are only slightly affected by collisions, but even a secure password hash cannot stop guessing attacks on weak passwords. Until the end of 2008, forged SSL certificates could be made using an MD5 collision.
Researchers found weaknesses in SHA-1 and its earlier version, SHA-0, over many years. In 2017, CWI and Google announced an attack that created two different PDF files with the same SHA-1 hash. After the 2004 results for SHA-0, the National Institute of Standards and Technology (NIST) planned to phase out SHA-1 by 2010 in favor of the SHA-2 variants. Implementations can be officially checked through the CMVP program, and by December 2013 there were over 2000 validated implementations of SHA-1.
Examples and pseudocode
The article shows examples of SHA-1 message digests, which are written as hexadecimal numbers and as Base64 text. For example, the sentence "The quick brown fox jumps over the lazy dog" gives the hash 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12. Changing just one word, "dog" to "cog", produces a very different hash, with 81 of the 160 bits changing. This is called the avalanche effect. An empty text also has its own hash, da39a3ee5e6b4b0d3255bfef95601890afd80709.
The section also gives pseudocode for the SHA-1 algorithm. Pseudocode is a set of step-by-step instructions written in a way that is close to computer code. It uses technical details, such as 32-bit numbers and starting values, and shows different ways to write some of the steps.
Comparison of SHA functions
Further information: Merkle–Damgård construction
In the table below, "internal state" means the internal hash value after each block of data is processed.
Implementations
Many cryptography libraries support SHA-1, including Botan, Bouncy Castle, cryptlib, Crypto++, Libgcrypt, Mbed TLS, Nettle, LibreSSL, OpenSSL, and GnuTLS. Some processors also speed up SHA-1 with built-in features. These include Intel SHA extensions, which are available on some Intel and AMD x86 processors, VIA PadLock, and IBM z/Architecture, where it has been available since 2003 as part of the Message-Security-Assist Extension.
After SHAttered, Marc Stevens and Dan Shumow published "sha1collisiondetection" (SHA-1CD), a version of SHA-1 that detects collision attacks and changes the hash output when one is detected. Its false positive rate is 2−90. GitHub has used SHA-1CD since March 2017, and git has used it since version 2.13.0 of May 2017.

Quiz time!
5 questions about SHA-1
What does SHA-1 produce from an input?
Keep exploring
This article is a child-friendly adaptation of the Wikipedia article on SHA-1, available under CC BY-SA 4.0.
Images from Wikimedia Commons. Tap any image to view credits and license.