Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 54 additions & 67 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,103 +2,90 @@ name: CI checks

on: [push, pull_request]

jobs:
build:
name: Build target ${{ matrix.target }}
runs-on: ubuntu-latest
strategy:
matrix:
target:
- wasm32-wasip1

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Add target
run: rustup target add ${{ matrix.target }}
- name: cargo build
run: cargo build --locked --verbose --no-default-features
permissions:
contents: read

jobs:
test:
name: Test on ${{ matrix.os }}
name: Tests (${{ matrix.os }}, Rust ${{ matrix.rust }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]

os: [ubuntu-latest, windows-latest, macos-latest]
rust: [1.85.0, stable]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Run tests
run: cargo test --locked --verbose
- run: rustup toolchain install ${{ matrix.rust }} --profile minimal
- run: cargo +${{ matrix.rust }} test --locked
- run: cargo +${{ matrix.rust }} test --locked --no-default-features --features alloc
- run: cargo +${{ matrix.rust }} test --locked --no-default-features
- run: cargo +${{ matrix.rust }} build --locked --benches
- run: cargo +${{ matrix.rust }} run --locked --example aes09

bitrot:
name: Bitrot check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Build benchmarks to prevent bitrot
- name: Build benchmarks
run: cargo build --benches

clippy-test:
name: Clippy (MSRV)
timeout-minutes: 30
no-std:
name: no_std (${{ matrix.rust }}, ${{ matrix.features }})
runs-on: ubuntu-latest
strategy:
matrix:
rust: [1.85.0, stable]
features: [none, alloc]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- run: rustup component add clippy
- name: Run clippy
uses: actions-rs/clippy-check@v1
with:
name: Clippy (MSRV)
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -D warnings
- run: rustup toolchain install ${{ matrix.rust }} --profile minimal --target wasm32-unknown-unknown
- if: matrix.features == 'none'
run: cargo +${{ matrix.rust }} check --locked --target wasm32-unknown-unknown --no-default-features
- if: matrix.features == 'alloc'
run: cargo +${{ matrix.rust }} check --locked --target wasm32-unknown-unknown --no-default-features --features alloc

clippy-beta:
name: Clippy (beta)
timeout-minutes: 30
test-32-bit:
name: Native 32-bit tests (${{ matrix.rust }})
runs-on: ubuntu-latest
continue-on-error: true
strategy:
matrix:
rust: [1.85.0, stable]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: dtolnay/rust-toolchain@beta
id: toolchain
- run: rustup override set ${{steps.toolchain.outputs.name}}
- run: rustup component add clippy
- name: Run Clippy (beta)
uses: actions-rs/clippy-check@v1
continue-on-error: true
with:
name: Clippy (beta)
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets -- -W clippy::all
- run: sudo apt-get update && sudo apt-get install -y gcc-multilib
- run: rustup toolchain install ${{ matrix.rust }} --profile minimal --target i686-unknown-linux-gnu
- run: cargo +${{ matrix.rust }} test --locked --target i686-unknown-linux-gnu
- run: cargo +${{ matrix.rust }} test --locked --target i686-unknown-linux-gnu --no-default-features --features alloc
- run: cargo +${{ matrix.rust }} test --locked --target i686-unknown-linux-gnu --no-default-features

doc-links:
name: Intra-doc links
lint:
name: Clippy (${{ matrix.rust }})
runs-on: ubuntu-latest
strategy:
matrix:
rust: [1.85.0, stable]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Requires #![deny(rustdoc::broken_intra_doc_links)] in crates.
- name: Check intra-doc links
run: cargo doc --all-features --document-private-items
- run: rustup toolchain install ${{ matrix.rust }} --profile minimal --component clippy
- run: cargo +${{ matrix.rust }} clippy --locked --all-targets -- -D warnings
- run: cargo +${{ matrix.rust }} clippy --locked --no-default-features --features alloc --lib --tests -- -D warnings
- run: cargo +${{ matrix.rust }} clippy --locked --no-default-features --lib --tests -- -D warnings

fmt:
name: Rustfmt
compatibility-and-docs:
name: Compatibility, formatting and documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Check formatting
run: cargo fmt -- --check
- run: rustup toolchain install 1.85.0 --profile minimal --component rustfmt
- run: python3 scripts/check-compatibility.py
- run: python3 scripts/reproduce-precision.py
- run: cargo +1.85.0 fmt -- --check
- run: cargo +1.85.0 doc --locked --all-features --document-private-items
env:
RUSTDOCFLAGS: -D warnings
- run: git diff --check
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,36 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this library adheres to Rust's notion of
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## Fork 0.2.0 — Unreleased

### Changed
- Merge upstream 0.7.0 (`e2654af6072f4d83588a29064f97ccbdb04eb34e`).
- Rust 1.85 / edition 2024, cipher 0.5.1, CBC 0.2, num-bigint 0.5;
AES 0.9 in tests/examples. Consumers using AES 0.8 or cipher 0.4 must migrate.
- Keep the fork's integer parameter calculation, tweak rejection, padding,
feature support and tests; do not restore the direct libm dependency.

### Fixed
- Increase fixed-log precision with a full-domain integer certificate. The old
62-bit calculation underestimates b for radix 56 and v=1766948378. This is an
explicitly approved compatibility exception for affected large inputs;
ciphertexts produced with the incorrect old parameter may differ.
- Avoid padding intermediate overflow and distinguish 32-/64-bit tweak limits.

### Added
- 672 unchanged synthetic-key fixtures recorded before migration, old/new
process compatibility checks, parameter certificate and an AES 0.9 example.
- Feature-matrix/MSRV CI, no_std target checks and native 32-bit tests.

## Fork 0.1.0

### Changed
- Added compatibility updates for the 2025 second public draft of NIST SP
800-38G Revision 1: FF1 parameter calculation no longer uses floating-point
arithmetic, and tweaks longer than the FF1 parameter block can encode are now
rejected.

The versions below belong to upstream, not to the fork's release sequence.

## [0.7.0] - 2026-09-30
### Changed
Expand Down
9 changes: 1 addition & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 22 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
[package]
name = "fpe"
version = "0.7.0"
version = "0.2.0"
authors = ["Jack Grigg <thestr4d@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2024"
rust-version = "1.85"
description = "Format-preserving encryption"
documentation = "https://docs.rs/fpe/"
homepage = "https://github.com/str4d/fpe"
repository = "https://github.com/str4d/fpe"
documentation = "https://github.com/liesware/fpe"
homepage = "https://github.com/liesware/fpe"
repository = "https://github.com/liesware/fpe"
keywords = ["ff1"]
categories = ["cryptography", "no-std"]

[dependencies]
cbc = { version = "0.2", default-features = false }
cipher = "0.5.1"
libm = "0.2"

num-bigint = { version = "0.5", optional = true, default-features = false }
num-integer = { version = "0.1", optional = true, default-features = false }
Expand All @@ -25,13 +24,11 @@ num-traits = { version = "0.2", optional = true, default-features = false }
aes = "0.9"

# Tests
proptest = "1.1"
static_assertions = "1.1"

# Benchmarks
#aes-old = { package = "aes", version = "0.3" }
#binary-ff1 = "0.1"
criterion = "0.5"

[target.'cfg(any(target_arch = "x86", target_arch = "x86_64"))'.dev-dependencies]
criterion-cycles-per-byte = "0.6"
Expand All @@ -40,6 +37,15 @@ criterion-cycles-per-byte = "0.6"
inferno = "0.12"
pprof = { version = "0.15", features = ["criterion", "flamegraph"] }

# WASI can run the property tests, but has no subprocess support for rusty-fork.
[target.'cfg(not(target_os = "wasi"))'.dev-dependencies]
proptest = "1.1"
criterion = "0.5"

[target.'cfg(target_os = "wasi")'.dev-dependencies]
proptest = { version = "1.1", default-features = false, features = ["std", "bit-set"] }
criterion = { version = "0.5", default-features = false }

[features]
default = ["std"]
alloc = ["num-bigint", "num-integer", "num-traits"]
Expand All @@ -51,3 +57,12 @@ bench = false
[[bench]]
name = "ff1"
harness = false
required-features = ["alloc"]

[[example]]
name = "compatibility"
required-features = ["alloc"]

[[example]]
name = "aes09"
required-features = ["alloc"]
74 changes: 71 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,80 @@
# fpe [![Crates.io](https://img.shields.io/crates/v/fpe.svg)](https://crates.io/crates/fpe) #
# fpe — Liesware fork

Upstream: [str4d/fpe](https://github.com/str4d/fpe). The
[crates.io package](https://crates.io/crates/fpe) follows upstream release numbering.

This crate contains pure-Rust implementations of format-preserving encryption
algorithms.

The following algorithms are implemented:
- FF1 (specified in [NIST Special Publication 800-38G](http://dx.doi.org/10.6028/NIST.SP.800-38G)).
- FF1 (specified in [NIST Special Publication 800-38G](http://dx.doi.org/10.6028/NIST.SP.800-38G), with compatibility updates from the [2025 second public draft of Revision 1](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-38Gr1.2pd.pdf)).

This crate does not implement FF3 or FF3-1.

## Liesware fork 0.2.0

This fork is based on upstream 0.7.0, commit
`e2654af6072f4d83588a29064f97ccbdb04eb34e`. Fork versions and tags are separate
from the upstream/crates.io release numbering.

This crate requires Rust **1.85** or greater (edition 2024), `cipher 0.5.1` or a
compatible 0.5 release, and `cbc 0.2`. Tests and examples use **AES 0.9**.
The `alloc` implementation uses `num-bigint 0.5`.

### Migrating a consumer

Update the FPE Git reference to the approved fork release and update `aes` from
0.8 to 0.9. Any direct `cipher` dependency used with FPE must move from 0.4 to
0.5. The old AES type implements a different trait version and cannot be passed
to this FPE; no trait adapter is provided.

The usual `FF1::new`, `encrypt`, and `decrypt` calls and the `NumeralString` and
`Operations` contracts retain their shape. Custom cipher implementations or
bounds must migrate to `BlockCipherEncrypt`; code using the old mutable block
mode traits must use `BlockModeEncrypt`. RustCrypto arrays now use `Array`
instead of `GenericArray`. Incorrect key lengths still panic in `FF1::new`.

See [`examples/aes09.rs`](examples/aes09.rs) for a compilable consumer:

```sh
cargo run --locked --example aes09
```

### Preserved fork behavior and compatibility exception

FF1 parameters use integer arithmetic without a direct `libm` dependency.
Tweaks longer than `u32::MAX` bytes are rejected with `TweakTooLong`; padding
avoids intermediate overflow. The 672 frozen baseline vectors retain their
ciphertexts and pass old/new decryption in both directions.

**Compatibility exception:** the prior 62-bit fixed logarithm could underestimate
FF1's byte count for very large valid inputs. Version 0.2.0 corrects its precision;
for example radix 56 and length 3,533,896,755 require one more byte than the old
calculation. Ciphertexts affected by that old defect may differ and must be
migrated with the old implementation before changing versions. No legacy mode
is provided. This exception was explicitly approved during the migration.
See the [integer calculation certificate](docs/integer-parameters.md) and
[migration record](docs/upstream-0.7.0.md).

### Features and validation

The default feature is `std`, which enables `alloc`. Use
`default-features = false, features = ["alloc"]` for allocation-backed numerals
in a `no_std` consumer, or disable all features to provide your own numeral
implementation without allocation. The library does not directly depend on AES.

```sh
cargo test --locked
cargo test --locked --no-default-features --features alloc
cargo test --locked --no-default-features
python3 scripts/check-compatibility.py --toolchain 1.85.0
python3 scripts/reproduce-precision.py
```

This crate requires Rust version 1.85 or greater.
The compatibility script builds the original commit and current implementation
in separate processes and exchanges the frozen fixtures. It never rewrites the
expected vectors. Both `no_std` configurations are also checked on
`wasm32-unknown-unknown`; CI runs native 32-bit tests on i686 Linux.

## License

Expand Down
Loading