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
// SPDX-FileCopyrightText: 2026 Shun Sakai
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! The `kcipher2` crate is an implementation of the [KCipher-2] stream cipher
//! as described in [RFC 7008].
//!
//! Cipher functionality is accessed using traits from re-exported [`cipher`]
//! crate.
//!
//! # Examples
//!
//! ```
//! use hex_literal::hex;
//! use kcipher2::{
//! KCipher2,
//! cipher::{KeyIvInit, StreamCipher},
//! };
//!
//! let key = [0x42; 16];
//! let nonce = [0x24; 16];
//! let plaintext = hex!("00010203 04050607 08090A0B 0C0D0E0F");
//! let ciphertext = hex!("471694B5 EB93E4A6 EABA73DF A6F77057");
//!
//! // Key and IV must be references to the `Array` type. Here we use the `Into`
//! // trait to convert arrays into it.
//! let mut cipher = KCipher2::new(&key.into(), &nonce.into());
//!
//! let mut buf = plaintext;
//!
//! // Apply keystream (encrypt).
//! cipher.apply_keystream(&mut buf);
//! assert_eq!(buf, ciphertext);
//!
//! let ciphertext = buf;
//!
//! // Decrypt ciphertext by applying keystream again.
//! let mut cipher = KCipher2::new(&key.into(), &nonce.into());
//! cipher.apply_keystream(&mut buf);
//! assert_eq!(buf, plaintext);
//!
//! // Stream ciphers can be used with streaming messages.
//! let mut cipher = KCipher2::new(&key.into(), &nonce.into());
//! for chunk in buf.chunks_mut(3) {
//! cipher.apply_keystream(chunk);
//! }
//! assert_eq!(buf, ciphertext);
//! ```
//!
//! [KCipher-2]: https://en.wikipedia.org/wiki/KCipher-2
//! [RFC 7008]: https://datatracker.ietf.org/doc/html/rfc7008
// Lint levels of rustc.
pub use cipher;
pub use crate;