Skip to main content

fastfpe

Fast Format Preserving Encryption (FPE) implementation in Rust with Python bindings.

Format-preserving encryption (FPE) is a cryptographic method that encrypts data while preserving its format. For example, encrypting a credit card number yields another valid-looking credit card number, making it useful for data protection while maintaining compatibility with existing systems.

Features

  • FF1 and FF3-1 Format Preserving Encryption algorithms
  • Fast Rust implementation with Python bindings
  • Support for custom alphabets
  • Thread-safe

[!Note]: As of late 2025, FF3/FF3-1 are no longer recommended in some security guidance due to design concerns. FF1 is fully supported here and recommended for new deployments. FF3-1 remains available for compatibility and migration.

Installation

pip install fastfpe

Usage (FF3-1)

>>> from fastfpe import ff3_1
>>>
>>> key = "3eaa133d22a7ee2432fb8ecfde1e97d9106dcf26b9edaa52b3ed4acd9a9b8445"
>>> tweak = "5be49f26c1dbb7"  # 7 bytes (14 hex chars)
>>> alphabet = "abcdef0123456789"
>>> plaintext = "024587931578"
>>>
>>> ciphertext = ff3_1.encrypt(key, tweak, alphabet, plaintext)
>>> ciphertext
'd756b8704a2d'
>>> ff3_1.decrypt(key, tweak, alphabet, ciphertext)
'024587931578'

Usage (FF1)

>>> from fastfpe import ff1
>>>
>>> # 128/192/256-bit AES keys supported (16/24/32 bytes -> 32/48/64 hex chars)
>>> key = "2b7e151628aed2a6abf7158809cf4f3c"  # 128-bit key
>>> tweak = ""  # FF1 tweak may be empty or longer (length impacts security domain sizing)
>>> alphabet = "0123456789"
>>> plaintext = "0123456789"
>>>
>>> ciphertext = ff1.encrypt(key, tweak, alphabet, plaintext)
>>> ciphertext
'2433477484'
>>> ff1.decrypt(key, tweak, alphabet, ciphertext)
'0123456789'

Notes:

  • FF1 tweak can be empty; size limits depend on NIST SP 800-38G constraints (radix and length bounds enforced internally).
  • Provide a non-empty tweak for domain separation across contexts.
  • Both algorithms return ValueError with descriptive messages on invalid inputs.

Performance

As expected, fastfpe is much faster than the reference python implementation. The gains are more pronounced with larger plaintexts.

The following benchmarks were performed on an Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz.

Running 10,000 iterations, 5 times each, 12-byte plaintext
--------------------------------------------------

Python implementation: 0.110 ms/op (± 0.001 ms)
Rust implementation:   0.008 ms/op (± 0.000 ms)
Rust is 13.2x faster

Running 10,000 iterations, 5 times each, 16-byte plaintext
--------------------------------------------------

Python implementation: 0.133 ms/op (± 0.002 ms)
Rust implementation:   0.009 ms/op (± 0.000 ms)
Rust is 14.5x faster

Running 10,000 iterations, 5 times each, 20-byte plaintext
--------------------------------------------------

Python implementation: 0.161 ms/op (± 0.005 ms)
Rust implementation:   0.010 ms/op (± 0.002 ms)
Rust is 15.9x faster

Running 10,000 iterations, 5 times each, 24-byte plaintext
--------------------------------------------------

Python implementation: 0.189 ms/op (± 0.004 ms)
Rust implementation:   0.011 ms/op (± 0.000 ms)
Rust is 16.8x faster

Support Matrix

Component Versions / Platforms
Python CPython 3.8 – 3.14 (abi3 single wheel per platform)
Operating Systems Linux (x86_64, aarch64 manylinux), macOS (universal2), Windows (x64, arm64)
Algorithms FF1 (recommended), FF3-1 (compatibility)
Key Sizes 128 / 192 / 256-bit AES
Tweak FF1: variable length (can be empty). FF3-1: exactly 7 bytes
Alphabet Custom per call; size defines radix (validated)

If you need other targets (e.g., musllinux, ppc64le) open an issue or PR.

License

Licensed under the MIT License. See LICENSE for more information.

Uses the rust-fpe implementation by johntyner, under the MIT License.

Uses the ff3 python package by mysto as a reference implementation, under the Apache 2.0 License.

Metadata

Release files for fastfpe 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for fastfpe 0.2.1
File
fastfpe-0.2.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl PyPy 3.10 PyPy 3.10 7.3 Linux glibc 2.17+ ARM64 Details
fastfpe-0.2.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl PyPy 3.9 PyPy 3.9 7.3 Linux glibc 2.17+ ARM64 Details
fastfpe-0.2.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl PyPy 3.8 PyPy 3.8 7.3 Linux glibc 2.17+ ARM64 Details
fastfpe-0.2.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl PyPy 3.7 PyPy 3.7 7.3 Linux glibc 2.17+ ARM64 Details
fastfpe-0.2.1-cp38-abi3-win_arm64.whl CPython 3.8 abi3 Windows ARM64 Details
fastfpe-0.2.1-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
fastfpe-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details
fastfpe-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.8 abi3 Linux glibc 2.17+ ARM64 Details
fastfpe-0.2.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.8 abi3 macOS 10.12+ universal2 (ARM64, x86-64), macOS 11.0+ ARM64, macOS 10.12+ x86-64 Details

Total release size: 2.6 MB

Release files / fastfpe-0.2.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL fastfpe-0.2.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 291.3 kB
Tags Linux glibc 2.17+ ARM64 PyPy 3.10 PyPy 3.10 7.3
SHA-256 checksum
How to use checksums
a210a8909f85834a24cd894bd9f611860c6f486d33da1d415057d2ca59a04382
BLAKE2b-256 checksum
How to use checksums
479a02ad61c1c2076a5b5773f77a6a883308e6a8f208f139d99294dd8e395da3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / fastfpe-0.2.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL fastfpe-0.2.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 291.5 kB
Tags Linux glibc 2.17+ ARM64 PyPy 3.9 PyPy 3.9 7.3
SHA-256 checksum
How to use checksums
2ed0d77199d2482359508e35a476f76ee55c0326981a8a1f26a0c57f37060aba
BLAKE2b-256 checksum
How to use checksums
2e1dd2560786b4be5227ada47587dc22fd9efefccabdbd06c47ce21f629dffe2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / fastfpe-0.2.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL fastfpe-0.2.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 291.5 kB
Tags Linux glibc 2.17+ ARM64 PyPy 3.8 PyPy 3.8 7.3
SHA-256 checksum
How to use checksums
c1beae26de2dedcc3ed8c2bee32c882b64a2c4b3730023675588db91462a4bff
BLAKE2b-256 checksum
How to use checksums
8d36fb68705b13f81ff4e292b9ae21f5092e9fe28cc9ca34a72526bbc0020342
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / fastfpe-0.2.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL fastfpe-0.2.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 294.8 kB
Tags Linux glibc 2.17+ ARM64 PyPy 3.7 PyPy 3.7 7.3
SHA-256 checksum
How to use checksums
a43d364ecafd97c27f9fe1116c408c26f70cad632a68864e35084989b3478436
BLAKE2b-256 checksum
How to use checksums
3d4740322f7a406a22a98405d03d6467576cb26d4cf78815853d8ad2ff54510b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / fastfpe-0.2.1-cp38-abi3-win_arm64.whl

Download URL fastfpe-0.2.1-cp38-abi3-win_arm64.whl
Size 159.1 kB
Tags CPython 3.8 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
38e00b5b521f5db7e97adae67231ff312d33e607f11788fb155bf745f853155a
BLAKE2b-256 checksum
How to use checksums
1ff4ce8de7ec876f8b6ff659ca34d86ca3684873ca634b9cf571b6665b3ba540
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / fastfpe-0.2.1-cp38-abi3-win_amd64.whl

Download URL fastfpe-0.2.1-cp38-abi3-win_amd64.whl
Size 169.6 kB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8059c30b589fef7cdca40d36f37b4fee7d7a4be1e1c17220b82522e1d7e1d2a2
BLAKE2b-256 checksum
How to use checksums
03643c3f2810fa433022eb3f17b52c1ccb6e28ac611d9c557c1a22b20ac0fc65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / fastfpe-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fastfpe-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 307.9 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
7608a00d481a0f6e3e13d0970c36c685ef1fa85d7c8b02c1ce2d606819b18e8d
BLAKE2b-256 checksum
How to use checksums
ff7f502d72186ab1e2713c17f206f6800af759773a45abe67ae328db24a9fb0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / fastfpe-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL fastfpe-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 292.4 kB
Tags CPython 3.8 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
bc050b6786a2290449ded4369ae18bada8571890de07a007f9f58be197f4bb6e
BLAKE2b-256 checksum
How to use checksums
e36bb4a1fb2b9a33cf298cbfcbff30e1b30850083adda4580931f3db5cb45ab5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / fastfpe-0.2.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL fastfpe-0.2.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 529.4 kB
Tags CPython 3.8 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f8fd8145785b07b6a94d9700381835db1bcc3364cfc2a623b564b10c891fda19
BLAKE2b-256 checksum
How to use checksums
b94217c7025776309793fc268f5114157300f6b3452ceae02506003be23c6f09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.2.1 This release

9 release files

0.2.0

5 release files

0.1.3

6 release files

0.1.2

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page