#nacl #libsodium #public-key #x25519 #xsalsa20poly1305

no-std crypto_box

Pure Rust implementation of NaCl's crypto_box public-key authenticated encryption primitive which combines the X25519 Elliptic Curve Diffie-Hellman function and the XSalsa20Poly1305 authenticated encryption cipher

12 releases (7 breaking)

Uses new Rust 2021

0.8.2 Oct 29, 2022
0.7.2 Mar 21, 2022
0.7.0 Aug 30, 2021
0.6.1 Jul 20, 2021
0.1.0 Feb 25, 2020

#65 in Cryptography

Download history 9034/week @ 2022-10-08 9244/week @ 2022-10-15 9661/week @ 2022-10-22 8835/week @ 2022-10-29 9768/week @ 2022-11-05 8449/week @ 2022-11-12 8827/week @ 2022-11-19 8538/week @ 2022-11-26 9569/week @ 2022-12-03 9737/week @ 2022-12-10 8112/week @ 2022-12-17 7112/week @ 2022-12-24 10361/week @ 2022-12-31 9765/week @ 2023-01-07 10200/week @ 2023-01-14 9658/week @ 2023-01-21

40,915 downloads per month
Used in 40 crates (17 directly)

Apache-2.0 OR MIT

251 lines

RustCrypto: crypto_box

crate Docs Apache2/MIT licensed Rust Version Project Chat Build Status

Pure Rust implementation of NaCl's crypto_box primitive, providing public-key authenticated encryption which combines the X25519 Diffie-Hellman function and the XSalsa20Poly1305 authenticated encryption cipher into an Elliptic Curve Integrated Encryption Scheme (ECIES).



Imagine Alice wants something valuable shipped to her. Because it's valuable, she wants to make sure it arrives securely (i.e. hasn't been opened or tampered with) and that it's not a forgery (i.e. it's actually from the sender she's expecting it to be from and nobody's pulling the old switcheroo).

One way she can do this is by providing the sender (let's call him Bob) with a high-security box of her choosing. She provides Bob with this box, and something else: a padlock, but a padlock without a key. Alice is keeping that key all to herself. Bob can put items in the box then put the padlock onto it, but once the padlock snaps shut, the box cannot be opened by anyone who doesn't have Alice's private key.

Here's the twist though, Bob also puts a padlock onto the box. This padlock uses a key Bob has published to the world, such that if you have one of Bob's keys, you know a box came from him because Bob's keys will open Bob's padlocks (let's imagine a world where padlocks cannot be forged even if you know the key). Bob then sends the box to Alice.

In order for Alice to open the box, she needs two keys: her private key that opens her own padlock, and Bob's well-known key. If Bob's key doesn't open the second padlock then Alice knows that this is not the box she was expecting from Bob, it's a forgery.

Security Notes

This crate has received one security audit by Cure53 (version 0.7.1), with no significant findings. We would like to thank Threema for funding the audit.


Licensed under either of:

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~62K SLoC