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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// SPDX-License-Identifier: GPL-3.0-or-later
//! ## Usage
//! False Bottom is a [deniable encryption](https://en.wikipedia.org/wiki/Deniable_encryption) scheme.
//! Unlike traditional encryption algorithms that map a given plaintext to ciphertext,
//! False Bottom works by "adding" messages to an existing ciphertext.
//! As such, the initial ciphertext and the keybase are generated from random data.
//! The ciphertext then grows as messages are added whereas the keybase is fixed
//! after initialization and is used to generate message specific keys for the ciphertext.
//! The parameters for the [`init()`](FalseBottom::init()) function determine the size
//! (in number of blocks) of the initial ciphertext and keybase respectively.
//! Type aliases [`Fb128`], [`Fb256`] and [`Fb512`] are provided to pick a block size.
//!
//! ### Cipher Initialization:
//! ```
//! use false_bottom::{FalseBottom, Fb128};
//! // Initialize 15 blocks of ciphertext and 12 blocks of keybase with a block size of 128 bits.
//! let fb = Fb128::init(15, 12);
//! ```
//!
//! ### Adding Messages:
//! Multiple messages can be added using the [`add()`](FalseBottom::add()) method.
//! This method returns an object [`FbKey`] that represents the message specific key for this message.
//! Only this key can decrypt the added message.
//! ```
//! # use false_bottom::{FalseBottom, Fb128};
//! # let mut fb = Fb128::init(15, 12);
//! let msg = "Hello World!";
//! let key = fb.add(msg.as_bytes());
//! ```
//!
//! ### Decryption:
//! The [`decrypt()`](FalseBottom::decrypt()) method returns the message that corresponds
//! to the provided [`FbKey`].
//! ```
//! # use false_bottom::{FalseBottom, Fb128};
//! # let mut fb = Fb128::init(15, 12);
//! # let msg = "Hello World!";
//! # let key = fb.add(msg.as_bytes());
//! let decrypted = fb.decrypt(&key).unwrap();
//! ```
//! An example has been provided [here](https://codeberg.org/skran/false-bottom/src/branch/main/examples/encryption.rs).
//!
//! ### Import and Export
//! Available formats: Raw bytes and Base64 encoded.
//! #### Raw Bytes:
//! The [`Encode`] trait provides methods for export and import of data.
//! ```
//! use false_bottom::{Encode, FalseBottom, Fb128, FbError, FbKey};
//! # let mut fb = Fb128::init(15, 12);
//! # let key = fb.add(b"Hello");
//! // Exporting
//! let (ciphertext_bytes, keybase_bytes) = fb.to_bytes();
//! let key_bytes = key.to_bytes();
//! // Importing
//! let fb_imported = Fb128::from_bytes(&ciphertext_bytes, &keybase_bytes)?;
//! let key_imported = FbKey::from_bytes(&key_bytes)?;
//! # Ok::<(), FbError>(())
//! ```
//! #### Base64 Encoded:
//! The feature `base64` needs to be enabled in your `Cargo.toml`.
//! ```
//! use false_bottom::{Encode, FalseBottom, Fb128, FbError, FbKey};
//! # let mut fb = Fb128::init(15, 12);
//! # let key = fb.add(b"Hello");
//! // Exporting
//! let (ciphertext_base64, keybase_base64) = fb.to_base64();
//! let key_base64 = key.to_base64();
//! // Importing
//! let fb_imported = Fb128::from_base64(&ciphertext_base64, &keybase_base64)?;
//! let key_imported = FbKey::from_base64(&key_base64)?;
//! # Ok::<(), FbError>(())
//! ```
//! An example has been provided [here](https://codeberg.org/skran/false-bottom/src/branch/main/examples/export.rs).
pub use crate::;
use crate::;