Overview of the Rust cryptography ecosystem
37.2% of vulnerabilities in cryptographic libraries are memory safety issues, while only 27.2% are cryptographic issues, according to an empirical Study of Vulnerabilities in Cryptographic Libraries (Jenny Blessing, Michael A. Specter, Daniel J. Weitzner - MIT).
I think it’s time that we move on from C as the de-facto language for implementing cryptographic primitive.
This post is an excerpt of my book Black Hat Rust
Due to its high-level nature with low-level controls, absence of garbage collector, portability, and ease of embedding, Rust is our best bet to replace today’s most famous crypto libraries: OpenSSL, BoringSSL and libsodium, which are all written in C.
It will take time for sure, but in 2019,
rustls (a library we will see later) was benchmarked to be 5% to 70% faster than
OpenSSL, depending on the task. One of the most important thing (that is missing today) to see broad adoption? Certifications (such as FIPS).
Without further ado, here is a survey of the Rust cryptography ecosystem in 2021.
The drawback of this library is that as it’s C bindings, it may introduce hard-to-debug bugs.
Also, please note that the original maintainer announced in November 2020 that he is stepping back from the project. That being said, at its current state, the project is fairly stable, and urgent issues (if any) will surely be fixed promptly.
ring is focused on the implementation, testing, and optimization of a core set of cryptographic operations exposed via an easy-to-use (and hard-to-misuse) API. ring exposes a Rust API and is written in a hybrid of Rust, C, and assembly language.
ring provides low-level primitives to use in your higher-level protocols and applications. The principal maintainer is known for being very serious about cryptography and the code to be high-quality.
The only problem is that some algorithms, such as
XChaCha20-Poly1305, are missing.
Rust Crypto is a GitHub organization regrouping all the crypto primitives you will need, in pure Rust, most of the time by providing a base trait and implementing it for all the different algorithms (look at aead for example).
Unfortunately, not all the crates are audited by a professional third party.
rustls is a modern TLS library written in Rust. It uses
ring under the hood for cryptography. Its goal is to provide only safe to use features by allowing only TLS 1.2 and upper, for example.
In my opinion, this library is on the right track to replace
There are many other crates such as
blake3, but, in my opinion, they should be evaluated only if you can’t find your primitive in the crates/organizations above.
As of June 2021