Coder Social home page Coder Social logo

aviramha / rfernet Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 5.0 44 KB

Python extension for Fernet encryption/decryption, faster than other alternatives.

License: MIT License

Python 52.75% Rust 47.25%
fernet-encryption python-extension decryption rust pyo3 python fernet rfernet cryptography

rfernet's Introduction

rfernet

Python extension for Fernet encryption/decryption, faster than other alternatives. This library uses the rust library fernet-rs https://github.com/mozilla-services/fernet-rs.

CI & Building wheels copied from cryptography and orjson

Benchmark

Compared to cryptography's Fernet (CPU):

In [2]: from cryptography.fernet import Fernet as cFernet

In [3]: from rfernet import Fernet as rFernet

In [4]:

In [4]: plain = b"asd" * 1000

In [5]: key = rFernet.generate_new_key()

In [7]: r_fernet = rFernet(key)

In [8]: c_fernet = cFernet(key)

In [9]: %timeit r_fernet.encrypt(plain)
18.4 µs ± 117 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [10]: %timeit c_fernet.encrypt(plain)
77.7 µs ± 921 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)

Memory:

# rfernet
[ Top 10 ]
<frozen importlib._bootstrap>:219: size=4444 B, count=38, average=117 B
test2.py:4: size=576 B, count=1, average=576 B
<frozen importlib._bootstrap_external>:59: size=156 B, count=1, average=156 B
test2.py:6: size=93 B, count=1, average=93 B
<frozen importlib._bootstrap>:371: size=80 B, count=1, average=80 B
<frozen importlib._bootstrap>:105: size=72 B, count=1, average=72 B
<frozen importlib._bootstrap_external>:1352: size=56 B, count=1, average=56 B
<frozen importlib._bootstrap_external>:606: size=56 B, count=1, average=56 B
test2.py:7: size=48 B, count=1, average=48 B
<frozen importlib._bootstrap_external>:1030: size=40 B, count=1, average=40 B

# cryptography's Fernet
[ Top 10 ]
<frozen importlib._bootstrap_external>:525: size=3134 KiB, count=31814, average=101 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py:91: size=449 KiB, count=3169, average=145 B
<frozen importlib._bootstrap>:219: size=404 KiB, count=3384, average=122 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/abc.py:126: size=146 KiB, count=717, average=209 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py:89: size=119 KiB, count=1773, average=69 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/abc.py:127: size=68.7 KiB, count=447, average=157 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py:2793: size=46.8 KiB, count=282, average=170 B
<frozen importlib._bootstrap_external>:59: size=41.7 KiB, count=265, average=161 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/abc.py:135: size=40.8 KiB, count=339, average=123 B
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/idna/idnadata.py:826: size=36.7 KiB, count=3, average=12.2 KiB

Memory test source code:

import tracemalloc

tracemalloc.start()
from cryptography.fernet import Fernet as cFernet
plain = b"asd" * 1000
key = cFernet.generate_key()
c_fernet = cFernet(key)
c_fernet.encrypt(plain)

snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')

print("[ Top 10 ]")
for stat in top_stats[:10]:
    print(stat)

rfernet's People

Contributors

aviramha avatar bentheiii avatar gburzynski-10clouds avatar hooksie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

rfernet's Issues

rfernet fails to install on aarch64 (Macbook M1)

Currently, off latest version of rfernet on PyPi, I receive this error when attempting to install on M1 macbook:

        × Building wheel for maturin (pyproject.toml) did not run successfully.
        │ exit code: 1
        ╰─> [257 lines of output]
            running bdist_wheel
            running build
            installing to build/bdist.macosx-13.4-arm64/wheel
            running install
               Compiling libc v0.2.67
               Compiling proc-macro2 v1.0.9
               Compiling unicode-xid v0.2.0
               Compiling syn v1.0.16
               Compiling cfg-if v0.1.10
               Compiling cc v1.0.50
               Compiling log v0.4.8
               Compiling version_check v0.9.1
               Compiling memchr v2.3.3
               Compiling lazy_static v1.4.0
               Compiling itoa v0.4.5
               Compiling untrusted v0.7.0
               Compiling spin v0.5.2
               Compiling slab v0.4.2
               Compiling serde v1.0.104
               Compiling bytes v0.5.4
               Compiling fnv v1.0.6
               Compiling bitflags v1.2.1
               Compiling core-foundation-sys v0.7.0
               Compiling futures-core v0.3.4
               Compiling autocfg v1.0.0
               Compiling ring v0.16.11
               Compiling proc-macro-nested v0.1.3
               Compiling getrandom v0.1.14
               Compiling pin-project-lite v0.1.4
               Compiling indexmap v1.3.2
               Compiling unicase v2.6.0
               Compiling typenum v1.11.2
               Compiling http v0.2.0
               Compiling proc-macro-error-attr v0.4.11
               Compiling quote v1.0.3
               Compiling net2 v0.2.33
               Compiling iovec v0.1.4
               Compiling num_cpus v1.12.0
            error: failed to run custom build command for `ring v0.16.11

I've pulled the repo locally, and updated the lock file. After doing so, ring is updated and the package installs successfully

Will prepare a PR to update the lock file, and maturin config as well. @aviramha Is this library still being maintained so that a release can be made?

rfernet dependencies fix

My rfernet installation failed due to missing once_cell = "1.17.0" dependency in Cargo.toml.
I also needed to bump maturin to 1.4.0 because of regression in version 1.2.0.
I'll be happy to provide PR with fixes 👍

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.