#elliptic-curve #x25519 #public-key #nacl #libsodium #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

16 releases (8 breaking)

0.9.1 Aug 17, 2023
0.9.0 Jul 22, 2023
0.9.0-rc.1 Jun 29, 2023
0.8.2 Oct 29, 2022
0.1.0 Feb 25, 2020

#2304 in Cryptography

Download history 7786/week @ 2023-12-18 3196/week @ 2023-12-25 8256/week @ 2024-01-01 8644/week @ 2024-01-08 7970/week @ 2024-01-15 9252/week @ 2024-01-22 8688/week @ 2024-01-29 8789/week @ 2024-02-05 8445/week @ 2024-02-12 7432/week @ 2024-02-19 12160/week @ 2024-02-26 20154/week @ 2024-03-04 13623/week @ 2024-03-11 15142/week @ 2024-03-18 11788/week @ 2024-03-25 12429/week @ 2024-04-01

53,807 downloads per month
Used in 71 crates (32 directly)

Apache-2.0 OR MIT

573 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.


~58K SLoC