Skip to content

A mobile-optimized Rust implementation of the Noise Protocol Framework, designed for iOS and Android integration in P2P messaging applications.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

devdotbo/noise-mobile-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

24 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

noise-mobile-rust

A mobile-optimized Rust implementation of the Noise Protocol Framework, designed for iOS and Android integration in P2P messaging applications.

Overview

noise-mobile-rust provides FFI-safe bindings for the Noise Protocol, making it easy to integrate secure, end-to-end encrypted communication into mobile applications. Built on top of the excellent snow library, this crate adds mobile-specific optimizations and a clean FFI interface.

Features

  • πŸ” Noise Protocol XX - Mutual authentication pattern
  • πŸ“± Mobile Optimized - Battery-efficient, background-task aware
  • πŸ”„ Network Resilient - Handles connection interruptions gracefully
  • πŸš€ High Performance - < 10ms handshakes on mobile CPUs
  • πŸ›‘οΈ Memory Safe - Rust's guarantees extend across FFI boundary
  • πŸ§ͺ Extensively Tested - Unit, integration, and device tests

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   iOS Swift     β”‚     β”‚ Android Kotlin  β”‚
β”‚      App        β”‚     β”‚      App        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ FFI                   β”‚ JNI
         β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
                     β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚   noise-mobile-rust   β”‚
         β”‚  (This Library)       β”‚
         β”‚                       β”‚
         β”‚ β€’ C-compatible API    β”‚
         β”‚ β€’ Mobile optimizationsβ”‚
         β”‚ β€’ Network resilience  β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚     snow library      β”‚
         β”‚ (Noise Protocol impl) β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

Rust Integration

use noise_mobile::{NoiseSession, NoiseMode};

// Initialize a session
let session = NoiseSession::new(NoiseMode::Initiator)?;

// Perform handshake
let handshake_msg = session.write_message(&[])?;
// Send handshake_msg to peer...

// After handshake completion
let encrypted = session.encrypt(b"Hello, secure world!")?;

iOS Integration

import NoiseMobile

let session = NoiseSession(mode: .initiator)
let handshakeData = try session.writeMessage(Data())
// Send to peer...

Android Integration

import com.noise.mobile.NoiseSession

val session = NoiseSession(NoiseMode.INITIATOR)
val handshakeData = session.writeMessage(ByteArray(0))
// Send to peer...

Performance

Operation Target Actual
Handshake < 10ms TBD
Encrypt 1MB < 100ms TBD
Memory/Session < 1KB TBD

Building

Prerequisites

  • Rust 1.75+ (2021 edition)
  • For iOS: Xcode 14+
  • For Android: NDK r25+

Build Library

# Debug build
cargo build

# Release build with optimizations
cargo build --release

# Run tests
cargo test

# Run benchmarks
cargo bench

Generate Mobile Bindings

# iOS
cargo build --target aarch64-apple-ios --release

# Android
cargo build --target aarch64-linux-android --release

Testing

We prioritize testing on real devices:

# Unit tests
cargo test

# FFI boundary tests
cargo test --features ffi-tests

# Integration tests (requires device/simulator)
cargo test --features integration-tests

# Benchmarks
cargo bench

Project Structure

noise-mobile-rust/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ core/        # Pure Rust implementation
β”‚   β”œβ”€β”€ ffi/         # FFI bindings
β”‚   └── mobile/      # Mobile-specific features
β”œβ”€β”€ tests/           # Comprehensive test suite
β”œβ”€β”€ benches/         # Performance benchmarks
└── examples/        # Integration examples

Security

  • All cryptographic operations via audited snow library
  • Zeroization of sensitive data
  • Constant-time operations where required
  • No runtime panics in FFI layer

Contributing

Contributions are welcome! Please ensure:

  1. All tests pass
  2. No compiler warnings
  3. Code is formatted with rustfmt
  4. New features include tests
  5. FFI changes are documented

Use Cases

  • P2P messaging apps (like BitChat)
  • Secure file transfer
  • IoT device communication
  • Any app requiring end-to-end encryption

License

MIT OR Apache-2.0

Acknowledgments

Built on top of snow by @mcginty

About

A mobile-optimized Rust implementation of the Noise Protocol Framework, designed for iOS and Android integration in P2P messaging applications.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published