#encryption #protocols #e2e #group #security

no-std phalanx-crypto

๐Ÿ›ก๏ธ Phalanx - General-purpose group E2E encryption protocol

1 unstable release

0.1.0 Aug 21, 2025

#1034 in Cryptography

Download history 133/week @ 2025-08-20 23/week @ 2025-08-27 24/week @ 2025-09-03 16/week @ 2025-09-10 14/week @ 2025-09-17 23/week @ 2025-09-24 22/week @ 2025-10-01

78 downloads per month
Used in 2 crates

MIT license

175KB
3.5K SLoC

Phalanx Protocol

๐Ÿ›ก๏ธ 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.

๐ŸŽฏ Overview

Phalanx provides military-grade security for group communications with:

  • End-to-End Encryption: Only group members can decrypt messages
  • Forward Secrecy: Past messages remain secure even if current keys are compromised
  • Post-Compromise Security: Future messages remain secure after key compromise recovery
  • Perfect Authentication: All messages are cryptographically signed and verified
  • Flexible Membership: Dynamic group membership with role-based permissions
  • Transport Agnostic: Works over any reliable communication channel

๐Ÿ” Security Features

Cryptographic Primitives

  • ChaCha20-Poly1305: Authenticated encryption for messages
  • X25519: Elliptic curve Diffie-Hellman for key exchange
  • Ed25519: Digital signatures for authentication
  • BLAKE3: Cryptographic hashing and key derivation
  • HKDF: Key derivation function for perfect forward secrecy

Security Properties

โœ… 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

๐Ÿš€ Quick Start

Add Phalanx to your Cargo.toml:

[dependencies]
phalanx = "0.1"

# Optional features
phalanx = { version = "0.1", features = ["serde", "async"] }

Basic Usage

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()?);

Async Support

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(())
}

๐Ÿ—๏ธ Architecture

Core Components

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    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   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Message Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    encrypt    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    transport    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Alice   โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ†’โ”‚ Phalanx     โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚ Network โ”‚
โ”‚         โ”‚               โ”‚ Group       โ”‚                 โ”‚         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚                              โ”‚
                                 โ”‚                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    decrypt    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    receive     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Bob     โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚ Phalanx     โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚ Network โ”‚
โ”‚         โ”‚               โ”‚ Group       โ”‚                 โ”‚         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“š Advanced Features

Group Management

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
}

Message Threading

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)?;

Handshake Protocol

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
}

๐Ÿ”ง Configuration

Feature Flags

  • std (default): Standard library support
  • serde: JSON serialization/deserialization support
  • async: Async/await support with Tokio

Security Parameters

use 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

๐Ÿงช Testing

Run the comprehensive test suite:

# Basic tests
cargo test

# All features
cargo test --all-features

# Benchmarks
cargo bench

๐Ÿ”’ Security Considerations

Key Management

  • Ephemeral Keys: Session keys are ephemeral and regularly rotated
  • Key Derivation: Strong key derivation using HKDF-BLAKE3
  • Secure Deletion: Keys are zeroized on drop
  • No Key Reuse: Each message uses a fresh nonce

Forward Secrecy

  • Automatic Rotation: Keys rotate based on time and membership changes
  • Ratcheting: Future keys cannot be derived from past keys
  • Member Changes: Key rotation triggered on member join/leave

Implementation Security

  • Constant-Time Operations: Timing attack resistance
  • Memory Safety: Written in Rust with no unsafe code
  • Zeroization: Sensitive data cleared from memory
  • Side-Channel Resistance: Careful implementation of crypto operations

๐Ÿค Integration Examples

Legion Protocol Integration

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
}

Custom Transport

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
}

๐Ÿ›ฃ๏ธ Roadmap

Version 0.2 (Planned)

  • Zero-knowledge membership proofs
  • Onion routing for metadata protection
  • Multi-device support per identity
  • Message deletion/redaction
  • Audit logging

Version 0.3 (Future)

  • Post-quantum cryptography migration
  • Cross-group messaging
  • Advanced permission systems
  • Formal verification of protocols

๐Ÿ“„ License

Licensed under the MIT License. See LICENSE for details.

๐Ÿค– Contributing

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.

Dependencies

~6โ€“18MB
~229K SLoC