Articles

FF1 explained for developers: format-preserving encryption, NIST SP 800-38G, and why not FF3-1

What format-preserving encryption is, how NIST's FF1 fits in, why FF3 and FF3-1 fell away, and how checksums like Luhn survive encryption.

Ordinary encryption changes the shape of your data. Encrypt a card number with AES and you get a block of random-looking bytes — AES works on fixed 128-bit blocks — which no longer fits in a column, a form field or a validator that expects digits. Format-preserving encryption (FPE) fixes that: the ciphertext has the same format as the plaintext. A sixteen-digit number encrypts to a sixteen-digit number.

What FF1 is

FF1 is one of the FPE methods NIST standardised in SP 800-38G, published in March 2016. It is a Feistel construction that uses AES as its building block and works over an alphabet of your choosing — digits for a card, letters and digits for an ID. Like any block cipher mode, it is keyed; it also takes a tweak, a non-secret input that changes the output, so the same value can encrypt differently in different contexts if you want it to.

Because FF1 is a permutation of the domain, it is reversible: decrypting with the same key and tweak gives back exactly the original.

Domain size matters

FPE on a tiny domain is weak — if a field can only take a few thousand values, an attacker can learn a lot from a modest number of plaintext–ciphertext pairs. The original SP 800-38G required a domain of at least 100 values and recommended one million. The Rev. 1 drafts make one million the minimum for FF1.

In practice that means short values — a two-letter code, a very short email address — should not be FF1-encrypted on their own. Obscate gives values below that minimum an authenticated AES-SIV token instead, which is still reversible with the key alone.

FF3, FF3-1, and why the standard now has only FF1

SP 800-38G originally specified two methods, FF1 and FF3.

  • 2017–2019. Durak and Vaudenay published an attack on FF3. NIST's February 2019 draft of Rev. 1 replaced FF3 with FF3-1, which shortened the tweak.
  • 2021. Tim Beyne's CRYPTO 2021 paper, Linear Cryptanalysis of FF3-1 and FEA, described practical attacks on FF3-1 that exploit its tweak schedule.
  • 2025. NIST's second public draft of Rev. 1, released on 3 February 2025, no longer specifies FF3 at all. It cites the tweak-schedule weakness described by Beyne, which affects FF3 and FF3-1 but not FF1.

As of this article's last review, Rev. 1 is still a draft and the final standard remains the 2016 SP 800-38G. If you are choosing an FPE method today, FF1 is the one both versions agree on.

Keeping checksums valid

Many identifiers carry a check digit: card numbers use Luhn, Aadhaar uses Verhoeff, IBANs use mod-97. Encrypt the digits with FF1 and the result is a well-formed string that, most of the time, fails its checksum — only about one in ten random digit strings passes Luhn. Downstream validators then reject it, and a detector looking for card numbers won't find it again on the way back.

The standard technique is cycle-walking: encrypt, and if the result is not in the valid set, encrypt the result again, until it is. Decryption walks back the same way. Because FF1 is a permutation, this stays reversible.

Obscate applies it per identifier type. It keeps separators and fixed prefixes as they are, encrypts the rest with FF1, and cycle-walks until the token is checksum-valid and is detected as the same type. A real example, with a throwaway key:

TypeOriginalTokenCheck
Card4111 1111 1111 11110381 2360 4214 0458Luhn ✓
Aadhaar2341 2341 23464640 9059 9315Verhoeff ✓
IBANDE89 3704 0044 0532 0130 00DE76 7956 2030 9150 9630 27mod-97 ✓

What to check in any FF1 implementation

  1. It is tested against NIST's published FF1 sample vectors. Obscate's implementation passes all nine.
  2. It enforces a minimum domain size, and does something sensible below it.
  3. Keys come from a proper key-derivation step and are never reused across unrelated purposes. On the hosted API, Obscate derives each account's FF1, AES-SIV and hash keys with HKDF-SHA256 from a service master key, the account and a key version, so one account can never restore another's tokens. If you store tokens to restore later, store the key_version returned with them.
  4. Restore is exact. Obscate self-checks every fpe redaction before returning it, and on our synthetic benchmark it restored 200/200 documents exactly.

Sources

Try the redact → restore round trip on your own text — no signup.

Get a free API key

Free plan: 1,000 requests a month, all strategies. Your key is shown once — we store only a hash of it.