1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#![no_std]
#![doc(
    html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
    html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
)]
#![warn(missing_docs, rust_2018_idioms)]

//! ## Usage
//!
//! ```rust
//! use crypto_secretstream::*;
//! use rand_core::OsRng;
//!
//! // Generate a key
//! let key = Key::generate(&mut OsRng);
//!
//! // Use some additional data
//! let some_additional_data = b"It needs to be known in advance";
//!
//! //
//! // Send messages
//! //
//!
//! // Create a stream to send messages, receive an header to send to the other
//! // side (it can be known by a thirdparty without security issue).
//! let (header, mut push_stream) = PushStream::init(&mut rand_core::OsRng, &key);
//!
//! // Messages to send
//! let mut first_message = Vec::from(&b"Top secret message we're encrypting"[..]);
//! let mut second_message = Vec::from(&b"Which can be followed by other messages"[..]);
//!
//! // Encrypt the messages using the stream
//! push_stream.push(&mut first_message, &[], Tag::Message).unwrap();
//! push_stream.push(&mut second_message, some_additional_data, Tag::Final).unwrap();
//!
//! //
//! // Receive messages
//! //
//!
//! // Create a stream to receive messages
//! let mut pull_stream = PullStream::init(header, &key);
//!
//! // Decrypt the ciphertexts using the stream
//! let first_tag = pull_stream.pull(&mut first_message, &[]).unwrap();
//! let second_tag = pull_stream.pull(&mut second_message, some_additional_data).unwrap();
//!
//! assert_eq!(first_message, b"Top secret message we're encrypting");
//! assert_eq!(first_tag, Tag::Message);
//! assert_eq!(second_message, b"Which can be followed by other messages");
//! assert_eq!(second_tag, Tag::Final);
//! ```
//!
//! [NaCl]: https://nacl.cr.yp.to/
//! [`crypto_secretstream`]: https://doc.libsodium.org/secret-key_cryptography/secretstream
//! [ChaCha20]: https://github.com/RustCrypto/stream-ciphers/tree/master/chacha20
//! [Poly1305]: https://github.com/RustCrypto/universal-hashes/tree/master/poly1305

mod header;
mod key;
mod nonce;
mod stream;
mod tags;

/// Errors generated by this crate.
pub mod errors;

pub use aead;
pub use header::Header;
pub use key::Key;
pub use stream::{PullStream, PushStream, Stream};
pub use tags::Tag;