---
title: OTPs Must Have 20-bit Entropy Minimum
impact: MEDIUM
impactDescription: prevents OTP brute-forcing
tags: otp, entropy, authentication, 2fa, security
---

## OTPs Must Have 20-bit Entropy Minimum

Low-entropy OTPs (like 4 digits) can be brute-forced easily. 20 bits of entropy requires at least 6 decimal digits.

**Incorrect (low entropy OTPs):**

```go
// 4 digits = ~13 bits entropy
otp := fmt.Sprintf("%04d", rand.Intn(10000))
```

**Correct (high entropy OTPs via crypto/rand):**

```go
import (
    "crypto/rand"
    "math/big"
)

// 6-digit numeric OTP (≈20 bits entropy)
func GenerateOTP() string {
    max := big.NewInt(1000000)
    n, _ := rand.Int(rand.Reader, max)
    return fmt.Sprintf("%06d", n)
}

// 8-digit for higher security (≈26 bits)
func GenerateStrongOTP() string {
    max := big.NewInt(100000000)
    n, _ := rand.Int(rand.Reader, max)
    return fmt.Sprintf("%08d", n)
}
```

**OTP requirements:**
- Must use `crypto/rand` (CSPRNG).
- Minimum 6 digits (20 bits).
- Short expiration (5-10 minutes).
- Rate limit verification attempts.

**Tools:** Manual Review, Unit Test
