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

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

Installation

pip install fastfpe

Usage

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

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

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.1.3-cp312-cp312-manylinux_2_34_x86_64.whl (296.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

fastfpe-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (302.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

fastfpe-0.1.3-cp311-cp311-manylinux_2_34_x86_64.whl (296.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

fastfpe-0.1.3-cp310-cp310-manylinux_2_34_x86_64.whl (296.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

fastfpe-0.1.3-cp39-cp39-manylinux_2_34_x86_64.whl (295.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

fastfpe-0.1.3-cp38-cp38-manylinux_2_34_x86_64.whl (295.5 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

File details

Details for the file fastfpe-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fastfpe-0.1.3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 37194679c2fab94a1dcd66029806c386f8985596b76ca3e3ea27bb6125df8c7f
MD5 ae1ae006d7c22c91da770714b9c3e7d8
BLAKE2b-256 012f6d02eaecb17d7a0255edea0c6b902c5eab3359ae6f0c3c069928962c79b6

See more details on using hashes here.

File details

Details for the file fastfpe-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastfpe-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f8ec16c8b5e542c23e7f4a1787857a1750a3c9880ba2919f712553e3110b8646
MD5 a6fe0bcb03482eaf8c790e0a52e4afcc
BLAKE2b-256 ec166e37809901c9550d4fc900ba787b96dba02b75545dbf212c702885f232b7

See more details on using hashes here.

File details

Details for the file fastfpe-0.1.3-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fastfpe-0.1.3-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e963b40351fea5740ed08495b66a27ac5f5ac9072120a1bb1d4cf8b360a56761
MD5 0546706968f93c252f3d80ce557d0a7b
BLAKE2b-256 e571798e194979df5230fd3abe618c1c631e39b6b5cb7900457dfd9d5bfddce1

See more details on using hashes here.

File details

Details for the file fastfpe-0.1.3-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fastfpe-0.1.3-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 86c25eebb301f6d31c34c63f30725b8bc4573977ec8e3da0ffafdc16ff4bfc81
MD5 f771edcd6d44ba08eba76c2cf285d99d
BLAKE2b-256 64d832534385c18569a104f8bfd9529c6b73884567ceb66224c66fb9f56b1444

See more details on using hashes here.

File details

Details for the file fastfpe-0.1.3-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fastfpe-0.1.3-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 aa2848b7cb2512eb3190825154eb4a60f50eb9ec3a2ada70e5e49ffae4ba484b
MD5 8e779e73291a981b9d634d49530f3762
BLAKE2b-256 89e86dcb9fd8ccfa9aa9f64defb8c8dbe29d40b92254159750620cbb212559d9

See more details on using hashes here.

File details

Details for the file fastfpe-0.1.3-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for fastfpe-0.1.3-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 936fdb4ab0cce2531470a305a5f89852ec833f0ec6a7ac7a134d789ae04601d0
MD5 1fdbe5b1b84f0af729997b701415c42e
BLAKE2b-256 7e2b3c05a7f55f72c058c61a5536d9d8c73fefc5a6f08c1aa4aac88331038c19

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