A rainbow table is a complete list of all possible passwords up to a given length, with their corresponding hash for a given hashing algorithm.
When implemented properly, passwords are never stored directly by software. Instead, a mathematical hash is stored instead. For example, instead of storing the password “iforgot”, software might store a value calculated from that password, such as “62072d95acb588c7ee9d6fa0c6c85155”. When someone logs in using the password, the hash is calculated again, and if it matches the saved hash, then the password must have been entered correctly.
This approach safeguards passwords because the password cannot be recovered from the hash. Even if the hash were exposed, as is often the case in large scale data breaches, it would be of little value to a hacker, because they would be unable to determine the corresponding password.
A rainbow table takes a brute force approach to this problem. For a given maximum password length, the hash values for all possible passwords are calculated and stored in a table. If a hash is known, it can simply be looked up in the table to determine the corresponding password, with no further calculation required.
Rainbow tables have severe limitations that make them less useful than we might fear.
- Password length. A rainbow table for 8-character passwords might be on the order of 20 trillion entries in length – currently a somewhat manageable number. Tables for a 10-character password requires over 4 quadrillion entries, and for a 12-character password, approaches 9 quintillion. The time to create such large tables, as well as the space to store them, remains impractical.
- Algorithm-specific. There are several standard hashing algorithms, and hackers would have to know which was used. A rainbow table would need to be created for each different algorithm. In addition, some algorithms are specifically designed to be slow. While fast enough for single-password use, when applied to all possible passwords it becomes impractical.
- Easily invalidated. Hashing algorithms are now often applied not on the password alone, but on some modification of the password. For example, rather than just hashing “password”, an implementation might hash “accountname-password”. This breaks the general purpose nature of rainbow tables.
Current best practice in password storage is to use all three: long passwords, a “slow” hashing algorithm, and a modified hash.
A rainbow table is a precomputed table for caching the output of cryptographic hash functions, usually for cracking password hashes. Tables are usually used in recovering a key derivation function (or credit card numbers, etc.) up to a certain length consisting of a limited set of characters. It is a practical example of a space–time tradeoff, using less computer processing time and more storage than a brute-force attack which calculates a hash on every attempt, but more processing time and less storage than a simple key derivation function with one entry per hash. Use of a key derivation that employs a salt makes this attack infeasible.
Rainbow tables were invented by Philippe Oechslin as an application of an earlier, simpler algorithm by Martin Hellman.