| Crates.io | phalanx-crypto |
| lib.rs | phalanx-crypto |
| version | 0.1.0 |
| created_at | 2025-08-21 03:27:19.77713+00 |
| updated_at | 2025-08-21 03:27:19.77713+00 |
| description | ๐ก๏ธ Phalanx - General-purpose group E2E encryption protocol |
| homepage | https://github.com/exec/phalanx |
| repository | https://github.com/exec/phalanx |
| max_upload_size | |
| id | 1804250 |
| size | 226,483 |
๐ก๏ธ General-purpose group E2E encryption protocol
Phalanx is a cryptographically secure group communication protocol designed for maximum security, flexibility, and ease of use. While originally created for the Legion Protocol ecosystem, Phalanx is a standalone crate that can be used by any communication system requiring group end-to-end encryption.
Phalanx provides military-grade security for group communications with:
โ
Confidentiality: Messages encrypted with group keys
โ
Integrity: Authenticated encryption prevents tampering
โ
Authentication: Every message is cryptographically signed
โ
Forward Secrecy: Regular key rotation protects past messages
โ
Post-Compromise Security: Key compromise recovery protects future messages
โ
Deniability: Messages cannot be proven to originate from specific users
โ
Metadata Protection: Minimal information leakage about group activity
Add Phalanx to your Cargo.toml:
[dependencies]
phalanx = "0.1"
# Optional features
phalanx = { version = "0.1", features = ["serde", "async"] }
use phalanx::{Identity, PhalanxGroup, MessageContent};
// Create identities for group members
let alice = Identity::generate();
let bob = Identity::generate();
// Alice creates a group
let mut alice_group = PhalanxGroup::new(alice.clone());
// Alice adds Bob to the group
alice_group.add_member(bob.public_key(), MemberRole::Member)?;
// Alice sends a message
let content = MessageContent::text("Hello, secure group!");
let encrypted_msg = alice_group.encrypt_message(&content)?;
// Bob receives and decrypts the message
let decrypted = alice_group.decrypt_message(&encrypted_msg)?;
println!("Decrypted: {}", decrypted.as_string()?);
use phalanx::{Identity, AsyncPhalanxGroup, MessageContent};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let alice = Identity::generate();
let group = AsyncPhalanxGroup::new(alice);
let content = MessageContent::text("Hello, async world!");
let encrypted = group.encrypt_message(&content).await?;
let decrypted = group.decrypt_message(&encrypted).await?;
println!("Message: {}", decrypted.as_string()?);
Ok(())
}
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Phalanx Protocol โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Identity Management โ Group Management โ Messages โ
โ - Key Generation โ - Member Roles โ - Encrypt โ
โ - Authentication โ - Permissions โ - Decrypt โ
โ - Key Exchange โ - Key Rotation โ - Verify โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Cryptographic Primitives โ
โ ChaCha20-Poly1305 โ X25519 โ Ed25519 โ BLAKE3 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโ encrypt โโโโโโโโโโโโโโโ transport โโโโโโโโโโโ
โ Alice โโโโโโโโโโโโโโโโ Phalanx โโโโโโโโโโโโโโโโโโโ Network โ
โ โ โ Group โ โ โ
โโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโ
โ โ
โ โผ
โโโโโโโโโโโ decrypt โโโโโโโโโโโโโโโ receive โโโโโโโโโโโ
โ Bob โโโโโโโโโโโโโโโโ Phalanx โโโโโโโโโโโโโโโโโโโ Network โ
โ โ โ Group โ โ โ
โโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโ
use phalanx::{PhalanxGroup, GroupConfig, GroupVisibility, MemberRole};
// Create group with custom configuration
let config = GroupConfig {
max_members: 50,
key_rotation_interval: 3600, // 1 hour
visibility: GroupVisibility::InviteOnly,
persistent_storage: true,
..Default::default()
};
let mut group = PhalanxGroup::with_config(identity, config);
// Add members with different roles
group.add_member(alice_key, MemberRole::Admin)?;
group.add_member(bob_key, MemberRole::Member)?;
// Rotate keys manually or automatically
if group.needs_key_rotation() {
let rotation_msg = group.rotate_keys()?;
// Broadcast rotation message to all members
}
use phalanx::MessageContent;
// Create a threaded conversation
let thread_id = [1u8; 32];
let reply_to_msg_id = [2u8; 32];
let content = MessageContent::reply("This is a reply", reply_to_msg_id)
.with_thread(thread_id)
.with_metadata("priority", "high");
let message = group.encrypt_message(&content)?;
use phalanx::{HandshakeMessage, Identity};
// Client creates handshake to join group
let client = Identity::generate();
let handshake = HandshakeMessage::new(
&client,
group_id,
vec!["phalanx/v1".to_string()],
"my-app/1.0".to_string(),
)?;
// Server verifies and processes handshake
let payload = handshake.verify_and_decrypt()?;
if payload.group_id == expected_group_id {
// Allow client to join group
}
std (default): Standard library supportserde: JSON serialization/deserialization supportasync: Async/await support with Tokiouse phalanx::constants::*;
// Protocol limits
MAX_GROUP_SIZE: 1000 members
MAX_MESSAGE_SIZE: 1MB
DEFAULT_KEY_ROTATION_INTERVAL: 24 hours
// Cryptographic parameters
KEY_SIZE: 32 bytes (256-bit)
NONCE_SIZE: 12 bytes
TAG_SIZE: 16 bytes
Run the comprehensive test suite:
# Basic tests
cargo test
# All features
cargo test --all-features
# Benchmarks
cargo bench
use legion_protocol::{IronSession, ChannelType};
use phalanx::{PhalanxGroup, Identity};
// Detect Legion encrypted channel
if let ChannelType::LegionEncrypted = get_channel_type("!secure") {
let group = PhalanxGroup::new(identity);
// Integrate with Legion Protocol session
}
use phalanx::{GroupMessage, EncryptedMessage};
// Implement your transport layer
trait MessageTransport {
async fn send(&self, msg: EncryptedMessage) -> Result<()>;
async fn receive(&self) -> Result<EncryptedMessage>;
}
// Phalanx works with any reliable transport
struct MyTransport;
impl MessageTransport for MyTransport {
// Your implementation here
}
Licensed under the MIT License. See LICENSE for details.
Contributions welcome! Please see CONTRIBUTING.md for guidelines.
Security Issues: Please report security issues privately to security@phalanx-protocol.org
Built with ๐ก๏ธ by the Phalanx Protocol team
Phalanx: Where privacy meets usability in group communications.