Crate fpe

source ·
Expand description

Format-preserving Encryption

Provides implementations of the NIST-specified FF1 and FF3-1 encryption algorithms. Format-preserving encryption, in short, means that both the plaintext and ciphertext will consist of the same alphabet of characters.

If no alphabet is supplied, as is the case in the example below, a default alphabet is used, consisting of the characters 0 through 9, followed by the letters a through z, and then by the letters A through Z. The maximum radix supported by this default alphabet is 62, the number of characters in the alphabet.

Example

let ff1 = fpe::ff1::FF1::new(
    &[
        0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
        0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
    ],    // the encryption key
    None, // no tweak specified, use an empty one
    0, 0, // no minimum and maximum tweak size
    10,   // radix specifies the number of characters in the alphabet
    None  // use (the first 10 characters of) the default alphabet
).unwrap();

// these are from the first NIST-specified test for FF1
let pt = "0123456789";
let ct = "2433477484";

let out = ff1.encrypt(pt, None).unwrap();
assert!(out == ct);

let out = ff1.decrypt(&ct, None).unwrap();
assert!(out == pt);

Modules

  • Errors returned by the FPE library
  • The FF1 algorithm
  • The FF3-1 algorithm
  • Results returned by the FPE library