Blog | G5 Cyber Security

Rainbow Tables: When Salt Makes Them Worth It

TL;DR

Rainbow tables become cost-effective when cracking passwords with a specific salt value is cheaper than brute-forcing. This happens when the table size needed to cover a reasonable percentage of possible salts (e.g., 90%) is smaller than the storage required for a full brute-force attack covering all possibilities. For typical password lengths and salt sizes, this often means rainbow tables are useful starting around 16-bit salts or larger.

Understanding the Problem

Rainbow tables precompute hashes to speed up password cracking. However, they’re vulnerable if passwords use a unique ‘salt’ for each user. A salt is random data added to the password before hashing. If salts are different for every password, you need a separate rainbow table entry for each salt.

Calculating Table Size

The key is figuring out when building and storing tables for multiple salts becomes cheaper than just trying all possible passwords (brute-forcing). Here’s how to approach it:

Step 1: Determine Password Space

First, estimate the total number of possible passwords. This depends on password length and character set.

Step 2: Determine Salt Space

The salt space is the number of unique salts used. This depends on how long the salt is and what characters it uses.

Step 3: Calculate Rainbow Table Size

To cover a reasonable percentage of the salt space, you need to build tables for multiple salts. A coverage of 90% is often used as a starting point.

Step 4: Calculate Brute-Force Storage

Brute-forcing requires storing information for every possible password.

Step 5: Compare Storage Requirements

Compare the rainbow table size (231 million entries) to the brute-force storage (2.18 TB). In this example, the rainbow table is significantly smaller.

When Rainbow Tables Become Practical

  1. Small Salt Space: If the salt space is small (e.g., 8 or 16 bits), rainbow tables are likely to be cost-effective.
  2. Large Password Space: With a large password space, brute-forcing becomes impractical.
  3. Computational Cost: The time it takes to generate the rainbow table needs to be less than the time it would take to brute-force a significant portion of the passwords.

Example Code (Python – Illustrative)

This is a simplified example to demonstrate calculating password space, not actual rainbow table generation.

import math

def calculate_password_space(length, charset_size):
  return charset_size ** length

password_length = 8
charset_size = 62 # Mixed-case alphanumeric
password_space = calculate_password_space(password_length, charset_size)
print(f"Password space: {password_space:,}")

salt_length = 16
salt_charset_size = 16 # Hexadecimal
salt_space = calculate_password_space(salt_length, salt_charset_size)
print(f"Salt space: {salt_space:,}")

Important Considerations

Exit mobile version