RGP
Relatively Good Privacy
Modes
There are currently three supported modes: Dh (Diffie-Hellman), Hmac, and Session. All modes provide the ability to sign content and verify the sender. Deniability is preserved by signing the plaintext and encrypting the signature alongside the plaintext.
Diffie-Hellman
Dh mode provides forward secrecy by generating a fresh/random content key for each message and encrypting a copy of that key for each recipient (similar to PGP session keys).
This mode can also be used to bootstrap the initial key exchange for Session and Hmac modes.
use ;
let = generate_fingerprint;
let = generate_dh_keys;
let = generate_dh_keys;
let mut pub_keys = vec!;
// 5mb
let content = vec!;
// add another 10,000 recipients
for _ in 0..10_000
// encrypt message for all recipients
let = encrypt
.unwrap;
// extract encrypted content key at position 0
if let Dh = extract_components_mut ;
Steps
- Generate one-time components
- nonce
- content key
- Sign plaintext to generate content signature
- Encrypt plaintext and content signature with content key
- Encrypt content key for all recipients
- Generate shared secret with recipient's public key and sender's private key
- Encrypt content key with shared secret
Format
- nonce = 24 bytes
- keys count
- IF 0..=127
- is single byte = 1 bit (set)
- count = 7 bits
- ELSE
- is single byte = 1 bit (unset)
- int size = 2 bits
- count = 8-64 bits
- IF 0..=127
- encrypted copies of content key = pub_keys.len() * 32 bytes
- encrypted content = content.len()
- signature = 64 bytes (encrypted along with the content)
- Poly1305 MAC = 16 bytes
- mode = 1 byte (set to 2 for
Dh)
HMAC
Hmac mode provides backward secrecy, and can enable forward secrecy when the HMAC key is kept secret, if only the content key is compromised. Includes an iterator to make "ratcheting" logic easier to implement.
use ;
let = generate_fingerprint;
// use actually secret values
let hmac_key = ;
let hmac_value = ;
// 5mb
let content = vec!;
// encrypt message keyed hash result
let = encrypt
.unwrap;
// extract iterator
if let Hmac = extract_components_mut ;
Steps
- Generate nonce
- Hash the provided components
- Sign plaintext to generate content signature
- Encrypt plaintext and content signature with the hashed key
Format
- nonce = 24 bytes
- iteration
- IF 0..=127
- is single byte = 1 bit (set)
- iteration = 7 bits
- ELSE
- is single byte = 1 bit (unset)
- int size = 2 bits
- iteration = 8-64 bits
- IF 0..=127
- encrypted content = content.len()
- signature = 64 bytes (encrypted along with the content)
- Poly1305 MAC = 16 bytes
- mode = 1 byte (set to 1 for
Hmac)
Session
Session provides no forward or backward secrecy, and uses the provided key "as is" without any modification.
use ;
let = generate_fingerprint;
// use an actually secret key
let session_key = ;
// 5mb
let content = vec!;
// encrypt message with a session key
let = encrypt
.unwrap;
// session doesn't need additional components but does need to be processed
if let Session = extract_components_mut
Steps
- Generate nonce
- Sign plaintext to generate content signature
- Encrypt plaintext and content signature with the provided key
Format
- nonce = 24 bytes
- encrypted content = content.len()
- signature = 64 bytes (encrypted along with the content)
- Poly1305 MAC = 16 bytes
- mode = 1 byte (set to 0 for
Session)
Ciphersuite
- Blake2s256 for hashing
- Ed25519 for signatures
- X25519 for shared secrets
- XChaCha20 for content keys
- XChaCha20Poly1305 for content
Disable Multi-threading
The "multi-thread" feature is enabled by default and utilizes the Rayon crate. Currently it only impacts the encrypt function when using Dh mode, but can be disabled by setting default-features to false.
[]
= { = "x.x.x", = false }
Performance
To check performance on your machine, run cargo bench. You can also view the latest benches in the GitHub CI workflow.
All benchmarks for multi-recipient Dh payloads are for 10,000 recipients, and all benchmarks for sign+encrypt/decrypt+verify are using 5mb of data.
License
Security
THIS CODE HAS NOT BEEN AUDITED OR REVIEWED. USE AT YOUR OWN RISK.