Skip to main content

Fast Format Preserving Encryption (FPE) implementation in Rust

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fastfpe-0.2.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (291.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

fastfpe-0.2.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (291.5 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

fastfpe-0.2.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (291.5 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

fastfpe-0.2.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (294.8 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

fastfpe-0.2.1-cp38-abi3-win_arm64.whl (159.1 kB view details)

Uploaded CPython 3.8+Windows ARM64

fastfpe-0.2.1-cp38-abi3-win_amd64.whl (169.6 kB view details)

Uploaded CPython 3.8+Windows x86-64

fastfpe-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (307.9 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

fastfpe-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (292.4 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

fastfpe-0.2.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (529.4 kB view details)

Uploaded CPython 3.8+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file fastfpe-0.2.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fastfpe-0.2.1-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a210a8909f85834a24cd894bd9f611860c6f486d33da1d415057d2ca59a04382
MD5 a0bc65819f211637f25c99088be3b1ec
BLAKE2b-256 479a02ad61c1c2076a5b5773f77a6a883308e6a8f208f139d99294dd8e395da3

See more details on using hashes here.

File details

Details for the file fastfpe-0.2.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fastfpe-0.2.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2ed0d77199d2482359508e35a476f76ee55c0326981a8a1f26a0c57f37060aba
MD5 15ae6eb102196ca1520c461f096e84dc
BLAKE2b-256 2e1dd2560786b4be5227ada47587dc22fd9efefccabdbd06c47ce21f629dffe2

See more details on using hashes here.

File details

Details for the file fastfpe-0.2.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fastfpe-0.2.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c1beae26de2dedcc3ed8c2bee32c882b64a2c4b3730023675588db91462a4bff
MD5 971ad70b376bf5eb099a5a9091cd1c16
BLAKE2b-256 8d36fb68705b13f81ff4e292b9ae21f5092e9fe28cc9ca34a72526bbc0020342

See more details on using hashes here.

File details

Details for the file fastfpe-0.2.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fastfpe-0.2.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a43d364ecafd97c27f9fe1116c408c26f70cad632a68864e35084989b3478436
MD5 64894c60f1d12f42a62f8fc7917df807
BLAKE2b-256 3d4740322f7a406a22a98405d03d6467576cb26d4cf78815853d8ad2ff54510b

See more details on using hashes here.

File details

Details for the file fastfpe-0.2.1-cp38-abi3-win_arm64.whl.

File metadata

  • Download URL: fastfpe-0.2.1-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 159.1 kB
  • Tags: CPython 3.8+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastfpe-0.2.1-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 38e00b5b521f5db7e97adae67231ff312d33e607f11788fb155bf745f853155a
MD5 e528490256ce287ee0553ac66d4077f3
BLAKE2b-256 1ff4ce8de7ec876f8b6ff659ca34d86ca3684873ca634b9cf571b6665b3ba540

See more details on using hashes here.

File details

Details for the file fastfpe-0.2.1-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: fastfpe-0.2.1-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 169.6 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for fastfpe-0.2.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8059c30b589fef7cdca40d36f37b4fee7d7a4be1e1c17220b82522e1d7e1d2a2
MD5 ce95b4bb463c90aad84bb5a28b45b11c
BLAKE2b-256 03643c3f2810fa433022eb3f17b52c1ccb6e28ac611d9c557c1a22b20ac0fc65

See more details on using hashes here.

File details

Details for the file fastfpe-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastfpe-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7608a00d481a0f6e3e13d0970c36c685ef1fa85d7c8b02c1ce2d606819b18e8d
MD5 e4b004d3e9410bbea0a6f78a2feaa2a5
BLAKE2b-256 ff7f502d72186ab1e2713c17f206f6800af759773a45abe67ae328db24a9fb0a

See more details on using hashes here.

File details

Details for the file fastfpe-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for fastfpe-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bc050b6786a2290449ded4369ae18bada8571890de07a007f9f58be197f4bb6e
MD5 c5ae77334376fb47cc40ca9d6ecd5053
BLAKE2b-256 e36bb4a1fb2b9a33cf298cbfcbff30e1b30850083adda4580931f3db5cb45ab5

See more details on using hashes here.

File details

Details for the file fastfpe-0.2.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for fastfpe-0.2.1-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 f8fd8145785b07b6a94d9700381835db1bcc3364cfc2a623b564b10c891fda19
MD5 8782ec2490890f5c970d71b202d3f902
BLAKE2b-256 b94217c7025776309793fc268f5114157300f6b3452ceae02506003be23c6f09

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page