Skip to content

[Patch pre-check] Fernet in Rust? #9095

@Hooksie

Description

@Hooksie

Hello all,

We've been doing some profiling on our application hotspots, and this recently led us to our usage of cryptography.Fernet. One of our Engineers noticed that an alternative implementation is currently available, rfernet, which is roughly 3.5x to 7.5x faster in our benchmarks than the cryptography implementation.

I'm assuming this is mostly due to rfernet being fully compiled, while much of the cryptograph implementation is in Python.

Is there any interest in a patch that would move the cryptography implementation into Rust? Would like to feel out the maintainers opinions here on what should and shouldn't be in Rust before jumping in

--
Benchmarks for completeness (against latest version), running on 2021 M1 pro.

Performance gap decreases as payload size increases. (Our use case is for small, ~25 byte payloads)

In [12]: payload = b"<...>" # ~25 bytes

In [13]: %timeit r_fernet.encrypt(payload)
2.25 µs ± 9.96 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

In [14]: %timeit cryptography_fernet.encrypt(payload)
19.4 µs ± 42.3 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions