#chacha20-poly1305 #chacha20 #poly1305 #libsodium #key-exchange #shared-key #nacl

no-std crypto_secretstream

Pure Rust implementation of libsodium's crypto_secretstream secret-key using ChaCha20 and Poly1305

4 releases (2 breaking)

0.2.0 Jul 22, 2023
0.1.1 Dec 1, 2022
0.1.0 Aug 14, 2022
0.0.1 Aug 30, 2021

#2686 in Cryptography

Download history 2918/week @ 2024-07-21 3728/week @ 2024-07-28 5041/week @ 2024-08-04 2404/week @ 2024-08-11 1696/week @ 2024-08-18 1475/week @ 2024-08-25 1799/week @ 2024-09-01 1789/week @ 2024-09-08 1870/week @ 2024-09-15 1701/week @ 2024-09-22 1578/week @ 2024-09-29 1716/week @ 2024-10-06 2042/week @ 2024-10-13 2825/week @ 2024-10-20 3353/week @ 2024-10-27 1561/week @ 2024-11-03

9,786 downloads per month
Used in 4 crates (2 directly)

Apache-2.0 OR MIT

25KB
403 lines

RustCrypto: crypto_secretstream

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

Pure Rust implementation of libsodium's crypto_secretstream primitive, providing an AEAD using ChaCha20 and Poly1305.

It is tested against sodiumoxide, a Rust libsodium bindings.

Documentation

About

Imagine Alice wants to open a safe channel of communication with Bob, one that can't be read or modified by anyone else.

One way she can do this is by first agreeing with Bob on a shared secret key (such as one generated via a key exchange protocol), then she opens a normal/unsafe channel of communication and sends her messages, encrypted under this shared key. Then, when Bob receives these messages, he can decrypt each one and the mere knowledge of this shared key ensures that it was indeed sent by Alice.

Under the hood, the first message is postfixed with a random number, called a nonce, generated by Alice, which is taken into account during encryption and decryption. It is then incremented for each new message.

It also allows for additional data to be sent with each message. This data is not encrypted but used in the encryption process thus it is needed to be known in advance by the receiver. It can be useful for adding another layer of security, and is not of a fixed size as the key is.

License

Licensed under either of:

at your option.

Contribution

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.

Caveats

  • auto-rekeying on counter overflow is not tested
  • Tag::Final doesn't actually do anything, as libsodium does but not sodiumoxide
  • Key and Nonce aren't zeroize, maybe it should
  • MAC check in PullStream is not constant time

Dependencies

~0.7–1.2MB
~23K SLoC