Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
|
4882fda20b | |
|
23e1d52b04 | |
|
2f7deacdb1 | |
|
4c8dac91b0 | |
|
5e17b672b7 |
|
@ -1,11 +1,13 @@
|
|||
[package]
|
||||
name = "false-bottom"
|
||||
version = "0.3.1"
|
||||
version = "0.3.4"
|
||||
categories = ["cryptography"]
|
||||
description = "A deniable encryption scheme"
|
||||
repository = "https://codeberg.org/skran/false-bottom"
|
||||
authors = ["K Shiva Kiran <shiva_kr@riseup.net>"]
|
||||
license = "GPL-3.0-or-later"
|
||||
edition = "2021"
|
||||
keywords = ["deniable"]
|
||||
|
||||
[dependencies]
|
||||
crypto-bigint = { version = "0.5.5", features = ["generic-array"] }
|
||||
|
@ -28,4 +30,4 @@ required-features = ["base64"]
|
|||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
rustdoc-args = ["--cfg", "docsrs"]
|
||||
|
|
32
README.md
32
README.md
|
@ -12,16 +12,42 @@ Run the following command in your project directory to add this library.
|
|||
```sh
|
||||
cargo add false-bottom
|
||||
```
|
||||
Or alternatively, check out the [crates.io](https://crates.io/crates/false-bottom) to add this library to your project using the `Cargo.toml` file.
|
||||
Or alternatively, check out [crates.io](https://crates.io/crates/false-bottom) to add this library to your project using the `Cargo.toml` file.
|
||||
The documentation is available at [docs.rs](https://docs.rs/false-bottom).
|
||||
|
||||
## Run the examples
|
||||
These are provided in the [examples](./examples) directory.
|
||||
## Examples
|
||||
These are provided in the [examples](https://codeberg.org/skran/false-bottom/src/branch/main/examples) directory.
|
||||
Run them using the following command:
|
||||
```sh
|
||||
cargo run --example <filename>
|
||||
```
|
||||
### Encryption
|
||||
```rust
|
||||
use false_bottom::{FalseBottom, Fb128};
|
||||
|
||||
fn main() {
|
||||
// Input messages
|
||||
let msg1 = "Weather department warns of heavy rains within the upcoming two days";
|
||||
let msg2 = "I have gathered intel regarding the government's illegal spying";
|
||||
|
||||
// Cipher initialization
|
||||
let mut fb = Fb128::init(12, 12);
|
||||
|
||||
// Encryption (Adding messages is not limited to 2)
|
||||
let key1 = fb.add(&msg1.as_bytes());
|
||||
let key2 = fb.add(&msg2.as_bytes());
|
||||
|
||||
// Decryption
|
||||
let decr1 = fb.decrypt(&key1).unwrap();
|
||||
let decr2 = fb.decrypt(&key2).unwrap();
|
||||
|
||||
let result1 = String::from_utf8(decr1).unwrap();
|
||||
let result2 = String::from_utf8(decr2).unwrap();
|
||||
|
||||
assert_eq!(msg1, result1);
|
||||
assert_eq!(msg2, result2);
|
||||
}
|
||||
```
|
||||
## Todo
|
||||
- [x] Add more block sizes.
|
||||
- [ ] Add capabilities to edit and delete added messages in the ciphertext.
|
||||
|
|
|
@ -4,6 +4,7 @@ use crypto_bigint::{ArrayEncoding, generic_array::GenericArray, Uint};
|
|||
use std::sync::RwLock;
|
||||
|
||||
#[cfg(feature = "base64")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
|
||||
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||
|
||||
/// Provides methods to encode and decode data to and from several formats.
|
||||
|
@ -21,6 +22,7 @@ pub trait Encode {
|
|||
|
||||
/// Returns the base64 encoded representation of the ciphertext and keybase.
|
||||
/// Requires `base64` feature to be enabled.
|
||||
#[cfg(feature = "base64")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
|
||||
fn to_base64(&self) -> (String, String);
|
||||
|
||||
|
@ -30,6 +32,7 @@ pub trait Encode {
|
|||
/// # Errors
|
||||
/// - [DecodeError](FbError::DecodeError)
|
||||
/// - [InvalidParams](FbError::InvalidParams) - Are the parameters in the wrong order?
|
||||
#[cfg(feature = "base64")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
|
||||
fn from_base64(cipher: &str, keybase: &str) -> Result<Self, FbError>
|
||||
where
|
||||
|
@ -68,6 +71,7 @@ where
|
|||
Ok(FbObj {c, r})
|
||||
}
|
||||
|
||||
#[cfg(feature = "base64")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
|
||||
fn to_base64(&self) -> (String, String) {
|
||||
let (c, r) = self.to_bytes();
|
||||
|
@ -75,6 +79,7 @@ where
|
|||
(BASE64_STANDARD.encode(c), BASE64_STANDARD.encode(r))
|
||||
}
|
||||
|
||||
#[cfg(feature = "base64")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
|
||||
fn from_base64(cipher: &str, keybase: &str) -> Result<Self, FbError> {
|
||||
let c_bytes = BASE64_STANDARD.decode(cipher)
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
use crate::{FBAlgo, FBObj, FieldOps, Packing, WrappingOps};
|
||||
use crypto_bigint::{Limb, NonZero, U128};
|
||||
|
||||
/// [`FBObj`] with a block size of 128 bits.
|
||||
pub type FB128 = FBObj<U128>;
|
||||
|
||||
const PRIME_POS_VAL: u16 = 159;
|
||||
const PRIME: U128 = U128::MAX.wrapping_sub(&U128::from_u16(PRIME_POS_VAL-1));
|
||||
const PRIME_POS: Limb = Limb::from_u16(PRIME_POS_VAL);
|
||||
|
||||
impl FBAlgo<U128> for FBObj<U128> {
|
||||
const MODULUS: NonZero<U128> = NonZero::<U128>::const_new(PRIME).0;
|
||||
}
|
||||
|
||||
impl FieldOps for U128 {
|
||||
fn field_add(&self, rhs: &Self) -> Self {
|
||||
self.add_mod_special(rhs, PRIME_POS)
|
||||
}
|
||||
fn field_sub(&self, rhs: &Self) -> Self {
|
||||
self.sub_mod_special(rhs, PRIME_POS)
|
||||
}
|
||||
fn field_mul(&self, rhs: &Self) -> Self {
|
||||
self.mul_mod_special(rhs, PRIME_POS)
|
||||
}
|
||||
fn field_inv(&self) -> Self {
|
||||
self.inv_odd_mod(&PRIME).0
|
||||
}
|
||||
}
|
||||
|
||||
impl Packing for U128 {
|
||||
const R_BOUND: U128 = PRIME.wrapping_sub(&U128::ONE);
|
||||
}
|
||||
|
||||
impl WrappingOps for U128 {
|
||||
fn wrapping_add(&self, rhs: &U128) -> U128 {
|
||||
self.wrapping_add(rhs)
|
||||
}
|
||||
fn wrapping_sub(&self, rhs: &U128) -> U128 {
|
||||
self.wrapping_sub(rhs)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue