Skip to content

Goodness5/privacy-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Privacy Engine πŸ”

A multi-protocol cryptographic library for secure message encryption and key management across different blockchain protocols.

Rust License Documentation

πŸš€ Features

  • Multi-Protocol Support: Encrypt messages for recipients using different cryptographic protocols (Starknet, X25519)
  • Hybrid Encryption: Combines symmetric encryption for messages with asymmetric key wrapping
  • Cross-Protocol Compatibility: Share encrypted data between users with different cryptographic schemes
  • Zero-Knowledge Ready: Designed to work with zero-knowledge proof systems
  • Production Ready: Built with industry-standard cryptographic primitives (AES-256-GCM, ECDSA, X25519)

πŸ“¦ Installation

Add to your Cargo.toml:

[dependencies]
privacy-engine = "0.1.0"

🎯 Quick Start

Basic Multi-Recipient Encryption

use privacy_engine::encrypt::encrypt_message;
use privacy_engine::types::{RecipientInfo, Protocol};

// Encrypt a message for multiple recipients
let message = b"Hello, secure world!";
let recipients = vec![
    RecipientInfo {
        pubkey: user1_pubkey,  // Vec<u8>
        protocol: Protocol::Starknet,
    },
    RecipientInfo {
        pubkey: user2_pubkey,  // Vec<u8>
        protocol: Protocol::X25519,
    },
];

let result = encrypt_message(message, recipients)?;

Decrypting Messages

use privacy_engine::decrypt::decrypt_shared_secret;
use aes_gcm::{Aes256Gcm, aead::{Aead, KeyInit}, Key, Nonce};

// Unwrap symmetric key using recipient's private key
let symmetric_key = decrypt_shared_secret(&recipient_private_key, &wrapped_key)?;

// Decrypt message using symmetric key
let cipher = Aes256Gcm::new(Key::<Aes256Gcm>::from_slice(&symmetric_key));
let nonce = Nonce::from_slice(&result.nonce);
let plaintext = cipher.decrypt(nonce, result.ciphertext.as_ref())?;

println!("Decrypted: {}", String::from_utf8_lossy(&plaintext));

πŸ”§ Supported Protocols

Protocol Curve Key Size Signature Key Recovery Use Case
Starknet Stark Curve 32 bytes βœ… ECDSA βœ… Yes Blockchain, ZK systems
X25519 Curve25519 32 bytes ❌ No ❌ No Standard key exchange

πŸ—οΈ Architecture

The Privacy Engine uses a hybrid encryption approach:

  1. Message Encryption: AES-256-GCM for message content
  2. Key Wrapping: Protocol-specific asymmetric encryption for symmetric keys
  3. Multi-Recipient: Each recipient gets their own wrapped key
  4. Cross-Protocol: Different protocols can be mixed in the same encryption
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Privacy Engine                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”‚
β”‚  β”‚   encrypt.rs    β”‚    β”‚   decrypt.rs    β”‚                β”‚
β”‚  β”‚                 β”‚    β”‚                 β”‚                β”‚
β”‚  β”‚ β€’ Message       β”‚    β”‚ β€’ Key unwrappingβ”‚                β”‚
β”‚  β”‚   encryption    β”‚    β”‚ β€’ Message       β”‚                β”‚
β”‚  β”‚ β€’ Key wrapping  β”‚    β”‚   decryption    β”‚                β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                    Protocol Layer                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                β”‚
β”‚  β”‚   Starknet      β”‚    β”‚     X25519      β”‚                β”‚
β”‚  β”‚   Protocol      β”‚    β”‚    Protocol     β”‚                β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ§ͺ Testing

Run Integration Tests

# Test multi-recipient encryption with pretty output
cargo test --test starknet_multi -- --nocapture

Environment Setup

Create a .env file for testing:

# Primary user (Starknet)
TEST_PRIVKEY=0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
TEST_PUBKEY=0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890
TEST_MSG_HASH=0xdeadbeef1234567890abcdef1234567890abcdef1234567890abcdef1234567890

# Secondary user (for multi-recipient tests)
USER2_PRIVATEKEY=0x9876543210fedcba9876543210fedcba9876543210fedcba9876543210fedcba
USER2_PUBLICKEY=0xfedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210

πŸ“š Documentation

πŸ”’ Security Features

  • AES-256-GCM: Authenticated encryption with 256-bit security
  • Random Nonces: Fresh random nonces for each encryption
  • Ephemeral Keys: Fresh ephemeral keys for each operation
  • Protocol Isolation: Each protocol maintains its security properties
  • Zero-Knowledge Compatible: Designed for ZK proof systems

πŸš€ Use Cases

  • Secure Messaging: Multi-recipient encrypted messaging
  • Blockchain Integration: Secure communication in blockchain applications
  • IoT Security: Device-to-device encrypted communication
  • Zero-Knowledge Systems: Privacy-preserving cryptographic applications
  • Cross-Platform: Interoperability between different cryptographic schemes

πŸ› οΈ Development

Project Structure

privacy-engine/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ encrypt.rs          # Main encryption functionality
β”‚   β”œβ”€β”€ decrypt.rs          # Decryption utilities
β”‚   β”œβ”€β”€ types.rs            # Core data structures
β”‚   β”œβ”€β”€ traits/
β”‚   β”‚   └── crypto.rs       # Cryptographic protocol trait
β”‚   └── chains/
β”‚       β”œβ”€β”€ starknet.rs     # Starknet protocol implementation
β”‚       └── x25519.rs       # X25519 protocol implementation
β”œβ”€β”€ tests/
β”‚   └── starknet_multi.rs   # Integration tests
└── docs/                   # Documentation

Building

cargo build

Running Tests

cargo test

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

  1. Clone the repository
  2. Install Rust 1.70+
  3. Run cargo build to build the project
  4. Run cargo test to run tests
  5. Create a .env file for integration tests

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ”— Links

⚑ Performance

Operation Starknet X25519
Key Generation ~2ms ~1ms
Key Agreement ~3ms ~2ms
Message Encryption ~1ms ~1ms
Memory Overhead Medium Low

🎯 Roadmap

  • Secp256k1 Protocol: Bitcoin/Ethereum compatibility
  • Ed25519 Protocol: High-performance signatures
  • P-256 Protocol: FIPS compliance
  • Custom Curves: Specialized use cases
  • WebAssembly Support: Browser compatibility
  • Python Bindings: Python integration
  • JavaScript Bindings: Node.js integration

Privacy Engine - Secure, multi-protocol cryptographic communication for the modern web. πŸ”βœ¨

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages